forked from babel/babel
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add parser support for optional chain in assignments
- Loading branch information
1 parent
cc110c6
commit ebf84be
Showing
43 changed files
with
779 additions
and
6 deletions.
There are no files selected for viewing
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
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
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
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
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
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
1 change: 1 addition & 0 deletions
1
...ages/babel-parser/test/fixtures/experimental/_no-plugin/optional-chaining-assign/input.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
a?.b = c; |
3 changes: 3 additions & 0 deletions
3
.../babel-parser/test/fixtures/experimental/_no-plugin/optional-chaining-assign/options.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"throws": "This experimental syntax requires enabling the parser plugin: \"optionalChainingAssign\". (1:0)" | ||
} |
1 change: 1 addition & 0 deletions
1
...ser/test/fixtures/experimental/optional-chaining-assign/invalid-destruturing-arr/input.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[a?.b] = []; |
52 changes: 52 additions & 0 deletions
52
.../test/fixtures/experimental/optional-chaining-assign/invalid-destruturing-arr/output.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":12,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":12,"index":12}}, | ||
"errors": [ | ||
"SyntaxError: Invalid optional chaining in the left-hand side of array destructuring pattern. (1:1)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":12,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":12,"index":12}}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":0,"end":12,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":12,"index":12}}, | ||
"expression": { | ||
"type": "AssignmentExpression", | ||
"start":0,"end":11,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":11,"index":11}}, | ||
"operator": "=", | ||
"left": { | ||
"type": "ArrayPattern", | ||
"start":0,"end":6,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":6,"index":6}}, | ||
"elements": [ | ||
{ | ||
"type": "OptionalMemberExpression", | ||
"start":1,"end":5,"loc":{"start":{"line":1,"column":1,"index":1},"end":{"line":1,"column":5,"index":5}}, | ||
"object": { | ||
"type": "Identifier", | ||
"start":1,"end":2,"loc":{"start":{"line":1,"column":1,"index":1},"end":{"line":1,"column":2,"index":2},"identifierName":"a"}, | ||
"name": "a" | ||
}, | ||
"computed": false, | ||
"property": { | ||
"type": "Identifier", | ||
"start":4,"end":5,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":5,"index":5},"identifierName":"b"}, | ||
"name": "b" | ||
}, | ||
"optional": true | ||
} | ||
] | ||
}, | ||
"right": { | ||
"type": "ArrayExpression", | ||
"start":9,"end":11,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":11,"index":11}}, | ||
"elements": [] | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...ser/test/fixtures/experimental/optional-chaining-assign/invalid-destruturing-obj/input.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
({ prop: a?.b } = {}); |
68 changes: 68 additions & 0 deletions
68
.../test/fixtures/experimental/optional-chaining-assign/invalid-destruturing-obj/output.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":22,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":22,"index":22}}, | ||
"errors": [ | ||
"SyntaxError: Invalid optional chaining in the left-hand side of object destructuring pattern. (1:9)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":22,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":22,"index":22}}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":0,"end":22,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":22,"index":22}}, | ||
"expression": { | ||
"type": "AssignmentExpression", | ||
"start":1,"end":20,"loc":{"start":{"line":1,"column":1,"index":1},"end":{"line":1,"column":20,"index":20}}, | ||
"operator": "=", | ||
"left": { | ||
"type": "ObjectPattern", | ||
"start":1,"end":15,"loc":{"start":{"line":1,"column":1,"index":1},"end":{"line":1,"column":15,"index":15}}, | ||
"properties": [ | ||
{ | ||
"type": "ObjectProperty", | ||
"start":3,"end":13,"loc":{"start":{"line":1,"column":3,"index":3},"end":{"line":1,"column":13,"index":13}}, | ||
"method": false, | ||
"key": { | ||
"type": "Identifier", | ||
"start":3,"end":7,"loc":{"start":{"line":1,"column":3,"index":3},"end":{"line":1,"column":7,"index":7},"identifierName":"prop"}, | ||
"name": "prop" | ||
}, | ||
"computed": false, | ||
"shorthand": false, | ||
"value": { | ||
"type": "OptionalMemberExpression", | ||
"start":9,"end":13,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":13,"index":13}}, | ||
"object": { | ||
"type": "Identifier", | ||
"start":9,"end":10,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":10,"index":10},"identifierName":"a"}, | ||
"name": "a" | ||
}, | ||
"computed": false, | ||
"property": { | ||
"type": "Identifier", | ||
"start":12,"end":13,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":1,"column":13,"index":13},"identifierName":"b"}, | ||
"name": "b" | ||
}, | ||
"optional": true | ||
} | ||
} | ||
] | ||
}, | ||
"right": { | ||
"type": "ObjectExpression", | ||
"start":18,"end":20,"loc":{"start":{"line":1,"column":18,"index":18},"end":{"line":1,"column":20,"index":20}}, | ||
"properties": [] | ||
}, | ||
"extra": { | ||
"parenthesized": true, | ||
"parenStart": 0 | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...arser/test/fixtures/experimental/optional-chaining-assign/invalid-fn-param-arrow/input.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(a?.b) => {} |
52 changes: 52 additions & 0 deletions
52
...er/test/fixtures/experimental/optional-chaining-assign/invalid-fn-param-arrow/output.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":12,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":12,"index":12}}, | ||
"errors": [ | ||
"SyntaxError: Invalid optional chaining in the left-hand side of function parameter list. (1:1)", | ||
"SyntaxError: Binding member expression. (1:1)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":12,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":12,"index":12}}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":0,"end":12,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":12,"index":12}}, | ||
"expression": { | ||
"type": "ArrowFunctionExpression", | ||
"start":0,"end":12,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":12,"index":12}}, | ||
"id": null, | ||
"generator": false, | ||
"async": false, | ||
"params": [ | ||
{ | ||
"type": "OptionalMemberExpression", | ||
"start":1,"end":5,"loc":{"start":{"line":1,"column":1,"index":1},"end":{"line":1,"column":5,"index":5}}, | ||
"object": { | ||
"type": "Identifier", | ||
"start":1,"end":2,"loc":{"start":{"line":1,"column":1,"index":1},"end":{"line":1,"column":2,"index":2},"identifierName":"a"}, | ||
"name": "a" | ||
}, | ||
"computed": false, | ||
"property": { | ||
"type": "Identifier", | ||
"start":4,"end":5,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":5,"index":5},"identifierName":"b"}, | ||
"name": "b" | ||
}, | ||
"optional": true | ||
} | ||
], | ||
"body": { | ||
"type": "BlockStatement", | ||
"start":10,"end":12,"loc":{"start":{"line":1,"column":10,"index":10},"end":{"line":1,"column":12,"index":12}}, | ||
"body": [], | ||
"directives": [] | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...rser/test/fixtures/experimental/optional-chaining-assign/invalid-fn-param-assign/input.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
function f(a?.b = c) {} |
3 changes: 3 additions & 0 deletions
3
.../test/fixtures/experimental/optional-chaining-assign/invalid-fn-param-assign/options.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"throws": "Unexpected token, expected \",\" (1:12)" | ||
} |
1 change: 1 addition & 0 deletions
1
...abel-parser/test/fixtures/experimental/optional-chaining-assign/invalid-fn-param/input.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
function f(a?.b) {} |
3 changes: 3 additions & 0 deletions
3
...-parser/test/fixtures/experimental/optional-chaining-assign/invalid-fn-param/options.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"throws": "Unexpected token, expected \",\" (1:12)" | ||
} |
1 change: 1 addition & 0 deletions
1
...-parser/test/fixtures/experimental/optional-chaining-assign/invalid-for-await-of/input.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
for (a?.b of x); |
46 changes: 46 additions & 0 deletions
46
...rser/test/fixtures/experimental/optional-chaining-assign/invalid-for-await-of/output.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":16,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":16,"index":16}}, | ||
"errors": [ | ||
"SyntaxError: Invalid optional chaining in the left-hand side of for-of statement. (1:5)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":16,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":16,"index":16}}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ForOfStatement", | ||
"start":0,"end":16,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":16,"index":16}}, | ||
"await": false, | ||
"left": { | ||
"type": "OptionalMemberExpression", | ||
"start":5,"end":9,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":9,"index":9}}, | ||
"object": { | ||
"type": "Identifier", | ||
"start":5,"end":6,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":6,"index":6},"identifierName":"a"}, | ||
"name": "a" | ||
}, | ||
"computed": false, | ||
"property": { | ||
"type": "Identifier", | ||
"start":8,"end":9,"loc":{"start":{"line":1,"column":8,"index":8},"end":{"line":1,"column":9,"index":9},"identifierName":"b"}, | ||
"name": "b" | ||
}, | ||
"optional": true | ||
}, | ||
"right": { | ||
"type": "Identifier", | ||
"start":13,"end":14,"loc":{"start":{"line":1,"column":13,"index":13},"end":{"line":1,"column":14,"index":14},"identifierName":"x"}, | ||
"name": "x" | ||
}, | ||
"body": { | ||
"type": "EmptyStatement", | ||
"start":15,"end":16,"loc":{"start":{"line":1,"column":15,"index":15},"end":{"line":1,"column":16,"index":16}} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
.../babel-parser/test/fixtures/experimental/optional-chaining-assign/invalid-for-in/input.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
for (a?.b in x); |
Oops, something went wrong.