diff --git a/crates/swc_ecma_parser/src/parser/expr.rs b/crates/swc_ecma_parser/src/parser/expr.rs index 7004456d8ffb..30336be39819 100644 --- a/crates/swc_ecma_parser/src/parser/expr.rs +++ b/crates/swc_ecma_parser/src/parser/expr.rs @@ -707,7 +707,7 @@ impl<'a, I: Tokens> Parser { params.is_simple_parameter_list(), )?; - if is_direct_child_of_cond && !is_one_of!(p, ':', ';') { + if is_direct_child_of_cond && !is_one_of!(p, ':', ';', ',', ')') { trace_cur!(p, parse_arrow_in_cond__fail); unexpected!(p, "fail") } diff --git a/crates/swc_ecma_parser/src/parser/expr/tests.rs b/crates/swc_ecma_parser/src/parser/expr/tests.rs index 11294d76a4aa..29a0ad7de6aa 100644 --- a/crates/swc_ecma_parser/src/parser/expr/tests.rs +++ b/crates/swc_ecma_parser/src/parser/expr/tests.rs @@ -494,6 +494,26 @@ fn super_expr_computed() { ); } +#[test] +fn issue_3672_1() { + test_parser( + "report({ + fix: fixable ? null : (): RuleFix => {}, +});", + Syntax::Typescript(Default::default()), + |p| p.parse_module(), + ); +} + +#[test] +fn issue_3672_2() { + test_parser( + "f(a ? (): void => { } : (): void => { })", + Syntax::Typescript(Default::default()), + |p| p.parse_module(), + ); +} + #[bench] fn bench_new_expr_ts(b: &mut Bencher) { bench_parser( diff --git a/crates/swc_ecma_parser/tests/typescript/issue-2174/case1/input.ts b/crates/swc_ecma_parser/tests/typescript/issue-2174/case1/input.ts deleted file mode 100644 index 063d1f7bc403..000000000000 --- a/crates/swc_ecma_parser/tests/typescript/issue-2174/case1/input.ts +++ /dev/null @@ -1,5 +0,0 @@ -const x = { - prop: isCorrect - ? fn => ({ }) - : fn => true, -}; \ No newline at end of file diff --git a/crates/swc_ecma_parser/tests/typescript/issue-2174/case1/input.ts.json b/crates/swc_ecma_parser/tests/typescript/issue-2174/case1/input.ts.json deleted file mode 100644 index a8f94e67b146..000000000000 --- a/crates/swc_ecma_parser/tests/typescript/issue-2174/case1/input.ts.json +++ /dev/null @@ -1,160 +0,0 @@ -{ - "type": "Script", - "span": { - "start": 0, - "end": 82, - "ctxt": 0 - }, - "body": [ - { - "type": "VariableDeclaration", - "span": { - "start": 0, - "end": 82, - "ctxt": 0 - }, - "kind": "const", - "declare": false, - "declarations": [ - { - "type": "VariableDeclarator", - "span": { - "start": 6, - "end": 81, - "ctxt": 0 - }, - "id": { - "type": "Identifier", - "span": { - "start": 6, - "end": 7, - "ctxt": 0 - }, - "value": "x", - "optional": false, - "typeAnnotation": null - }, - "init": { - "type": "ObjectExpression", - "span": { - "start": 10, - "end": 81, - "ctxt": 0 - }, - "properties": [ - { - "type": "KeyValueProperty", - "key": { - "type": "Identifier", - "span": { - "start": 16, - "end": 20, - "ctxt": 0 - }, - "value": "prop", - "optional": false - }, - "value": { - "type": "ConditionalExpression", - "span": { - "start": 22, - "end": 78, - "ctxt": 0 - }, - "test": { - "type": "Identifier", - "span": { - "start": 22, - "end": 31, - "ctxt": 0 - }, - "value": "isCorrect", - "optional": false - }, - "consequent": { - "type": "ArrowFunctionExpression", - "span": { - "start": 42, - "end": 53, - "ctxt": 0 - }, - "params": [ - { - "type": "Identifier", - "span": { - "start": 42, - "end": 44, - "ctxt": 0 - }, - "value": "fn", - "optional": false, - "typeAnnotation": null - } - ], - "body": { - "type": "ParenthesisExpression", - "span": { - "start": 48, - "end": 53, - "ctxt": 0 - }, - "expression": { - "type": "ObjectExpression", - "span": { - "start": 49, - "end": 52, - "ctxt": 0 - }, - "properties": [] - } - }, - "async": false, - "generator": false, - "typeParameters": null, - "returnType": null - }, - "alternate": { - "type": "ArrowFunctionExpression", - "span": { - "start": 68, - "end": 78, - "ctxt": 0 - }, - "params": [ - { - "type": "Identifier", - "span": { - "start": 68, - "end": 70, - "ctxt": 0 - }, - "value": "fn", - "optional": false, - "typeAnnotation": null - } - ], - "body": { - "type": "BooleanLiteral", - "span": { - "start": 74, - "end": 78, - "ctxt": 0 - }, - "value": true - }, - "async": false, - "generator": false, - "typeParameters": null, - "returnType": null - } - } - } - ] - }, - "definite": false - } - ] - } - ], - "interpreter": null -} diff --git a/crates/swc_ecma_parser/tests/typescript/issue-2174/case2/input.tsx b/crates/swc_ecma_parser/tests/typescript/issue-2174/case2/input.tsx deleted file mode 100644 index 063d1f7bc403..000000000000 --- a/crates/swc_ecma_parser/tests/typescript/issue-2174/case2/input.tsx +++ /dev/null @@ -1,5 +0,0 @@ -const x = { - prop: isCorrect - ? fn => ({ }) - : fn => true, -}; \ No newline at end of file diff --git a/crates/swc_ecma_parser/tests/typescript/issue-2174/case2/input.tsx.json b/crates/swc_ecma_parser/tests/typescript/issue-2174/case2/input.tsx.json deleted file mode 100644 index a8f94e67b146..000000000000 --- a/crates/swc_ecma_parser/tests/typescript/issue-2174/case2/input.tsx.json +++ /dev/null @@ -1,160 +0,0 @@ -{ - "type": "Script", - "span": { - "start": 0, - "end": 82, - "ctxt": 0 - }, - "body": [ - { - "type": "VariableDeclaration", - "span": { - "start": 0, - "end": 82, - "ctxt": 0 - }, - "kind": "const", - "declare": false, - "declarations": [ - { - "type": "VariableDeclarator", - "span": { - "start": 6, - "end": 81, - "ctxt": 0 - }, - "id": { - "type": "Identifier", - "span": { - "start": 6, - "end": 7, - "ctxt": 0 - }, - "value": "x", - "optional": false, - "typeAnnotation": null - }, - "init": { - "type": "ObjectExpression", - "span": { - "start": 10, - "end": 81, - "ctxt": 0 - }, - "properties": [ - { - "type": "KeyValueProperty", - "key": { - "type": "Identifier", - "span": { - "start": 16, - "end": 20, - "ctxt": 0 - }, - "value": "prop", - "optional": false - }, - "value": { - "type": "ConditionalExpression", - "span": { - "start": 22, - "end": 78, - "ctxt": 0 - }, - "test": { - "type": "Identifier", - "span": { - "start": 22, - "end": 31, - "ctxt": 0 - }, - "value": "isCorrect", - "optional": false - }, - "consequent": { - "type": "ArrowFunctionExpression", - "span": { - "start": 42, - "end": 53, - "ctxt": 0 - }, - "params": [ - { - "type": "Identifier", - "span": { - "start": 42, - "end": 44, - "ctxt": 0 - }, - "value": "fn", - "optional": false, - "typeAnnotation": null - } - ], - "body": { - "type": "ParenthesisExpression", - "span": { - "start": 48, - "end": 53, - "ctxt": 0 - }, - "expression": { - "type": "ObjectExpression", - "span": { - "start": 49, - "end": 52, - "ctxt": 0 - }, - "properties": [] - } - }, - "async": false, - "generator": false, - "typeParameters": null, - "returnType": null - }, - "alternate": { - "type": "ArrowFunctionExpression", - "span": { - "start": 68, - "end": 78, - "ctxt": 0 - }, - "params": [ - { - "type": "Identifier", - "span": { - "start": 68, - "end": 70, - "ctxt": 0 - }, - "value": "fn", - "optional": false, - "typeAnnotation": null - } - ], - "body": { - "type": "BooleanLiteral", - "span": { - "start": 74, - "end": 78, - "ctxt": 0 - }, - "value": true - }, - "async": false, - "generator": false, - "typeParameters": null, - "returnType": null - } - } - } - ] - }, - "definite": false - } - ] - } - ], - "interpreter": null -}