mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
fix(parser): terminate parsing if an EmptyParenthesizedExpression error occurs (#1874)
close: https://github.com/oxc-project/oxc/issues/1870#issue-2061901976
This commit is contained in:
parent
8a1e894330
commit
c3090c2c70
4 changed files with 4 additions and 51 deletions
|
|
@ -202,13 +202,14 @@ impl<'a> Parser<'a> {
|
||||||
let mut expressions = list.elements;
|
let mut expressions = list.elements;
|
||||||
let paren_span = self.end_span(span);
|
let paren_span = self.end_span(span);
|
||||||
|
|
||||||
|
if expressions.is_empty() {
|
||||||
|
return Err(diagnostics::EmptyParenthesizedExpression(paren_span).into());
|
||||||
|
}
|
||||||
|
|
||||||
// ParenthesizedExpression is from acorn --preserveParens
|
// ParenthesizedExpression is from acorn --preserveParens
|
||||||
let expression = if expressions.len() == 1 {
|
let expression = if expressions.len() == 1 {
|
||||||
expressions.remove(0)
|
expressions.remove(0)
|
||||||
} else {
|
} else {
|
||||||
if expressions.is_empty() {
|
|
||||||
self.error(diagnostics::EmptyParenthesizedExpression(paren_span));
|
|
||||||
}
|
|
||||||
self.ast.sequence_expression(
|
self.ast.sequence_expression(
|
||||||
Span::new(paren_span.start + 1, paren_span.end - 1),
|
Span::new(paren_span.start + 1, paren_span.end - 1),
|
||||||
expressions,
|
expressions,
|
||||||
|
|
|
||||||
|
|
@ -4156,13 +4156,6 @@ Expect to Parse: "typescript/types/const-type-parameters-babel-7/input.ts"
|
||||||
· ──
|
· ──
|
||||||
╰────
|
╰────
|
||||||
|
|
||||||
× Expected `,` but found `=>`
|
|
||||||
╭─[es2015/uncategorised/38/input.js:1:1]
|
|
||||||
1 │ console.log(typeof () => {});
|
|
||||||
· ─┬
|
|
||||||
· ╰── `,` expected
|
|
||||||
╰────
|
|
||||||
|
|
||||||
× Unexpected token
|
× Unexpected token
|
||||||
╭─[es2015/uncategorised/386/input.js:1:1]
|
╭─[es2015/uncategorised/386/input.js:1:1]
|
||||||
1 │ export typeof foo;
|
1 │ export typeof foo;
|
||||||
|
|
@ -8352,11 +8345,6 @@ Expect to Parse: "typescript/types/const-type-parameters-babel-7/input.ts"
|
||||||
· ──
|
· ──
|
||||||
╰────
|
╰────
|
||||||
|
|
||||||
× Expected `:` but found `EOF`
|
|
||||||
╭─[esprima/invalid-syntax/migrated_0096/input.js:1:1]
|
|
||||||
1 │ () ? 42
|
|
||||||
╰────
|
|
||||||
|
|
||||||
× Empty parenthesized expression
|
× Empty parenthesized expression
|
||||||
╭─[esprima/invalid-syntax/migrated_0097/input.js:1:1]
|
╭─[esprima/invalid-syntax/migrated_0097/input.js:1:1]
|
||||||
1 │ () + 42
|
1 │ () + 42
|
||||||
|
|
|
||||||
|
|
@ -9678,15 +9678,6 @@ Expect Syntax Error: "language/import/import-attributes/json-named-bindings.js"
|
||||||
24 │
|
24 │
|
||||||
╰────
|
╰────
|
||||||
|
|
||||||
× Expected `{` but found `=>`
|
|
||||||
╭─[language/expressions/class/elements/syntax/early-errors/class-heritage-array-literal-arrow-heritage.js:22:1]
|
|
||||||
22 │
|
|
||||||
23 │ var C = class extends () => {} {
|
|
||||||
· ─┬
|
|
||||||
· ╰── `{` expected
|
|
||||||
24 │
|
|
||||||
╰────
|
|
||||||
|
|
||||||
× Expected `{` but found `=>`
|
× Expected `{` but found `=>`
|
||||||
╭─[language/expressions/class/elements/syntax/early-errors/class-heritage-array-literal-async-arrow-heritage.js:22:1]
|
╭─[language/expressions/class/elements/syntax/early-errors/class-heritage-array-literal-async-arrow-heritage.js:22:1]
|
||||||
22 │
|
22 │
|
||||||
|
|
@ -14744,15 +14735,6 @@ Expect Syntax Error: "language/import/import-attributes/json-named-bindings.js"
|
||||||
25 │ }
|
25 │ }
|
||||||
╰────
|
╰────
|
||||||
|
|
||||||
× Expected a semicolon or an implicit semicolon after a statement, but found none
|
|
||||||
╭─[language/expressions/in/private-field-invalid-rhs.js:23:1]
|
|
||||||
23 │ constructor() {
|
|
||||||
24 │ #field in () => {};
|
|
||||||
· ─
|
|
||||||
25 │ }
|
|
||||||
╰────
|
|
||||||
help: Try insert a semicolon here
|
|
||||||
|
|
||||||
× The keyword 'yield' is reserved
|
× The keyword 'yield' is reserved
|
||||||
╭─[language/expressions/in/private-field-rhs-yield-absent.js:30:1]
|
╭─[language/expressions/in/private-field-rhs-yield-absent.js:30:1]
|
||||||
30 │ static method() {
|
30 │ static method() {
|
||||||
|
|
@ -25173,15 +25155,6 @@ Expect Syntax Error: "language/import/import-attributes/json-named-bindings.js"
|
||||||
24 │
|
24 │
|
||||||
╰────
|
╰────
|
||||||
|
|
||||||
× Expected `{` but found `=>`
|
|
||||||
╭─[language/statements/class/elements/syntax/early-errors/class-heritage-array-literal-arrow-heritage.js:22:1]
|
|
||||||
22 │
|
|
||||||
23 │ class C extends () => {} {
|
|
||||||
· ─┬
|
|
||||||
· ╰── `{` expected
|
|
||||||
24 │
|
|
||||||
╰────
|
|
||||||
|
|
||||||
× Expected `{` but found `=>`
|
× Expected `{` but found `=>`
|
||||||
╭─[language/statements/class/elements/syntax/early-errors/class-heritage-array-literal-async-arrow-heritage.js:22:1]
|
╭─[language/statements/class/elements/syntax/early-errors/class-heritage-array-literal-async-arrow-heritage.js:22:1]
|
||||||
22 │
|
22 │
|
||||||
|
|
|
||||||
|
|
@ -17097,15 +17097,6 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts"
|
||||||
3 │ }
|
3 │ }
|
||||||
╰────
|
╰────
|
||||||
|
|
||||||
× Expected a semicolon or an implicit semicolon after a statement, but found none
|
|
||||||
╭─[conformance/parser/ecmascript5/RegressionTests/parser509669.ts:1:1]
|
|
||||||
1 │ function foo():any {
|
|
||||||
2 │ return ():void {};
|
|
||||||
· ▲
|
|
||||||
3 │ }
|
|
||||||
╰────
|
|
||||||
help: Try insert a semicolon here
|
|
||||||
|
|
||||||
× Expected `}` but found `EOF`
|
× Expected `}` but found `EOF`
|
||||||
╭─[conformance/parser/ecmascript5/RegressionTests/parser512084.ts:1:1]
|
╭─[conformance/parser/ecmascript5/RegressionTests/parser512084.ts:1:1]
|
||||||
1 │ class foo {
|
1 │ class foo {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue