Browse Source

fix: ignore `debugger` statement (#3976)

Co-authored-by: shurizzle <me@shurizzle.dev>
pull/3979/head
shurizzle 4 months ago committed by GitHub
parent
commit
9a553db188
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 8
      core/ast/src/expression/mod.rs
  2. 1
      core/engine/src/bytecompiler/expression/mod.rs
  3. 4
      core/parser/src/parser/expression/primary/mod.rs

8
core/ast/src/expression/mod.rs

@ -175,6 +175,9 @@ pub enum Expression {
/// It is not a valid expression node.
#[doc(hidden)]
FormalParameterList(FormalParameterList),
#[doc(hidden)]
Debugger,
}
impl Expression {
@ -220,6 +223,7 @@ impl Expression {
Self::Parenthesized(expr) => expr.to_interned_string(interner),
Self::RegExpLiteral(regexp) => regexp.to_interned_string(interner),
Self::FormalParameterList(_) => unreachable!(),
Self::Debugger => "debugger".to_owned(),
}
}
@ -326,7 +330,7 @@ impl VisitWith for Expression {
Self::Yield(y) => visitor.visit_yield(y),
Self::Parenthesized(e) => visitor.visit_parenthesized(e),
Self::FormalParameterList(fpl) => visitor.visit_formal_parameter_list(fpl),
Self::This | Self::NewTarget | Self::ImportMeta => {
Self::This | Self::NewTarget | Self::ImportMeta | Self::Debugger => {
// do nothing; can be handled as special case by visitor
ControlFlow::Continue(())
}
@ -369,7 +373,7 @@ impl VisitWith for Expression {
Self::Yield(y) => visitor.visit_yield_mut(y),
Self::Parenthesized(e) => visitor.visit_parenthesized_mut(e),
Self::FormalParameterList(fpl) => visitor.visit_formal_parameter_list_mut(fpl),
Self::This | Self::NewTarget | Self::ImportMeta => {
Self::This | Self::NewTarget | Self::ImportMeta | Self::Debugger => {
// do nothing; can be handled as special case by visitor
ControlFlow::Continue(())
}

1
core/engine/src/bytecompiler/expression/mod.rs

@ -363,6 +363,7 @@ impl ByteCompiler<'_> {
}
// TODO: try to remove this variant somehow
Expression::FormalParameterList(_) => unreachable!(),
Expression::Debugger => (),
}
}
}

4
core/parser/src/parser/expression/primary/mod.rs

@ -133,6 +133,10 @@ where
.parse(cursor, interner)
.map(Into::into)
}
TokenKind::Keyword((Keyword::Debugger, _)) => {
cursor.advance(interner);
Ok(ast::Expression::Debugger)
}
TokenKind::Keyword((Keyword::Async, contain_escaped_char)) => {
let contain_escaped_char = *contain_escaped_char;
let skip_n = if cursor.peek_is_line_terminator(0, interner).or_abrupt()? {

Loading…
Cancel
Save