Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: preserve tokensLength in tryParse (#13326)
* fix: preserve tokensLength in tryParse * Apply suggestions from code review Co-authored-by: Brian Ng <bng412@gmail.com> Co-authored-by: Brian Ng <bng412@gmail.com>
- Loading branch information
1 parent
9d620c2
commit 0d0950f
Showing
4 changed files
with
301 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
1 change: 1 addition & 0 deletions
1
...es/babel-parser/test/fixtures/flow/typecasts/fail-without-parens-jsx-tokens-true/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 @@ | ||
<div propA={[key: value]} /> |
4 changes: 4 additions & 0 deletions
4
...abel-parser/test/fixtures/flow/typecasts/fail-without-parens-jsx-tokens-true/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 @@ | ||
{ | ||
"tokens": true, | ||
"plugins": ["jsx", "flow"] | ||
} |
292 changes: 292 additions & 0 deletions
292
...babel-parser/test/fixtures/flow/typecasts/fail-without-parens-jsx-tokens-true/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,292 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":28,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":28}}, | ||
"errors": [ | ||
"SyntaxError: The type cast expression is expected to be wrapped with parenthesis. (1:16)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":28,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":28}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":0,"end":28,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":28}}, | ||
"expression": { | ||
"type": "JSXElement", | ||
"start":0,"end":28,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":28}}, | ||
"openingElement": { | ||
"type": "JSXOpeningElement", | ||
"start":0,"end":28,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":28}}, | ||
"name": { | ||
"type": "JSXIdentifier", | ||
"start":1,"end":4,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":4}}, | ||
"name": "div" | ||
}, | ||
"attributes": [ | ||
{ | ||
"type": "JSXAttribute", | ||
"start":5,"end":25,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":25}}, | ||
"name": { | ||
"type": "JSXIdentifier", | ||
"start":5,"end":10,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":10}}, | ||
"name": "propA" | ||
}, | ||
"value": { | ||
"type": "JSXExpressionContainer", | ||
"start":11,"end":25,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":25}}, | ||
"expression": { | ||
"type": "ArrayExpression", | ||
"start":12,"end":24,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":24}}, | ||
"elements": [ | ||
{ | ||
"type": "TypeCastExpression", | ||
"start":13,"end":23,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":23}}, | ||
"expression": { | ||
"type": "Identifier", | ||
"start":13,"end":16,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":16},"identifierName":"key"}, | ||
"name": "key" | ||
}, | ||
"typeAnnotation": { | ||
"type": "TypeAnnotation", | ||
"start":16,"end":23,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":23}}, | ||
"typeAnnotation": { | ||
"type": "GenericTypeAnnotation", | ||
"start":18,"end":23,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":23}}, | ||
"typeParameters": null, | ||
"id": { | ||
"type": "Identifier", | ||
"start":18,"end":23,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":23},"identifierName":"value"}, | ||
"name": "value" | ||
} | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
], | ||
"selfClosing": true | ||
}, | ||
"closingElement": null, | ||
"children": [] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
}, | ||
"tokens": [ | ||
{ | ||
"type": { | ||
"label": "jsxTagStart", | ||
"beforeExpr": false, | ||
"startsExpr": true, | ||
"rightAssociative": false, | ||
"isLoop": false, | ||
"isAssign": false, | ||
"prefix": false, | ||
"postfix": false, | ||
"binop": null | ||
}, | ||
"start":0,"end":1,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":1}} | ||
}, | ||
{ | ||
"type": { | ||
"label": "jsxName", | ||
"beforeExpr": false, | ||
"startsExpr": false, | ||
"rightAssociative": false, | ||
"isLoop": false, | ||
"isAssign": false, | ||
"prefix": false, | ||
"postfix": false, | ||
"binop": null, | ||
"updateContext": null | ||
}, | ||
"value": "div", | ||
"start":1,"end":4,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":4}} | ||
}, | ||
{ | ||
"type": { | ||
"label": "jsxName", | ||
"beforeExpr": false, | ||
"startsExpr": false, | ||
"rightAssociative": false, | ||
"isLoop": false, | ||
"isAssign": false, | ||
"prefix": false, | ||
"postfix": false, | ||
"binop": null, | ||
"updateContext": null | ||
}, | ||
"value": "propA", | ||
"start":5,"end":10,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":10}} | ||
}, | ||
{ | ||
"type": { | ||
"label": "=", | ||
"beforeExpr": true, | ||
"startsExpr": false, | ||
"rightAssociative": false, | ||
"isLoop": false, | ||
"isAssign": true, | ||
"prefix": false, | ||
"postfix": false, | ||
"binop": null, | ||
"updateContext": null | ||
}, | ||
"value": "=", | ||
"start":10,"end":11,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":11}} | ||
}, | ||
{ | ||
"type": { | ||
"label": "{", | ||
"beforeExpr": true, | ||
"startsExpr": true, | ||
"rightAssociative": false, | ||
"isLoop": false, | ||
"isAssign": false, | ||
"prefix": false, | ||
"postfix": false, | ||
"binop": null | ||
}, | ||
"start":11,"end":12,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":12}} | ||
}, | ||
{ | ||
"type": { | ||
"label": "[", | ||
"beforeExpr": true, | ||
"startsExpr": true, | ||
"rightAssociative": false, | ||
"isLoop": false, | ||
"isAssign": false, | ||
"prefix": false, | ||
"postfix": false, | ||
"binop": null, | ||
"updateContext": null | ||
}, | ||
"start":12,"end":13,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":13}} | ||
}, | ||
{ | ||
"type": { | ||
"label": "name", | ||
"beforeExpr": false, | ||
"startsExpr": true, | ||
"rightAssociative": false, | ||
"isLoop": false, | ||
"isAssign": false, | ||
"prefix": false, | ||
"postfix": false, | ||
"binop": null | ||
}, | ||
"value": "key", | ||
"start":13,"end":16,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":16}} | ||
}, | ||
{ | ||
"type": { | ||
"label": ":", | ||
"beforeExpr": true, | ||
"startsExpr": false, | ||
"rightAssociative": false, | ||
"isLoop": false, | ||
"isAssign": false, | ||
"prefix": false, | ||
"postfix": false, | ||
"binop": null, | ||
"updateContext": null | ||
}, | ||
"start":16,"end":17,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":17}} | ||
}, | ||
{ | ||
"type": { | ||
"label": "name", | ||
"beforeExpr": false, | ||
"startsExpr": true, | ||
"rightAssociative": false, | ||
"isLoop": false, | ||
"isAssign": false, | ||
"prefix": false, | ||
"postfix": false, | ||
"binop": null | ||
}, | ||
"value": "value", | ||
"start":18,"end":23,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":23}} | ||
}, | ||
{ | ||
"type": { | ||
"label": "]", | ||
"beforeExpr": false, | ||
"startsExpr": false, | ||
"rightAssociative": false, | ||
"isLoop": false, | ||
"isAssign": false, | ||
"prefix": false, | ||
"postfix": false, | ||
"binop": null, | ||
"updateContext": null | ||
}, | ||
"start":23,"end":24,"loc":{"start":{"line":1,"column":23},"end":{"line":1,"column":24}} | ||
}, | ||
{ | ||
"type": { | ||
"label": "}", | ||
"beforeExpr": false, | ||
"startsExpr": false, | ||
"rightAssociative": false, | ||
"isLoop": false, | ||
"isAssign": false, | ||
"prefix": false, | ||
"postfix": false, | ||
"binop": null | ||
}, | ||
"start":24,"end":25,"loc":{"start":{"line":1,"column":24},"end":{"line":1,"column":25}} | ||
}, | ||
{ | ||
"type": { | ||
"label": "/", | ||
"beforeExpr": true, | ||
"startsExpr": false, | ||
"rightAssociative": false, | ||
"isLoop": false, | ||
"isAssign": false, | ||
"prefix": false, | ||
"postfix": false, | ||
"binop": 10, | ||
"updateContext": null | ||
}, | ||
"value": "/", | ||
"start":26,"end":27,"loc":{"start":{"line":1,"column":26},"end":{"line":1,"column":27}} | ||
}, | ||
{ | ||
"type": { | ||
"label": "jsxTagEnd", | ||
"beforeExpr": false, | ||
"startsExpr": false, | ||
"rightAssociative": false, | ||
"isLoop": false, | ||
"isAssign": false, | ||
"prefix": false, | ||
"postfix": false, | ||
"binop": null | ||
}, | ||
"start":27,"end":28,"loc":{"start":{"line":1,"column":27},"end":{"line":1,"column":28}} | ||
}, | ||
{ | ||
"type": { | ||
"label": "eof", | ||
"beforeExpr": false, | ||
"startsExpr": false, | ||
"rightAssociative": false, | ||
"isLoop": false, | ||
"isAssign": false, | ||
"prefix": false, | ||
"postfix": false, | ||
"binop": null, | ||
"updateContext": null | ||
}, | ||
"start":28,"end":28,"loc":{"start":{"line":1,"column":28},"end":{"line":1,"column":28}} | ||
} | ||
] | ||
} |