-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
fix: eliminate unused statements in certain scenarios #19536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
fdf2360
to
2280284
Compare
lib/ConstPlugin.js
Outdated
} | ||
return bool; | ||
} | ||
}); | ||
parser.hooks.deadStatement.tap(PLUGIN_NAME, statement => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about unusedStatement
? dead
is more a harsher word 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine for me. :)
parser.walkStatement(successExpression.fn.body); | ||
parser.scope.terminated = oldTerminated; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we need here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We walk successExpressionArg
and then walk errorExpressionArg
in
if (successExpression) { |
In this test case
it("should not call error callback on exception thrown in require callback", function(done) { |
successExpressionArg
and parsing scope will be terminated which leads to failed.
To keep it short and to the point, show the input and output.
input:
it("should call error callback on exception thrown in loading module", function(done) {
require.ensure(['./throwing'], function(){
require('./throwing');
}, function(error) {
expect(error).toBeInstanceOf(Error);
expect(error.message).toBe('message');
done();
});
});
eliminated output
it("should call error callback on exception thrown in loading module", function(done) {
require.ensure(['./throwing'], function(){
require('./throwing');
}, function(error) {
expect(error).toBeInstanceOf(Error);
{}
{}
});
});
I think it's very very rare user case and i also add some test for it.
lib/ConstPlugin.js
Outdated
const replacement = | ||
declarations.length > 0 ? `{ var ${declarations.join(", ")}; }` : "{}"; | ||
const dep = new ConstDependency( | ||
replacement, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a comment // removed by dead control flow\n${replacement}
(maybe better) for debug reasons
CodSpeed Performance ReportMerging #19536 will degrade performances by 81.71%Comparing Summary
Benchmarks breakdown
|
/lgtm |
What kind of change does this PR introduce?
We have previously supported the elimination of unreachable (dead) branches in if statements in #6273.
In this PR, we adopt the same approach to remove some dead statements when tracked completely return/throw statement, as implemented in #14357.
And it also fixes #19514.
Did you add tests for your changes?
Yes
Does this PR introduce a breaking change?
No
What needs to be documented once your changes are merged?
No