From b55e450f997cf19ec332bf481c57ba7a5c885990 Mon Sep 17 00:00:00 2001 From: Iban Eguia Moraza Date: Thu, 14 May 2020 17:41:14 +0200 Subject: [PATCH] Reverted kind(), might have caused some performance regressions in the parser --- boa/src/syntax/ast/node/mod.rs | 1 - boa/src/syntax/ast/token.rs | 16 +- boa/src/syntax/lexer/tests.rs | 472 ++++++++---------- boa/src/syntax/parser/cursor.rs | 26 +- .../expression/assignment/arrow_function.rs | 4 +- .../expression/assignment/conditional.rs | 2 +- .../expression/assignment/exponentiation.rs | 4 +- .../parser/expression/assignment/mod.rs | 6 +- .../expression/left_hand_side/arguments.rs | 2 +- .../parser/expression/left_hand_side/call.rs | 6 +- .../expression/left_hand_side/member.rs | 8 +- .../parser/expression/left_hand_side/mod.rs | 2 +- boa/src/syntax/parser/expression/mod.rs | 6 +- .../syntax/parser/expression/primary/mod.rs | 2 +- boa/src/syntax/parser/expression/unary.rs | 2 +- boa/src/syntax/parser/expression/update.rs | 4 +- boa/src/syntax/parser/function/mod.rs | 10 +- boa/src/syntax/parser/statement/block/mod.rs | 2 +- .../syntax/parser/statement/break_stm/mod.rs | 2 +- .../parser/statement/continue_stm/mod.rs | 2 +- .../parser/statement/declaration/lexical.rs | 4 +- .../parser/statement/declaration/mod.rs | 2 +- boa/src/syntax/parser/statement/if_stm/mod.rs | 2 +- .../statement/iteration/do_while_statement.rs | 2 +- .../statement/iteration/for_statement.rs | 2 +- boa/src/syntax/parser/statement/mod.rs | 8 +- .../syntax/parser/statement/return_stm/mod.rs | 4 +- boa/src/syntax/parser/statement/throw/mod.rs | 2 +- .../syntax/parser/statement/try_stm/mod.rs | 8 +- boa/src/syntax/parser/statement/variable.rs | 2 +- 30 files changed, 265 insertions(+), 350 deletions(-) diff --git a/boa/src/syntax/ast/node/mod.rs b/boa/src/syntax/ast/node/mod.rs index 44ab13bfe46..2f4bb0ba125 100644 --- a/boa/src/syntax/ast/node/mod.rs +++ b/boa/src/syntax/ast/node/mod.rs @@ -28,7 +28,6 @@ use std::{ #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; -/// A Javascript AST Node. #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Clone, Debug, Trace, Finalize, PartialEq)] pub enum Node { diff --git a/boa/src/syntax/ast/token.rs b/boa/src/syntax/ast/token.rs index 037a17d40da..9da760c0372 100644 --- a/boa/src/syntax/ast/token.rs +++ b/boa/src/syntax/ast/token.rs @@ -21,7 +21,7 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, PartialEq)] pub struct Token { /// The token kind, which contains the actual data of the token. - kind: TokenKind, + pub(crate) kind: TokenKind, /// The token position in the original source code. span: Span, } @@ -32,6 +32,7 @@ impl Token { Self { kind, span } } + /// Gets the kind of the token. pub fn kind(&self) -> &TokenKind { &self.kind } @@ -48,19 +49,6 @@ impl Display for Token { } } -/// A continuous sequence of tokens. -pub struct VecToken(Vec); - -impl Debug for VecToken { - fn fmt(&self, f: &mut Formatter<'_>) -> Result { - let mut buffer = String::new(); - for token in &self.0 { - buffer.push_str(&token.to_string()); - } - write!(f, "{}", buffer) - } -} - /// Represents the type differenct types of numeric literals. #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Clone, Copy, PartialEq, Debug)] diff --git a/boa/src/syntax/lexer/tests.rs b/boa/src/syntax/lexer/tests.rs index 855d8b46a30..e8b235b77ad 100644 --- a/boa/src/syntax/lexer/tests.rs +++ b/boa/src/syntax/lexer/tests.rs @@ -13,9 +13,9 @@ fn check_single_line_comment() { let s1 = "var \n//This is a comment\ntrue"; let mut lexer = Lexer::new(s1); lexer.lex().expect("failed to lex"); - assert_eq!(lexer.tokens[0].kind(), &TokenKind::Keyword(Keyword::Var)); - assert_eq!(lexer.tokens[1].kind(), &TokenKind::LineTerminator); - assert_eq!(lexer.tokens[2].kind(), &TokenKind::BooleanLiteral(true)); + assert_eq!(lexer.tokens[0].kind, TokenKind::Keyword(Keyword::Var)); + assert_eq!(lexer.tokens[1].kind, TokenKind::LineTerminator); + assert_eq!(lexer.tokens[2].kind, TokenKind::BooleanLiteral(true)); } #[test] @@ -23,8 +23,8 @@ fn check_multi_line_comment() { let s = "var /* await \n break \n*/ x"; let mut lexer = Lexer::new(s); lexer.lex().expect("failed to lex"); - assert_eq!(lexer.tokens[0].kind(), &TokenKind::Keyword(Keyword::Var)); - assert_eq!(lexer.tokens[1].kind(), &TokenKind::identifier("x")); + assert_eq!(lexer.tokens[0].kind, TokenKind::Keyword(Keyword::Var)); + assert_eq!(lexer.tokens[1].kind, TokenKind::identifier("x")); } #[test] @@ -32,9 +32,9 @@ fn check_string() { let s = "'aaa' \"bbb\""; let mut lexer = Lexer::new(s); lexer.lex().expect("failed to lex"); - assert_eq!(lexer.tokens[0].kind(), &TokenKind::string_literal("aaa")); + assert_eq!(lexer.tokens[0].kind, TokenKind::string_literal("aaa")); - assert_eq!(lexer.tokens[1].kind(), &TokenKind::string_literal("bbb")); + assert_eq!(lexer.tokens[1].kind, TokenKind::string_literal("bbb")); } #[test] @@ -46,200 +46,191 @@ fn check_punctuators() { let mut lexer = Lexer::new(s); lexer.lex().expect("failed to lex"); assert_eq!( - lexer.tokens[0].kind(), - &TokenKind::Punctuator(Punctuator::OpenBlock) + lexer.tokens[0].kind, + TokenKind::Punctuator(Punctuator::OpenBlock) ); assert_eq!( - lexer.tokens[1].kind(), - &TokenKind::Punctuator(Punctuator::OpenParen) + lexer.tokens[1].kind, + TokenKind::Punctuator(Punctuator::OpenParen) ); assert_eq!( - lexer.tokens[2].kind(), - &TokenKind::Punctuator(Punctuator::CloseParen) + lexer.tokens[2].kind, + TokenKind::Punctuator(Punctuator::CloseParen) ); assert_eq!( - lexer.tokens[3].kind(), - &TokenKind::Punctuator(Punctuator::OpenBracket) + lexer.tokens[3].kind, + TokenKind::Punctuator(Punctuator::OpenBracket) ); assert_eq!( - lexer.tokens[4].kind(), - &TokenKind::Punctuator(Punctuator::CloseBracket) + lexer.tokens[4].kind, + TokenKind::Punctuator(Punctuator::CloseBracket) ); + assert_eq!(lexer.tokens[5].kind, TokenKind::Punctuator(Punctuator::Dot)); assert_eq!( - lexer.tokens[5].kind(), - &TokenKind::Punctuator(Punctuator::Dot) + lexer.tokens[6].kind, + TokenKind::Punctuator(Punctuator::Spread) ); assert_eq!( - lexer.tokens[6].kind(), - &TokenKind::Punctuator(Punctuator::Spread) + lexer.tokens[7].kind, + TokenKind::Punctuator(Punctuator::Semicolon) ); assert_eq!( - lexer.tokens[7].kind(), - &TokenKind::Punctuator(Punctuator::Semicolon) + lexer.tokens[8].kind, + TokenKind::Punctuator(Punctuator::Comma) ); assert_eq!( - lexer.tokens[8].kind(), - &TokenKind::Punctuator(Punctuator::Comma) + lexer.tokens[9].kind, + TokenKind::Punctuator(Punctuator::LessThan) ); assert_eq!( - lexer.tokens[9].kind(), - &TokenKind::Punctuator(Punctuator::LessThan) + lexer.tokens[10].kind, + TokenKind::Punctuator(Punctuator::GreaterThan) ); assert_eq!( - lexer.tokens[10].kind(), - &TokenKind::Punctuator(Punctuator::GreaterThan) + lexer.tokens[11].kind, + TokenKind::Punctuator(Punctuator::LessThanOrEq) ); assert_eq!( - lexer.tokens[11].kind(), - &TokenKind::Punctuator(Punctuator::LessThanOrEq) + lexer.tokens[12].kind, + TokenKind::Punctuator(Punctuator::GreaterThanOrEq) ); + assert_eq!(lexer.tokens[13].kind, TokenKind::Punctuator(Punctuator::Eq)); assert_eq!( - lexer.tokens[12].kind(), - &TokenKind::Punctuator(Punctuator::GreaterThanOrEq) + lexer.tokens[14].kind, + TokenKind::Punctuator(Punctuator::NotEq) ); assert_eq!( - lexer.tokens[13].kind(), - &TokenKind::Punctuator(Punctuator::Eq) + lexer.tokens[15].kind, + TokenKind::Punctuator(Punctuator::StrictEq) ); assert_eq!( - lexer.tokens[14].kind(), - &TokenKind::Punctuator(Punctuator::NotEq) + lexer.tokens[16].kind, + TokenKind::Punctuator(Punctuator::StrictNotEq) ); assert_eq!( - lexer.tokens[15].kind(), - &TokenKind::Punctuator(Punctuator::StrictEq) + lexer.tokens[17].kind, + TokenKind::Punctuator(Punctuator::Add) ); assert_eq!( - lexer.tokens[16].kind(), - &TokenKind::Punctuator(Punctuator::StrictNotEq) + lexer.tokens[18].kind, + TokenKind::Punctuator(Punctuator::Sub) ); assert_eq!( - lexer.tokens[17].kind(), - &TokenKind::Punctuator(Punctuator::Add) + lexer.tokens[19].kind, + TokenKind::Punctuator(Punctuator::Mul) ); assert_eq!( - lexer.tokens[18].kind(), - &TokenKind::Punctuator(Punctuator::Sub) + lexer.tokens[20].kind, + TokenKind::Punctuator(Punctuator::Mod) ); assert_eq!( - lexer.tokens[19].kind(), - &TokenKind::Punctuator(Punctuator::Mul) + lexer.tokens[21].kind, + TokenKind::Punctuator(Punctuator::Dec) ); assert_eq!( - lexer.tokens[20].kind(), - &TokenKind::Punctuator(Punctuator::Mod) + lexer.tokens[22].kind, + TokenKind::Punctuator(Punctuator::LeftSh) ); assert_eq!( - lexer.tokens[21].kind(), - &TokenKind::Punctuator(Punctuator::Dec) + lexer.tokens[23].kind, + TokenKind::Punctuator(Punctuator::RightSh) ); assert_eq!( - lexer.tokens[22].kind(), - &TokenKind::Punctuator(Punctuator::LeftSh) + lexer.tokens[24].kind, + TokenKind::Punctuator(Punctuator::URightSh) ); assert_eq!( - lexer.tokens[23].kind(), - &TokenKind::Punctuator(Punctuator::RightSh) + lexer.tokens[25].kind, + TokenKind::Punctuator(Punctuator::And) ); + assert_eq!(lexer.tokens[26].kind, TokenKind::Punctuator(Punctuator::Or)); assert_eq!( - lexer.tokens[24].kind(), - &TokenKind::Punctuator(Punctuator::URightSh) + lexer.tokens[27].kind, + TokenKind::Punctuator(Punctuator::Xor) ); assert_eq!( - lexer.tokens[25].kind(), - &TokenKind::Punctuator(Punctuator::And) + lexer.tokens[28].kind, + TokenKind::Punctuator(Punctuator::Not) ); assert_eq!( - lexer.tokens[26].kind(), - &TokenKind::Punctuator(Punctuator::Or) + lexer.tokens[29].kind, + TokenKind::Punctuator(Punctuator::Neg) ); assert_eq!( - lexer.tokens[27].kind(), - &TokenKind::Punctuator(Punctuator::Xor) + lexer.tokens[30].kind, + TokenKind::Punctuator(Punctuator::BoolAnd) ); assert_eq!( - lexer.tokens[28].kind(), - &TokenKind::Punctuator(Punctuator::Not) + lexer.tokens[31].kind, + TokenKind::Punctuator(Punctuator::BoolOr) ); assert_eq!( - lexer.tokens[29].kind(), - &TokenKind::Punctuator(Punctuator::Neg) + lexer.tokens[32].kind, + TokenKind::Punctuator(Punctuator::Question) ); assert_eq!( - lexer.tokens[30].kind(), - &TokenKind::Punctuator(Punctuator::BoolAnd) + lexer.tokens[33].kind, + TokenKind::Punctuator(Punctuator::Colon) ); assert_eq!( - lexer.tokens[31].kind(), - &TokenKind::Punctuator(Punctuator::BoolOr) + lexer.tokens[34].kind, + TokenKind::Punctuator(Punctuator::Assign) ); assert_eq!( - lexer.tokens[32].kind(), - &TokenKind::Punctuator(Punctuator::Question) + lexer.tokens[35].kind, + TokenKind::Punctuator(Punctuator::AssignAdd) ); assert_eq!( - lexer.tokens[33].kind(), - &TokenKind::Punctuator(Punctuator::Colon) + lexer.tokens[36].kind, + TokenKind::Punctuator(Punctuator::AssignSub) ); assert_eq!( - lexer.tokens[34].kind(), - &TokenKind::Punctuator(Punctuator::Assign) + lexer.tokens[37].kind, + TokenKind::Punctuator(Punctuator::AssignMul) ); assert_eq!( - lexer.tokens[35].kind(), - &TokenKind::Punctuator(Punctuator::AssignAdd) + lexer.tokens[38].kind, + TokenKind::Punctuator(Punctuator::AssignAnd) ); assert_eq!( - lexer.tokens[36].kind(), - &TokenKind::Punctuator(Punctuator::AssignSub) + lexer.tokens[39].kind, + TokenKind::Punctuator(Punctuator::AssignPow) ); assert_eq!( - lexer.tokens[37].kind(), - &TokenKind::Punctuator(Punctuator::AssignMul) + lexer.tokens[40].kind, + TokenKind::Punctuator(Punctuator::Inc) ); assert_eq!( - lexer.tokens[38].kind(), - &TokenKind::Punctuator(Punctuator::AssignAnd) + lexer.tokens[41].kind, + TokenKind::Punctuator(Punctuator::Exp) ); assert_eq!( - lexer.tokens[39].kind(), - &TokenKind::Punctuator(Punctuator::AssignPow) + lexer.tokens[42].kind, + TokenKind::Punctuator(Punctuator::AssignLeftSh) ); assert_eq!( - lexer.tokens[40].kind(), - &TokenKind::Punctuator(Punctuator::Inc) + lexer.tokens[43].kind, + TokenKind::Punctuator(Punctuator::AssignRightSh) ); assert_eq!( - lexer.tokens[41].kind(), - &TokenKind::Punctuator(Punctuator::Exp) + lexer.tokens[44].kind, + TokenKind::Punctuator(Punctuator::AssignURightSh) ); assert_eq!( - lexer.tokens[42].kind(), - &TokenKind::Punctuator(Punctuator::AssignLeftSh) + lexer.tokens[45].kind, + TokenKind::Punctuator(Punctuator::AssignAnd) ); assert_eq!( - lexer.tokens[43].kind(), - &TokenKind::Punctuator(Punctuator::AssignRightSh) + lexer.tokens[46].kind, + TokenKind::Punctuator(Punctuator::AssignOr) ); assert_eq!( - lexer.tokens[44].kind(), - &TokenKind::Punctuator(Punctuator::AssignURightSh) + lexer.tokens[47].kind, + TokenKind::Punctuator(Punctuator::AssignXor) ); assert_eq!( - lexer.tokens[45].kind(), - &TokenKind::Punctuator(Punctuator::AssignAnd) - ); - assert_eq!( - lexer.tokens[46].kind(), - &TokenKind::Punctuator(Punctuator::AssignOr) - ); - assert_eq!( - lexer.tokens[47].kind(), - &TokenKind::Punctuator(Punctuator::AssignXor) - ); - assert_eq!( - lexer.tokens[48].kind(), - &TokenKind::Punctuator(Punctuator::Arrow) + lexer.tokens[48].kind, + TokenKind::Punctuator(Punctuator::Arrow) ); } @@ -252,76 +243,43 @@ fn check_keywords() { let mut lexer = Lexer::new(s); lexer.lex().expect("failed to lex"); - assert_eq!(lexer.tokens[0].kind(), &TokenKind::Keyword(Keyword::Await)); - assert_eq!(lexer.tokens[1].kind(), &TokenKind::Keyword(Keyword::Break)); - assert_eq!(lexer.tokens[2].kind(), &TokenKind::Keyword(Keyword::Case)); - assert_eq!(lexer.tokens[3].kind(), &TokenKind::Keyword(Keyword::Catch)); - assert_eq!(lexer.tokens[4].kind(), &TokenKind::Keyword(Keyword::Class)); - assert_eq!(lexer.tokens[5].kind(), &TokenKind::Keyword(Keyword::Const)); - assert_eq!( - lexer.tokens[6].kind(), - &TokenKind::Keyword(Keyword::Continue) - ); - assert_eq!( - lexer.tokens[7].kind(), - &TokenKind::Keyword(Keyword::Debugger) - ); - assert_eq!( - lexer.tokens[8].kind(), - &TokenKind::Keyword(Keyword::Default) - ); - assert_eq!(lexer.tokens[9].kind(), &TokenKind::Keyword(Keyword::Delete)); - assert_eq!(lexer.tokens[10].kind(), &TokenKind::Keyword(Keyword::Do)); - assert_eq!(lexer.tokens[11].kind(), &TokenKind::Keyword(Keyword::Else)); - assert_eq!( - lexer.tokens[12].kind(), - &TokenKind::Keyword(Keyword::Export) - ); - assert_eq!( - lexer.tokens[13].kind(), - &TokenKind::Keyword(Keyword::Extends) - ); - assert_eq!( - lexer.tokens[14].kind(), - &TokenKind::Keyword(Keyword::Finally) - ); - assert_eq!(lexer.tokens[15].kind(), &TokenKind::Keyword(Keyword::For)); - assert_eq!( - lexer.tokens[16].kind(), - &TokenKind::Keyword(Keyword::Function) - ); - assert_eq!(lexer.tokens[17].kind(), &TokenKind::Keyword(Keyword::If)); - assert_eq!( - lexer.tokens[18].kind(), - &TokenKind::Keyword(Keyword::Import) - ); - assert_eq!(lexer.tokens[19].kind(), &TokenKind::Keyword(Keyword::In)); - assert_eq!( - lexer.tokens[20].kind(), - &TokenKind::Keyword(Keyword::InstanceOf) - ); - assert_eq!(lexer.tokens[21].kind(), &TokenKind::Keyword(Keyword::New)); - assert_eq!( - lexer.tokens[22].kind(), - &TokenKind::Keyword(Keyword::Return) - ); - assert_eq!(lexer.tokens[23].kind(), &TokenKind::Keyword(Keyword::Super)); - assert_eq!( - lexer.tokens[24].kind(), - &TokenKind::Keyword(Keyword::Switch) - ); - assert_eq!(lexer.tokens[25].kind(), &TokenKind::Keyword(Keyword::This)); - assert_eq!(lexer.tokens[26].kind(), &TokenKind::Keyword(Keyword::Throw)); - assert_eq!(lexer.tokens[27].kind(), &TokenKind::Keyword(Keyword::Try)); - assert_eq!( - lexer.tokens[28].kind(), - &TokenKind::Keyword(Keyword::TypeOf) - ); - assert_eq!(lexer.tokens[29].kind(), &TokenKind::Keyword(Keyword::Var)); - assert_eq!(lexer.tokens[30].kind(), &TokenKind::Keyword(Keyword::Void)); - assert_eq!(lexer.tokens[31].kind(), &TokenKind::Keyword(Keyword::While)); - assert_eq!(lexer.tokens[32].kind(), &TokenKind::Keyword(Keyword::With)); - assert_eq!(lexer.tokens[33].kind(), &TokenKind::Keyword(Keyword::Yield)); + assert_eq!(lexer.tokens[0].kind, TokenKind::Keyword(Keyword::Await)); + assert_eq!(lexer.tokens[1].kind, TokenKind::Keyword(Keyword::Break)); + assert_eq!(lexer.tokens[2].kind, TokenKind::Keyword(Keyword::Case)); + assert_eq!(lexer.tokens[3].kind, TokenKind::Keyword(Keyword::Catch)); + assert_eq!(lexer.tokens[4].kind, TokenKind::Keyword(Keyword::Class)); + assert_eq!(lexer.tokens[5].kind, TokenKind::Keyword(Keyword::Const)); + assert_eq!(lexer.tokens[6].kind, TokenKind::Keyword(Keyword::Continue)); + assert_eq!(lexer.tokens[7].kind, TokenKind::Keyword(Keyword::Debugger)); + assert_eq!(lexer.tokens[8].kind, TokenKind::Keyword(Keyword::Default)); + assert_eq!(lexer.tokens[9].kind, TokenKind::Keyword(Keyword::Delete)); + assert_eq!(lexer.tokens[10].kind, TokenKind::Keyword(Keyword::Do)); + assert_eq!(lexer.tokens[11].kind, TokenKind::Keyword(Keyword::Else)); + assert_eq!(lexer.tokens[12].kind, TokenKind::Keyword(Keyword::Export)); + assert_eq!(lexer.tokens[13].kind, TokenKind::Keyword(Keyword::Extends)); + assert_eq!(lexer.tokens[14].kind, TokenKind::Keyword(Keyword::Finally)); + assert_eq!(lexer.tokens[15].kind, TokenKind::Keyword(Keyword::For)); + assert_eq!(lexer.tokens[16].kind, TokenKind::Keyword(Keyword::Function)); + assert_eq!(lexer.tokens[17].kind, TokenKind::Keyword(Keyword::If)); + assert_eq!(lexer.tokens[18].kind, TokenKind::Keyword(Keyword::Import)); + assert_eq!(lexer.tokens[19].kind, TokenKind::Keyword(Keyword::In)); + assert_eq!( + lexer.tokens[20].kind, + TokenKind::Keyword(Keyword::InstanceOf) + ); + assert_eq!(lexer.tokens[21].kind, TokenKind::Keyword(Keyword::New)); + assert_eq!(lexer.tokens[22].kind, TokenKind::Keyword(Keyword::Return)); + assert_eq!(lexer.tokens[23].kind, TokenKind::Keyword(Keyword::Super)); + assert_eq!(lexer.tokens[24].kind, TokenKind::Keyword(Keyword::Switch)); + assert_eq!(lexer.tokens[25].kind, TokenKind::Keyword(Keyword::This)); + assert_eq!(lexer.tokens[26].kind, TokenKind::Keyword(Keyword::Throw)); + assert_eq!(lexer.tokens[27].kind, TokenKind::Keyword(Keyword::Try)); + assert_eq!(lexer.tokens[28].kind, TokenKind::Keyword(Keyword::TypeOf)); + assert_eq!(lexer.tokens[29].kind, TokenKind::Keyword(Keyword::Var)); + assert_eq!(lexer.tokens[30].kind, TokenKind::Keyword(Keyword::Void)); + assert_eq!(lexer.tokens[31].kind, TokenKind::Keyword(Keyword::While)); + assert_eq!(lexer.tokens[32].kind, TokenKind::Keyword(Keyword::With)); + assert_eq!(lexer.tokens[33].kind, TokenKind::Keyword(Keyword::Yield)); } #[test] @@ -329,13 +287,13 @@ fn check_variable_definition_tokens() { let s = "let a = 'hello';"; let mut lexer = Lexer::new(s); lexer.lex().expect("failed to lex"); - assert_eq!(lexer.tokens[0].kind(), &TokenKind::Keyword(Keyword::Let)); - assert_eq!(lexer.tokens[1].kind(), &TokenKind::identifier("a")); + assert_eq!(lexer.tokens[0].kind, TokenKind::Keyword(Keyword::Let)); + assert_eq!(lexer.tokens[1].kind, TokenKind::identifier("a")); assert_eq!( - lexer.tokens[2].kind(), - &TokenKind::Punctuator(Punctuator::Assign) + lexer.tokens[2].kind, + TokenKind::Punctuator(Punctuator::Assign) ); - assert_eq!(lexer.tokens[3].kind(), &TokenKind::string_literal("hello")); + assert_eq!(lexer.tokens[3].kind, TokenKind::string_literal("hello")); } #[test] @@ -397,15 +355,12 @@ fn check_decrement_advances_lexer_2_places() { let s = "let a = b--;"; let mut lexer = Lexer::new(s); lexer.lex().expect("failed to lex"); - assert_eq!( - lexer.tokens[4].kind(), - &TokenKind::Punctuator(Punctuator::Dec) - ); + assert_eq!(lexer.tokens[4].kind, TokenKind::Punctuator(Punctuator::Dec)); // Decrementing means adding 2 characters '--', the lexer should consume it as a single token // and move the curser forward by 2, meaning the next token should be a semicolon assert_eq!( - lexer.tokens[5].kind(), - &TokenKind::Punctuator(Punctuator::Semicolon) + lexer.tokens[5].kind, + TokenKind::Punctuator(Punctuator::Semicolon) ); } @@ -416,24 +371,24 @@ fn numbers() { ); lexer.lex().expect("failed to lex"); - assert_eq!(lexer.tokens[0].kind(), &TokenKind::numeric_literal(1)); - assert_eq!(lexer.tokens[1].kind(), &TokenKind::numeric_literal(2)); - assert_eq!(lexer.tokens[2].kind(), &TokenKind::numeric_literal(52)); - assert_eq!(lexer.tokens[3].kind(), &TokenKind::numeric_literal(46)); - assert_eq!(lexer.tokens[4].kind(), &TokenKind::numeric_literal(7.89)); - assert_eq!(lexer.tokens[5].kind(), &TokenKind::numeric_literal(42.0)); - assert_eq!(lexer.tokens[6].kind(), &TokenKind::numeric_literal(5000.0)); - assert_eq!(lexer.tokens[7].kind(), &TokenKind::numeric_literal(5000.0)); - assert_eq!(lexer.tokens[8].kind(), &TokenKind::numeric_literal(0.005)); - assert_eq!(lexer.tokens[9].kind(), &TokenKind::numeric_literal(2)); - assert_eq!(lexer.tokens[10].kind(), &TokenKind::numeric_literal(83)); - assert_eq!(lexer.tokens[11].kind(), &TokenKind::numeric_literal(999)); - assert_eq!(lexer.tokens[12].kind(), &TokenKind::numeric_literal(10.0)); - assert_eq!(lexer.tokens[13].kind(), &TokenKind::numeric_literal(0.1)); - assert_eq!(lexer.tokens[14].kind(), &TokenKind::numeric_literal(10.0)); - assert_eq!(lexer.tokens[15].kind(), &TokenKind::numeric_literal(10.0)); - assert_eq!(lexer.tokens[16].kind(), &TokenKind::numeric_literal(0.0)); - assert_eq!(lexer.tokens[17].kind(), &TokenKind::numeric_literal(0.12)); + assert_eq!(lexer.tokens[0].kind, TokenKind::numeric_literal(1)); + assert_eq!(lexer.tokens[1].kind, TokenKind::numeric_literal(2)); + assert_eq!(lexer.tokens[2].kind, TokenKind::numeric_literal(52)); + assert_eq!(lexer.tokens[3].kind, TokenKind::numeric_literal(46)); + assert_eq!(lexer.tokens[4].kind, TokenKind::numeric_literal(7.89)); + assert_eq!(lexer.tokens[5].kind, TokenKind::numeric_literal(42.0)); + assert_eq!(lexer.tokens[6].kind, TokenKind::numeric_literal(5000.0)); + assert_eq!(lexer.tokens[7].kind, TokenKind::numeric_literal(5000.0)); + assert_eq!(lexer.tokens[8].kind, TokenKind::numeric_literal(0.005)); + assert_eq!(lexer.tokens[9].kind, TokenKind::numeric_literal(2)); + assert_eq!(lexer.tokens[10].kind, TokenKind::numeric_literal(83)); + assert_eq!(lexer.tokens[11].kind, TokenKind::numeric_literal(999)); + assert_eq!(lexer.tokens[12].kind, TokenKind::numeric_literal(10.0)); + assert_eq!(lexer.tokens[13].kind, TokenKind::numeric_literal(0.1)); + assert_eq!(lexer.tokens[14].kind, TokenKind::numeric_literal(10.0)); + assert_eq!(lexer.tokens[15].kind, TokenKind::numeric_literal(10.0)); + assert_eq!(lexer.tokens[16].kind, TokenKind::numeric_literal(0.0)); + assert_eq!(lexer.tokens[17].kind, TokenKind::numeric_literal(0.12)); } #[test] @@ -441,14 +396,11 @@ fn implicit_octal_edge_case() { let mut lexer = Lexer::new("044.5 094.5"); lexer.lex().expect("failed to lex"); - assert_eq!(lexer.tokens[0].kind(), &TokenKind::numeric_literal(36)); - assert_eq!( - lexer.tokens[1].kind(), - &TokenKind::Punctuator(Punctuator::Dot) - ); - assert_eq!(lexer.tokens[2].kind(), &TokenKind::numeric_literal(5)); + assert_eq!(lexer.tokens[0].kind, TokenKind::numeric_literal(36)); + assert_eq!(lexer.tokens[1].kind, TokenKind::Punctuator(Punctuator::Dot)); + assert_eq!(lexer.tokens[2].kind, TokenKind::numeric_literal(5)); - assert_eq!(lexer.tokens[3].kind(), &TokenKind::numeric_literal(94.5)); + assert_eq!(lexer.tokens[3].kind, TokenKind::numeric_literal(94.5)); } #[test] @@ -456,19 +408,16 @@ fn hexadecimal_edge_case() { let mut lexer = Lexer::new("0xffff.ff 0xffffff"); lexer.lex().expect("failed to lex"); - assert_eq!(lexer.tokens[0].kind(), &TokenKind::numeric_literal(0xffff)); - assert_eq!( - lexer.tokens[1].kind(), - &TokenKind::Punctuator(Punctuator::Dot) - ); + assert_eq!(lexer.tokens[0].kind, TokenKind::numeric_literal(0xffff)); + assert_eq!(lexer.tokens[1].kind, TokenKind::Punctuator(Punctuator::Dot)); assert_eq!( - lexer.tokens[2].kind(), - &TokenKind::Identifier(String::from("ff")) + lexer.tokens[2].kind, + TokenKind::Identifier(String::from("ff")) ); assert_eq!( - lexer.tokens[3].kind(), - &TokenKind::numeric_literal(0x00ff_ffff) + lexer.tokens[3].kind, + TokenKind::numeric_literal(0x00ff_ffff) ); } @@ -482,11 +431,8 @@ fn single_number_without_semicolon() { fn number_followed_by_dot() { let mut lexer = Lexer::new("1.."); lexer.lex().expect("failed to lex"); - assert_eq!(lexer.tokens[0].kind(), &TokenKind::numeric_literal(1.0)); - assert_eq!( - lexer.tokens[1].kind(), - &TokenKind::Punctuator(Punctuator::Dot) - ); + assert_eq!(lexer.tokens[0].kind, TokenKind::numeric_literal(1.0)); + assert_eq!(lexer.tokens[1].kind, TokenKind::Punctuator(Punctuator::Dot)); } #[test] @@ -494,8 +440,8 @@ fn regex_literal() { let mut lexer = Lexer::new("/(?:)/"); lexer.lex().expect("failed to lex"); assert_eq!( - lexer.tokens[0].kind(), - &TokenKind::regular_expression_literal("(?:)", "") + lexer.tokens[0].kind, + TokenKind::regular_expression_literal("(?:)", "") ); } @@ -504,8 +450,8 @@ fn regex_literal_flags() { let mut lexer = Lexer::new(r"/\/[^\/]*\/*/gmi"); lexer.lex().expect("failed to lex"); assert_eq!( - lexer.tokens[0].kind(), - &TokenKind::regular_expression_literal("\\/[^\\/]*\\/*", "gmi") + lexer.tokens[0].kind, + TokenKind::regular_expression_literal("\\/[^\\/]*\\/*", "gmi") ); } @@ -513,73 +459,55 @@ fn regex_literal_flags() { fn addition_no_spaces() { let mut lexer = Lexer::new("1+1"); lexer.lex().expect("failed to lex"); - assert_eq!(lexer.tokens[0].kind(), &TokenKind::numeric_literal(1)); - assert_eq!( - lexer.tokens[1].kind(), - &TokenKind::Punctuator(Punctuator::Add) - ); - assert_eq!(lexer.tokens[2].kind(), &TokenKind::numeric_literal(1)); + assert_eq!(lexer.tokens[0].kind, TokenKind::numeric_literal(1)); + assert_eq!(lexer.tokens[1].kind, TokenKind::Punctuator(Punctuator::Add)); + assert_eq!(lexer.tokens[2].kind, TokenKind::numeric_literal(1)); } #[test] fn addition_no_spaces_left_side() { let mut lexer = Lexer::new("1+ 1"); lexer.lex().expect("failed to lex"); - assert_eq!(lexer.tokens[0].kind(), &TokenKind::numeric_literal(1)); - assert_eq!( - lexer.tokens[1].kind(), - &TokenKind::Punctuator(Punctuator::Add) - ); - assert_eq!(lexer.tokens[2].kind(), &TokenKind::numeric_literal(1)); + assert_eq!(lexer.tokens[0].kind, TokenKind::numeric_literal(1)); + assert_eq!(lexer.tokens[1].kind, TokenKind::Punctuator(Punctuator::Add)); + assert_eq!(lexer.tokens[2].kind, TokenKind::numeric_literal(1)); } #[test] fn addition_no_spaces_right_side() { let mut lexer = Lexer::new("1 +1"); lexer.lex().expect("failed to lex"); - assert_eq!(lexer.tokens[0].kind(), &TokenKind::numeric_literal(1)); - assert_eq!( - lexer.tokens[1].kind(), - &TokenKind::Punctuator(Punctuator::Add) - ); - assert_eq!(lexer.tokens[2].kind(), &TokenKind::numeric_literal(1)); + assert_eq!(lexer.tokens[0].kind, TokenKind::numeric_literal(1)); + assert_eq!(lexer.tokens[1].kind, TokenKind::Punctuator(Punctuator::Add)); + assert_eq!(lexer.tokens[2].kind, TokenKind::numeric_literal(1)); } #[test] fn addition_no_spaces_e_number_left_side() { let mut lexer = Lexer::new("1e2+ 1"); lexer.lex().expect("failed to lex"); - assert_eq!(lexer.tokens[0].kind(), &TokenKind::numeric_literal(100.0)); - assert_eq!( - lexer.tokens[1].kind(), - &TokenKind::Punctuator(Punctuator::Add) - ); - assert_eq!(lexer.tokens[2].kind(), &TokenKind::numeric_literal(1)); + assert_eq!(lexer.tokens[0].kind, TokenKind::numeric_literal(100.0)); + assert_eq!(lexer.tokens[1].kind, TokenKind::Punctuator(Punctuator::Add)); + assert_eq!(lexer.tokens[2].kind, TokenKind::numeric_literal(1)); } #[test] fn addition_no_spaces_e_number_right_side() { let mut lexer = Lexer::new("1 +1e3"); lexer.lex().expect("failed to lex"); - assert_eq!(lexer.tokens[0].kind(), &TokenKind::numeric_literal(1)); - assert_eq!( - lexer.tokens[1].kind(), - &TokenKind::Punctuator(Punctuator::Add) - ); - assert_eq!(lexer.tokens[2].kind(), &TokenKind::numeric_literal(1000.0)); + assert_eq!(lexer.tokens[0].kind, TokenKind::numeric_literal(1)); + assert_eq!(lexer.tokens[1].kind, TokenKind::Punctuator(Punctuator::Add)); + assert_eq!(lexer.tokens[2].kind, TokenKind::numeric_literal(1000.0)); } #[test] fn addition_no_spaces_e_number() { let mut lexer = Lexer::new("1e3+1e11"); lexer.lex().expect("failed to lex"); - assert_eq!(lexer.tokens[0].kind(), &TokenKind::numeric_literal(1000.0)); - assert_eq!( - lexer.tokens[1].kind(), - &TokenKind::Punctuator(Punctuator::Add) - ); + assert_eq!(lexer.tokens[0].kind, TokenKind::numeric_literal(1000.0)); + assert_eq!(lexer.tokens[1].kind, TokenKind::Punctuator(Punctuator::Add)); assert_eq!( - lexer.tokens[2].kind(), - &TokenKind::numeric_literal(100_000_000_000.0) + lexer.tokens[2].kind, + TokenKind::numeric_literal(100_000_000_000.0) ); } diff --git a/boa/src/syntax/parser/cursor.rs b/boa/src/syntax/parser/cursor.rs index 82686b675d6..69b116ce3e4 100644 --- a/boa/src/syntax/parser/cursor.rs +++ b/boa/src/syntax/parser/cursor.rs @@ -45,7 +45,7 @@ impl<'a> Cursor<'a> { if let Some(tk) = token { self.pos += 1; - if tk.kind() != &TokenKind::LineTerminator { + if tk.kind != TokenKind::LineTerminator { break Some(tk); } } else { @@ -63,7 +63,7 @@ impl<'a> Cursor<'a> { count += 1; if let Some(tk) = token { - if tk.kind() != &TokenKind::LineTerminator { + if tk.kind != TokenKind::LineTerminator { if skipped == skip { break Some(tk); } @@ -88,8 +88,8 @@ impl<'a> Cursor<'a> { .tokens .get(self.pos - 1) .expect("token disappeared") - .kind() - == &TokenKind::LineTerminator + .kind + == TokenKind::LineTerminator && self.pos > 0 { self.pos -= 1; @@ -103,7 +103,7 @@ impl<'a> Cursor<'a> { } else { let mut back = 1; let mut tok = self.tokens.get(self.pos - back).expect("token disappeared"); - while self.pos >= back && tok.kind() == &TokenKind::LineTerminator { + while self.pos >= back && tok.kind == TokenKind::LineTerminator { back += 1; tok = self.tokens.get(self.pos - back).expect("token disappeared"); } @@ -126,7 +126,7 @@ impl<'a> Cursor<'a> { let next_token = self.next().ok_or(ParseError::AbruptEnd)?; let kind = kind.into(); - if next_token.kind() == &kind { + if next_token.kind == kind { Ok(()) } else { Err(ParseError::expected( @@ -144,7 +144,7 @@ impl<'a> Cursor<'a> { /// [spec]: https://tc39.es/ecma262/#sec-automatic-semicolon-insertion pub(super) fn peek_semicolon(&self, do_while: bool) -> (bool, Option<&Token>) { match self.tokens.get(self.pos) { - Some(tk) => match *tk.kind() { + Some(tk) => match tk.kind { TokenKind::Punctuator(Punctuator::Semicolon) => (true, Some(tk)), TokenKind::LineTerminator | TokenKind::Punctuator(Punctuator::CloseBlock) => { (true, Some(tk)) @@ -160,7 +160,7 @@ impl<'a> Cursor<'a> { .tokens .get(self.pos - 1) .expect("could not find previous token"); - if tok.kind() == &TokenKind::Punctuator(Punctuator::CloseParen) { + if tok.kind == TokenKind::Punctuator(Punctuator::CloseParen) { return (true, Some(tk)); } } @@ -183,7 +183,7 @@ impl<'a> Cursor<'a> { context: &'static str, ) -> Result<(), ParseError> { match self.peek_semicolon(do_while) { - (true, Some(tk)) => match *tk.kind() { + (true, Some(tk)) => match tk.kind { TokenKind::Punctuator(Punctuator::Semicolon) | TokenKind::LineTerminator => { self.pos += 1; Ok(()) @@ -210,11 +210,11 @@ impl<'a> Cursor<'a> { let token = self.tokens.get(self.pos + count); count += 1; if let Some(tk) = token { - if skipped == skip && tk.kind() == &TokenKind::LineTerminator { + if skipped == skip && tk.kind == TokenKind::LineTerminator { break Err(ParseError::unexpected(tk.clone(), None)); - } else if skipped == skip && tk.kind() != &TokenKind::LineTerminator { + } else if skipped == skip && tk.kind != TokenKind::LineTerminator { break Ok(()); - } else if tk.kind() != &TokenKind::LineTerminator { + } else if tk.kind != TokenKind::LineTerminator { skipped += 1; } } else { @@ -233,7 +233,7 @@ impl<'a> Cursor<'a> { { let next_token = self.peek(0)?; - if next_token.kind() == &kind.into() { + if next_token.kind == kind.into() { self.next() } else { None diff --git a/boa/src/syntax/parser/expression/assignment/arrow_function.rs b/boa/src/syntax/parser/expression/assignment/arrow_function.rs index aa59abb6a93..ccab9a104bc 100644 --- a/boa/src/syntax/parser/expression/assignment/arrow_function.rs +++ b/boa/src/syntax/parser/expression/assignment/arrow_function.rs @@ -61,7 +61,7 @@ impl TokenParser for ArrowFunction { fn parse(self, cursor: &mut Cursor<'_>) -> Result { let next_token = cursor.peek(0).ok_or(ParseError::AbruptEnd)?; - let params = if let TokenKind::Punctuator(Punctuator::OpenParen) = &next_token.kind() { + let params = if let TokenKind::Punctuator(Punctuator::OpenParen) = &next_token.kind { // CoverParenthesizedExpressionAndArrowParameterList cursor.expect(Punctuator::OpenParen, "arrow function")?; let params = FormalParameters::new(self.allow_yield, self.allow_await).parse(cursor)?; @@ -106,7 +106,7 @@ impl TokenParser for ConciseBody { type Output = StatementList; fn parse(self, cursor: &mut Cursor<'_>) -> Result { - match cursor.peek(0).ok_or(ParseError::AbruptEnd)?.kind() { + match cursor.peek(0).ok_or(ParseError::AbruptEnd)?.kind { TokenKind::Punctuator(Punctuator::OpenBlock) => { let _ = cursor.next(); let body = FunctionBody::new(false, false).parse(cursor)?; diff --git a/boa/src/syntax/parser/expression/assignment/conditional.rs b/boa/src/syntax/parser/expression/assignment/conditional.rs index b55d063c273..2bea95cc9bb 100644 --- a/boa/src/syntax/parser/expression/assignment/conditional.rs +++ b/boa/src/syntax/parser/expression/assignment/conditional.rs @@ -59,7 +59,7 @@ impl TokenParser for ConditionalExpression { .parse(cursor)?; if let Some(tok) = cursor.next() { - if tok.kind() == &TokenKind::Punctuator(Punctuator::Question) { + if tok.kind == TokenKind::Punctuator(Punctuator::Question) { let then_clause = AssignmentExpression::new(self.allow_in, self.allow_yield, self.allow_await) .parse(cursor)?; diff --git a/boa/src/syntax/parser/expression/assignment/exponentiation.rs b/boa/src/syntax/parser/expression/assignment/exponentiation.rs index 78a5f9a4b8f..f21b96e99ce 100644 --- a/boa/src/syntax/parser/expression/assignment/exponentiation.rs +++ b/boa/src/syntax/parser/expression/assignment/exponentiation.rs @@ -51,7 +51,7 @@ impl ExponentiationExpression { /// Checks by looking at the next token to see whether it's a unary operator or not. fn is_unary_expression(cursor: &mut Cursor<'_>) -> bool { if let Some(tok) = cursor.peek(0) { - match tok.kind() { + match tok.kind { TokenKind::Keyword(Keyword::Delete) | TokenKind::Keyword(Keyword::Void) | TokenKind::Keyword(Keyword::TypeOf) @@ -77,7 +77,7 @@ impl TokenParser for ExponentiationExpression { let lhs = UpdateExpression::new(self.allow_yield, self.allow_await).parse(cursor)?; if let Some(tok) = cursor.next() { - if let TokenKind::Punctuator(Punctuator::Exp) = tok.kind() { + if let TokenKind::Punctuator(Punctuator::Exp) = tok.kind { return Ok(Node::from(BinOp::new(NumOp::Exp, lhs, self.parse(cursor)?))); } else { cursor.back(); diff --git a/boa/src/syntax/parser/expression/assignment/mod.rs b/boa/src/syntax/parser/expression/assignment/mod.rs index d67330a7464..65a5ee7fd03 100644 --- a/boa/src/syntax/parser/expression/assignment/mod.rs +++ b/boa/src/syntax/parser/expression/assignment/mod.rs @@ -72,7 +72,7 @@ impl TokenParser for AssignmentExpression { fn parse(self, cursor: &mut Cursor<'_>) -> ParseResult { // Arrow function let next_token = cursor.peek(0).ok_or(ParseError::AbruptEnd)?; - match next_token.kind() { + match next_token.kind { // a=>{} TokenKind::Identifier(_) | TokenKind::Keyword(Keyword::Yield) @@ -80,7 +80,7 @@ impl TokenParser for AssignmentExpression { if cursor.peek_expect_no_lineterminator(1).is_ok() => { if let Some(tok) = cursor.peek(1) { - if tok.kind() == &TokenKind::Punctuator(Punctuator::Arrow) { + if tok.kind == TokenKind::Punctuator(Punctuator::Arrow) { return ArrowFunction::new( self.allow_in, self.allow_yield, @@ -108,7 +108,7 @@ impl TokenParser for AssignmentExpression { .parse(cursor)?; if let Some(tok) = cursor.next() { - match tok.kind() { + match tok.kind { TokenKind::Punctuator(Punctuator::Assign) => { lhs = Node::from(Assign::new(lhs, self.parse(cursor)?)); } diff --git a/boa/src/syntax/parser/expression/left_hand_side/arguments.rs b/boa/src/syntax/parser/expression/left_hand_side/arguments.rs index 87653787935..a5caf3a9383 100644 --- a/boa/src/syntax/parser/expression/left_hand_side/arguments.rs +++ b/boa/src/syntax/parser/expression/left_hand_side/arguments.rs @@ -50,7 +50,7 @@ impl TokenParser for Arguments { let mut args = Vec::new(); loop { let next_token = cursor.next().ok_or(ParseError::AbruptEnd)?; - match next_token.kind() { + match next_token.kind { TokenKind::Punctuator(Punctuator::CloseParen) => break, TokenKind::Punctuator(Punctuator::Comma) => { if args.is_empty() { diff --git a/boa/src/syntax/parser/expression/left_hand_side/call.rs b/boa/src/syntax/parser/expression/left_hand_side/call.rs index 8691a55fb6b..2af767c23aa 100644 --- a/boa/src/syntax/parser/expression/left_hand_side/call.rs +++ b/boa/src/syntax/parser/expression/left_hand_side/call.rs @@ -49,7 +49,7 @@ impl TokenParser for CallExpression { fn parse(self, cursor: &mut Cursor<'_>) -> ParseResult { let mut lhs = match cursor.peek(0) { - Some(tk) if tk.kind() == &TokenKind::Punctuator(Punctuator::OpenParen) => { + Some(tk) if tk.kind == TokenKind::Punctuator(Punctuator::OpenParen) => { let args = Arguments::new(self.allow_yield, self.allow_await).parse(cursor)?; Node::call(self.first_member_expr, args) } @@ -64,14 +64,14 @@ impl TokenParser for CallExpression { }; while let Some(tok) = cursor.peek(0) { - match tok.kind() { + match tok.kind { TokenKind::Punctuator(Punctuator::OpenParen) => { let args = Arguments::new(self.allow_yield, self.allow_await).parse(cursor)?; lhs = Node::call(lhs, args); } TokenKind::Punctuator(Punctuator::Dot) => { let _ = cursor.next().ok_or(ParseError::AbruptEnd)?; // We move the cursor. - match &cursor.next().ok_or(ParseError::AbruptEnd)?.kind() { + match &cursor.next().ok_or(ParseError::AbruptEnd)?.kind { TokenKind::Identifier(name) => { lhs = Node::get_const_field(lhs, name.clone().into_boxed_str()); } diff --git a/boa/src/syntax/parser/expression/left_hand_side/member.rs b/boa/src/syntax/parser/expression/left_hand_side/member.rs index 6bf088c7312..22c4fa3cb68 100644 --- a/boa/src/syntax/parser/expression/left_hand_side/member.rs +++ b/boa/src/syntax/parser/expression/left_hand_side/member.rs @@ -44,8 +44,8 @@ impl TokenParser for MemberExpression { type Output = Node; fn parse(self, cursor: &mut Cursor<'_>) -> ParseResult { - let mut lhs = if cursor.peek(0).ok_or(ParseError::AbruptEnd)?.kind() - == &TokenKind::Keyword(Keyword::New) + let mut lhs = if cursor.peek(0).ok_or(ParseError::AbruptEnd)?.kind + == TokenKind::Keyword(Keyword::New) { let _ = cursor.next().expect("keyword disappeared"); let lhs = self.parse(cursor)?; @@ -57,10 +57,10 @@ impl TokenParser for MemberExpression { PrimaryExpression::new(self.allow_yield, self.allow_await).parse(cursor)? }; while let Some(tok) = cursor.peek(0) { - match &tok.kind() { + match &tok.kind { TokenKind::Punctuator(Punctuator::Dot) => { let _ = cursor.next().ok_or(ParseError::AbruptEnd)?; // We move the cursor forward. - match &cursor.next().ok_or(ParseError::AbruptEnd)?.kind() { + match &cursor.next().ok_or(ParseError::AbruptEnd)?.kind { TokenKind::Identifier(name) => { lhs = Node::get_const_field(lhs, name.clone().into_boxed_str()) } diff --git a/boa/src/syntax/parser/expression/left_hand_side/mod.rs b/boa/src/syntax/parser/expression/left_hand_side/mod.rs index 461ed9b6c13..737dfdbe85c 100644 --- a/boa/src/syntax/parser/expression/left_hand_side/mod.rs +++ b/boa/src/syntax/parser/expression/left_hand_side/mod.rs @@ -52,7 +52,7 @@ impl TokenParser for LeftHandSideExpression { // TODO: Implement NewExpression: new MemberExpression let lhs = MemberExpression::new(self.allow_yield, self.allow_await).parse(cursor)?; match cursor.peek(0) { - Some(ref tok) if tok.kind() == &TokenKind::Punctuator(Punctuator::OpenParen) => { + Some(ref tok) if tok.kind == TokenKind::Punctuator(Punctuator::OpenParen) => { CallExpression::new(self.allow_yield, self.allow_await, lhs).parse(cursor) } _ => Ok(lhs), // TODO: is this correct? diff --git a/boa/src/syntax/parser/expression/mod.rs b/boa/src/syntax/parser/expression/mod.rs index f3a4d777536..c68c7c28e5e 100644 --- a/boa/src/syntax/parser/expression/mod.rs +++ b/boa/src/syntax/parser/expression/mod.rs @@ -53,8 +53,8 @@ macro_rules! expression { ($name:ident, $lower:ident, [$( $op:path ),*], [$( $lo fn parse(self, cursor: &mut Cursor<'_>) -> ParseResult { let mut lhs = $lower::new($( self.$low_param ),*).parse(cursor)?; while let Some(tok) = cursor.peek(0) { - match tok.kind() { - TokenKind::Punctuator(op) if $( *op == $op )||* => { + match tok.kind { + TokenKind::Punctuator(op) if $( op == $op )||* => { let _ = cursor.next().expect("token disappeared"); lhs = Node::from(BinOp::new( op.as_binop().expect("Could not get binary operation."), @@ -62,7 +62,7 @@ macro_rules! expression { ($name:ident, $lower:ident, [$( $op:path ),*], [$( $lo $lower::new($( self.$low_param ),*).parse(cursor)? )); } - TokenKind::Keyword(op) if $( *op == $op )||* => { + TokenKind::Keyword(op) if $( op == $op )||* => { let _ = cursor.next().expect("token disappeared"); lhs = Node::from(BinOp::new( op.as_binop().expect("Could not get binary operation."), diff --git a/boa/src/syntax/parser/expression/primary/mod.rs b/boa/src/syntax/parser/expression/primary/mod.rs index 505228d14a1..6f4a50bbe81 100644 --- a/boa/src/syntax/parser/expression/primary/mod.rs +++ b/boa/src/syntax/parser/expression/primary/mod.rs @@ -63,7 +63,7 @@ impl TokenParser for PrimaryExpression { fn parse(self, cursor: &mut Cursor<'_>) -> ParseResult { let tok = cursor.next().ok_or(ParseError::AbruptEnd)?; - match &tok.kind() { + match &tok.kind { TokenKind::Keyword(Keyword::This) => Ok(Node::This), // TokenKind::Keyword(Keyword::Arguments) => Ok(Node::new(NodeBase::Arguments, tok.pos)), TokenKind::Keyword(Keyword::Function) => { diff --git a/boa/src/syntax/parser/expression/unary.rs b/boa/src/syntax/parser/expression/unary.rs index ffd24c2fa7e..76abd183678 100644 --- a/boa/src/syntax/parser/expression/unary.rs +++ b/boa/src/syntax/parser/expression/unary.rs @@ -48,7 +48,7 @@ impl TokenParser for UnaryExpression { fn parse(self, cursor: &mut Cursor<'_>) -> ParseResult { let tok = cursor.next().ok_or(ParseError::AbruptEnd)?; - match tok.kind() { + match tok.kind { TokenKind::Keyword(Keyword::Delete) => { Ok(Node::unary_op(UnaryOp::Delete, self.parse(cursor)?)) } diff --git a/boa/src/syntax/parser/expression/update.rs b/boa/src/syntax/parser/expression/update.rs index 1ed38e62e17..67eabf73231 100644 --- a/boa/src/syntax/parser/expression/update.rs +++ b/boa/src/syntax/parser/expression/update.rs @@ -42,7 +42,7 @@ impl TokenParser for UpdateExpression { fn parse(self, cursor: &mut Cursor<'_>) -> ParseResult { let tok = cursor.peek(0).ok_or(ParseError::AbruptEnd)?; - match tok.kind() { + match tok.kind { TokenKind::Punctuator(Punctuator::Inc) => { cursor.next().expect("token disappeared"); return Ok(Node::unary_op( @@ -64,7 +64,7 @@ impl TokenParser for UpdateExpression { let lhs = LeftHandSideExpression::new(self.allow_yield, self.allow_await).parse(cursor)?; if let Some(tok) = cursor.peek(0) { - match tok.kind() { + match tok.kind { TokenKind::Punctuator(Punctuator::Inc) => { cursor.next().expect("token disappeared"); return Ok(Node::unary_op(UnaryOp::IncrementPost, lhs)); diff --git a/boa/src/syntax/parser/function/mod.rs b/boa/src/syntax/parser/function/mod.rs index 27b0c024ad4..6005404ec4e 100644 --- a/boa/src/syntax/parser/function/mod.rs +++ b/boa/src/syntax/parser/function/mod.rs @@ -56,8 +56,8 @@ impl TokenParser for FormalParameters { fn parse(self, cursor: &mut Cursor<'_>) -> Result { let mut params = Vec::new(); - if cursor.peek(0).ok_or(ParseError::AbruptEnd)?.kind() - == &TokenKind::Punctuator(Punctuator::CloseParen) + if cursor.peek(0).ok_or(ParseError::AbruptEnd)?.kind + == TokenKind::Punctuator(Punctuator::CloseParen) { return Ok(params.into_boxed_slice()); } @@ -72,8 +72,8 @@ impl TokenParser for FormalParameters { FormalParameter::new(self.allow_yield, self.allow_await).parse(cursor)? }); - if cursor.peek(0).ok_or(ParseError::AbruptEnd)?.kind() - == &TokenKind::Punctuator(Punctuator::CloseParen) + if cursor.peek(0).ok_or(ParseError::AbruptEnd)?.kind + == TokenKind::Punctuator(Punctuator::CloseParen) { break; } @@ -228,7 +228,7 @@ impl TokenParser for FunctionStatementList { fn parse(self, cursor: &mut Cursor<'_>) -> Result { if let Some(tk) = cursor.peek(0) { - if tk.kind() == &Punctuator::CloseBlock.into() { + if tk.kind == Punctuator::CloseBlock.into() { return Ok(Vec::new().into()); } } diff --git a/boa/src/syntax/parser/statement/block/mod.rs b/boa/src/syntax/parser/statement/block/mod.rs index 1717834b8b6..3db21706cb9 100644 --- a/boa/src/syntax/parser/statement/block/mod.rs +++ b/boa/src/syntax/parser/statement/block/mod.rs @@ -61,7 +61,7 @@ impl TokenParser for Block { fn parse(self, cursor: &mut Cursor<'_>) -> Result { cursor.expect(Punctuator::OpenBlock, "block")?; if let Some(tk) = cursor.peek(0) { - if tk.kind() == &TokenKind::Punctuator(Punctuator::CloseBlock) { + if tk.kind == TokenKind::Punctuator(Punctuator::CloseBlock) { cursor.next(); return Ok(node::Block::from(vec![])); } diff --git a/boa/src/syntax/parser/statement/break_stm/mod.rs b/boa/src/syntax/parser/statement/break_stm/mod.rs index 18aa1c8050d..d203097b059 100644 --- a/boa/src/syntax/parser/statement/break_stm/mod.rs +++ b/boa/src/syntax/parser/statement/break_stm/mod.rs @@ -52,7 +52,7 @@ impl TokenParser for BreakStatement { let label = if let (true, tok) = cursor.peek_semicolon(false) { match tok { - Some(tok) if tok.kind() == &TokenKind::Punctuator(Punctuator::Semicolon) => { + Some(tok) if tok.kind == TokenKind::Punctuator(Punctuator::Semicolon) => { let _ = cursor.next(); } _ => {} diff --git a/boa/src/syntax/parser/statement/continue_stm/mod.rs b/boa/src/syntax/parser/statement/continue_stm/mod.rs index 89414faa2e9..7da0b5414cb 100644 --- a/boa/src/syntax/parser/statement/continue_stm/mod.rs +++ b/boa/src/syntax/parser/statement/continue_stm/mod.rs @@ -52,7 +52,7 @@ impl TokenParser for ContinueStatement { let label = if let (true, tok) = cursor.peek_semicolon(false) { match tok { - Some(tok) if tok.kind() == &TokenKind::Punctuator(Punctuator::Semicolon) => { + Some(tok) if tok.kind == TokenKind::Punctuator(Punctuator::Semicolon) => { let _ = cursor.next(); } _ => {} diff --git a/boa/src/syntax/parser/statement/declaration/lexical.rs b/boa/src/syntax/parser/statement/declaration/lexical.rs index f8e37f9d8a2..16b0d0ba7d8 100644 --- a/boa/src/syntax/parser/statement/declaration/lexical.rs +++ b/boa/src/syntax/parser/statement/declaration/lexical.rs @@ -50,7 +50,7 @@ impl TokenParser for LexicalDeclaration { fn parse(self, cursor: &mut Cursor<'_>) -> ParseResult { let tok = cursor.next().ok_or(ParseError::AbruptEnd)?; - match tok.kind() { + match tok.kind { TokenKind::Keyword(Keyword::Const) => { BindingList::new(self.allow_in, self.allow_yield, self.allow_await, true) .parse(cursor) @@ -128,7 +128,7 @@ impl TokenParser for BindingList { match cursor.peek_semicolon(false) { (true, _) => break, - (false, Some(tk)) if tk.kind() == &TokenKind::Punctuator(Punctuator::Comma) => { + (false, Some(tk)) if tk.kind == TokenKind::Punctuator(Punctuator::Comma) => { let _ = cursor.next(); } _ => { diff --git a/boa/src/syntax/parser/statement/declaration/mod.rs b/boa/src/syntax/parser/statement/declaration/mod.rs index e7e9b463f2b..c8f44aee9f7 100644 --- a/boa/src/syntax/parser/statement/declaration/mod.rs +++ b/boa/src/syntax/parser/statement/declaration/mod.rs @@ -49,7 +49,7 @@ impl TokenParser for Declaration { fn parse(self, cursor: &mut Cursor<'_>) -> ParseResult { let tok = cursor.peek(0).ok_or(ParseError::AbruptEnd)?; - match tok.kind() { + match tok.kind { TokenKind::Keyword(Keyword::Function) => { HoistableDeclaration::new(self.allow_yield, self.allow_await, false).parse(cursor) } diff --git a/boa/src/syntax/parser/statement/if_stm/mod.rs b/boa/src/syntax/parser/statement/if_stm/mod.rs index 93ebcb934eb..e20840303f4 100644 --- a/boa/src/syntax/parser/statement/if_stm/mod.rs +++ b/boa/src/syntax/parser/statement/if_stm/mod.rs @@ -58,7 +58,7 @@ impl TokenParser for IfStatement { Statement::new(self.allow_yield, self.allow_await, self.allow_return).parse(cursor)?; let else_stm = match cursor.next() { - Some(else_tok) if else_tok.kind() == &TokenKind::Keyword(Keyword::Else) => Some( + Some(else_tok) if else_tok.kind == TokenKind::Keyword(Keyword::Else) => Some( Statement::new(self.allow_yield, self.allow_await, self.allow_return) .parse(cursor)?, ), diff --git a/boa/src/syntax/parser/statement/iteration/do_while_statement.rs b/boa/src/syntax/parser/statement/iteration/do_while_statement.rs index d650108f5ad..5b71869af4e 100644 --- a/boa/src/syntax/parser/statement/iteration/do_while_statement.rs +++ b/boa/src/syntax/parser/statement/iteration/do_while_statement.rs @@ -61,7 +61,7 @@ impl TokenParser for DoWhileStatement { let next_token = cursor.peek(0).ok_or(ParseError::AbruptEnd)?; - if next_token.kind() != &TokenKind::Keyword(Keyword::While) { + if next_token.kind != TokenKind::Keyword(Keyword::While) { return Err(ParseError::expected( vec![TokenKind::Keyword(Keyword::While)], next_token.clone(), diff --git a/boa/src/syntax/parser/statement/iteration/for_statement.rs b/boa/src/syntax/parser/statement/iteration/for_statement.rs index 1913f415443..bec25783cfa 100644 --- a/boa/src/syntax/parser/statement/iteration/for_statement.rs +++ b/boa/src/syntax/parser/statement/iteration/for_statement.rs @@ -62,7 +62,7 @@ impl TokenParser for ForStatement { cursor.expect(Keyword::For, "for statement")?; cursor.expect(Punctuator::OpenParen, "for statement")?; - let init = match cursor.peek(0).ok_or(ParseError::AbruptEnd)?.kind() { + let init = match cursor.peek(0).ok_or(ParseError::AbruptEnd)?.kind { TokenKind::Keyword(Keyword::Var) => Some( VariableDeclarationList::new(false, self.allow_yield, self.allow_await) .parse(cursor) diff --git a/boa/src/syntax/parser/statement/mod.rs b/boa/src/syntax/parser/statement/mod.rs index 61b527b75b5..503c1bbc19a 100644 --- a/boa/src/syntax/parser/statement/mod.rs +++ b/boa/src/syntax/parser/statement/mod.rs @@ -93,7 +93,7 @@ impl TokenParser for Statement { // TODO: add BreakableStatement and divide Whiles, fors and so on to another place. let tok = cursor.peek(0).ok_or(ParseError::AbruptEnd)?; - match tok.kind() { + match tok.kind { TokenKind::Keyword(Keyword::If) => { IfStatement::new(self.allow_yield, self.allow_await, self.allow_return) .parse(cursor) @@ -199,7 +199,7 @@ impl TokenParser for StatementList { loop { match cursor.peek(0) { - Some(token) if token.kind() == &TokenKind::Punctuator(Punctuator::CloseBlock) => { + Some(token) if token.kind == TokenKind::Punctuator(Punctuator::CloseBlock) => { if self.break_when_closingbrase { break; } else { @@ -270,7 +270,7 @@ impl TokenParser for StatementListItem { fn parse(self, cursor: &mut Cursor<'_>) -> ParseResult { let tok = cursor.peek(0).ok_or(ParseError::AbruptEnd)?; - match tok.kind() { + match tok.kind { TokenKind::Keyword(Keyword::Function) | TokenKind::Keyword(Keyword::Const) | TokenKind::Keyword(Keyword::Let) => { @@ -366,7 +366,7 @@ impl TokenParser for BindingIdentifier { let next_token = cursor.next().ok_or(ParseError::AbruptEnd)?; - match next_token.kind() { + match next_token.kind { TokenKind::Identifier(ref s) => Ok(s.as_str().into()), TokenKind::Keyword(k @ Keyword::Yield) if !self.allow_yield.0 => Ok(k.as_str().into()), TokenKind::Keyword(k @ Keyword::Await) if !self.allow_await.0 => Ok(k.as_str().into()), diff --git a/boa/src/syntax/parser/statement/return_stm/mod.rs b/boa/src/syntax/parser/statement/return_stm/mod.rs index e2167515c37..096b3be17ae 100644 --- a/boa/src/syntax/parser/statement/return_stm/mod.rs +++ b/boa/src/syntax/parser/statement/return_stm/mod.rs @@ -43,8 +43,8 @@ impl TokenParser for ReturnStatement { if let (true, tok) = cursor.peek_semicolon(false) { match tok { Some(tok) - if tok.kind() == &TokenKind::Punctuator(Punctuator::Semicolon) - || tok.kind() == &TokenKind::LineTerminator => + if tok.kind == TokenKind::Punctuator(Punctuator::Semicolon) + || tok.kind == TokenKind::LineTerminator => { let _ = cursor.next(); } diff --git a/boa/src/syntax/parser/statement/throw/mod.rs b/boa/src/syntax/parser/statement/throw/mod.rs index 7430818a283..4d788424e7e 100644 --- a/boa/src/syntax/parser/statement/throw/mod.rs +++ b/boa/src/syntax/parser/statement/throw/mod.rs @@ -44,7 +44,7 @@ impl TokenParser for ThrowStatement { let expr = Expression::new(true, self.allow_yield, self.allow_await).parse(cursor)?; if let Some(tok) = cursor.peek(0) { - if tok.kind() == &TokenKind::Punctuator(Punctuator::Semicolon) { + if tok.kind == TokenKind::Punctuator(Punctuator::Semicolon) { let _ = cursor.next(); } } diff --git a/boa/src/syntax/parser/statement/try_stm/mod.rs b/boa/src/syntax/parser/statement/try_stm/mod.rs index 79020cb09d0..5bb18e95242 100644 --- a/boa/src/syntax/parser/statement/try_stm/mod.rs +++ b/boa/src/syntax/parser/statement/try_stm/mod.rs @@ -55,8 +55,8 @@ impl TokenParser for TryStatement { let next_token = cursor.peek(0).ok_or(ParseError::AbruptEnd)?; - if next_token.kind() != &TokenKind::Keyword(Keyword::Catch) - && next_token.kind() != &TokenKind::Keyword(Keyword::Finally) + if next_token.kind != TokenKind::Keyword(Keyword::Catch) + && next_token.kind != TokenKind::Keyword(Keyword::Finally) { return Err(ParseError::expected( vec![ @@ -68,7 +68,7 @@ impl TokenParser for TryStatement { )); } - let catch = if next_token.kind() == &TokenKind::Keyword(Keyword::Catch) { + let catch = if next_token.kind == TokenKind::Keyword(Keyword::Catch) { Some(Catch::new(self.allow_yield, self.allow_await, self.allow_return).parse(cursor)?) } else { None @@ -76,7 +76,7 @@ impl TokenParser for TryStatement { let next_token = cursor.peek(0); let finally_block = match next_token { - Some(token) => match token.kind() { + Some(token) => match token.kind { TokenKind::Keyword(Keyword::Finally) => Some( Finally::new(self.allow_yield, self.allow_await, self.allow_return) .parse(cursor)?, diff --git a/boa/src/syntax/parser/statement/variable.rs b/boa/src/syntax/parser/statement/variable.rs index ae34e2b9af2..a5f750140d9 100644 --- a/boa/src/syntax/parser/statement/variable.rs +++ b/boa/src/syntax/parser/statement/variable.rs @@ -104,7 +104,7 @@ impl TokenParser for VariableDeclarationList { match cursor.peek_semicolon(false) { (true, _) => break, - (false, Some(tk)) if tk.kind() == &TokenKind::Punctuator(Punctuator::Comma) => { + (false, Some(tk)) if tk.kind == TokenKind::Punctuator(Punctuator::Comma) => { let _ = cursor.next(); } _ => {