fix(es/parser): Use a hard error for missing r-paren in an if stmt (#7223)

**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/7104.
This commit is contained in:
Yukang 2023-04-10 16:46:01 +08:00 committed by GitHub
parent 0fe90881b5
commit b1c40a411f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 13 deletions

View File

@ -470,20 +470,8 @@ impl<'a, I: Tokens> Parser<I> {
},
)
})?;
if !eat!(self, ')') {
self.emit_err(self.input.cur_span(), SyntaxError::TS1005);
let span = span!(self, start);
return Ok(IfStmt {
span,
test,
cons: Box::new(Stmt::Expr(ExprStmt {
span,
expr: Box::new(Expr::Invalid(Invalid { span })),
})),
alt: Default::default(),
});
}
expect!(self, ')');
let cons = {
// Prevent stack overflow

View File

@ -0,0 +1,5 @@
const foo = <T extends {}>() => {
if (bar() {
console.log(1);
}
};

View File

@ -0,0 +1,14 @@
x An arrow function is not allowed here
,-[$DIR/tests/typescript-errors/issue-7104/case1/input.ts:1:1]
1 | const foo = <T extends {}>() => {
: ^^
2 | if (bar() {
`----
x Expression expected
,-[$DIR/tests/typescript-errors/issue-7104/case1/input.ts:1:1]
1 | const foo = <T extends {}>() => {
: ^
2 | if (bar() {
`----

View File

@ -0,0 +1,5 @@
const foo = () => {
if (bar() {
console.log(1);
}
};

View File

@ -0,0 +1,8 @@
x Expected ')', got '{'
,-[$DIR/tests/typescript-errors/issue-7104/case2/input.ts:1:1]
1 | const foo = () => {
2 | if (bar() {
: ^
3 | console.log(1);
`----