-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
track returned state in function body #14357
base: main
Are you sure you want to change the base?
Conversation
For maintainers only:
|
Thank you for your pull request! The most important CI builds succeeded, we鈥檒l review the pull request soon. |
fix case when in try we throw and terminated=undefined for current scope
@vankop Can you rebase? Thank you |
# Conflicts: # lib/ConstPlugin.js
|
@@ -1799,6 +1805,7 @@ class JavascriptParser extends Parser { | |||
for (let index = 0, len = statements.length; index < len; index++) { | |||
const statement = statements[index]; | |||
this.walkStatement(statement); | |||
if (this.scope.terminated) break; |
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.
I like this solution, I'm only afraid of one thing, that some plugins could rely on it and rewrite something, and now we just will not handle them at all
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.
but this code is unreachable.. so I dont see a reason to waste cpu =)
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.
Yeah, I agree with you, I'm just worried that someone could use similar logic, but we can merge and look at feedback, It's not difficult to do a revert
What kind of change does this PR introduce?
feature
closes #14347
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?
nothing
Notes regarding feature design
Added 2 properties to parser current scope (
parser.scope
)terminated
marks that further parsing of nearestBlockStatement
should be terminated. Has 3 states'return'|'throw'|undefined
, whereundefined
= false,'return'|'throw'
types of terminationreturned
is inherited from childBlockStatement
(or terminate node in case ofif (true) return;
) to nearest parentBlockStatement
ifexecutedPath=true
executedPath
marks that current statement will be executed if nearestBlockStatement
will be reached, e.g.complex example
and one more 馃敒
Notes regarding feature implementation
parser.hooks.terminate
looks kind of useless, not sure about it..TODO
drop skipped code. Any ideas how to do it better? we should do this from
terminated!=undefined
blocks tillterminated=undefined
blocks