Skip to content
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

rescan gt token at the end of type args parsing #15631

Merged
merged 1 commit into from May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/babel-parser/src/plugins/typescript/index.ts
Expand Up @@ -2281,6 +2281,10 @@ export default (superClass: ClassWithMixin<typeof Parser, IJSXParserMixin>) =>
);
if (node.params.length === 0) {
this.raise(TSErrors.EmptyTypeArguments, { at: node });
} else if (!this.state.inType && this.curContext() === tc.brace) {
// rescan `>` when we are no longer in type context and JSX parsing context
// since it was tokenized when `inType` is `true`.
this.reScan_lt_gt();
}
this.expect(tt.gt);
return this.finishNode(node, "TSTypeParameterInstantiation");
Expand Down
@@ -0,0 +1 @@
fn(x < y, x >= y)
@@ -0,0 +1,58 @@
{
"type": "File",
"start":0,"end":17,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":17,"index":17}},
"program": {
"type": "Program",
"start":0,"end":17,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":17,"index":17}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start":0,"end":17,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":17,"index":17}},
"expression": {
"type": "CallExpression",
"start":0,"end":17,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":17,"index":17}},
"callee": {
"type": "Identifier",
"start":0,"end":2,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":2,"index":2},"identifierName":"fn"},
"name": "fn"
},
"arguments": [
{
"type": "BinaryExpression",
"start":3,"end":8,"loc":{"start":{"line":1,"column":3,"index":3},"end":{"line":1,"column":8,"index":8}},
"left": {
"type": "Identifier",
"start":3,"end":4,"loc":{"start":{"line":1,"column":3,"index":3},"end":{"line":1,"column":4,"index":4},"identifierName":"x"},
"name": "x"
},
"operator": "<",
"right": {
"type": "Identifier",
"start":7,"end":8,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":8,"index":8},"identifierName":"y"},
"name": "y"
}
},
{
"type": "BinaryExpression",
"start":10,"end":16,"loc":{"start":{"line":1,"column":10,"index":10},"end":{"line":1,"column":16,"index":16}},
"left": {
"type": "Identifier",
"start":10,"end":11,"loc":{"start":{"line":1,"column":10,"index":10},"end":{"line":1,"column":11,"index":11},"identifierName":"x"},
"name": "x"
},
"operator": ">=",
"right": {
"type": "Identifier",
"start":15,"end":16,"loc":{"start":{"line":1,"column":15,"index":15},"end":{"line":1,"column":16,"index":16},"identifierName":"y"},
"name": "y"
}
}
]
}
}
],
"directives": []
}
}