Skip to content
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: properly parse member expression after property initializer #11031

Merged
merged 1 commit into from Jan 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions packages/babel-parser/src/parser/expression.js
Expand Up @@ -532,10 +532,6 @@ export default class ExpressionParser extends LValParser {
return expr;
}

if (this.checkExpressionErrors(refExpressionErrors, false)) {
Copy link
Contributor

@JLHwung JLHwung Jan 19, 2020

Choose a reason for hiding this comment

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

We should investigate if the other this.checkExpressionErrors(refExpressionErrors, false) checks are necessary. They are not caught by any test cases in babel-parser now.

(They are not even caught by acorn testcases)

Copy link
Contributor Author

@vedantroy vedantroy Jan 19, 2020

Choose a reason for hiding this comment

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

I will look into removing the other instances of this.checkExpressionErrors(refExpressionErrors, false). I didn't remove them in this PR because it wasn't necessary to fix the bug, but I can always add some more changes to this PR/open a new one.

return expr;
}

return this.parseSubscripts(expr, startPos, startLoc);
}

Expand Down
@@ -0,0 +1 @@
({a = 42, b: test.d} = {})
@@ -0,0 +1,278 @@
{
"type": "File",
"start": 0,
"end": 26,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 26
}
},
"program": {
"type": "Program",
"start": 0,
"end": 26,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 26
}
},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 26,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 26
}
},
"expression": {
"type": "AssignmentExpression",
"start": 1,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 25
}
},
"operator": "=",
"left": {
"type": "ObjectPattern",
"start": 1,
"end": 20,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 20
}
},
"properties": [
{
"type": "ObjectProperty",
"start": 2,
"end": 8,
"loc": {
"start": {
"line": 1,
"column": 2
},
"end": {
"line": 1,
"column": 8
}
},
"method": false,
"key": {
"type": "Identifier",
"start": 2,
"end": 3,
"loc": {
"start": {
"line": 1,
"column": 2
},
"end": {
"line": 1,
"column": 3
},
"identifierName": "a"
},
"name": "a"
},
"computed": false,
"shorthand": true,
"value": {
"type": "AssignmentPattern",
"start": 2,
"end": 8,
"loc": {
"start": {
"line": 1,
"column": 2
},
"end": {
"line": 1,
"column": 8
}
},
"left": {
"type": "Identifier",
"start": 2,
"end": 3,
"loc": {
"start": {
"line": 1,
"column": 2
},
"end": {
"line": 1,
"column": 3
},
"identifierName": "a"
},
"name": "a"
},
"right": {
"type": "NumericLiteral",
"start": 6,
"end": 8,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 8
}
},
"extra": {
"rawValue": 42,
"raw": "42"
},
"value": 42
}
},
"extra": {
"shorthand": true
}
},
{
"type": "ObjectProperty",
"start": 10,
"end": 19,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 19
}
},
"method": false,
"key": {
"type": "Identifier",
"start": 10,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 11
},
"identifierName": "b"
},
"name": "b"
},
"computed": false,
"shorthand": false,
"value": {
"type": "MemberExpression",
"start": 13,
"end": 19,
"loc": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 1,
"column": 19
}
},
"object": {
"type": "Identifier",
"start": 13,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 1,
"column": 17
},
"identifierName": "test"
},
"name": "test"
},
"property": {
"type": "Identifier",
"start": 18,
"end": 19,
"loc": {
"start": {
"line": 1,
"column": 18
},
"end": {
"line": 1,
"column": 19
},
"identifierName": "d"
},
"name": "d"
},
"computed": false
}
}
]
},
"right": {
"type": "ObjectExpression",
"start": 23,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 23
},
"end": {
"line": 1,
"column": 25
}
},
"properties": []
},
"extra": {
"parenthesized": true,
"parenStart": 0
}
}
}
],
"directives": []
}
}
@@ -0,0 +1 @@
({a = 42, b: {}.d} = {})