Skip to content

Commit

Permalink
fix: bail out only when they could form bitshift
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Aug 2, 2022
1 parent ec722f5 commit c413671
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/babel-parser/src/plugins/typescript/index.ts
Expand Up @@ -2493,10 +2493,11 @@ export default (superClass: {

const tokenType = this.state.type;
if (
// a<b>>c is not (a<b>)>c, but a<(b>>c)
tokenType === tt.gt ||
// a<b>>>c is not (a<b>)>>c, but a<(b>>>c)
tokenType === tt.bitShiftR ||
(this.state.start === this.state.lastTokStart + 1 &&
// a<b>>c is not (a<b>)>c, but a<(b>>c)
(tokenType === tt.gt ||
// a<b>>>c is not (a<b>)>>c, but a<(b>>>c)
tokenType === tt.bitShiftR)) ||
// a<b>c is (a<b)>c
(tokenType !== tt.parenL &&
tokenCanStartExpression(tokenType) &&
Expand Down
@@ -0,0 +1 @@
a<b> > c;
@@ -0,0 +1,51 @@
{
"type": "File",
"start":0,"end":9,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":9,"index":9}},
"program": {
"type": "Program",
"start":0,"end":9,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":9,"index":9}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start":0,"end":9,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":9,"index":9}},
"expression": {
"type": "BinaryExpression",
"start":0,"end":8,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":8,"index":8}},
"left": {
"type": "TSInstantiationExpression",
"start":0,"end":4,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":4,"index":4}},
"expression": {
"type": "Identifier",
"start":0,"end":1,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":1,"index":1},"identifierName":"a"},
"name": "a"
},
"typeParameters": {
"type": "TSTypeParameterInstantiation",
"start":1,"end":4,"loc":{"start":{"line":1,"column":1,"index":1},"end":{"line":1,"column":4,"index":4}},
"params": [
{
"type": "TSTypeReference",
"start":2,"end":3,"loc":{"start":{"line":1,"column":2,"index":2},"end":{"line":1,"column":3,"index":3}},
"typeName": {
"type": "Identifier",
"start":2,"end":3,"loc":{"start":{"line":1,"column":2,"index":2},"end":{"line":1,"column":3,"index":3},"identifierName":"b"},
"name": "b"
}
}
]
}
},
"operator": ">",
"right": {
"type": "Identifier",
"start":7,"end":8,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":8,"index":8},"identifierName":"c"},
"name": "c"
}
}
}
],
"directives": []
}
}
@@ -0,0 +1 @@
a<b> >> c;
@@ -0,0 +1,51 @@
{
"type": "File",
"start":0,"end":10,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":10,"index":10}},
"program": {
"type": "Program",
"start":0,"end":10,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":10,"index":10}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start":0,"end":10,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":10,"index":10}},
"expression": {
"type": "BinaryExpression",
"start":0,"end":9,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":9,"index":9}},
"left": {
"type": "TSInstantiationExpression",
"start":0,"end":4,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":4,"index":4}},
"expression": {
"type": "Identifier",
"start":0,"end":1,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":1,"index":1},"identifierName":"a"},
"name": "a"
},
"typeParameters": {
"type": "TSTypeParameterInstantiation",
"start":1,"end":4,"loc":{"start":{"line":1,"column":1,"index":1},"end":{"line":1,"column":4,"index":4}},
"params": [
{
"type": "TSTypeReference",
"start":2,"end":3,"loc":{"start":{"line":1,"column":2,"index":2},"end":{"line":1,"column":3,"index":3}},
"typeName": {
"type": "Identifier",
"start":2,"end":3,"loc":{"start":{"line":1,"column":2,"index":2},"end":{"line":1,"column":3,"index":3},"identifierName":"b"},
"name": "b"
}
}
]
}
},
"operator": ">>",
"right": {
"type": "Identifier",
"start":8,"end":9,"loc":{"start":{"line":1,"column":8,"index":8},"end":{"line":1,"column":9,"index":9},"identifierName":"c"},
"name": "c"
}
}
}
],
"directives": []
}
}

0 comments on commit c413671

Please sign in to comment.