Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix parsing ts type casts and nested patterns in destructuring#14500

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

nicolo-ribaudo
Copy link
Member

@nicolo-ribaudonicolo-ribaudo commentedApr 27, 2022
edited
Loading

Q                      A
Fixed Issues?Fixes#14498,fixes#14504
Patch: Bug Fix?Yes
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass?Yes
Documentation PR Link
Any Dependency Changes?
LicenseMIT

@nicolo-ribaudonicolo-ribaudo added PR: Bug Fix 🐛A type of pull request used for our changelog categories pkg: parser area: typescript labelsApr 27, 2022
@@ -625,7 +631,8 @@ export default class LValParser extends NodeUtils {

const validity = this.isValidLVal(
expression.type,
hasParenthesizedAncestor || expression.extra?.parenthesized,
!(hasParenthesizedAncestor || expression.extra?.parenthesized) &&
ancestor.type === "AssignmentExpression",
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This code was needed to disallowa as b = c, however we must now make sure tonot disallow[a as b] = c.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Can you add a new test case?

for(aasbof[]);

It is disallowed in 7.16.2 but tsc allows it, and it seems this PR also fixes this one, too.

existentialism reacted with thumbs up emoji
@@ -3,8 +3,7 @@
"start":0,"end":46,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":29,"index":46}},
"errors": [
"SyntaxError: Invalid left-hand side in assignment expression. (1:0)",
"SyntaxError: Invalid left-hand side in assignment expression. (2:6)",
"SyntaxError: Invalid left-hand side in object destructuring pattern. (2:6)"
"SyntaxError: Invalid left-hand side in assignment expression. (2:6)"
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

These two errors were at the same location.

It would be better to only keep the "object destructuring pattern" rather than "assignment expression", but it's quite complex because it requires delaying errors until we know what the outer object is (destructuring or object). I might improve it in a follow-up PR.

JLHwung reacted with thumbs up emoji
@babel-bot
Copy link
Collaborator

babel-bot commentedApr 27, 2022
edited
Loading

Build successful! You can test your changes in the REPL here:https://babeljs.io/repl/build/51815/

JLHwung
JLHwung previously approved these changesApr 28, 2022
@@ -625,7 +631,8 @@ export default class LValParser extends NodeUtils {

const validity = this.isValidLVal(
expression.type,
hasParenthesizedAncestor || expression.extra?.parenthesized,
!(hasParenthesizedAncestor || expression.extra?.parenthesized) &&
ancestor.type === "AssignmentExpression",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Can you add a new test case?

for(aasbof[]);

It is disallowed in 7.16.2 but tsc allows it, and it seems this PR also fixes this one, too.

existentialism reacted with thumbs up emoji
existentialism
existentialism previously approved these changesApr 28, 2022
@nicolo-ribaudonicolo-ribaudo dismissed stale reviews fromexistentialism andJLHwungApril 28, 2022 14:12

I'm going to push a few more commits for the new comments in#14498

@nicolo-ribaudo
Copy link
MemberAuthor

nicolo-ribaudo commentedApr 28, 2022
edited
Loading

@thorn0 I would appreciate if you could check if there is any missing new test!

thorn0 reacted with eyes emoji

@nicolo-ribaudonicolo-ribaudo changed the title[ts] Fix AST for type assertions in destructuringFix parsing for type assertions and nested patterns in destructuringApr 28, 2022
@nicolo-ribaudonicolo-ribaudo changed the titleFix parsing for type assertions and nested patterns in destructuringFix parsing of ts type casts and nested patterns in destructApr 28, 2022
@thorn0
Copy link
Contributor

({ ...[] }=x); and({ ...{} }=x); should be errors, but they're parsed successfully if thetypescript plugin is enabled.REPL

@thorn0
Copy link
Contributor

thorn0 commentedApr 28, 2022
edited
Loading

(a as T)! = b:TS,Babel (this PR)
Same witha!! = b.

@nicolo-ribaudo
Copy link
MemberAuthor

Thanks, fixed!

@@ -162,11 +171,10 @@ export default class LValParser extends NodeUtils {
}

case "SpreadElement": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We can handleSpreadElement intoAssignableObjectExpressionProp andtoAssignableList, so we don't need to trackisInObjectPattern anymore.

nicolo-ribaudo reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Done!69719e4

@@ -23,7 +22,7 @@
"start":1,"end":13,"loc":{"start":{"line":1,"column":1,"index":1},"end":{"line":1,"column":13,"index":13}},
"properties": [
{
"type": "SpreadElement",
"type": "RestElement",
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This is a slight improvement, since it gives a better shape to the recovered AST (the input code is({ ...rest, x } = {}).

JLHwung reacted with thumbs up emoji
@nicolo-ribaudonicolo-ribaudoforce-pushed thets-ast-as-in-destructuring branch from4cbc10d to69719e4CompareApril 29, 2022 23:17
The function sometimes mutated its argument, sometimes it returned a new node. However,almost all usages didn't handle the "new node"case: this commit removes it, and the functionalways mutates its argument.
@nicolo-ribaudonicolo-ribaudoforce-pushed thets-ast-as-in-destructuring branch from72cc585 to8be7c27CompareMay 1, 2022 11:02
@nicolo-ribaudonicolo-ribaudo changed the titleFix parsing of ts type casts and nested patterns in destructFix parsing ts type casts and nested patterns in destructuringMay 1, 2022
@nicolo-ribaudonicolo-ribaudo merged commit0e6900d intobabel:mainMay 1, 2022
@nicolo-ribaudonicolo-ribaudo deleted the ts-ast-as-in-destructuring branchMay 1, 2022 12:39
@github-actionsgithub-actionsbot added the outdatedA closed issue/PR that is archived due to age. Recommended to make a new issue labelAug 2, 2022
@github-actionsgithub-actionsbot locked asresolvedand limited conversation to collaboratorsAug 2, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@JLHwungJLHwungJLHwung approved these changes

@existentialismexistentialismexistentialism approved these changes

Assignees
No one assigned
Labels
area: typescriptoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issuepkg: parserPR: Bug Fix 🐛A type of pull request used for our changelog categories
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

[Bug]:createParenthesizedExpressions and parens around object rest [Bug]: Weird AST foras inArrayPattern
5 participants
@nicolo-ribaudo@babel-bot@thorn0@existentialism@JLHwung

[8]ページ先頭

©2009-2025 Movatter.jp