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
refactor: simplify toAssignable routine #11032
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JLHwung
added
PR: Internal 🏠
A type of pull request used for our changelog categories
pkg: parser
labels
Jan 20, 2020
nicolo-ribaudo
approved these changes
Jan 20, 2020
existentialism
approved these changes
Jan 20, 2020
This was referenced Feb 24, 2020
This was referenced Mar 7, 2020
This was referenced Mar 14, 2020
This was referenced Mar 25, 2020
This was referenced Apr 2, 2020
This was referenced Apr 9, 2020
github-actions
bot
added
the
outdated
A closed issue/PR that is archived due to age. Recommended to make a new issue
label
Apr 21, 2020
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
outdated
A closed issue/PR that is archived due to age. Recommended to make a new issue
pkg: parser
PR: Internal 🏠
A type of pull request used for our changelog categories
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.
This PR is a series of parser refactoring and is supposed to review commit-by-commit. It focuses on simplifying the
toAssignable
routinebabel/packages/babel-parser/src/parser/lval.js
Line 53 in de75dbf
Remove
isBinding
parameterThe first commit removes the
isBinding
parameter. This parameter is used intoAssignableList
intypescript
plugin and meant to check if theTSAsExpression
orTSTypeAssertion
is allowed to casted as type parameters.babel/packages/babel-parser/src/plugins/typescript/index.js
Line 2540 in de75dbf
However it suffices to check
state.maybeInArrowParameters
sincetoAssignableList
is called withtrue
only inbabel/packages/babel-parser/src/parser/expression.js
Line 1879 in de75dbf
Other than that, this parameter is also used to skip
MemberExpression
check, which was copied from acorn.babel/packages/babel-parser/src/parser/lval.js
Line 145 in 2b23c28
Apparently the check here is now redundant because the default branch is noop.
Remove
contextDescription
parameterThe
contextDescription
was introduced in babel/babylon#123 in order to provide better error message for thedefault
case oftoAssignable
https://github.com/babel/babylon/pull/123/files#diff-3d279f04a39b1aaba84ac7b20b0f2625R62
However the error message was moved to
checkLVal
later so the context description is now redundant. It prevails in the calls oftoAssignable
so it is difficult for linters to detect this variable is unused.Remove unnecessary nullish check
The nullish check not only contradict with the type annotation of
toAssignable
babel/packages/babel-parser/src/parser/lval.js
Line 54 in 2b23c28
where
node
is indeed aNode
, but also can be proved unnecessary here. Among the possible syntax nodes wheretoAssignable
will be called, only array elements can be nullish. However the nullish check of array elements has been implemented inbabel/packages/babel-parser/src/parser/lval.js
Line 210 in 2b23c28
therefore the nullish check is unecessary.
Simplify on the ParenthesizedExpression
toAssignable
will unwrap parenthesized expression again after it is unwrapped in the dedicateParenthesizedExpression
check.babel/packages/babel-parser/src/parser/lval.js
Line 64 in 2b23c28
The second unwrap is unnecessary. Also added a test case for the
SyntaxError: Invalid left-hand side in parenthesized expression (1:1)
error.