From 823a120d8a06b4345b5478de7ee6801188101b67 Mon Sep 17 00:00:00 2001 From: Josh Barthelmess Date: Thu, 14 Jul 2022 12:35:06 -0400 Subject: [PATCH 1/3] remove cursor.set_goal --- boa_engine/src/syntax/lexer/tests.rs | 16 ++++++++++++++++ .../syntax/parser/expression/assignment/mod.rs | 1 - 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/boa_engine/src/syntax/lexer/tests.rs b/boa_engine/src/syntax/lexer/tests.rs index 2553f25c2b5..783980ab393 100644 --- a/boa_engine/src/syntax/lexer/tests.rs +++ b/boa_engine/src/syntax/lexer/tests.rs @@ -634,6 +634,22 @@ 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"[..]); diff --git a/boa_engine/src/syntax/parser/expression/assignment/mod.rs b/boa_engine/src/syntax/parser/expression/assignment/mod.rs index 46bde867c76..414ece80540 100644 --- a/boa_engine/src/syntax/parser/expression/assignment/mod.rs +++ b/boa_engine/src/syntax/parser/expression/assignment/mod.rs @@ -90,7 +90,6 @@ where fn parse(mut self, cursor: &mut Cursor, interner: &mut Interner) -> ParseResult { let _timer = Profiler::global().start_event("AssignmentExpression", "Parsing"); - cursor.set_goal(InputElement::Div); match cursor .peek(0, interner)? From e67b7402244bb25e35c328d1b43f4eb3826d5b04 Mon Sep 17 00:00:00 2001 From: Josh Barthelmess Date: Thu, 14 Jul 2022 13:09:01 -0400 Subject: [PATCH 2/3] fix rust-fmt issue --- boa_engine/src/syntax/lexer/tests.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/boa_engine/src/syntax/lexer/tests.rs b/boa_engine/src/syntax/lexer/tests.rs index 783980ab393..0736c346b50 100644 --- a/boa_engine/src/syntax/lexer/tests.rs +++ b/boa_engine/src/syntax/lexer/tests.rs @@ -643,7 +643,10 @@ fn regex_equals_following_assignment() { 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::regular_expression_literal( + interner.get_or_intern_static("="), + Sym::EMPTY_STRING + ), TokenKind::Punctuator(Punctuator::Semicolon), ]; From bbe1f506f890fda7f912ac87e6b21668ec7639eb Mon Sep 17 00:00:00 2001 From: Josh Barthelmess Date: Thu, 14 Jul 2022 15:24:48 -0400 Subject: [PATCH 3/3] fixed rust-fmt again and added parser test --- boa_engine/src/syntax/lexer/tests.rs | 4 ++-- boa_engine/src/syntax/parser/tests.rs | 25 ++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/boa_engine/src/syntax/lexer/tests.rs b/boa_engine/src/syntax/lexer/tests.rs index 0736c346b50..9c975fe23cc 100644 --- a/boa_engine/src/syntax/lexer/tests.rs +++ b/boa_engine/src/syntax/lexer/tests.rs @@ -644,8 +644,8 @@ fn regex_equals_following_assignment() { TokenKind::identifier(interner.get_or_intern_static("myRegex")), TokenKind::Punctuator(Punctuator::Assign), TokenKind::regular_expression_literal( - interner.get_or_intern_static("="), - Sym::EMPTY_STRING + interner.get_or_intern_static("="), + Sym::EMPTY_STRING, ), TokenKind::Punctuator(Punctuator::Semicolon), ]; diff --git a/boa_engine/src/syntax/parser/tests.rs b/boa_engine/src/syntax/parser/tests.rs index 5ccc45a0cf5..cfbc9788a6c 100644 --- a/boa_engine/src/syntax/parser/tests.rs +++ b/boa_engine/src/syntax/parser/tests.rs @@ -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)] @@ -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();