Skip to content

Commit

Permalink
rescan gt token at the end of type args parsing (#15631)
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed May 17, 2023
1 parent 1e6551f commit c5f68eb
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
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": []
}
}

0 comments on commit c5f68eb

Please sign in to comment.