Browse Source

Allow escaped `async` as binding name (#2936)

pull/2939/head
José Julián Espina 2 years ago committed by GitHub
parent
commit
4f25f2c749
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      boa_parser/src/parser/expression/assignment/mod.rs
  2. 8
      boa_parser/src/parser/expression/primary/mod.rs
  3. 6
      boa_parser/src/parser/statement/expression/mod.rs
  4. 2
      boa_parser/src/parser/statement/iteration/for_statement.rs
  5. 2
      boa_parser/src/parser/statement/mod.rs

2
boa_parser/src/parser/expression/assignment/mod.rs

@ -134,7 +134,7 @@ where
} }
} }
// AsyncArrowFunction[?In, ?Yield, ?Await] // 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()? { let skip_n = if cursor.peek_is_line_terminator(0, interner).or_abrupt()? {
2 2
} else { } else {

8
boa_parser/src/parser/expression/primary/mod.rs

@ -143,14 +143,8 @@ where
match cursor.peek(1, interner)?.map(Token::kind) { match cursor.peek(1, interner)?.map(Token::kind) {
Some(TokenKind::Keyword((Keyword::Function, _))) 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); cursor.advance(interner);
match cursor.peek(1, interner)?.map(Token::kind) { match cursor.peek(1, interner)?.map(Token::kind) {
Some(TokenKind::Punctuator(Punctuator::Mul)) => { Some(TokenKind::Punctuator(Punctuator::Mul)) => {

6
boa_parser/src/parser/statement/expression/mod.rs

@ -47,7 +47,7 @@ where
let next_token = cursor.peek(0, interner).or_abrupt()?; let next_token = cursor.peek(0, interner).or_abrupt()?;
match next_token.kind() { match next_token.kind() {
TokenKind::Keyword((Keyword::Function | Keyword::Class | Keyword::Async, true)) => { TokenKind::Keyword((Keyword::Function | Keyword::Class, true)) => {
return Err(Error::general( return Err(Error::general(
"Keyword must not contain escaped characters", "Keyword must not contain escaped characters",
next_token.span().start(), next_token.span().start(),
@ -69,9 +69,7 @@ where
.peek_is_line_terminator(skip_n, interner)? .peek_is_line_terminator(skip_n, interner)?
.unwrap_or(true); .unwrap_or(true);
if is_line_terminator { if !is_line_terminator {
{}
} else {
let next_token = cursor.peek(1, interner).or_abrupt()?; let next_token = cursor.peek(1, interner).or_abrupt()?;
match next_token.kind() { match next_token.kind() {
TokenKind::Keyword((Keyword::Function, true)) => { TokenKind::Keyword((Keyword::Function, true)) => {

2
boa_parser/src/parser/statement/iteration/for_statement.rs

@ -135,7 +135,7 @@ where
.parse(cursor, interner)? .parse(cursor, interner)?
.into(), .into(),
), ),
TokenKind::Keyword((Keyword::Async, false)) => { TokenKind::Keyword((Keyword::Async, false)) if !r#await => {
match cursor.peek(1, interner).or_abrupt()?.kind() { match cursor.peek(1, interner).or_abrupt()?.kind() {
TokenKind::Keyword((Keyword::Of, _)) => { TokenKind::Keyword((Keyword::Of, _)) => {
return Err(Error::lex(LexError::Syntax( return Err(Error::lex(LexError::Syntax(

2
boa_parser/src/parser/statement/mod.rs

@ -421,7 +421,7 @@ where
) => Declaration::new(self.allow_yield, self.allow_await) ) => Declaration::new(self.allow_yield, self.allow_await)
.parse(cursor, interner) .parse(cursor, interner)
.map(ast::StatementListItem::from), .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()? { let skip_n = if cursor.peek_is_line_terminator(0, interner).or_abrupt()? {
2 2
} else { } else {

Loading…
Cancel
Save