Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Throw error on invalid async generic arrow syntax
- Loading branch information
1 parent
e6ef400
commit 846baa7
Showing
5 changed files
with
199 additions
and
0 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
7 changes: 7 additions & 0 deletions
7
packages/babel-parser/test/fixtures/flow/type-generics/async-arrow-2/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,7 @@ | ||
const f = async <T, R, S>( | ||
x: T, | ||
y: R, | ||
z: S, | ||
) => { | ||
return null; | ||
}; |
134 changes: 134 additions & 0 deletions
134
packages/babel-parser/test/fixtures/flow/type-generics/async-arrow-2/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,134 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":75,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":2}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":75,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":2}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "VariableDeclaration", | ||
"start":0,"end":75,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":2}}, | ||
"declarations": [ | ||
{ | ||
"type": "VariableDeclarator", | ||
"start":6,"end":74,"loc":{"start":{"line":1,"column":6},"end":{"line":7,"column":1}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"f"}, | ||
"name": "f" | ||
}, | ||
"init": { | ||
"type": "ArrowFunctionExpression", | ||
"start":10,"end":74,"loc":{"start":{"line":1,"column":10},"end":{"line":7,"column":1}}, | ||
"typeParameters": { | ||
"type": "TypeParameterDeclaration", | ||
"start":16,"end":25,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":25}}, | ||
"params": [ | ||
{ | ||
"type": "TypeParameter", | ||
"start":17,"end":18,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":18}}, | ||
"name": "T", | ||
"variance": null | ||
}, | ||
{ | ||
"type": "TypeParameter", | ||
"start":20,"end":21,"loc":{"start":{"line":1,"column":20},"end":{"line":1,"column":21}}, | ||
"name": "R", | ||
"variance": null | ||
}, | ||
{ | ||
"type": "TypeParameter", | ||
"start":23,"end":24,"loc":{"start":{"line":1,"column":23},"end":{"line":1,"column":24}}, | ||
"name": "S", | ||
"variance": null | ||
} | ||
] | ||
}, | ||
"params": [ | ||
{ | ||
"type": "Identifier", | ||
"start":29,"end":33,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":6},"identifierName":"x"}, | ||
"name": "x", | ||
"typeAnnotation": { | ||
"type": "TypeAnnotation", | ||
"start":30,"end":33,"loc":{"start":{"line":2,"column":3},"end":{"line":2,"column":6}}, | ||
"typeAnnotation": { | ||
"type": "GenericTypeAnnotation", | ||
"start":32,"end":33,"loc":{"start":{"line":2,"column":5},"end":{"line":2,"column":6}}, | ||
"typeParameters": null, | ||
"id": { | ||
"type": "Identifier", | ||
"start":32,"end":33,"loc":{"start":{"line":2,"column":5},"end":{"line":2,"column":6},"identifierName":"T"}, | ||
"name": "T" | ||
} | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "Identifier", | ||
"start":37,"end":41,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":6},"identifierName":"y"}, | ||
"name": "y", | ||
"typeAnnotation": { | ||
"type": "TypeAnnotation", | ||
"start":38,"end":41,"loc":{"start":{"line":3,"column":3},"end":{"line":3,"column":6}}, | ||
"typeAnnotation": { | ||
"type": "GenericTypeAnnotation", | ||
"start":40,"end":41,"loc":{"start":{"line":3,"column":5},"end":{"line":3,"column":6}}, | ||
"typeParameters": null, | ||
"id": { | ||
"type": "Identifier", | ||
"start":40,"end":41,"loc":{"start":{"line":3,"column":5},"end":{"line":3,"column":6},"identifierName":"R"}, | ||
"name": "R" | ||
} | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "Identifier", | ||
"start":45,"end":49,"loc":{"start":{"line":4,"column":2},"end":{"line":4,"column":6},"identifierName":"z"}, | ||
"name": "z", | ||
"typeAnnotation": { | ||
"type": "TypeAnnotation", | ||
"start":46,"end":49,"loc":{"start":{"line":4,"column":3},"end":{"line":4,"column":6}}, | ||
"typeAnnotation": { | ||
"type": "GenericTypeAnnotation", | ||
"start":48,"end":49,"loc":{"start":{"line":4,"column":5},"end":{"line":4,"column":6}}, | ||
"typeParameters": null, | ||
"id": { | ||
"type": "Identifier", | ||
"start":48,"end":49,"loc":{"start":{"line":4,"column":5},"end":{"line":4,"column":6},"identifierName":"S"}, | ||
"name": "S" | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"id": null, | ||
"generator": false, | ||
"async": true, | ||
"body": { | ||
"type": "BlockStatement", | ||
"start":56,"end":74,"loc":{"start":{"line":5,"column":5},"end":{"line":7,"column":1}}, | ||
"body": [ | ||
{ | ||
"type": "ReturnStatement", | ||
"start":60,"end":72,"loc":{"start":{"line":6,"column":2},"end":{"line":6,"column":14}}, | ||
"argument": { | ||
"type": "NullLiteral", | ||
"start":67,"end":71,"loc":{"start":{"line":6,"column":9},"end":{"line":6,"column":13}} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} | ||
} | ||
], | ||
"kind": "const" | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
packages/babel-parser/test/fixtures/flow/type-generics/async-arrow-invalid/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 @@ | ||
<T> async () => {} |
46 changes: 46 additions & 0 deletions
46
packages/babel-parser/test/fixtures/flow/type-generics/async-arrow-invalid/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":18,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":18}}, | ||
"errors": [ | ||
"SyntaxError: Type parameters must come after the async keyword, e.g. instead of `<T> async () => {}`, use `async <T>() => {}` (1:0)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":18,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":18}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":0,"end":18,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":18}}, | ||
"expression": { | ||
"type": "ArrowFunctionExpression", | ||
"start":0,"end":18,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":18}}, | ||
"id": null, | ||
"generator": false, | ||
"async": true, | ||
"params": [], | ||
"body": { | ||
"type": "BlockStatement", | ||
"start":16,"end":18,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":18}}, | ||
"body": [], | ||
"directives": [] | ||
}, | ||
"typeParameters": { | ||
"type": "TypeParameterDeclaration", | ||
"start":0,"end":3,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":3}}, | ||
"params": [ | ||
{ | ||
"type": "TypeParameter", | ||
"start":1,"end":2,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":2}}, | ||
"name": "T", | ||
"variance": null | ||
} | ||
] | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |