mirror of
https://github.com/swc-project/swc.git
synced 2024-12-25 06:36:08 +03:00
fix(es/parser): Fix priority of >>>
(#6748)
**Related issue:** - Closes https://github.com/swc-project/swc/issues/6739.
This commit is contained in:
parent
d7081cc8a6
commit
65a0d3a310
8
crates/swc/tests/fixture/issues-6xxx/6739/input/.swcrc
Normal file
8
crates/swc/tests/fixture/issues-6xxx/6739/input/.swcrc
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"jsc": {
|
||||
"parser": {
|
||||
"syntax": "typescript",
|
||||
"tsx": false
|
||||
}
|
||||
}
|
||||
}
|
1
crates/swc/tests/fixture/issues-6xxx/6739/input/index.ts
Normal file
1
crates/swc/tests/fixture/issues-6xxx/6739/input/index.ts
Normal file
@ -0,0 +1 @@
|
||||
console.log(x < y >>> z);
|
@ -0,0 +1 @@
|
||||
console.log(x < y >>> z);
|
@ -0,0 +1 @@
|
||||
console.log(x < y >>> z);
|
@ -329,7 +329,7 @@ impl<'a, I: Input> Iterator for Lexer<'a, I> {
|
||||
if c == '<' {
|
||||
self.input.bump();
|
||||
return Ok(Some(tok!('<')));
|
||||
} else if c == '>' {
|
||||
} else if c == '>' && !self.ctx.prefer_bin_op_over_type_arg_closing {
|
||||
self.input.bump();
|
||||
return Ok(Some(tok!('>')));
|
||||
}
|
||||
|
@ -375,6 +375,10 @@ pub struct Context {
|
||||
ignore_else_clause: bool,
|
||||
|
||||
disallow_conditional_types: bool,
|
||||
|
||||
/// Used for parsing `>`. If true, `>>` and `>>>` are parsed as binary
|
||||
/// operators.
|
||||
prefer_bin_op_over_type_arg_closing: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default)]
|
||||
|
@ -671,7 +671,11 @@ impl<I: Tokens> Parser<I> {
|
||||
return_if_arrow!(self, obj);
|
||||
|
||||
let type_args = if self.syntax().typescript() && is!(self, '<') {
|
||||
self.try_parse_ts_type_args()
|
||||
self.with_ctx(Context {
|
||||
prefer_bin_op_over_type_arg_closing: true,
|
||||
..self.ctx()
|
||||
})
|
||||
.try_parse_ts_type_args()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
@ -557,7 +557,11 @@ impl<I: Tokens> Parser<I> {
|
||||
pub(super) fn try_parse_ts_type_args(&mut self) -> Option<Box<TsTypeParamInstantiation>> {
|
||||
debug_assert!(self.input.syntax().typescript());
|
||||
|
||||
self.try_parse_ts(|p| {
|
||||
self.with_ctx(Context {
|
||||
prefer_bin_op_over_type_arg_closing: true,
|
||||
..self.ctx()
|
||||
})
|
||||
.try_parse_ts(|p| {
|
||||
let type_args = p.parse_ts_type_args()?;
|
||||
if is_one_of!(
|
||||
p, '<', // invalid syntax
|
||||
|
1
crates/swc_ecma_parser/tests/typescript/issue-6739/1.ts
Normal file
1
crates/swc_ecma_parser/tests/typescript/issue-6739/1.ts
Normal file
@ -0,0 +1 @@
|
||||
console.log(x < y >>> z);
|
109
crates/swc_ecma_parser/tests/typescript/issue-6739/1.ts.json
Normal file
109
crates/swc_ecma_parser/tests/typescript/issue-6739/1.ts.json
Normal file
@ -0,0 +1,109 @@
|
||||
{
|
||||
"type": "Script",
|
||||
"span": {
|
||||
"start": 1,
|
||||
"end": 26,
|
||||
"ctxt": 0
|
||||
},
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"span": {
|
||||
"start": 1,
|
||||
"end": 26,
|
||||
"ctxt": 0
|
||||
},
|
||||
"expression": {
|
||||
"type": "CallExpression",
|
||||
"span": {
|
||||
"start": 1,
|
||||
"end": 25,
|
||||
"ctxt": 0
|
||||
},
|
||||
"callee": {
|
||||
"type": "MemberExpression",
|
||||
"span": {
|
||||
"start": 1,
|
||||
"end": 12,
|
||||
"ctxt": 0
|
||||
},
|
||||
"object": {
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 1,
|
||||
"end": 8,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "console",
|
||||
"optional": false
|
||||
},
|
||||
"property": {
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 9,
|
||||
"end": 12,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "log",
|
||||
"optional": false
|
||||
}
|
||||
},
|
||||
"arguments": [
|
||||
{
|
||||
"spread": null,
|
||||
"expression": {
|
||||
"type": "BinaryExpression",
|
||||
"span": {
|
||||
"start": 13,
|
||||
"end": 24,
|
||||
"ctxt": 0
|
||||
},
|
||||
"operator": "<",
|
||||
"left": {
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 13,
|
||||
"end": 14,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "x",
|
||||
"optional": false
|
||||
},
|
||||
"right": {
|
||||
"type": "BinaryExpression",
|
||||
"span": {
|
||||
"start": 17,
|
||||
"end": 24,
|
||||
"ctxt": 0
|
||||
},
|
||||
"operator": ">>>",
|
||||
"left": {
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 17,
|
||||
"end": 18,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "y",
|
||||
"optional": false
|
||||
},
|
||||
"right": {
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 23,
|
||||
"end": 24,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "z",
|
||||
"optional": false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"typeArguments": null
|
||||
}
|
||||
}
|
||||
],
|
||||
"interpreter": null
|
||||
}
|
1
crates/swc_ecma_parser/tests/typescript/issue-6739/2.tsx
Normal file
1
crates/swc_ecma_parser/tests/typescript/issue-6739/2.tsx
Normal file
@ -0,0 +1 @@
|
||||
console.log(x < y >>> z);
|
109
crates/swc_ecma_parser/tests/typescript/issue-6739/2.tsx.json
Normal file
109
crates/swc_ecma_parser/tests/typescript/issue-6739/2.tsx.json
Normal file
@ -0,0 +1,109 @@
|
||||
{
|
||||
"type": "Script",
|
||||
"span": {
|
||||
"start": 1,
|
||||
"end": 26,
|
||||
"ctxt": 0
|
||||
},
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"span": {
|
||||
"start": 1,
|
||||
"end": 26,
|
||||
"ctxt": 0
|
||||
},
|
||||
"expression": {
|
||||
"type": "CallExpression",
|
||||
"span": {
|
||||
"start": 1,
|
||||
"end": 25,
|
||||
"ctxt": 0
|
||||
},
|
||||
"callee": {
|
||||
"type": "MemberExpression",
|
||||
"span": {
|
||||
"start": 1,
|
||||
"end": 12,
|
||||
"ctxt": 0
|
||||
},
|
||||
"object": {
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 1,
|
||||
"end": 8,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "console",
|
||||
"optional": false
|
||||
},
|
||||
"property": {
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 9,
|
||||
"end": 12,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "log",
|
||||
"optional": false
|
||||
}
|
||||
},
|
||||
"arguments": [
|
||||
{
|
||||
"spread": null,
|
||||
"expression": {
|
||||
"type": "BinaryExpression",
|
||||
"span": {
|
||||
"start": 13,
|
||||
"end": 24,
|
||||
"ctxt": 0
|
||||
},
|
||||
"operator": "<",
|
||||
"left": {
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 13,
|
||||
"end": 14,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "x",
|
||||
"optional": false
|
||||
},
|
||||
"right": {
|
||||
"type": "BinaryExpression",
|
||||
"span": {
|
||||
"start": 17,
|
||||
"end": 24,
|
||||
"ctxt": 0
|
||||
},
|
||||
"operator": ">>>",
|
||||
"left": {
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 17,
|
||||
"end": 18,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "y",
|
||||
"optional": false
|
||||
},
|
||||
"right": {
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 23,
|
||||
"end": 24,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "z",
|
||||
"optional": false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"typeArguments": null
|
||||
}
|
||||
}
|
||||
],
|
||||
"interpreter": null
|
||||
}
|
Loading…
Reference in New Issue
Block a user