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
Add more parser test cases #11923
Merged
Merged
Add more parser test cases #11923
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
54ad4ab
remove unused codes
JLHwung 0911a64
refactor: remove unused parseAccessModifier
JLHwung 49b161b
refactor: remove redundant async function checks
JLHwung c1b28ff
refactor: remove redundant class check in checkExport
JLHwung e64d164
add more parser test cases
JLHwung c4afd22
Update packages/babel-parser/src/parser/statement.js
JLHwung cb65cb3
chore: add sourceType: unambiguous test
JLHwung File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
2 changes: 2 additions & 0 deletions
2
packages/babel-parser/test/expressions/experimental/top-level-await/module/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,2 @@ | ||
// prettier-ignore | ||
await +42 |
3 changes: 3 additions & 0 deletions
3
packages/babel-parser/test/expressions/experimental/top-level-await/module/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 @@ | ||
{ | ||
"sourceType": "module" | ||
} |
33 changes: 33 additions & 0 deletions
33
packages/babel-parser/test/expressions/experimental/top-level-await/module/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,33 @@ | ||
{ | ||
"type": "AwaitExpression", | ||
"start":19,"end":28,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":9}}, | ||
"argument": { | ||
"type": "UnaryExpression", | ||
"start":25,"end":28,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":9}}, | ||
"operator": "+", | ||
"prefix": true, | ||
"argument": { | ||
"type": "NumericLiteral", | ||
"start":26,"end":28,"loc":{"start":{"line":2,"column":7},"end":{"line":2,"column":9}}, | ||
"extra": { | ||
"rawValue": 42, | ||
"raw": "42" | ||
}, | ||
"value": 42 | ||
} | ||
}, | ||
"leadingComments": [ | ||
{ | ||
"type": "CommentLine", | ||
"value": " prettier-ignore", | ||
"start":0,"end":18,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":18}} | ||
} | ||
], | ||
"comments": [ | ||
{ | ||
"type": "CommentLine", | ||
"value": " prettier-ignore", | ||
"start":0,"end":18,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":18}} | ||
} | ||
] | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/babel-parser/test/expressions/experimental/top-level-await/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 @@ | ||
{ | ||
"plugins": ["topLevelAwait"] | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/babel-parser/test/expressions/experimental/top-level-await/script/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,2 @@ | ||
// prettier-ignore | ||
await +42 | ||
JLHwung marked this conversation as resolved.
Show resolved
Hide resolved
|
3 changes: 3 additions & 0 deletions
3
packages/babel-parser/test/expressions/experimental/top-level-await/script/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 @@ | ||
{ | ||
"sourceType": "script" | ||
} |
33 changes: 33 additions & 0 deletions
33
packages/babel-parser/test/expressions/experimental/top-level-await/script/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,33 @@ | ||
{ | ||
"type": "BinaryExpression", | ||
"start":19,"end":28,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":9}}, | ||
"left": { | ||
"type": "Identifier", | ||
"start":19,"end":24,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":5},"identifierName":"await"}, | ||
"name": "await" | ||
}, | ||
"operator": "+", | ||
"right": { | ||
"type": "NumericLiteral", | ||
"start":26,"end":28,"loc":{"start":{"line":2,"column":7},"end":{"line":2,"column":9}}, | ||
"extra": { | ||
"rawValue": 42, | ||
"raw": "42" | ||
}, | ||
"value": 42 | ||
}, | ||
"leadingComments": [ | ||
{ | ||
"type": "CommentLine", | ||
"value": " prettier-ignore", | ||
"start":0,"end":18,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":18}} | ||
} | ||
], | ||
"comments": [ | ||
{ | ||
"type": "CommentLine", | ||
"value": " prettier-ignore", | ||
"start":0,"end":18,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":18}} | ||
} | ||
] | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/babel-parser/test/expressions/experimental/top-level-await/unambiguous/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,2 @@ | ||
// prettier-ignore | ||
await +42 |
3 changes: 3 additions & 0 deletions
3
packages/babel-parser/test/expressions/experimental/top-level-await/unambiguous/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 @@ | ||
{ | ||
"sourceType": "unambiguous" | ||
} |
33 changes: 33 additions & 0 deletions
33
packages/babel-parser/test/expressions/experimental/top-level-await/unambiguous/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,33 @@ | ||
{ | ||
"type": "BinaryExpression", | ||
"start":19,"end":28,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":9}}, | ||
"left": { | ||
"type": "Identifier", | ||
"start":19,"end":24,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":5},"identifierName":"await"}, | ||
"name": "await" | ||
}, | ||
"operator": "+", | ||
"right": { | ||
"type": "NumericLiteral", | ||
"start":26,"end":28,"loc":{"start":{"line":2,"column":7},"end":{"line":2,"column":9}}, | ||
"extra": { | ||
"rawValue": 42, | ||
"raw": "42" | ||
}, | ||
"value": 42 | ||
}, | ||
"leadingComments": [ | ||
{ | ||
"type": "CommentLine", | ||
"value": " prettier-ignore", | ||
"start":0,"end":18,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":18}} | ||
} | ||
], | ||
"comments": [ | ||
{ | ||
"type": "CommentLine", | ||
"value": " prettier-ignore", | ||
"start":0,"end":18,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":18}} | ||
} | ||
] | ||
} |
1 change: 1 addition & 0 deletions
1
packages/babel-parser/test/fixtures/es2015/destructuring/invalid-object-method/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 @@ | ||
const { foo() {} } = foo(); |
3 changes: 3 additions & 0 deletions
3
packages/babel-parser/test/fixtures/es2015/destructuring/invalid-object-method/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 (1:11)" | ||
} |
1 change: 1 addition & 0 deletions
1
packages/babel-parser/test/fixtures/es2020/export-ns-from/ns-dangling-comma/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 @@ | ||
export * as foo, |
3 changes: 3 additions & 0 deletions
3
packages/babel-parser/test/fixtures/es2020/export-ns-from/ns-dangling-comma/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:16)" | ||
} |
1 change: 1 addition & 0 deletions
1
...el-parser/test/fixtures/experimental/bind-operator/invalid-non-member-expression/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; |
6 changes: 6 additions & 0 deletions
6
...arser/test/fixtures/experimental/bind-operator/invalid-non-member-expression/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,6 @@ | ||
{ | ||
"plugins": [ | ||
"functionBind" | ||
], | ||
"throws": "Binding should be performed on object property. (1:2)" | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/babel-parser/test/fixtures/experimental/bind-operator/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 @@ | ||
{ | ||
"plugins": ["functionBind"] | ||
} |
1 change: 1 addition & 0 deletions
1
...el-parser/test/fixtures/experimental/decorators/invalid-decorator-spread-element/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 @@ | ||
({ @foo ...foo }); |
4 changes: 4 additions & 0 deletions
4
...arser/test/fixtures/experimental/decorators/invalid-decorator-spread-element/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,4 @@ | ||
{ | ||
"plugins": ["decorators-legacy"], | ||
"throws": "Unexpected token (1:8)" | ||
} |
1 change: 1 addition & 0 deletions
1
...babel-parser/test/fixtures/experimental/export-extensions/default-dangling-comma/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 @@ | ||
export default, |
3 changes: 3 additions & 0 deletions
3
...l-parser/test/fixtures/experimental/export-extensions/default-dangling-comma/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:15)" | ||
} |
1 change: 1 addition & 0 deletions
1
...st/fixtures/experimental/pipeline-operator/proposal-fsharp-invalid-primary-topic/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 @@ | ||
x |> # + 1 |
3 changes: 3 additions & 0 deletions
3
...ixtures/experimental/pipeline-operator/proposal-fsharp-invalid-primary-topic/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 @@ | ||
{ | ||
"plugins": [["pipelineOperator", { "proposal": "fsharp" }]] | ||
} |
49 changes: 49 additions & 0 deletions
49
...fixtures/experimental/pipeline-operator/proposal-fsharp-invalid-primary-topic/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,49 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":10,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":10}}, | ||
"errors": [ | ||
"SyntaxError: Primary Topic Reference found but pipelineOperator not passed 'smart' for 'proposal' option. (1:5)", | ||
"SyntaxError: Topic reference was used in a lexical context without topic binding (1:5)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":10,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":10}}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":0,"end":10,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":10}}, | ||
"expression": { | ||
"type": "BinaryExpression", | ||
"start":0,"end":10,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":10}}, | ||
"left": { | ||
"type": "Identifier", | ||
"start":0,"end":1,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":1},"identifierName":"x"}, | ||
"name": "x" | ||
}, | ||
"operator": "|>", | ||
"right": { | ||
"type": "BinaryExpression", | ||
"start":5,"end":10,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":10}}, | ||
"left": { | ||
"type": "PipelinePrimaryTopicReference", | ||
"start":5,"end":6,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":6}} | ||
}, | ||
"operator": "+", | ||
"right": { | ||
"type": "NumericLiteral", | ||
"start":9,"end":10,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":10}}, | ||
"extra": { | ||
"rawValue": 1, | ||
"raw": "1" | ||
}, | ||
"value": 1 | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...es/babel-parser/test/fixtures/experimental/record-and-tuple/invalid-record-proto/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 @@ | ||
#{ __proto__: null } |
3 changes: 3 additions & 0 deletions
3
...abel-parser/test/fixtures/experimental/record-and-tuple/invalid-record-proto/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 @@ | ||
{ | ||
"plugins": [["recordAndTuple", { "syntaxType": "hash" }]] | ||
} |
42 changes: 42 additions & 0 deletions
42
...babel-parser/test/fixtures/experimental/record-and-tuple/invalid-record-proto/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,42 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":20,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":20}}, | ||
"errors": [ | ||
"SyntaxError: '__proto__' is not allowed in Record expressions (1:3)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":20,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":20}}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":0,"end":20,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":20}}, | ||
"expression": { | ||
"type": "RecordExpression", | ||
"start":0,"end":20,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":20}}, | ||
"properties": [ | ||
{ | ||
"type": "ObjectProperty", | ||
"start":3,"end":18,"loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":18}}, | ||
"method": false, | ||
"key": { | ||
"type": "Identifier", | ||
"start":3,"end":12,"loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":12},"identifierName":"__proto__"}, | ||
"name": "__proto__" | ||
}, | ||
"computed": false, | ||
"shorthand": false, | ||
"value": { | ||
"type": "NullLiteral", | ||
"start":14,"end":18,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":18}} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These checks are redundant because
shouldParseExportDeclaration
will checkisAsyncFunction
babel/packages/babel-parser/src/parser/statement.js
Lines 1918 to 1938 in a827ca4
When
this.isContextual("async")
is true,isAsyncFunction()
must be true andasync
must be followed by afunction
token, thereforethis.unexpected(next, tt._function);
is never reached.