refactor: simplify toAssignable routine#11032
Merged
nicolo-ribaudo merged 5 commits intobabel:masterfrom Jan 20, 2020
Merged
Conversation
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
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
toAssignableroutinebabel/packages/babel-parser/src/parser/lval.js
Line 53 in de75dbf
Remove
isBindingparameterThe first commit removes the
isBindingparameter. This parameter is used intoAssignableListintypescriptplugin and meant to check if theTSAsExpressionorTSTypeAssertionis 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.maybeInArrowParameterssincetoAssignableListis called withtrueonly inbabel/packages/babel-parser/src/parser/expression.js
Line 1879 in de75dbf
Other than that, this parameter is also used to skip
MemberExpressioncheck, 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
contextDescriptionparameterThe
contextDescriptionwas introduced in babel/babylon#123 in order to provide better error message for thedefaultcase oftoAssignablehttps://github.com/babel/babylon/pull/123/files#diff-3d279f04a39b1aaba84ac7b20b0f2625R62
However the error message was moved to
checkLVallater so the context description is now redundant. It prevails in the calls oftoAssignableso 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
toAssignablebabel/packages/babel-parser/src/parser/lval.js
Line 54 in 2b23c28
where
nodeis indeed aNode, but also can be proved unnecessary here. Among the possible syntax nodes wheretoAssignablewill 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
toAssignablewill unwrap parenthesized expression again after it is unwrapped in the dedicateParenthesizedExpressioncheck.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.