Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove incorrect cursor.set_goal() call in AssignmentExpression parsing #2177

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions boa_engine/src/syntax/lexer/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,25 @@ fn regex_literal() {
expect_tokens(&mut lexer, &expected, &mut interner);
}

#[test]
fn regex_equals_following_assignment() {
let mut lexer = Lexer::new(&b"const myRegex = /=/;"[..]);
let mut interner = Interner::default();

let expected = [
TokenKind::Keyword((Keyword::Const, false)),
TokenKind::identifier(interner.get_or_intern_static("myRegex")),
TokenKind::Punctuator(Punctuator::Assign),
TokenKind::regular_expression_literal(
interner.get_or_intern_static("="),
Sym::EMPTY_STRING,
),
TokenKind::Punctuator(Punctuator::Semicolon),
];

expect_tokens(&mut lexer, &expected, &mut interner);
}

#[test]
fn regex_literal_flags() {
let mut lexer = Lexer::new(&br"/\/[^\/]*\/*/gmi"[..]);
Expand Down
1 change: 0 additions & 1 deletion boa_engine/src/syntax/parser/expression/assignment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ where

fn parse(mut self, cursor: &mut Cursor<R>, interner: &mut Interner) -> ParseResult {
let _timer = Profiler::global().start_event("AssignmentExpression", "Parsing");
cursor.set_goal(InputElement::Div);

match cursor
.peek(0, interner)?
Expand Down
25 changes: 24 additions & 1 deletion boa_engine/src/syntax/parser/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
},
Context,
};
use boa_interner::Interner;
use boa_interner::{Interner, Sym};

/// Checks that the given JavaScript string gives the expected expression.
#[allow(clippy::unwrap_used)]
Expand Down Expand Up @@ -78,6 +78,29 @@ fn assign_operator_precedence() {
);
}

#[test]
fn assign_regex_equals() {
let mut interner = Interner::default();
check_parser(
"let myRegex = /=/;",
vec![DeclarationList::Let(
vec![Declaration::new_with_identifier(
interner.get_or_intern_static("myRegex"),
Node::from(New::from(Call::new(
Identifier::new(Sym::REGEXP),
vec![
Node::from(Const::from(interner.get_or_intern_static("="))),
Node::from(Const::from(Sym::EMPTY_STRING)),
],
))),
)]
.into(),
)
.into()],
interner,
);
}

#[test]
fn hoisting() {
let mut interner = Interner::default();
Expand Down