Skip to content

Extract to parser helpers extended#3846

Merged
sokra merged 17 commits intowebpack:masterfrom
timse:extract-to-parser-helpers-extended
Jan 27, 2017
Merged

Extract to parser helpers extended#3846
sokra merged 17 commits intowebpack:masterfrom
timse:extract-to-parser-helpers-extended

Conversation

@timse
Copy link
Copy Markdown
Contributor

@timse timse commented Jan 8, 2017

What kind of change does this PR introduce?

refactoring

Did you add tests for your changes?

Is covered by existing tests

If relevant, link to documentation update:

N/A

Summary

See #3843

Does this PR introduce a breaking change?

No

Other information

extends/continues #3843

@TheLarkInn
Copy link
Copy Markdown
Member

Need to sync up branch again after merging #3843

@timse timse force-pushed the extract-to-parser-helpers-extended branch from f423f8d to dbf54e7 Compare January 9, 2017 10:04
Comment thread lib/APIPlugin.js Outdated
});
IGNORES.forEach(key => {
parser.plugin(key, () => true);
parser.plugin(key, ParserHelpers.returnTrue);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really? This is not an optimization?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I probably went a bit too far here 😨
All those lonely () => true, i thought i give them a new home.
(at least it only creates one function instead of many. but thats the best excuse I can come up with.)
that being said, happy to revert :)

Copy link
Copy Markdown
Member

@TheLarkInn TheLarkInn Jan 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually doesn't this yield better performance simply for the case of the same hidden class being reused by the JIT Optimizer? Maybe that is just for the case of property access. I'm on the fence really. Either work. Less dedupe but also less flexible.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should, but probably so small if even measurable, that it is kind of premature if it doesnt have any other advantages.
except those functions get called a lot, because they would need to be created on each call, not sure if that counts for this code?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are extracting this into a helper, it's probably better to describe what it actually does in the context of the parser instead of just "returns true". ParserHelpers.skipTraversal?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would ParserHelpers.skipTraversal be acceptable @sokra ?
would describe a lot better what it would do in this context than a simple "return true", no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well I guess the only problem with skipTraversal is that it is only true in 3 cases, and in the other cases it just "confirmes" can-rename.
Would it be ok for me to add two helper functions, one approve and one skip so they semantically work? given that a simple () => true can have these meanings make the code hard to read imho

Comment thread lib/APIPlugin.js Outdated
});
IGNORES.forEach(key => {
parser.plugin(key, () => true);
parser.plugin(key, ParserHelpers.returnTrue);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are extracting this into a helper, it's probably better to describe what it actually does in the context of the parser instead of just "returns true". ParserHelpers.skipTraversal?

Comment thread lib/RequireJsStuffPlugin.js Outdated
parser.plugin("call require.config", remove);
parser.plugin("call requirejs.config", remove);
parser.plugin("call require.config", ParserHelpers.toConstantDependency(";"));
parser.plugin("call requirejs.config", ParserHelpers.toConstantDependency(";"));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(unrelated) this probably should resolve to undefined instead of ;; CallExpression is an expression after all.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. But we could do this in a seprate PR, as this also require tests...

Do you want to open one?

@sokra
Copy link
Copy Markdown
Member

sokra commented Jan 11, 2017

/home/travis/build/webpack/webpack/lib/ParserHelpers.js
  62:2  error  Missing semicolon  semi
  66:2  error  Missing semicolon  semi

@timse
Copy link
Copy Markdown
Contributor Author

timse commented Jan 11, 2017

Urgs will fix!

@sokra sokra modified the milestone: webpack 2.3 Bugfix release Jan 12, 2017
@timse timse force-pushed the extract-to-parser-helpers-extended branch from 9891c24 to cf7bb83 Compare January 12, 2017 08:39
@timse timse mentioned this pull request Jan 12, 2017
1 task
@TheLarkInn
Copy link
Copy Markdown
Member

Let's sync master and see how this guess against new benchmarks for perf against master.

timse added 14 commits January 21, 2017 13:38
- rename module and file from ModuleParserHelpers to ParserHelpers
- change imports and usages
- rename addParsedVariable to addParsedVariableToModule to add module context again
- reduces sideeffects as parser is called outside of helper
- allows better reuse
convert all usages of new BasicEvaluatedExpression().setBoolean to ParserHelper.evaluateToBoolean
changes usages of toConstantDependency so far
the initial method does not need really another name
…ate methods

- skipTraversal if a "return true" indicates to break walking
- approve if "return true" means to approve a "parse request" such as "can-rename"
…d of `undefined`

this may lead to potential Syntaxerrors as `const x = requirejs.config();` would be transformed to `const x = ;;`
@timse timse force-pushed the extract-to-parser-helpers-extended branch from cf7bb83 to f46dac8 Compare January 21, 2017 03:00
@timse
Copy link
Copy Markdown
Contributor Author

timse commented Jan 26, 2017

ill resolve the conflicts

Conflicts:
	lib/dependencies/AMDPlugin.js
@sokra sokra closed this Jan 26, 2017
@sokra sokra reopened this Jan 26, 2017
@sokra
Copy link
Copy Markdown
Member

sokra commented Jan 26, 2017

/home/travis/build/webpack/webpack/lib/dependencies/CommonJsRequireDependencyParserPlugin.js
  7:7  error  'ConstDependency' is assigned a value but never used  no-unused-vars

@timse
Copy link
Copy Markdown
Contributor Author

timse commented Jan 26, 2017

done

@sokra sokra merged commit 1ff8d69 into webpack:master Jan 27, 2017
@sokra
Copy link
Copy Markdown
Member

sokra commented Jan 27, 2017

Thanks

@timse timse deleted the extract-to-parser-helpers-extended branch January 27, 2017 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants