mirror of
https://github.com/swc-project/swc.git
synced 2024-12-18 03:01:48 +03:00
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:
parent
0fe90881b5
commit
b1c40a411f
@ -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
|
||||
|
@ -0,0 +1,5 @@
|
||||
const foo = <T extends {}>() => {
|
||||
if (bar() {
|
||||
console.log(1);
|
||||
}
|
||||
};
|
@ -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() {
|
||||
`----
|
@ -0,0 +1,5 @@
|
||||
const foo = () => {
|
||||
if (bar() {
|
||||
console.log(1);
|
||||
}
|
||||
};
|
@ -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);
|
||||
`----
|
Loading…
Reference in New Issue
Block a user