Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
fix: do-statementlist behavior #11724
fix: do-statementlist behavior #11724
Changes from 3 commits
ed2759d
3fea0ec
6812a42
42ea46e
78cdd64
87a9784
8001aef
f469bdf
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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 don't think we need to check specifically
nodes.length === 2
? i.e.do { ;;; }
should also returnundefined
.To mark non-leading EmptyStatement as no-op, we can reset
ensureLastUndefined = false
only ifnode
is not an EmptyStatement.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 added the
node.length
because()
always threw an error regardless of the amount of;
given.just to clarify what does no-op mean ?
and do we need to explicitly mark it
false
since we're in the condition that it istrue
?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 is syntax error if there is only empty statement in the
()
, i.e.()
,(;)
,(;;)
should throw.no-op means we do not change
ensureLastUndefined
, as you can see it is reset asfalse
in the beginning of loop. We can check empty statement before validating.Let
eLU
beensureLastUndefined
, we can illustrate howeLU
is changed between EmptyStatements ant other statements.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.
if
()
,(;)
,(;;)
should throw would it be a different issue because checking ifnode
is first fails the cases just mentioned?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.
Babel currently throws syntax error for
()
,(;)
, which is expected. Generally when you are working on AST, you may assume that it is always valid combinations of AST nodes, in this case, it isEmptyStatement
nested inBlockStatement
. The combinations of punctuators, i.e.(
,)
should be cared by the parser, and by the time when you have a valid AST, it can not be a representation of the source like()
.Generally parentheses do not affect the semantic meaning, it is a valid combination only if there is an expression wrapped inside parentheses: https://tc39.es/ecma262/#prod-ParenthesizedExpression
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.
right, ok the changes i just did keeps the checking if
node
is first and letting it throw if()
,(;)
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 think I understand what you mean by
()
and(;)
In the example
{ ;; }
, the parse AST isIn the first loop,
ensureLastUndefined
is set totrue
.In the second loop,
ensureLastUndefined
is set tofalse
in the beginning of the loop body:babel/packages/babel-types/src/converters/gatherSequenceExpressions.js
Line 28 in 6812a42
Since
exprs
is an empty array,ensureLastUndefined
isfalse
,sequenceExpression(exprs)
will be printed as()
, which will throw syntax error because sequence expression can not be empty.We can reset
ensureLastUndefined
only ifnode
is not anEmptyStatement
.So this ensures that when we are processing an EmptyStatement following any statements, it becomes an no-op, which does not change
ensureLastUndefined
.If we only check
node is first of nodes && nodes.length === 2
, it can not handledo { ;;; }
: When processing the third empty statement,ensureLastUndefined
will still be reset tofalse
andgatherSequenceExpressions
will still generate an empty sequence expression.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.
That makes so much sense, thank u!