-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disallow await before exponential (#12441)
* refactor: move unary exponential check to parseMaybeUnary * fix: disallow await before exponential * add test cases
- Loading branch information
Showing
18 changed files
with
501 additions
and
16 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
1 change: 1 addition & 0 deletions
1
...re/create-parenthesized-expressions/valid-parenthesized-await-before-exponential/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 @@ | ||
async () => (await 5) ** 6; |
56 changes: 56 additions & 0 deletions
56
...create-parenthesized-expressions/valid-parenthesized-await-before-exponential/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,56 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":27,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":27}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":27,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":27}}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":0,"end":27,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":27}}, | ||
"expression": { | ||
"type": "ArrowFunctionExpression", | ||
"start":0,"end":26,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":26}}, | ||
"id": null, | ||
"generator": false, | ||
"async": true, | ||
"params": [], | ||
"body": { | ||
"type": "BinaryExpression", | ||
"start":12,"end":26,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":26}}, | ||
"left": { | ||
"type": "ParenthesizedExpression", | ||
"start":12,"end":21,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":21}}, | ||
"expression": { | ||
"type": "AwaitExpression", | ||
"start":13,"end":20,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":20}}, | ||
"argument": { | ||
"type": "NumericLiteral", | ||
"start":19,"end":20,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":20}}, | ||
"extra": { | ||
"rawValue": 5, | ||
"raw": "5" | ||
}, | ||
"value": 5 | ||
} | ||
} | ||
}, | ||
"operator": "**", | ||
"right": { | ||
"type": "NumericLiteral", | ||
"start":25,"end":26,"loc":{"start":{"line":1,"column":25},"end":{"line":1,"column":26}}, | ||
"extra": { | ||
"rawValue": 6, | ||
"raw": "6" | ||
}, | ||
"value": 6 | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...bel-parser/test/fixtures/es2016/exponentiation-operator/await-before-exponential/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 @@ | ||
async () => await 5 ** 6; |
55 changes: 55 additions & 0 deletions
55
...-parser/test/fixtures/es2016/exponentiation-operator/await-before-exponential/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,55 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":25,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":25}}, | ||
"errors": [ | ||
"SyntaxError: Illegal expression. Wrap left hand side or entire exponentiation in parentheses. (1:18)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":25,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":25}}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":0,"end":25,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":25}}, | ||
"expression": { | ||
"type": "ArrowFunctionExpression", | ||
"start":0,"end":24,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":24}}, | ||
"id": null, | ||
"generator": false, | ||
"async": true, | ||
"params": [], | ||
"body": { | ||
"type": "BinaryExpression", | ||
"start":12,"end":24,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":24}}, | ||
"left": { | ||
"type": "AwaitExpression", | ||
"start":12,"end":19,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":19}}, | ||
"argument": { | ||
"type": "NumericLiteral", | ||
"start":18,"end":19,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":19}}, | ||
"extra": { | ||
"rawValue": 5, | ||
"raw": "5" | ||
}, | ||
"value": 5 | ||
} | ||
}, | ||
"operator": "**", | ||
"right": { | ||
"type": "NumericLiteral", | ||
"start":23,"end":24,"loc":{"start":{"line":1,"column":23},"end":{"line":1,"column":24}}, | ||
"extra": { | ||
"rawValue": 6, | ||
"raw": "6" | ||
}, | ||
"value": 6 | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...rser/test/fixtures/es2016/exponentiation-operator/await-unary-before-exponential/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 @@ | ||
async () => await -5 ** 6; |
61 changes: 61 additions & 0 deletions
61
...r/test/fixtures/es2016/exponentiation-operator/await-unary-before-exponential/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,61 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":26,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":26}}, | ||
"errors": [ | ||
"SyntaxError: Illegal expression. Wrap left hand side or entire exponentiation in parentheses. (1:18)" | ||
], | ||
"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": "ArrowFunctionExpression", | ||
"start":0,"end":25,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":25}}, | ||
"id": null, | ||
"generator": false, | ||
"async": true, | ||
"params": [], | ||
"body": { | ||
"type": "BinaryExpression", | ||
"start":12,"end":25,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":25}}, | ||
"left": { | ||
"type": "AwaitExpression", | ||
"start":12,"end":20,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":20}}, | ||
"argument": { | ||
"type": "UnaryExpression", | ||
"start":18,"end":20,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":20}}, | ||
"operator": "-", | ||
"prefix": true, | ||
"argument": { | ||
"type": "NumericLiteral", | ||
"start":19,"end":20,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":20}}, | ||
"extra": { | ||
"rawValue": 5, | ||
"raw": "5" | ||
}, | ||
"value": 5 | ||
} | ||
} | ||
}, | ||
"operator": "**", | ||
"right": { | ||
"type": "NumericLiteral", | ||
"start":24,"end":25,"loc":{"start":{"line":1,"column":24},"end":{"line":1,"column":25}}, | ||
"extra": { | ||
"rawValue": 6, | ||
"raw": "6" | ||
}, | ||
"value": 6 | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...ser/test/fixtures/es2016/exponentiation-operator/nested-unary-before-exponential/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 @@ | ||
(-+5 ** 6); |
59 changes: 59 additions & 0 deletions
59
.../test/fixtures/es2016/exponentiation-operator/nested-unary-before-exponential/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,59 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":11,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":11}}, | ||
"errors": [ | ||
"SyntaxError: Illegal expression. Wrap left hand side or entire exponentiation in parentheses. (1:2)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":11,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":11}}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":0,"end":11,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":11}}, | ||
"expression": { | ||
"type": "BinaryExpression", | ||
"start":1,"end":9,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":9}}, | ||
"extra": { | ||
"parenthesized": true, | ||
"parenStart": 0 | ||
}, | ||
"left": { | ||
"type": "UnaryExpression", | ||
"start":1,"end":4,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":4}}, | ||
"operator": "-", | ||
"prefix": true, | ||
"argument": { | ||
"type": "UnaryExpression", | ||
"start":2,"end":4,"loc":{"start":{"line":1,"column":2},"end":{"line":1,"column":4}}, | ||
"operator": "+", | ||
"prefix": true, | ||
"argument": { | ||
"type": "NumericLiteral", | ||
"start":3,"end":4,"loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":4}}, | ||
"extra": { | ||
"rawValue": 5, | ||
"raw": "5" | ||
}, | ||
"value": 5 | ||
} | ||
} | ||
}, | ||
"operator": "**", | ||
"right": { | ||
"type": "NumericLiteral", | ||
"start":8,"end":9,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":9}}, | ||
"extra": { | ||
"rawValue": 6, | ||
"raw": "6" | ||
}, | ||
"value": 6 | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...ures/es2016/exponentiation-operator/valid-parenthesized-await-before-exponential/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 @@ | ||
async () => (await 5) ** 6; |
56 changes: 56 additions & 0 deletions
56
...s/es2016/exponentiation-operator/valid-parenthesized-await-before-exponential/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,56 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":27,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":27}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":27,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":27}}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":0,"end":27,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":27}}, | ||
"expression": { | ||
"type": "ArrowFunctionExpression", | ||
"start":0,"end":26,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":26}}, | ||
"id": null, | ||
"generator": false, | ||
"async": true, | ||
"params": [], | ||
"body": { | ||
"type": "BinaryExpression", | ||
"start":12,"end":26,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":26}}, | ||
"left": { | ||
"type": "AwaitExpression", | ||
"start":13,"end":20,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":20}}, | ||
"extra": { | ||
"parenthesized": true, | ||
"parenStart": 12 | ||
}, | ||
"argument": { | ||
"type": "NumericLiteral", | ||
"start":19,"end":20,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":20}}, | ||
"extra": { | ||
"rawValue": 5, | ||
"raw": "5" | ||
}, | ||
"value": 5 | ||
} | ||
}, | ||
"operator": "**", | ||
"right": { | ||
"type": "NumericLiteral", | ||
"start":25,"end":26,"loc":{"start":{"line":1,"column":25},"end":{"line":1,"column":26}}, | ||
"extra": { | ||
"rawValue": 6, | ||
"raw": "6" | ||
}, | ||
"value": 6 | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...parser/test/fixtures/typescript/exponentiation/await-non-null-before-exponential/input.ts
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 @@ | ||
async (a) => await a! ** 6; |
Oops, something went wrong.