From 4f25f2c74907f876b57d4f79bc711dd85a9a9361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Juli=C3=A1n=20Espina?= Date: Wed, 17 May 2023 17:27:58 +0000 Subject: [PATCH] Allow escaped `async` as binding name (#2936) --- boa_parser/src/parser/expression/assignment/mod.rs | 2 +- boa_parser/src/parser/expression/primary/mod.rs | 8 +------- boa_parser/src/parser/statement/expression/mod.rs | 6 ++---- .../src/parser/statement/iteration/for_statement.rs | 2 +- boa_parser/src/parser/statement/mod.rs | 2 +- 5 files changed, 6 insertions(+), 14 deletions(-) diff --git a/boa_parser/src/parser/expression/assignment/mod.rs b/boa_parser/src/parser/expression/assignment/mod.rs index 3bda3a0f3f..33ea651efc 100644 --- a/boa_parser/src/parser/expression/assignment/mod.rs +++ b/boa_parser/src/parser/expression/assignment/mod.rs @@ -134,7 +134,7 @@ where } } // AsyncArrowFunction[?In, ?Yield, ?Await] - TokenKind::Keyword((Keyword::Async, _)) => { + TokenKind::Keyword((Keyword::Async, false)) => { let skip_n = if cursor.peek_is_line_terminator(0, interner).or_abrupt()? { 2 } else { diff --git a/boa_parser/src/parser/expression/primary/mod.rs b/boa_parser/src/parser/expression/primary/mod.rs index e542f6ef36..16a8c258c7 100644 --- a/boa_parser/src/parser/expression/primary/mod.rs +++ b/boa_parser/src/parser/expression/primary/mod.rs @@ -143,14 +143,8 @@ where match cursor.peek(1, interner)?.map(Token::kind) { Some(TokenKind::Keyword((Keyword::Function, _))) - if !is_line_terminator && contain_escaped_char => + if !is_line_terminator && !contain_escaped_char => { - Err(Error::general( - "Keyword must not contain escaped characters", - tok_position, - )) - } - Some(TokenKind::Keyword((Keyword::Function, _))) if !is_line_terminator => { cursor.advance(interner); match cursor.peek(1, interner)?.map(Token::kind) { Some(TokenKind::Punctuator(Punctuator::Mul)) => { diff --git a/boa_parser/src/parser/statement/expression/mod.rs b/boa_parser/src/parser/statement/expression/mod.rs index 287b224002..60a7c2e031 100644 --- a/boa_parser/src/parser/statement/expression/mod.rs +++ b/boa_parser/src/parser/statement/expression/mod.rs @@ -47,7 +47,7 @@ where let next_token = cursor.peek(0, interner).or_abrupt()?; match next_token.kind() { - TokenKind::Keyword((Keyword::Function | Keyword::Class | Keyword::Async, true)) => { + TokenKind::Keyword((Keyword::Function | Keyword::Class, true)) => { return Err(Error::general( "Keyword must not contain escaped characters", next_token.span().start(), @@ -69,9 +69,7 @@ where .peek_is_line_terminator(skip_n, interner)? .unwrap_or(true); - if is_line_terminator { - {} - } else { + if !is_line_terminator { let next_token = cursor.peek(1, interner).or_abrupt()?; match next_token.kind() { TokenKind::Keyword((Keyword::Function, true)) => { diff --git a/boa_parser/src/parser/statement/iteration/for_statement.rs b/boa_parser/src/parser/statement/iteration/for_statement.rs index 3c839d727b..7808876d46 100644 --- a/boa_parser/src/parser/statement/iteration/for_statement.rs +++ b/boa_parser/src/parser/statement/iteration/for_statement.rs @@ -135,7 +135,7 @@ where .parse(cursor, interner)? .into(), ), - TokenKind::Keyword((Keyword::Async, false)) => { + TokenKind::Keyword((Keyword::Async, false)) if !r#await => { match cursor.peek(1, interner).or_abrupt()?.kind() { TokenKind::Keyword((Keyword::Of, _)) => { return Err(Error::lex(LexError::Syntax( diff --git a/boa_parser/src/parser/statement/mod.rs b/boa_parser/src/parser/statement/mod.rs index 79eb8678fa..70f846dbc7 100644 --- a/boa_parser/src/parser/statement/mod.rs +++ b/boa_parser/src/parser/statement/mod.rs @@ -421,7 +421,7 @@ where ) => Declaration::new(self.allow_yield, self.allow_await) .parse(cursor, interner) .map(ast::StatementListItem::from), - TokenKind::Keyword((Keyword::Async, _)) => { + TokenKind::Keyword((Keyword::Async, false)) => { let skip_n = if cursor.peek_is_line_terminator(0, interner).or_abrupt()? { 2 } else {