Browse Source

Rename `check_parser` and `Identifier` (#2576)

Extracted from #2411 to reduce its size a bit.

This PR:
- Renames `Identifier` to `IdentifierName`, which is the name stated in the spec.
- Renames the utility function `check_parser` to `check_script_parser` to prepare for modules.
- Adds some missing `#[inline]` and rewrites some patterns.
pull/2577/head
José Julián Espina 2 years ago
parent
commit
5a201daa98
  1. 9
      boa_parser/src/lexer/error.rs
  2. 2
      boa_parser/src/lexer/identifier.rs
  3. 6
      boa_parser/src/lexer/tests.rs
  4. 42
      boa_parser/src/lexer/token.rs
  5. 5
      boa_parser/src/parser/expression/assignment/mod.rs
  6. 2
      boa_parser/src/parser/expression/assignment/yield.rs
  7. 20
      boa_parser/src/parser/expression/identifiers.rs
  8. 2
      boa_parser/src/parser/expression/left_hand_side/call.rs
  9. 8
      boa_parser/src/parser/expression/left_hand_side/member.rs
  10. 6
      boa_parser/src/parser/expression/left_hand_side/optional/mod.rs
  11. 6
      boa_parser/src/parser/expression/left_hand_side/optional/tests.rs
  12. 6
      boa_parser/src/parser/expression/left_hand_side/tests.rs
  13. 18
      boa_parser/src/parser/expression/primary/array_initializer/tests.rs
  14. 2
      boa_parser/src/parser/expression/primary/async_function_expression/mod.rs
  15. 6
      boa_parser/src/parser/expression/primary/async_function_expression/tests.rs
  16. 2
      boa_parser/src/parser/expression/primary/async_generator_expression/mod.rs
  17. 6
      boa_parser/src/parser/expression/primary/async_generator_expression/tests.rs
  18. 3
      boa_parser/src/parser/expression/primary/class_expression/mod.rs
  19. 2
      boa_parser/src/parser/expression/primary/function_expression/mod.rs
  20. 22
      boa_parser/src/parser/expression/primary/function_expression/tests.rs
  21. 2
      boa_parser/src/parser/expression/primary/generator_expression/mod.rs
  22. 6
      boa_parser/src/parser/expression/primary/generator_expression/tests.rs
  23. 2
      boa_parser/src/parser/expression/primary/mod.rs
  24. 4
      boa_parser/src/parser/expression/primary/object_initializer/mod.rs
  25. 30
      boa_parser/src/parser/expression/primary/object_initializer/tests.rs
  26. 6
      boa_parser/src/parser/expression/primary/tests.rs
  27. 100
      boa_parser/src/parser/expression/tests.rs
  28. 42
      boa_parser/src/parser/function/tests.rs
  29. 4
      boa_parser/src/parser/statement/block/tests.rs
  30. 22
      boa_parser/src/parser/statement/break_stm/tests.rs
  31. 22
      boa_parser/src/parser/statement/continue_stm/tests.rs
  32. 8
      boa_parser/src/parser/statement/declaration/hoistable/async_function_decl/tests.rs
  33. 4
      boa_parser/src/parser/statement/declaration/hoistable/async_generator_decl/tests.rs
  34. 33
      boa_parser/src/parser/statement/declaration/hoistable/class_decl/mod.rs
  35. 8
      boa_parser/src/parser/statement/declaration/hoistable/class_decl/tests.rs
  36. 24
      boa_parser/src/parser/statement/declaration/hoistable/function_decl/tests.rs
  37. 4
      boa_parser/src/parser/statement/declaration/hoistable/generator_decl/tests.rs
  38. 36
      boa_parser/src/parser/statement/declaration/tests.rs
  39. 6
      boa_parser/src/parser/statement/if_stm/tests.rs
  40. 12
      boa_parser/src/parser/statement/iteration/tests.rs
  41. 4
      boa_parser/src/parser/statement/mod.rs
  42. 4
      boa_parser/src/parser/statement/switch/tests.rs
  43. 4
      boa_parser/src/parser/statement/throw/tests.rs
  44. 2
      boa_parser/src/parser/statement/try_stm/catch.rs
  45. 22
      boa_parser/src/parser/statement/try_stm/tests.rs
  46. 42
      boa_parser/src/parser/tests/mod.rs

9
boa_parser/src/lexer/error.rs

@ -6,7 +6,7 @@
//! [spec]: https://tc39.es/ecma262/#sec-native-error-types-used-in-this-standard //! [spec]: https://tc39.es/ecma262/#sec-native-error-types-used-in-this-standard
use boa_ast::Position; use boa_ast::Position;
use std::{error::Error as StdError, fmt, io}; use std::{error, fmt, io};
/// An error that occurred during the lexing. /// An error that occurred during the lexing.
#[derive(Debug)] #[derive(Debug)]
@ -25,6 +25,7 @@ pub enum Error {
} }
impl From<io::Error> for Error { impl From<io::Error> for Error {
#[inline]
fn from(err: io::Error) -> Self { fn from(err: io::Error) -> Self {
Self::IO(err) Self::IO(err)
} }
@ -42,6 +43,7 @@ impl Error {
} }
impl fmt::Display for Error { impl fmt::Display for Error {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
Self::IO(e) => write!(f, "I/O error: {e}"), Self::IO(e) => write!(f, "I/O error: {e}"),
@ -50,8 +52,9 @@ impl fmt::Display for Error {
} }
} }
impl StdError for Error { impl error::Error for Error {
fn source(&self) -> Option<&(dyn StdError + 'static)> { #[inline]
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match self { match self {
Self::IO(err) => Some(err), Self::IO(err) => Some(err),
Self::Syntax(_, _) => None, Self::Syntax(_, _) => None,

2
boa_parser/src/lexer/identifier.rs

@ -73,7 +73,7 @@ impl<R> Tokenizer<R> for Identifier {
Ok(Keyword::False) => TokenKind::BooleanLiteral(false), Ok(Keyword::False) => TokenKind::BooleanLiteral(false),
Ok(Keyword::Null) => TokenKind::NullLiteral, Ok(Keyword::Null) => TokenKind::NullLiteral,
Ok(keyword) => TokenKind::Keyword((keyword, contains_escaped_chars)), Ok(keyword) => TokenKind::Keyword((keyword, contains_escaped_chars)),
_ => TokenKind::Identifier(( _ => TokenKind::IdentifierName((
interner.get_or_intern(identifier_name.as_str()), interner.get_or_intern(identifier_name.as_str()),
ContainsEscapeSequence(contains_escaped_chars), ContainsEscapeSequence(contains_escaped_chars),
)), )),

6
boa_parser/src/lexer/tests.rs

@ -95,15 +95,15 @@ fn check_identifier() {
TokenKind::identifier( TokenKind::identifier(
interner.get_or_intern_static("x\u{200C}\u{200D}", utf16!("x\u{200C}\u{200D}")), interner.get_or_intern_static("x\u{200C}\u{200D}", utf16!("x\u{200C}\u{200D}")),
), ),
TokenKind::Identifier(( TokenKind::IdentifierName((
interner.get_or_intern_static("x", utf16!("x")), interner.get_or_intern_static("x", utf16!("x")),
ContainsEscapeSequence(true), ContainsEscapeSequence(true),
)), )),
TokenKind::Identifier(( TokenKind::IdentifierName((
interner.get_or_intern_static("xx", utf16!("xx")), interner.get_or_intern_static("xx", utf16!("xx")),
ContainsEscapeSequence(true), ContainsEscapeSequence(true),
)), )),
TokenKind::Identifier(( TokenKind::IdentifierName((
interner.get_or_intern_static("xxx", utf16!("xxx")), interner.get_or_intern_static("xxx", utf16!("xxx")),
ContainsEscapeSequence(true), ContainsEscapeSequence(true),
)), )),

42
boa_parser/src/lexer/token.rs

@ -98,16 +98,24 @@ pub enum TokenKind {
/// The end of the file. /// The end of the file.
EOF, EOF,
/// An identifier. /// An [**identifier name**][spec].
Identifier((Sym, ContainsEscapeSequence)), ///
/// [spec]: https://tc39.es/ecma262/#prod-IdentifierName
IdentifierName((Sym, ContainsEscapeSequence)),
/// A private identifier. /// A [**private identifier**][spec].
///
/// [spec]: https://tc39.es/ecma262/#prod-PrivateIdentifier
PrivateIdentifier(Sym), PrivateIdentifier(Sym),
/// A keyword and a flag if the keyword contains unicode escaped chars. /// A keyword and a flag if the keyword contains unicode escaped chars.
///
/// For more information, see [`Keyword`].
Keyword((Keyword, bool)), Keyword((Keyword, bool)),
/// A `null` literal. /// The [`null` literal][spec].
///
/// [spec]: https://tc39.es/ecma262/#prod-NullLiteral
NullLiteral, NullLiteral,
/// A numeric literal. /// A numeric literal.
@ -116,7 +124,9 @@ pub enum TokenKind {
/// A piece of punctuation /// A piece of punctuation
Punctuator(Punctuator), Punctuator(Punctuator),
/// A string literal. /// A [**string literal**][spec].
///
/// [spec]: https://tc39.es/ecma262/#prod-StringLiteral
StringLiteral((Sym, Option<EscapeSequence>)), StringLiteral((Sym, Option<EscapeSequence>)),
/// A part of a template literal without substitution. /// A part of a template literal without substitution.
@ -128,7 +138,9 @@ pub enum TokenKind {
/// A regular expression, consisting of body and flags. /// A regular expression, consisting of body and flags.
RegularExpressionLiteral(Sym, Sym), RegularExpressionLiteral(Sym, Sym),
/// Indicates the end of a line (`\n`). /// Indicates a [**line terminator (`\n`)**][spec].
///
/// [spec]: https://tc39.es/ecma262/#prod-LineTerminator
LineTerminator, LineTerminator,
/// Indicates a comment, the content isn't stored. /// Indicates a comment, the content isn't stored.
@ -136,24 +148,28 @@ pub enum TokenKind {
} }
impl From<bool> for TokenKind { impl From<bool> for TokenKind {
#[inline]
fn from(oth: bool) -> Self { fn from(oth: bool) -> Self {
Self::BooleanLiteral(oth) Self::BooleanLiteral(oth)
} }
} }
impl From<(Keyword, bool)> for TokenKind { impl From<(Keyword, bool)> for TokenKind {
#[inline]
fn from(kw: (Keyword, bool)) -> Self { fn from(kw: (Keyword, bool)) -> Self {
Self::Keyword(kw) Self::Keyword(kw)
} }
} }
impl From<Punctuator> for TokenKind { impl From<Punctuator> for TokenKind {
#[inline]
fn from(punc: Punctuator) -> Self { fn from(punc: Punctuator) -> Self {
Self::Punctuator(punc) Self::Punctuator(punc)
} }
} }
impl From<Numeric> for TokenKind { impl From<Numeric> for TokenKind {
#[inline]
fn from(num: Numeric) -> Self { fn from(num: Numeric) -> Self {
Self::NumericLiteral(num) Self::NumericLiteral(num)
} }
@ -161,21 +177,24 @@ impl From<Numeric> for TokenKind {
impl TokenKind { impl TokenKind {
/// Creates a `BooleanLiteral` token kind. /// Creates a `BooleanLiteral` token kind.
#[inline]
#[must_use] #[must_use]
pub const fn boolean_literal(lit: bool) -> Self { pub const fn boolean_literal(lit: bool) -> Self {
Self::BooleanLiteral(lit) Self::BooleanLiteral(lit)
} }
/// Creates an `EOF` token kind. /// Creates an `EOF` token kind.
#[inline]
#[must_use] #[must_use]
pub const fn eof() -> Self { pub const fn eof() -> Self {
Self::EOF Self::EOF
} }
/// Creates an `Identifier` token type. /// Creates an `Identifier` token type.
#[inline]
#[must_use] #[must_use]
pub const fn identifier(ident: Sym) -> Self { pub const fn identifier(ident: Sym) -> Self {
Self::Identifier((ident, ContainsEscapeSequence(false))) Self::IdentifierName((ident, ContainsEscapeSequence(false)))
} }
/// Creates a `NumericLiteral` token kind. /// Creates a `NumericLiteral` token kind.
@ -187,42 +206,49 @@ impl TokenKind {
} }
/// Creates a `Punctuator` token type. /// Creates a `Punctuator` token type.
#[inline]
#[must_use] #[must_use]
pub const fn punctuator(punc: Punctuator) -> Self { pub const fn punctuator(punc: Punctuator) -> Self {
Self::Punctuator(punc) Self::Punctuator(punc)
} }
/// Creates a `StringLiteral` token type. /// Creates a `StringLiteral` token type.
#[inline]
#[must_use] #[must_use]
pub const fn string_literal(lit: Sym, escape_sequence: Option<EscapeSequence>) -> Self { pub const fn string_literal(lit: Sym, escape_sequence: Option<EscapeSequence>) -> Self {
Self::StringLiteral((lit, escape_sequence)) Self::StringLiteral((lit, escape_sequence))
} }
/// Creates a `TemplateMiddle` token type. /// Creates a `TemplateMiddle` token type.
#[inline]
#[must_use] #[must_use]
pub const fn template_middle(template_string: TemplateString) -> Self { pub const fn template_middle(template_string: TemplateString) -> Self {
Self::TemplateMiddle(template_string) Self::TemplateMiddle(template_string)
} }
/// Creates a `TemplateNoSubstitution` token type. /// Creates a `TemplateNoSubstitution` token type.
#[inline]
#[must_use] #[must_use]
pub const fn template_no_substitution(template_string: TemplateString) -> Self { pub const fn template_no_substitution(template_string: TemplateString) -> Self {
Self::TemplateNoSubstitution(template_string) Self::TemplateNoSubstitution(template_string)
} }
/// Creates a `RegularExpressionLiteral` token kind. /// Creates a `RegularExpressionLiteral` token kind.
#[inline]
#[must_use] #[must_use]
pub const fn regular_expression_literal(body: Sym, flags: Sym) -> Self { pub const fn regular_expression_literal(body: Sym, flags: Sym) -> Self {
Self::RegularExpressionLiteral(body, flags) Self::RegularExpressionLiteral(body, flags)
} }
/// Creates a `LineTerminator` token kind. /// Creates a `LineTerminator` token kind.
#[inline]
#[must_use] #[must_use]
pub const fn line_terminator() -> Self { pub const fn line_terminator() -> Self {
Self::LineTerminator Self::LineTerminator
} }
/// Creates a 'Comment' token kind. /// Creates a 'Comment' token kind.
#[inline]
#[must_use] #[must_use]
pub const fn comment() -> Self { pub const fn comment() -> Self {
Self::Comment Self::Comment
@ -234,7 +260,7 @@ impl TokenKind {
match *self { match *self {
Self::BooleanLiteral(val) => val.to_string(), Self::BooleanLiteral(val) => val.to_string(),
Self::EOF => "end of file".to_owned(), Self::EOF => "end of file".to_owned(),
Self::Identifier((ident, _)) => interner.resolve_expect(ident).to_string(), Self::IdentifierName((ident, _)) => interner.resolve_expect(ident).to_string(),
Self::PrivateIdentifier(ident) => format!("#{}", interner.resolve_expect(ident)), Self::PrivateIdentifier(ident) => format!("#{}", interner.resolve_expect(ident)),
Self::Keyword((word, _)) => word.to_string(), Self::Keyword((word, _)) => word.to_string(),
Self::NullLiteral => "null".to_owned(), Self::NullLiteral => "null".to_owned(),

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

@ -108,7 +108,8 @@ where
.parse(cursor, interner) .parse(cursor, interner)
} }
// ArrowFunction[?In, ?Yield, ?Await] -> ArrowParameters[?Yield, ?Await] -> BindingIdentifier[?Yield, ?Await] // ArrowFunction[?In, ?Yield, ?Await] -> ArrowParameters[?Yield, ?Await] -> BindingIdentifier[?Yield, ?Await]
TokenKind::Identifier(_) | TokenKind::Keyword((Keyword::Yield | Keyword::Await, _)) => { TokenKind::IdentifierName(_)
| TokenKind::Keyword((Keyword::Yield | Keyword::Await, _)) => {
cursor.set_goal(InputElement::Div); cursor.set_goal(InputElement::Div);
// Because we already peeked the identifier token, there may be a line terminator before the identifier token. // Because we already peeked the identifier token, there may be a line terminator before the identifier token.
@ -146,7 +147,7 @@ where
.or_abrupt()? .or_abrupt()?
&& matches!( && matches!(
cursor.peek(1, interner).or_abrupt()?.kind(), cursor.peek(1, interner).or_abrupt()?.kind(),
TokenKind::Identifier(_) TokenKind::IdentifierName(_)
| TokenKind::Keyword((Keyword::Yield | Keyword::Await, _)) | TokenKind::Keyword((Keyword::Yield | Keyword::Await, _))
| TokenKind::Punctuator(Punctuator::OpenParen) | TokenKind::Punctuator(Punctuator::OpenParen)
) )

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

@ -75,7 +75,7 @@ where
.parse(cursor, interner)?; .parse(cursor, interner)?;
Ok(Yield::new(Some(expr), true).into()) Ok(Yield::new(Some(expr), true).into())
} }
TokenKind::Identifier(_) TokenKind::IdentifierName(_)
| TokenKind::Punctuator( | TokenKind::Punctuator(
Punctuator::OpenParen Punctuator::OpenParen
| Punctuator::Add | Punctuator::Add

20
boa_parser/src/parser/expression/identifiers.rs

@ -65,7 +65,7 @@ where
let token = cursor.next(interner).or_abrupt()?; let token = cursor.next(interner).or_abrupt()?;
match token.kind() { match token.kind() {
TokenKind::Identifier((ident, _)) TokenKind::IdentifierName((ident, _))
if cursor.strict_mode() && RESERVED_IDENTIFIERS_STRICT.contains(ident) => if cursor.strict_mode() && RESERVED_IDENTIFIERS_STRICT.contains(ident) =>
{ {
Err(Error::general( Err(Error::general(
@ -73,7 +73,7 @@ where
token.span().start(), token.span().start(),
)) ))
} }
TokenKind::Identifier((ident, _)) => Ok(Identifier::new(*ident)), TokenKind::IdentifierName((ident, _)) => Ok(Identifier::new(*ident)),
TokenKind::Keyword((Keyword::Let, _)) if cursor.strict_mode() => Err(Error::general( TokenKind::Keyword((Keyword::Let, _)) if cursor.strict_mode() => Err(Error::general(
"using future reserved keyword not allowed in strict mode IdentifierReference", "using future reserved keyword not allowed in strict mode IdentifierReference",
token.span().start(), token.span().start(),
@ -155,19 +155,17 @@ where
let next_token = cursor.next(interner).or_abrupt()?; let next_token = cursor.next(interner).or_abrupt()?;
match next_token.kind() { match next_token.kind() {
TokenKind::Identifier((Sym::ARGUMENTS, _)) if cursor.strict_mode() => { TokenKind::IdentifierName((Sym::ARGUMENTS | Sym::EVAL, _)) if cursor.strict_mode() => {
Err(Error::lex(LexError::Syntax( Err(Error::lex(LexError::Syntax(
"unexpected identifier 'arguments' in strict mode".into(), format!(
"unexpected identifier '{}' in strict mode",
next_token.to_string(interner)
)
.into(),
next_token.span().start(), next_token.span().start(),
))) )))
} }
TokenKind::Identifier((Sym::EVAL, _)) if cursor.strict_mode() => { TokenKind::IdentifierName((ident, _)) => {
Err(Error::lex(LexError::Syntax(
"unexpected identifier 'eval' in strict mode".into(),
next_token.span().start(),
)))
}
TokenKind::Identifier((ident, _)) => {
if cursor.strict_mode() && RESERVED_IDENTIFIERS_STRICT.contains(ident) { if cursor.strict_mode() && RESERVED_IDENTIFIERS_STRICT.contains(ident) {
return Err(Error::general( return Err(Error::general(
"using future reserved keyword not allowed in strict mode", "using future reserved keyword not allowed in strict mode",

2
boa_parser/src/parser/expression/left_hand_side/call.rs

@ -98,7 +98,7 @@ where
cursor.advance(interner); cursor.advance(interner);
let access = match cursor.next(interner).or_abrupt()?.kind() { let access = match cursor.next(interner).or_abrupt()?.kind() {
TokenKind::Identifier((name, _)) => { TokenKind::IdentifierName((name, _)) => {
SimplePropertyAccess::new(lhs, *name).into() SimplePropertyAccess::new(lhs, *name).into()
} }
TokenKind::Keyword((kw, _)) => { TokenKind::Keyword((kw, _)) => {

8
boa_parser/src/parser/expression/left_hand_side/member.rs

@ -85,13 +85,13 @@ where
if cursor.next_if(Punctuator::Dot, interner)?.is_some() { if cursor.next_if(Punctuator::Dot, interner)?.is_some() {
let token = cursor.next(interner).or_abrupt()?; let token = cursor.next(interner).or_abrupt()?;
match token.kind() { match token.kind() {
TokenKind::Identifier((Sym::TARGET, ContainsEscapeSequence(true))) => { TokenKind::IdentifierName((Sym::TARGET, ContainsEscapeSequence(true))) => {
return Err(Error::general( return Err(Error::general(
"'new.target' must not contain escaped characters", "'new.target' must not contain escaped characters",
token.span().start(), token.span().start(),
)); ));
} }
TokenKind::Identifier((Sym::TARGET, ContainsEscapeSequence(false))) => { TokenKind::IdentifierName((Sym::TARGET, ContainsEscapeSequence(false))) => {
return Ok(ast::Expression::NewTarget) return Ok(ast::Expression::NewTarget)
} }
_ => { _ => {
@ -122,7 +122,7 @@ where
TokenKind::Punctuator(Punctuator::Dot) => { TokenKind::Punctuator(Punctuator::Dot) => {
let token = cursor.next(interner).or_abrupt()?; let token = cursor.next(interner).or_abrupt()?;
let field = match token.kind() { let field = match token.kind() {
TokenKind::Identifier((name, _)) => { TokenKind::IdentifierName((name, _)) => {
SuperPropertyAccess::new(PropertyAccessField::from(*name)) SuperPropertyAccess::new(PropertyAccessField::from(*name))
} }
TokenKind::Keyword((kw, _)) => { TokenKind::Keyword((kw, _)) => {
@ -184,7 +184,7 @@ where
let token = cursor.next(interner).or_abrupt()?; let token = cursor.next(interner).or_abrupt()?;
let access = match token.kind() { let access = match token.kind() {
TokenKind::Identifier((name, _)) => { TokenKind::IdentifierName((name, _)) => {
SimplePropertyAccess::new(lhs, *name).into() SimplePropertyAccess::new(lhs, *name).into()
} }
TokenKind::Keyword((kw, _)) => { TokenKind::Keyword((kw, _)) => {

6
boa_parser/src/parser/expression/left_hand_side/optional/mod.rs

@ -66,9 +66,11 @@ where
interner: &mut Interner, interner: &mut Interner,
) -> ParseResult<OptionalOperationKind> { ) -> ParseResult<OptionalOperationKind> {
let item = match token.kind() { let item = match token.kind() {
TokenKind::Identifier((name, _)) => OptionalOperationKind::SimplePropertyAccess { TokenKind::IdentifierName((name, _)) => {
OptionalOperationKind::SimplePropertyAccess {
field: PropertyAccessField::Const(*name), field: PropertyAccessField::Const(*name),
}, }
}
TokenKind::Keyword((kw, _)) => OptionalOperationKind::SimplePropertyAccess { TokenKind::Keyword((kw, _)) => OptionalOperationKind::SimplePropertyAccess {
field: PropertyAccessField::Const(kw.to_sym(interner)), field: PropertyAccessField::Const(kw.to_sym(interner)),
}, },

6
boa_parser/src/parser/expression/left_hand_side/optional/tests.rs

@ -1,7 +1,7 @@
use boa_interner::Interner; use boa_interner::Interner;
use boa_macros::utf16; use boa_macros::utf16;
use crate::parser::tests::{check_invalid, check_parser}; use crate::parser::tests::{check_invalid, check_script_parser};
use boa_ast::{ use boa_ast::{
expression::{ expression::{
access::PropertyAccessField, literal::Literal, Identifier, Optional, OptionalOperation, access::PropertyAccessField, literal::Literal, Identifier, Optional, OptionalOperation,
@ -14,7 +14,7 @@ use boa_ast::{
fn simple() { fn simple() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
r#"5?.name"#, r#"5?.name"#,
vec![Statement::Expression( vec![Statement::Expression(
Optional::new( Optional::new(
@ -40,7 +40,7 @@ fn simple() {
fn complex_chain() { fn complex_chain() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
r#"a?.b(true)?.["c"]"#, r#"a?.b(true)?.["c"]"#,
vec![Statement::Expression( vec![Statement::Expression(
Optional::new( Optional::new(

6
boa_parser/src/parser/expression/left_hand_side/tests.rs

@ -1,4 +1,4 @@
use crate::parser::tests::check_parser; use crate::parser::tests::check_script_parser;
use boa_ast::{ use boa_ast::{
expression::{access::SimplePropertyAccess, Call, Identifier}, expression::{access::SimplePropertyAccess, Call, Identifier},
Expression, Statement, Expression, Statement,
@ -9,7 +9,7 @@ use boa_macros::utf16;
macro_rules! check_call_property_identifier { macro_rules! check_call_property_identifier {
($property:literal) => {{ ($property:literal) => {{
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
format!("a().{}", $property).as_str(), format!("a().{}", $property).as_str(),
vec![Statement::Expression(Expression::PropertyAccess( vec![Statement::Expression(Expression::PropertyAccess(
SimplePropertyAccess::new( SimplePropertyAccess::new(
@ -40,7 +40,7 @@ fn check_call_properties() {
macro_rules! check_member_property_identifier { macro_rules! check_member_property_identifier {
($property:literal) => {{ ($property:literal) => {{
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
format!("a.{}", $property).as_str(), format!("a.{}", $property).as_str(),
vec![Statement::Expression(Expression::PropertyAccess( vec![Statement::Expression(Expression::PropertyAccess(
SimplePropertyAccess::new( SimplePropertyAccess::new(

18
boa_parser/src/parser/expression/primary/array_initializer/tests.rs

@ -1,6 +1,6 @@
// ! Tests for array initializer parsing. // ! Tests for array initializer parsing.
use crate::parser::tests::check_parser; use crate::parser::tests::check_script_parser;
use boa_ast::{ use boa_ast::{
expression::literal::{ArrayLiteral, Literal}, expression::literal::{ArrayLiteral, Literal},
Expression, Statement, Expression, Statement,
@ -11,7 +11,7 @@ use boa_macros::utf16;
/// Checks an empty array. /// Checks an empty array.
#[test] #[test]
fn check_empty() { fn check_empty() {
check_parser( check_script_parser(
"[]", "[]",
vec![Statement::Expression(Expression::from(ArrayLiteral::from(vec![]))).into()], vec![Statement::Expression(Expression::from(ArrayLiteral::from(vec![]))).into()],
&mut Interner::default(), &mut Interner::default(),
@ -21,7 +21,7 @@ fn check_empty() {
/// Checks an array with empty slot. /// Checks an array with empty slot.
#[test] #[test]
fn check_empty_slot() { fn check_empty_slot() {
check_parser( check_script_parser(
"[,]", "[,]",
vec![Statement::Expression(Expression::from(ArrayLiteral::from(vec![None]))).into()], vec![Statement::Expression(Expression::from(ArrayLiteral::from(vec![None]))).into()],
&mut Interner::default(), &mut Interner::default(),
@ -31,7 +31,7 @@ fn check_empty_slot() {
/// Checks a numeric array. /// Checks a numeric array.
#[test] #[test]
fn check_numeric_array() { fn check_numeric_array() {
check_parser( check_script_parser(
"[1, 2, 3]", "[1, 2, 3]",
vec![ vec![
Statement::Expression(Expression::from(ArrayLiteral::from(vec![ Statement::Expression(Expression::from(ArrayLiteral::from(vec![
@ -48,7 +48,7 @@ fn check_numeric_array() {
// Checks a numeric array with trailing comma // Checks a numeric array with trailing comma
#[test] #[test]
fn check_numeric_array_trailing() { fn check_numeric_array_trailing() {
check_parser( check_script_parser(
"[1, 2, 3,]", "[1, 2, 3,]",
vec![ vec![
Statement::Expression(Expression::from(ArrayLiteral::from(vec![ Statement::Expression(Expression::from(ArrayLiteral::from(vec![
@ -65,7 +65,7 @@ fn check_numeric_array_trailing() {
/// Checks a numeric array with an elision. /// Checks a numeric array with an elision.
#[test] #[test]
fn check_numeric_array_elision() { fn check_numeric_array_elision() {
check_parser( check_script_parser(
"[1, 2, , 3]", "[1, 2, , 3]",
vec![ vec![
Statement::Expression(Expression::from(ArrayLiteral::from(vec![ Statement::Expression(Expression::from(ArrayLiteral::from(vec![
@ -83,7 +83,7 @@ fn check_numeric_array_elision() {
/// Checks a numeric array with repeated elisions. /// Checks a numeric array with repeated elisions.
#[test] #[test]
fn check_numeric_array_repeated_elision() { fn check_numeric_array_repeated_elision() {
check_parser( check_script_parser(
"[1, 2, ,, 3]", "[1, 2, ,, 3]",
vec![ vec![
Statement::Expression(Expression::from(ArrayLiteral::from(vec![ Statement::Expression(Expression::from(ArrayLiteral::from(vec![
@ -103,7 +103,7 @@ fn check_numeric_array_repeated_elision() {
#[test] #[test]
fn check_combined() { fn check_combined() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"[1, \"a\", 2]", "[1, \"a\", 2]",
vec![ vec![
Statement::Expression(Expression::from(ArrayLiteral::from(vec![ Statement::Expression(Expression::from(ArrayLiteral::from(vec![
@ -120,7 +120,7 @@ fn check_combined() {
/// Checks a combined array with an empty string /// Checks a combined array with an empty string
#[test] #[test]
fn check_combined_empty_str() { fn check_combined_empty_str() {
check_parser( check_script_parser(
"[1, \"\", 2]", "[1, \"\", 2]",
vec![ vec![
Statement::Expression(Expression::from(ArrayLiteral::from(vec![ Statement::Expression(Expression::from(ArrayLiteral::from(vec![

2
boa_parser/src/parser/expression/primary/async_function_expression/mod.rs

@ -60,7 +60,7 @@ where
let token = cursor.peek(0, interner).or_abrupt()?; let token = cursor.peek(0, interner).or_abrupt()?;
let (name, name_span) = match token.kind() { let (name, name_span) = match token.kind() {
TokenKind::Identifier(_) TokenKind::IdentifierName(_)
| TokenKind::Keyword(( | TokenKind::Keyword((
Keyword::Yield | Keyword::Await | Keyword::Async | Keyword::Of, Keyword::Yield | Keyword::Await | Keyword::Async | Keyword::Of,
_, _,

6
boa_parser/src/parser/expression/primary/async_function_expression/tests.rs

@ -1,4 +1,4 @@
use crate::parser::tests::check_parser; use crate::parser::tests::check_script_parser;
use boa_ast::{ use boa_ast::{
declaration::{Declaration, LexicalDeclaration, Variable}, declaration::{Declaration, LexicalDeclaration, Variable},
expression::literal::Literal, expression::literal::Literal,
@ -14,7 +14,7 @@ use boa_macros::utf16;
fn check_async_expression() { fn check_async_expression() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
let add = interner.get_or_intern_static("add", utf16!("add")); let add = interner.get_or_intern_static("add", utf16!("add"));
check_parser( check_script_parser(
"const add = async function() { "const add = async function() {
return 1; return 1;
}; };
@ -48,7 +48,7 @@ fn check_nested_async_expression() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
let a = interner.get_or_intern_static("a", utf16!("a")); let a = interner.get_or_intern_static("a", utf16!("a"));
let b = interner.get_or_intern_static("b", utf16!("b")); let b = interner.get_or_intern_static("b", utf16!("b"));
check_parser( check_script_parser(
"const a = async function() { "const a = async function() {
const b = async function() { const b = async function() {
return 1; return 1;

2
boa_parser/src/parser/expression/primary/async_generator_expression/mod.rs

@ -74,7 +74,7 @@ where
let token = cursor.peek(0, interner).or_abrupt()?; let token = cursor.peek(0, interner).or_abrupt()?;
let (name, name_span) = match token.kind() { let (name, name_span) = match token.kind() {
TokenKind::Identifier(_) TokenKind::IdentifierName(_)
| TokenKind::Keyword(( | TokenKind::Keyword((
Keyword::Yield | Keyword::Await | Keyword::Async | Keyword::Of, Keyword::Yield | Keyword::Await | Keyword::Async | Keyword::Of,
_, _,

6
boa_parser/src/parser/expression/primary/async_generator_expression/tests.rs

@ -1,6 +1,6 @@
use std::convert::TryInto; use std::convert::TryInto;
use crate::parser::tests::check_parser; use crate::parser::tests::check_script_parser;
use boa_ast::{ use boa_ast::{
declaration::{LexicalDeclaration, Variable}, declaration::{LexicalDeclaration, Variable},
expression::literal::Literal, expression::literal::Literal,
@ -17,7 +17,7 @@ use boa_macros::utf16;
fn check_async_generator_expr() { fn check_async_generator_expr() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
let add = interner.get_or_intern_static("add", utf16!("add")); let add = interner.get_or_intern_static("add", utf16!("add"));
check_parser( check_script_parser(
"const add = async function*(){ "const add = async function*(){
return 1; return 1;
}; };
@ -51,7 +51,7 @@ fn check_nested_async_generator_expr() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
let a = interner.get_or_intern_static("a", utf16!("a")); let a = interner.get_or_intern_static("a", utf16!("a"));
let b = interner.get_or_intern_static("b", utf16!("b")); let b = interner.get_or_intern_static("b", utf16!("b"));
check_parser( check_script_parser(
"const a = async function*() { "const a = async function*() {
const b = async function*() { const b = async function*() {
return 1; return 1;

3
boa_parser/src/parser/expression/primary/class_expression/mod.rs

@ -53,7 +53,8 @@ where
let mut has_binding_identifier = false; let mut has_binding_identifier = false;
let token = cursor.peek(0, interner).or_abrupt()?; let token = cursor.peek(0, interner).or_abrupt()?;
let name = match token.kind() { let name = match token.kind() {
TokenKind::Identifier(_) | TokenKind::Keyword((Keyword::Yield | Keyword::Await, _)) => { TokenKind::IdentifierName(_)
| TokenKind::Keyword((Keyword::Yield | Keyword::Await, _)) => {
has_binding_identifier = true; has_binding_identifier = true;
BindingIdentifier::new(self.allow_yield, self.allow_await) BindingIdentifier::new(self.allow_yield, self.allow_await)
.parse(cursor, interner)? .parse(cursor, interner)?

2
boa_parser/src/parser/expression/primary/function_expression/mod.rs

@ -63,7 +63,7 @@ where
let token = cursor.peek(0, interner).or_abrupt()?; let token = cursor.peek(0, interner).or_abrupt()?;
let (name, name_span) = match token.kind() { let (name, name_span) = match token.kind() {
TokenKind::Identifier(_) TokenKind::IdentifierName(_)
| TokenKind::Keyword(( | TokenKind::Keyword((
Keyword::Yield | Keyword::Await | Keyword::Async | Keyword::Of, Keyword::Yield | Keyword::Await | Keyword::Async | Keyword::Of,
_, _,

22
boa_parser/src/parser/expression/primary/function_expression/tests.rs

@ -1,4 +1,4 @@
use crate::parser::tests::check_parser; use crate::parser::tests::check_script_parser;
use boa_ast::{ use boa_ast::{
declaration::{LexicalDeclaration, Variable}, declaration::{LexicalDeclaration, Variable},
expression::literal::Literal, expression::literal::Literal,
@ -14,7 +14,7 @@ use boa_macros::utf16;
fn check_function_expression() { fn check_function_expression() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
let add = interner.get_or_intern_static("add", utf16!("add")); let add = interner.get_or_intern_static("add", utf16!("add"));
check_parser( check_script_parser(
"const add = function() { "const add = function() {
return 1; return 1;
}; };
@ -47,7 +47,7 @@ fn check_nested_function_expression() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
let a = interner.get_or_intern_static("a", utf16!("a")); let a = interner.get_or_intern_static("a", utf16!("a"));
let b = interner.get_or_intern_static("b", utf16!("b")); let b = interner.get_or_intern_static("b", utf16!("b"));
check_parser( check_script_parser(
"const a = function() { "const a = function() {
const b = function() { const b = function() {
return 1; return 1;
@ -118,35 +118,35 @@ fn check_function_non_reserved_keyword() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
let ast = genast!("as", interner); let ast = genast!("as", interner);
check_parser("const add = function as() { return 1; };", ast, interner); check_script_parser("const add = function as() { return 1; };", ast, interner);
let interner = &mut Interner::default(); let interner = &mut Interner::default();
let ast = genast!("async", interner); let ast = genast!("async", interner);
check_parser("const add = function async() { return 1; };", ast, interner); check_script_parser("const add = function async() { return 1; };", ast, interner);
let interner = &mut Interner::default(); let interner = &mut Interner::default();
let ast = genast!("from", interner); let ast = genast!("from", interner);
check_parser("const add = function from() { return 1; };", ast, interner); check_script_parser("const add = function from() { return 1; };", ast, interner);
let interner = &mut Interner::default(); let interner = &mut Interner::default();
let ast = genast!("get", interner); let ast = genast!("get", interner);
check_parser("const add = function get() { return 1; };", ast, interner); check_script_parser("const add = function get() { return 1; };", ast, interner);
let interner = &mut Interner::default(); let interner = &mut Interner::default();
let ast = genast!("meta", interner); let ast = genast!("meta", interner);
check_parser("const add = function meta() { return 1; };", ast, interner); check_script_parser("const add = function meta() { return 1; };", ast, interner);
let interner = &mut Interner::default(); let interner = &mut Interner::default();
let ast = genast!("of", interner); let ast = genast!("of", interner);
check_parser("const add = function of() { return 1; };", ast, interner); check_script_parser("const add = function of() { return 1; };", ast, interner);
let interner = &mut Interner::default(); let interner = &mut Interner::default();
let ast = genast!("set", interner); let ast = genast!("set", interner);
check_parser("const add = function set() { return 1; };", ast, interner); check_script_parser("const add = function set() { return 1; };", ast, interner);
let interner = &mut Interner::default(); let interner = &mut Interner::default();
let ast = genast!("target", interner); let ast = genast!("target", interner);
check_parser( check_script_parser(
"const add = function target() { return 1; };", "const add = function target() { return 1; };",
ast, ast,
interner, interner,

2
boa_parser/src/parser/expression/primary/generator_expression/mod.rs

@ -69,7 +69,7 @@ where
let token = cursor.peek(0, interner).or_abrupt()?; let token = cursor.peek(0, interner).or_abrupt()?;
let (name, name_span) = match token.kind() { let (name, name_span) = match token.kind() {
TokenKind::Identifier(_) TokenKind::IdentifierName(_)
| TokenKind::Keyword(( | TokenKind::Keyword((
Keyword::Yield | Keyword::Await | Keyword::Async | Keyword::Of, Keyword::Yield | Keyword::Await | Keyword::Async | Keyword::Of,
_, _,

6
boa_parser/src/parser/expression/primary/generator_expression/tests.rs

@ -1,4 +1,4 @@
use crate::parser::tests::check_parser; use crate::parser::tests::check_script_parser;
use boa_ast::{ use boa_ast::{
declaration::{LexicalDeclaration, Variable}, declaration::{LexicalDeclaration, Variable},
expression::{literal::Literal, Yield}, expression::{literal::Literal, Yield},
@ -12,7 +12,7 @@ use boa_macros::utf16;
fn check_generator_function_expression() { fn check_generator_function_expression() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
let gen = interner.get_or_intern_static("gen", utf16!("gen")); let gen = interner.get_or_intern_static("gen", utf16!("gen"));
check_parser( check_script_parser(
"const gen = function*() { "const gen = function*() {
yield 1; yield 1;
}; };
@ -45,7 +45,7 @@ fn check_generator_function_expression() {
fn check_generator_function_delegate_yield_expression() { fn check_generator_function_delegate_yield_expression() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
let gen = interner.get_or_intern_static("gen", utf16!("gen")); let gen = interner.get_or_intern_static("gen", utf16!("gen"));
check_parser( check_script_parser(
"const gen = function*() { "const gen = function*() {
yield* 1; yield* 1;
}; };

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

@ -202,7 +202,7 @@ where
cursor.advance(interner); cursor.advance(interner);
Ok(Literal::Null.into()) Ok(Literal::Null.into())
} }
TokenKind::Identifier(_) TokenKind::IdentifierName(_)
| TokenKind::Keyword(( | TokenKind::Keyword((
Keyword::Let | Keyword::Yield | Keyword::Await | Keyword::Of, Keyword::Let | Keyword::Yield | Keyword::Await | Keyword::Of,
_, _,

4
boa_parser/src/parser/expression/primary/object_initializer/mod.rs

@ -291,7 +291,7 @@ where
} }
let set_or_get_escaped_position = match token.kind() { let set_or_get_escaped_position = match token.kind() {
TokenKind::Identifier((Sym::GET | Sym::SET, ContainsEscapeSequence(true))) => { TokenKind::IdentifierName((Sym::GET | Sym::SET, ContainsEscapeSequence(true))) => {
Some(token.span().start()) Some(token.span().start())
} }
_ => None, _ => None,
@ -578,7 +578,7 @@ where
cursor.expect(Punctuator::CloseBracket, "expected token ']'", interner)?; cursor.expect(Punctuator::CloseBracket, "expected token ']'", interner)?;
return Ok(node.into()); return Ok(node.into());
} }
TokenKind::Identifier((name, _)) | TokenKind::StringLiteral((name, _)) => { TokenKind::IdentifierName((name, _)) | TokenKind::StringLiteral((name, _)) => {
(*name).into() (*name).into()
} }
TokenKind::NumericLiteral(num) => match num { TokenKind::NumericLiteral(num) => match num {

30
boa_parser/src/parser/expression/primary/object_initializer/tests.rs

@ -1,4 +1,4 @@
use crate::parser::tests::{check_invalid, check_parser}; use crate::parser::tests::{check_invalid, check_script_parser};
use boa_ast::{ use boa_ast::{
declaration::{LexicalDeclaration, Variable}, declaration::{LexicalDeclaration, Variable},
expression::{ expression::{
@ -31,7 +31,7 @@ fn check_object_literal() {
), ),
]; ];
check_parser( check_script_parser(
"const x = { "const x = {
a: true, a: true,
b: false, b: false,
@ -70,7 +70,7 @@ fn check_object_short_function() {
), ),
]; ];
check_parser( check_script_parser(
"const x = { "const x = {
a: true, a: true,
b() {}, b() {},
@ -120,7 +120,7 @@ fn check_object_short_function_arguments() {
), ),
]; ];
check_parser( check_script_parser(
"const x = { "const x = {
a: true, a: true,
b(test) {} b(test) {}
@ -162,7 +162,7 @@ fn check_object_getter() {
), ),
]; ];
check_parser( check_script_parser(
"const x = { "const x = {
a: true, a: true,
get b() {} get b() {}
@ -215,7 +215,7 @@ fn check_object_setter() {
), ),
]; ];
check_parser( check_script_parser(
"const x = { "const x = {
a: true, a: true,
set b(test) {} set b(test) {}
@ -247,7 +247,7 @@ fn check_object_short_function_get() {
)), )),
)]; )];
check_parser( check_script_parser(
"const x = { "const x = {
get() {} get() {}
}; };
@ -278,7 +278,7 @@ fn check_object_short_function_set() {
)), )),
)]; )];
check_parser( check_script_parser(
"const x = { "const x = {
set() {} set() {}
}; };
@ -304,7 +304,7 @@ fn check_object_shorthand_property_names() {
interner.get_or_intern_static("a", utf16!("a")).into(), interner.get_or_intern_static("a", utf16!("a")).into(),
)]; )];
check_parser( check_script_parser(
"const a = true; "const a = true;
const x = { a }; const x = { a };
", ",
@ -345,7 +345,7 @@ fn check_object_shorthand_multiple_properties() {
), ),
]; ];
check_parser( check_script_parser(
"const a = true; "const a = true;
const b = false; const b = false;
const x = { a, b, }; const x = { a, b, };
@ -397,7 +397,7 @@ fn check_object_spread() {
), ),
]; ];
check_parser( check_script_parser(
"const x = { a: 1, ...b }; "const x = { a: 1, ...b };
", ",
vec![Declaration::Lexical(LexicalDeclaration::Const( vec![Declaration::Lexical(LexicalDeclaration::Const(
@ -427,7 +427,7 @@ fn check_async_method() {
)), )),
)]; )];
check_parser( check_script_parser(
"const x = { "const x = {
async dive() {} async dive() {}
}; };
@ -465,7 +465,7 @@ fn check_async_generator_method() {
)), )),
)]; )];
check_parser( check_script_parser(
"const x = { "const x = {
async* vroom() {} async* vroom() {}
}; };
@ -522,7 +522,7 @@ fn check_async_ordinary_method() {
)), )),
)]; )];
check_parser( check_script_parser(
"const x = { "const x = {
async() {} async() {}
}; };
@ -549,7 +549,7 @@ fn check_async_property() {
Literal::from(true).into(), Literal::from(true).into(),
)]; )];
check_parser( check_script_parser(
"const x = { "const x = {
async: true async: true
}; };

6
boa_parser/src/parser/expression/primary/tests.rs

@ -1,4 +1,4 @@
use crate::parser::tests::check_parser; use crate::parser::tests::check_script_parser;
use boa_ast::{expression::literal::Literal, Expression, Statement}; use boa_ast::{expression::literal::Literal, Expression, Statement};
use boa_interner::{Interner, Sym}; use boa_interner::{Interner, Sym};
use boa_macros::utf16; use boa_macros::utf16;
@ -6,7 +6,7 @@ use boa_macros::utf16;
#[test] #[test]
fn check_string() { fn check_string() {
// Check empty string // Check empty string
check_parser( check_script_parser(
"\"\"", "\"\"",
vec![Statement::Expression(Expression::from(Literal::from(Sym::EMPTY_STRING))).into()], vec![Statement::Expression(Expression::from(Literal::from(Sym::EMPTY_STRING))).into()],
&mut Interner::default(), &mut Interner::default(),
@ -14,7 +14,7 @@ fn check_string() {
// Check non-empty string // Check non-empty string
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"\"hello\"", "\"hello\"",
vec![Statement::Expression(Expression::from(Literal::from( vec![Statement::Expression(Expression::from(Literal::from(
interner.get_or_intern_static("hello", utf16!("hello")), interner.get_or_intern_static("hello", utf16!("hello")),

100
boa_parser/src/parser/expression/tests.rs

@ -1,4 +1,4 @@
use crate::parser::tests::{check_invalid, check_parser}; use crate::parser::tests::{check_invalid, check_script_parser};
use boa_ast::{ use boa_ast::{
declaration::{LexicalDeclaration, Variable}, declaration::{LexicalDeclaration, Variable},
expression::{ expression::{
@ -19,7 +19,7 @@ use boa_macros::utf16;
#[test] #[test]
fn check_numeric_operations() { fn check_numeric_operations() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a + b", "a + b",
vec![Statement::Expression(Expression::from(Binary::new( vec![Statement::Expression(Expression::from(Binary::new(
ArithmeticOp::Add.into(), ArithmeticOp::Add.into(),
@ -31,7 +31,7 @@ fn check_numeric_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a+1", "a+1",
vec![Statement::Expression(Expression::from(Binary::new( vec![Statement::Expression(Expression::from(Binary::new(
ArithmeticOp::Add.into(), ArithmeticOp::Add.into(),
@ -43,7 +43,7 @@ fn check_numeric_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a - b", "a - b",
vec![Statement::Expression(Expression::from(Binary::new( vec![Statement::Expression(Expression::from(Binary::new(
ArithmeticOp::Sub.into(), ArithmeticOp::Sub.into(),
@ -55,7 +55,7 @@ fn check_numeric_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a-1", "a-1",
vec![Statement::Expression(Expression::from(Binary::new( vec![Statement::Expression(Expression::from(Binary::new(
ArithmeticOp::Sub.into(), ArithmeticOp::Sub.into(),
@ -67,7 +67,7 @@ fn check_numeric_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a / b", "a / b",
vec![Statement::Expression(Expression::from(Binary::new( vec![Statement::Expression(Expression::from(Binary::new(
ArithmeticOp::Div.into(), ArithmeticOp::Div.into(),
@ -79,7 +79,7 @@ fn check_numeric_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a/2", "a/2",
vec![Statement::Expression(Expression::from(Binary::new( vec![Statement::Expression(Expression::from(Binary::new(
ArithmeticOp::Div.into(), ArithmeticOp::Div.into(),
@ -91,7 +91,7 @@ fn check_numeric_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"let myRegex = /=/;", "let myRegex = /=/;",
vec![Declaration::Lexical(LexicalDeclaration::Let( vec![Declaration::Lexical(LexicalDeclaration::Let(
vec![Variable::from_identifier( vec![Variable::from_identifier(
@ -118,7 +118,7 @@ fn check_numeric_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"fn(/=/);", "fn(/=/);",
vec![Statement::Expression(Expression::from(Call::new( vec![Statement::Expression(Expression::from(Call::new(
Identifier::new(interner.get_or_intern_static("fn", utf16!("fn"))).into(), Identifier::new(interner.get_or_intern_static("fn", utf16!("fn"))).into(),
@ -138,7 +138,7 @@ fn check_numeric_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"fn(a / b);", "fn(a / b);",
vec![Statement::Expression(Expression::from(Call::new( vec![Statement::Expression(Expression::from(Call::new(
Identifier::new(interner.get_or_intern_static("fn", utf16!("fn"))).into(), Identifier::new(interner.get_or_intern_static("fn", utf16!("fn"))).into(),
@ -154,7 +154,7 @@ fn check_numeric_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"fn(a) / b;", "fn(a) / b;",
vec![Statement::Expression(Expression::from(Binary::new( vec![Statement::Expression(Expression::from(Binary::new(
ArithmeticOp::Div.into(), ArithmeticOp::Div.into(),
@ -171,7 +171,7 @@ fn check_numeric_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a * b", "a * b",
vec![Statement::Expression(Expression::from(Binary::new( vec![Statement::Expression(Expression::from(Binary::new(
ArithmeticOp::Mul.into(), ArithmeticOp::Mul.into(),
@ -183,7 +183,7 @@ fn check_numeric_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a*2", "a*2",
vec![Statement::Expression(Expression::from(Binary::new( vec![Statement::Expression(Expression::from(Binary::new(
ArithmeticOp::Mul.into(), ArithmeticOp::Mul.into(),
@ -195,7 +195,7 @@ fn check_numeric_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a ** b", "a ** b",
vec![Statement::Expression(Expression::from(Binary::new( vec![Statement::Expression(Expression::from(Binary::new(
ArithmeticOp::Exp.into(), ArithmeticOp::Exp.into(),
@ -207,7 +207,7 @@ fn check_numeric_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a**2", "a**2",
vec![Statement::Expression(Expression::from(Binary::new( vec![Statement::Expression(Expression::from(Binary::new(
ArithmeticOp::Exp.into(), ArithmeticOp::Exp.into(),
@ -219,7 +219,7 @@ fn check_numeric_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a % b", "a % b",
vec![Statement::Expression(Expression::from(Binary::new( vec![Statement::Expression(Expression::from(Binary::new(
ArithmeticOp::Mod.into(), ArithmeticOp::Mod.into(),
@ -231,7 +231,7 @@ fn check_numeric_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a%2", "a%2",
vec![Statement::Expression(Expression::from(Binary::new( vec![Statement::Expression(Expression::from(Binary::new(
ArithmeticOp::Mod.into(), ArithmeticOp::Mod.into(),
@ -247,7 +247,7 @@ fn check_numeric_operations() {
#[test] #[test]
fn check_complex_numeric_operations() { fn check_complex_numeric_operations() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a + d*(b-3)+1", "a + d*(b-3)+1",
vec![Statement::Expression(Expression::from(Binary::new( vec![Statement::Expression(Expression::from(Binary::new(
ArithmeticOp::Add.into(), ArithmeticOp::Add.into(),
@ -278,7 +278,7 @@ fn check_complex_numeric_operations() {
#[test] #[test]
fn check_bitwise_operations() { fn check_bitwise_operations() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a & b", "a & b",
vec![Statement::Expression(Expression::from(Binary::new( vec![Statement::Expression(Expression::from(Binary::new(
BitwiseOp::And.into(), BitwiseOp::And.into(),
@ -290,7 +290,7 @@ fn check_bitwise_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a&b", "a&b",
vec![Statement::Expression(Expression::from(Binary::new( vec![Statement::Expression(Expression::from(Binary::new(
BitwiseOp::And.into(), BitwiseOp::And.into(),
@ -302,7 +302,7 @@ fn check_bitwise_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a | b", "a | b",
vec![Statement::Expression(Expression::from(Binary::new( vec![Statement::Expression(Expression::from(Binary::new(
BitwiseOp::Or.into(), BitwiseOp::Or.into(),
@ -314,7 +314,7 @@ fn check_bitwise_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a|b", "a|b",
vec![Statement::Expression(Expression::from(Binary::new( vec![Statement::Expression(Expression::from(Binary::new(
BitwiseOp::Or.into(), BitwiseOp::Or.into(),
@ -326,7 +326,7 @@ fn check_bitwise_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a ^ b", "a ^ b",
vec![Statement::Expression(Expression::from(Binary::new( vec![Statement::Expression(Expression::from(Binary::new(
BitwiseOp::Xor.into(), BitwiseOp::Xor.into(),
@ -338,7 +338,7 @@ fn check_bitwise_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a^b", "a^b",
vec![Statement::Expression(Expression::from(Binary::new( vec![Statement::Expression(Expression::from(Binary::new(
BitwiseOp::Xor.into(), BitwiseOp::Xor.into(),
@ -350,7 +350,7 @@ fn check_bitwise_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a << b", "a << b",
vec![Statement::Expression(Expression::from(Binary::new( vec![Statement::Expression(Expression::from(Binary::new(
BitwiseOp::Shl.into(), BitwiseOp::Shl.into(),
@ -362,7 +362,7 @@ fn check_bitwise_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a<<b", "a<<b",
vec![Statement::Expression(Expression::from(Binary::new( vec![Statement::Expression(Expression::from(Binary::new(
BitwiseOp::Shl.into(), BitwiseOp::Shl.into(),
@ -374,7 +374,7 @@ fn check_bitwise_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a >> b", "a >> b",
vec![Statement::Expression(Expression::from(Binary::new( vec![Statement::Expression(Expression::from(Binary::new(
BitwiseOp::Shr.into(), BitwiseOp::Shr.into(),
@ -386,7 +386,7 @@ fn check_bitwise_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a>>b", "a>>b",
vec![Statement::Expression(Expression::from(Binary::new( vec![Statement::Expression(Expression::from(Binary::new(
BitwiseOp::Shr.into(), BitwiseOp::Shr.into(),
@ -402,7 +402,7 @@ fn check_bitwise_operations() {
#[test] #[test]
fn check_assign_operations() { fn check_assign_operations() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a += b", "a += b",
vec![Statement::Expression(Expression::from(Assign::new( vec![Statement::Expression(Expression::from(Assign::new(
AssignOp::Add, AssignOp::Add,
@ -414,7 +414,7 @@ fn check_assign_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a -= b", "a -= b",
vec![Statement::Expression(Expression::from(Assign::new( vec![Statement::Expression(Expression::from(Assign::new(
AssignOp::Sub, AssignOp::Sub,
@ -426,7 +426,7 @@ fn check_assign_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a *= b", "a *= b",
vec![Statement::Expression(Expression::from(Assign::new( vec![Statement::Expression(Expression::from(Assign::new(
AssignOp::Mul, AssignOp::Mul,
@ -438,7 +438,7 @@ fn check_assign_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a **= b", "a **= b",
vec![Statement::Expression(Expression::from(Assign::new( vec![Statement::Expression(Expression::from(Assign::new(
AssignOp::Exp, AssignOp::Exp,
@ -450,7 +450,7 @@ fn check_assign_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a /= b", "a /= b",
vec![Statement::Expression(Expression::from(Assign::new( vec![Statement::Expression(Expression::from(Assign::new(
AssignOp::Div, AssignOp::Div,
@ -462,7 +462,7 @@ fn check_assign_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a %= b", "a %= b",
vec![Statement::Expression(Expression::from(Assign::new( vec![Statement::Expression(Expression::from(Assign::new(
AssignOp::Mod, AssignOp::Mod,
@ -474,7 +474,7 @@ fn check_assign_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a &= b", "a &= b",
vec![Statement::Expression(Expression::from(Assign::new( vec![Statement::Expression(Expression::from(Assign::new(
AssignOp::And, AssignOp::And,
@ -486,7 +486,7 @@ fn check_assign_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a |= b", "a |= b",
vec![Statement::Expression(Expression::from(Assign::new( vec![Statement::Expression(Expression::from(Assign::new(
AssignOp::Or, AssignOp::Or,
@ -498,7 +498,7 @@ fn check_assign_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a ^= b", "a ^= b",
vec![Statement::Expression(Expression::from(Assign::new( vec![Statement::Expression(Expression::from(Assign::new(
AssignOp::Xor, AssignOp::Xor,
@ -510,7 +510,7 @@ fn check_assign_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a <<= b", "a <<= b",
vec![Statement::Expression(Expression::from(Assign::new( vec![Statement::Expression(Expression::from(Assign::new(
AssignOp::Shl, AssignOp::Shl,
@ -522,7 +522,7 @@ fn check_assign_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a >>= b", "a >>= b",
vec![Statement::Expression(Expression::from(Assign::new( vec![Statement::Expression(Expression::from(Assign::new(
AssignOp::Shr, AssignOp::Shr,
@ -534,7 +534,7 @@ fn check_assign_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a >>>= b", "a >>>= b",
vec![Statement::Expression(Expression::from(Assign::new( vec![Statement::Expression(Expression::from(Assign::new(
AssignOp::Ushr, AssignOp::Ushr,
@ -546,7 +546,7 @@ fn check_assign_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a %= 10 / 2", "a %= 10 / 2",
vec![Statement::Expression(Expression::from(Assign::new( vec![Statement::Expression(Expression::from(Assign::new(
AssignOp::Mod, AssignOp::Mod,
@ -563,7 +563,7 @@ fn check_assign_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a ??= b", "a ??= b",
vec![Statement::Expression(Expression::from(Assign::new( vec![Statement::Expression(Expression::from(Assign::new(
AssignOp::Coalesce, AssignOp::Coalesce,
@ -578,7 +578,7 @@ fn check_assign_operations() {
#[test] #[test]
fn check_relational_operations() { fn check_relational_operations() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a < b", "a < b",
vec![Statement::Expression(Expression::from(Binary::new( vec![Statement::Expression(Expression::from(Binary::new(
RelationalOp::LessThan.into(), RelationalOp::LessThan.into(),
@ -590,7 +590,7 @@ fn check_relational_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a > b", "a > b",
vec![Statement::Expression(Expression::from(Binary::new( vec![Statement::Expression(Expression::from(Binary::new(
RelationalOp::GreaterThan.into(), RelationalOp::GreaterThan.into(),
@ -602,7 +602,7 @@ fn check_relational_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a <= b", "a <= b",
vec![Statement::Expression(Expression::from(Binary::new( vec![Statement::Expression(Expression::from(Binary::new(
RelationalOp::LessThanOrEqual.into(), RelationalOp::LessThanOrEqual.into(),
@ -614,7 +614,7 @@ fn check_relational_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a >= b", "a >= b",
vec![Statement::Expression(Expression::from(Binary::new( vec![Statement::Expression(Expression::from(Binary::new(
RelationalOp::GreaterThanOrEqual.into(), RelationalOp::GreaterThanOrEqual.into(),
@ -626,7 +626,7 @@ fn check_relational_operations() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"p in o", "p in o",
vec![Statement::Expression(Expression::from(Binary::new( vec![Statement::Expression(Expression::from(Binary::new(
RelationalOp::In.into(), RelationalOp::In.into(),
@ -641,7 +641,7 @@ fn check_relational_operations() {
#[test] #[test]
fn check_logical_expressions() { fn check_logical_expressions() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a && b || c && d || e", "a && b || c && d || e",
vec![Statement::Expression(Expression::from(Binary::new( vec![Statement::Expression(Expression::from(Binary::new(
LogicalOp::Or.into(), LogicalOp::Or.into(),
@ -668,7 +668,7 @@ fn check_logical_expressions() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a ?? b ?? c", "a ?? b ?? c",
vec![Statement::Expression(Expression::from(Binary::new( vec![Statement::Expression(Expression::from(Binary::new(
LogicalOp::Coalesce.into(), LogicalOp::Coalesce.into(),
@ -693,7 +693,7 @@ fn check_logical_expressions() {
macro_rules! check_non_reserved_identifier { macro_rules! check_non_reserved_identifier {
($keyword:literal) => {{ ($keyword:literal) => {{
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
format!("({})", $keyword).as_str(), format!("({})", $keyword).as_str(),
vec![Statement::Expression(Expression::from(Identifier::new( vec![Statement::Expression(Expression::from(Identifier::new(
interner.get_or_intern_static($keyword, utf16!($keyword)), interner.get_or_intern_static($keyword, utf16!($keyword)),

42
boa_parser/src/parser/function/tests.rs

@ -1,4 +1,4 @@
use crate::parser::tests::{check_invalid, check_parser}; use crate::parser::tests::{check_invalid, check_script_parser};
use boa_ast::{ use boa_ast::{
declaration::{LexicalDeclaration, Variable}, declaration::{LexicalDeclaration, Variable},
expression::{ expression::{
@ -25,7 +25,7 @@ fn check_basic() {
assert_eq!(params.flags(), FormalParameterListFlags::default()); assert_eq!(params.flags(), FormalParameterListFlags::default());
assert_eq!(params.length(), 1); assert_eq!(params.length(), 1);
check_parser( check_script_parser(
"function foo(a) { return a; }", "function foo(a) { return a; }",
vec![Declaration::Function(Function::new( vec![Declaration::Function(Function::new(
Some(interner.get_or_intern_static("foo", utf16!("foo")).into()), Some(interner.get_or_intern_static("foo", utf16!("foo")).into()),
@ -61,7 +61,7 @@ fn check_duplicates_strict_off() {
FormalParameterListFlags::default().union(FormalParameterListFlags::HAS_DUPLICATES) FormalParameterListFlags::default().union(FormalParameterListFlags::HAS_DUPLICATES)
); );
assert_eq!(params.length(), 2); assert_eq!(params.length(), 2);
check_parser( check_script_parser(
"function foo(a, a) { return a; }", "function foo(a, a) { return a; }",
vec![Declaration::Function(Function::new( vec![Declaration::Function(Function::new(
Some(interner.get_or_intern_static("foo", utf16!("foo")).into()), Some(interner.get_or_intern_static("foo", utf16!("foo")).into()),
@ -95,7 +95,7 @@ fn check_basic_semicolon_insertion() {
assert_eq!(params.flags(), FormalParameterListFlags::default()); assert_eq!(params.flags(), FormalParameterListFlags::default());
assert_eq!(params.length(), 1); assert_eq!(params.length(), 1);
check_parser( check_script_parser(
"function foo(a) { return a }", "function foo(a) { return a }",
vec![Declaration::Function(Function::new( vec![Declaration::Function(Function::new(
Some(interner.get_or_intern_static("foo", utf16!("foo")).into()), Some(interner.get_or_intern_static("foo", utf16!("foo")).into()),
@ -122,7 +122,7 @@ fn check_empty_return() {
)); ));
assert_eq!(params.flags(), FormalParameterListFlags::default()); assert_eq!(params.flags(), FormalParameterListFlags::default());
assert_eq!(params.length(), 1); assert_eq!(params.length(), 1);
check_parser( check_script_parser(
"function foo(a) { return; }", "function foo(a) { return; }",
vec![Declaration::Function(Function::new( vec![Declaration::Function(Function::new(
Some(interner.get_or_intern_static("foo", utf16!("foo")).into()), Some(interner.get_or_intern_static("foo", utf16!("foo")).into()),
@ -147,7 +147,7 @@ fn check_empty_return_semicolon_insertion() {
)); ));
assert_eq!(params.flags(), FormalParameterListFlags::default()); assert_eq!(params.flags(), FormalParameterListFlags::default());
assert_eq!(params.length(), 1); assert_eq!(params.length(), 1);
check_parser( check_script_parser(
"function foo(a) { return }", "function foo(a) { return }",
vec![Declaration::Function(Function::new( vec![Declaration::Function(Function::new(
Some(interner.get_or_intern_static("foo", utf16!("foo")).into()), Some(interner.get_or_intern_static("foo", utf16!("foo")).into()),
@ -181,7 +181,7 @@ fn check_rest_operator() {
FormalParameterListFlags::empty().union(FormalParameterListFlags::HAS_REST_PARAMETER) FormalParameterListFlags::empty().union(FormalParameterListFlags::HAS_REST_PARAMETER)
); );
assert_eq!(params.length(), 1); assert_eq!(params.length(), 1);
check_parser( check_script_parser(
"function foo(a, ...b) {}", "function foo(a, ...b) {}",
vec![Declaration::Function(Function::new( vec![Declaration::Function(Function::new(
Some(interner.get_or_intern_static("foo", utf16!("foo")).into()), Some(interner.get_or_intern_static("foo", utf16!("foo")).into()),
@ -206,7 +206,7 @@ fn check_arrow_only_rest() {
FormalParameterListFlags::empty().union(FormalParameterListFlags::HAS_REST_PARAMETER) FormalParameterListFlags::empty().union(FormalParameterListFlags::HAS_REST_PARAMETER)
); );
assert_eq!(params.length(), 0); assert_eq!(params.length(), 0);
check_parser( check_script_parser(
"(...a) => {}", "(...a) => {}",
vec![Statement::Expression(Expression::from(ArrowFunction::new( vec![Statement::Expression(Expression::from(ArrowFunction::new(
None, None,
@ -241,7 +241,7 @@ fn check_arrow_rest() {
FormalParameterListFlags::empty().union(FormalParameterListFlags::HAS_REST_PARAMETER) FormalParameterListFlags::empty().union(FormalParameterListFlags::HAS_REST_PARAMETER)
); );
assert_eq!(params.length(), 2); assert_eq!(params.length(), 2);
check_parser( check_script_parser(
"(a, b, ...c) => {}", "(a, b, ...c) => {}",
vec![Statement::Expression(Expression::from(ArrowFunction::new( vec![Statement::Expression(Expression::from(ArrowFunction::new(
None, None,
@ -269,7 +269,7 @@ fn check_arrow() {
]); ]);
assert_eq!(params.flags(), FormalParameterListFlags::default()); assert_eq!(params.flags(), FormalParameterListFlags::default());
assert_eq!(params.length(), 2); assert_eq!(params.length(), 2);
check_parser( check_script_parser(
"(a, b) => { return a + b; }", "(a, b) => { return a + b; }",
vec![Statement::Expression(Expression::from(ArrowFunction::new( vec![Statement::Expression(Expression::from(ArrowFunction::new(
None, None,
@ -305,7 +305,7 @@ fn check_arrow_semicolon_insertion() {
false, false,
), ),
]); ]);
check_parser( check_script_parser(
"(a, b) => { return a + b }", "(a, b) => { return a + b }",
vec![Statement::Expression(Expression::from(ArrowFunction::new( vec![Statement::Expression(Expression::from(ArrowFunction::new(
None, None,
@ -341,7 +341,7 @@ fn check_arrow_epty_return() {
false, false,
), ),
]); ]);
check_parser( check_script_parser(
"(a, b) => { return; }", "(a, b) => { return; }",
vec![Statement::Expression(Expression::from(ArrowFunction::new( vec![Statement::Expression(Expression::from(ArrowFunction::new(
None, None,
@ -370,7 +370,7 @@ fn check_arrow_empty_return_semicolon_insertion() {
false, false,
), ),
]); ]);
check_parser( check_script_parser(
"(a, b) => { return }", "(a, b) => { return }",
vec![Statement::Expression(Expression::from(ArrowFunction::new( vec![Statement::Expression(Expression::from(ArrowFunction::new(
None, None,
@ -394,7 +394,7 @@ fn check_arrow_assignment() {
)); ));
assert_eq!(params.flags(), FormalParameterListFlags::default()); assert_eq!(params.flags(), FormalParameterListFlags::default());
assert_eq!(params.length(), 1); assert_eq!(params.length(), 1);
check_parser( check_script_parser(
"let foo = (a) => { return a };", "let foo = (a) => { return a };",
vec![Declaration::Lexical(LexicalDeclaration::Let( vec![Declaration::Lexical(LexicalDeclaration::Let(
vec![Variable::from_identifier( vec![Variable::from_identifier(
@ -431,7 +431,7 @@ fn check_arrow_assignment_nobrackets() {
)); ));
assert_eq!(params.flags(), FormalParameterListFlags::default()); assert_eq!(params.flags(), FormalParameterListFlags::default());
assert_eq!(params.length(), 1); assert_eq!(params.length(), 1);
check_parser( check_script_parser(
"let foo = (a) => a;", "let foo = (a) => a;",
vec![Declaration::Lexical(LexicalDeclaration::Let( vec![Declaration::Lexical(LexicalDeclaration::Let(
vec![Variable::from_identifier( vec![Variable::from_identifier(
@ -468,7 +468,7 @@ fn check_arrow_assignment_noparenthesis() {
)); ));
assert_eq!(params.flags(), FormalParameterListFlags::default()); assert_eq!(params.flags(), FormalParameterListFlags::default());
assert_eq!(params.length(), 1); assert_eq!(params.length(), 1);
check_parser( check_script_parser(
"let foo = a => { return a };", "let foo = a => { return a };",
vec![Declaration::Lexical(LexicalDeclaration::Let( vec![Declaration::Lexical(LexicalDeclaration::Let(
vec![Variable::from_identifier( vec![Variable::from_identifier(
@ -505,7 +505,7 @@ fn check_arrow_assignment_noparenthesis_nobrackets() {
)); ));
assert_eq!(params.flags(), FormalParameterListFlags::default()); assert_eq!(params.flags(), FormalParameterListFlags::default());
assert_eq!(params.length(), 1); assert_eq!(params.length(), 1);
check_parser( check_script_parser(
"let foo = a => a;", "let foo = a => a;",
vec![Declaration::Lexical(LexicalDeclaration::Let( vec![Declaration::Lexical(LexicalDeclaration::Let(
vec![Variable::from_identifier( vec![Variable::from_identifier(
@ -548,7 +548,7 @@ fn check_arrow_assignment_2arg() {
]); ]);
assert_eq!(params.flags(), FormalParameterListFlags::default()); assert_eq!(params.flags(), FormalParameterListFlags::default());
assert_eq!(params.length(), 2); assert_eq!(params.length(), 2);
check_parser( check_script_parser(
"let foo = (a, b) => { return a };", "let foo = (a, b) => { return a };",
vec![Declaration::Lexical(LexicalDeclaration::Let( vec![Declaration::Lexical(LexicalDeclaration::Let(
vec![Variable::from_identifier( vec![Variable::from_identifier(
@ -591,7 +591,7 @@ fn check_arrow_assignment_2arg_nobrackets() {
]); ]);
assert_eq!(params.flags(), FormalParameterListFlags::default()); assert_eq!(params.flags(), FormalParameterListFlags::default());
assert_eq!(params.length(), 2); assert_eq!(params.length(), 2);
check_parser( check_script_parser(
"let foo = (a, b) => a;", "let foo = (a, b) => a;",
vec![Declaration::Lexical(LexicalDeclaration::Let( vec![Declaration::Lexical(LexicalDeclaration::Let(
vec![Variable::from_identifier( vec![Variable::from_identifier(
@ -638,7 +638,7 @@ fn check_arrow_assignment_3arg() {
]); ]);
assert_eq!(params.flags(), FormalParameterListFlags::default()); assert_eq!(params.flags(), FormalParameterListFlags::default());
assert_eq!(params.length(), 3); assert_eq!(params.length(), 3);
check_parser( check_script_parser(
"let foo = (a, b, c) => { return a };", "let foo = (a, b, c) => { return a };",
vec![Declaration::Lexical(LexicalDeclaration::Let( vec![Declaration::Lexical(LexicalDeclaration::Let(
vec![Variable::from_identifier( vec![Variable::from_identifier(
@ -685,7 +685,7 @@ fn check_arrow_assignment_3arg_nobrackets() {
]); ]);
assert_eq!(params.flags(), FormalParameterListFlags::default()); assert_eq!(params.flags(), FormalParameterListFlags::default());
assert_eq!(params.length(), 3); assert_eq!(params.length(), 3);
check_parser( check_script_parser(
"let foo = (a, b, c) => a;", "let foo = (a, b, c) => a;",
vec![Declaration::Lexical(LexicalDeclaration::Let( vec![Declaration::Lexical(LexicalDeclaration::Let(
vec![Variable::from_identifier( vec![Variable::from_identifier(

4
boa_parser/src/parser/statement/block/tests.rs

@ -2,7 +2,7 @@
use std::convert::TryInto; use std::convert::TryInto;
use crate::parser::tests::check_parser; use crate::parser::tests::check_script_parser;
use boa_ast::{ use boa_ast::{
declaration::{VarDeclaration, Variable}, declaration::{VarDeclaration, Variable},
expression::{ expression::{
@ -23,7 +23,7 @@ fn check_block<B>(js: &str, block: B, interner: &mut Interner)
where where
B: Into<Box<[StatementListItem]>>, B: Into<Box<[StatementListItem]>>,
{ {
check_parser( check_script_parser(
js, js,
vec![Statement::Block(Block::from(block.into())).into()], vec![Statement::Block(Block::from(block.into())).into()],
interner, interner,

22
boa_parser/src/parser/statement/break_stm/tests.rs

@ -1,4 +1,4 @@
use crate::parser::tests::check_parser; use crate::parser::tests::check_script_parser;
use boa_ast::{ use boa_ast::{
expression::literal::Literal, expression::literal::Literal,
statement::{Block, Break, WhileLoop}, statement::{Block, Break, WhileLoop},
@ -9,7 +9,7 @@ use boa_macros::utf16;
#[test] #[test]
fn inline() { fn inline() {
check_parser( check_script_parser(
"while (true) break;", "while (true) break;",
vec![Statement::WhileLoop(WhileLoop::new( vec![Statement::WhileLoop(WhileLoop::new(
Literal::from(true).into(), Literal::from(true).into(),
@ -22,7 +22,7 @@ fn inline() {
#[test] #[test]
fn new_line() { fn new_line() {
check_parser( check_script_parser(
"while (true) "while (true)
break;", break;",
vec![Statement::WhileLoop(WhileLoop::new( vec![Statement::WhileLoop(WhileLoop::new(
@ -36,7 +36,7 @@ fn new_line() {
#[test] #[test]
fn inline_block_semicolon_insertion() { fn inline_block_semicolon_insertion() {
check_parser( check_script_parser(
"while (true) {break}", "while (true) {break}",
vec![Statement::WhileLoop(WhileLoop::new( vec![Statement::WhileLoop(WhileLoop::new(
Literal::from(true).into(), Literal::from(true).into(),
@ -53,7 +53,7 @@ fn inline_block_semicolon_insertion() {
#[test] #[test]
fn new_line_semicolon_insertion() { fn new_line_semicolon_insertion() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"while (true) { "while (true) {
break test break test
}", }",
@ -71,7 +71,7 @@ fn new_line_semicolon_insertion() {
#[test] #[test]
fn inline_block() { fn inline_block() {
check_parser( check_script_parser(
"while (true) {break;}", "while (true) {break;}",
vec![Statement::WhileLoop(WhileLoop::new( vec![Statement::WhileLoop(WhileLoop::new(
Literal::from(true).into(), Literal::from(true).into(),
@ -88,7 +88,7 @@ fn inline_block() {
#[test] #[test]
fn new_line_block() { fn new_line_block() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"while (true) { "while (true) {
break test; break test;
}", }",
@ -107,7 +107,7 @@ fn new_line_block() {
#[test] #[test]
fn reserved_label() { fn reserved_label() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"while (true) { "while (true) {
break await; break await;
}", }",
@ -125,7 +125,7 @@ fn reserved_label() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"while (true) { "while (true) {
break yield; break yield;
}", }",
@ -145,7 +145,7 @@ fn reserved_label() {
#[test] #[test]
fn new_line_block_empty() { fn new_line_block_empty() {
check_parser( check_script_parser(
"while (true) { "while (true) {
break; break;
}", }",
@ -163,7 +163,7 @@ fn new_line_block_empty() {
#[test] #[test]
fn new_line_block_empty_semicolon_insertion() { fn new_line_block_empty_semicolon_insertion() {
check_parser( check_script_parser(
"while (true) { "while (true) {
break break
}", }",

22
boa_parser/src/parser/statement/continue_stm/tests.rs

@ -1,4 +1,4 @@
use crate::parser::tests::check_parser; use crate::parser::tests::check_script_parser;
use boa_ast::{ use boa_ast::{
expression::literal::Literal, expression::literal::Literal,
statement::{Block, Continue, WhileLoop}, statement::{Block, Continue, WhileLoop},
@ -9,7 +9,7 @@ use boa_macros::utf16;
#[test] #[test]
fn inline() { fn inline() {
check_parser( check_script_parser(
"while (true) continue;", "while (true) continue;",
vec![Statement::WhileLoop(WhileLoop::new( vec![Statement::WhileLoop(WhileLoop::new(
Literal::from(true).into(), Literal::from(true).into(),
@ -22,7 +22,7 @@ fn inline() {
#[test] #[test]
fn new_line() { fn new_line() {
check_parser( check_script_parser(
"while (true) "while (true)
continue;", continue;",
vec![Statement::WhileLoop(WhileLoop::new( vec![Statement::WhileLoop(WhileLoop::new(
@ -36,7 +36,7 @@ fn new_line() {
#[test] #[test]
fn inline_block_semicolon_insertion() { fn inline_block_semicolon_insertion() {
check_parser( check_script_parser(
"while (true) {continue}", "while (true) {continue}",
vec![Statement::WhileLoop(WhileLoop::new( vec![Statement::WhileLoop(WhileLoop::new(
Literal::from(true).into(), Literal::from(true).into(),
@ -53,7 +53,7 @@ fn inline_block_semicolon_insertion() {
#[test] #[test]
fn new_line_semicolon_insertion() { fn new_line_semicolon_insertion() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"while (true) { "while (true) {
continue test continue test
}", }",
@ -71,7 +71,7 @@ fn new_line_semicolon_insertion() {
#[test] #[test]
fn inline_block() { fn inline_block() {
check_parser( check_script_parser(
"while (true) {continue;}", "while (true) {continue;}",
vec![Statement::WhileLoop(WhileLoop::new( vec![Statement::WhileLoop(WhileLoop::new(
Literal::from(true).into(), Literal::from(true).into(),
@ -88,7 +88,7 @@ fn inline_block() {
#[test] #[test]
fn new_line_block() { fn new_line_block() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"while (true) { "while (true) {
continue test; continue test;
}", }",
@ -107,7 +107,7 @@ fn new_line_block() {
#[test] #[test]
fn reserved_label() { fn reserved_label() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"while (true) { "while (true) {
continue await; continue await;
}", }",
@ -125,7 +125,7 @@ fn reserved_label() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"while (true) { "while (true) {
continue yield; continue yield;
}", }",
@ -145,7 +145,7 @@ fn reserved_label() {
#[test] #[test]
fn new_line_block_empty() { fn new_line_block_empty() {
check_parser( check_script_parser(
"while (true) { "while (true) {
continue; continue;
}", }",
@ -163,7 +163,7 @@ fn new_line_block_empty() {
#[test] #[test]
fn new_line_block_empty_semicolon_insertion() { fn new_line_block_empty_semicolon_insertion() {
check_parser( check_script_parser(
"while (true) { "while (true) {
continue continue
}", }",

8
boa_parser/src/parser/statement/declaration/hoistable/async_function_decl/tests.rs

@ -1,4 +1,4 @@
use crate::parser::tests::check_parser; use crate::parser::tests::check_script_parser;
use boa_ast::{ use boa_ast::{
function::{AsyncFunction, FormalParameterList}, function::{AsyncFunction, FormalParameterList},
Declaration, StatementList, Declaration, StatementList,
@ -10,7 +10,7 @@ use boa_macros::utf16;
#[test] #[test]
fn async_function_declaration() { fn async_function_declaration() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"async function hello() {}", "async function hello() {}",
vec![Declaration::AsyncFunction(AsyncFunction::new( vec![Declaration::AsyncFunction(AsyncFunction::new(
Some( Some(
@ -31,7 +31,7 @@ fn async_function_declaration() {
#[test] #[test]
fn async_function_declaration_keywords() { fn async_function_declaration_keywords() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"async function yield() {}", "async function yield() {}",
vec![Declaration::AsyncFunction(AsyncFunction::new( vec![Declaration::AsyncFunction(AsyncFunction::new(
Some( Some(
@ -48,7 +48,7 @@ fn async_function_declaration_keywords() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"async function await() {}", "async function await() {}",
vec![Declaration::AsyncFunction(AsyncFunction::new( vec![Declaration::AsyncFunction(AsyncFunction::new(
Some( Some(

4
boa_parser/src/parser/statement/declaration/hoistable/async_generator_decl/tests.rs

@ -1,4 +1,4 @@
use crate::parser::tests::check_parser; use crate::parser::tests::check_script_parser;
use boa_ast::{ use boa_ast::{
function::{AsyncGenerator, FormalParameterList}, function::{AsyncGenerator, FormalParameterList},
Declaration, StatementList, Declaration, StatementList,
@ -9,7 +9,7 @@ use boa_macros::utf16;
#[test] #[test]
fn async_generator_function_declaration() { fn async_generator_function_declaration() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"async function* gen() {}", "async function* gen() {}",
vec![Declaration::AsyncGenerator(AsyncGenerator::new( vec![Declaration::AsyncGenerator(AsyncGenerator::new(
Some(interner.get_or_intern_static("gen", utf16!("gen")).into()), Some(interner.get_or_intern_static("gen", utf16!("gen")).into()),

33
boa_parser/src/parser/statement/declaration/hoistable/class_decl/mod.rs

@ -76,7 +76,8 @@ where
let mut has_binding_identifier = false; let mut has_binding_identifier = false;
let token = cursor.peek(0, interner).or_abrupt()?; let token = cursor.peek(0, interner).or_abrupt()?;
let name = match token.kind() { let name = match token.kind() {
TokenKind::Identifier(_) | TokenKind::Keyword((Keyword::Yield | Keyword::Await, _)) => { TokenKind::IdentifierName(_)
| TokenKind::Keyword((Keyword::Yield | Keyword::Await, _)) => {
has_binding_identifier = true; has_binding_identifier = true;
BindingIdentifier::new(self.allow_yield, self.allow_await) BindingIdentifier::new(self.allow_yield, self.allow_await)
.parse(cursor, interner)? .parse(cursor, interner)?
@ -595,11 +596,11 @@ where
cursor.advance(interner); cursor.advance(interner);
return Ok((None, None)); return Ok((None, None));
} }
TokenKind::Identifier((Sym::STATIC, ContainsEscapeSequence(contains_escape))) => { TokenKind::IdentifierName((Sym::STATIC, ContainsEscapeSequence(contains_escape))) => {
let contains_escape = *contains_escape; let contains_escape = *contains_escape;
let token = cursor.peek(1, interner).or_abrupt()?; let token = cursor.peek(1, interner).or_abrupt()?;
match token.kind() { match token.kind() {
TokenKind::Identifier(_) TokenKind::IdentifierName(_)
| TokenKind::StringLiteral(_) | TokenKind::StringLiteral(_)
| TokenKind::NumericLiteral(_) | TokenKind::NumericLiteral(_)
| TokenKind::Keyword(_) | TokenKind::Keyword(_)
@ -637,7 +638,7 @@ where
let token = cursor.peek(0, interner).or_abrupt()?; let token = cursor.peek(0, interner).or_abrupt()?;
let position = token.span().start(); let position = token.span().start();
let element = match token.kind() { let element = match token.kind() {
TokenKind::Identifier((Sym::CONSTRUCTOR, _)) if !r#static => { TokenKind::IdentifierName((Sym::CONSTRUCTOR, _)) if !r#static => {
cursor.advance(interner); cursor.advance(interner);
let strict = cursor.strict_mode(); let strict = cursor.strict_mode();
cursor.set_strict_mode(true); cursor.set_strict_mode(true);
@ -716,7 +717,7 @@ where
let token = cursor.peek(1, interner).or_abrupt()?; let token = cursor.peek(1, interner).or_abrupt()?;
let name_position = token.span().start(); let name_position = token.span().start();
if !r#static { if !r#static {
if let TokenKind::Identifier((Sym::CONSTRUCTOR, _)) = token.kind() { if let TokenKind::IdentifierName((Sym::CONSTRUCTOR, _)) = token.kind() {
return Err(Error::general( return Err(Error::general(
"class constructor may not be a generator method", "class constructor may not be a generator method",
token.span().start(), token.span().start(),
@ -780,7 +781,7 @@ where
token.span().start(), token.span().start(),
)); ));
} }
TokenKind::Identifier((Sym::CONSTRUCTOR, _)) if !r#static => { TokenKind::IdentifierName((Sym::CONSTRUCTOR, _)) if !r#static => {
return Err(Error::general( return Err(Error::general(
"class constructor may not be a generator method", "class constructor may not be a generator method",
token.span().start(), token.span().start(),
@ -824,7 +825,7 @@ where
} }
} }
} }
TokenKind::Identifier((Sym::CONSTRUCTOR, _)) if !r#static => { TokenKind::IdentifierName((Sym::CONSTRUCTOR, _)) if !r#static => {
return Err(Error::general( return Err(Error::general(
"class constructor may not be an async method", "class constructor may not be an async method",
token.span().start(), token.span().start(),
@ -875,13 +876,13 @@ where
} }
} }
} }
TokenKind::Identifier((Sym::GET, ContainsEscapeSequence(true))) if is_keyword => { TokenKind::IdentifierName((Sym::GET, ContainsEscapeSequence(true))) if is_keyword => {
return Err(Error::general( return Err(Error::general(
"keyword must not contain escaped characters", "keyword must not contain escaped characters",
token.span().start(), token.span().start(),
)) ))
} }
TokenKind::Identifier((Sym::GET, ContainsEscapeSequence(false))) if is_keyword => { TokenKind::IdentifierName((Sym::GET, ContainsEscapeSequence(false))) if is_keyword => {
cursor.advance(interner); cursor.advance(interner);
let token = cursor.peek(0, interner).or_abrupt()?; let token = cursor.peek(0, interner).or_abrupt()?;
match token.kind() { match token.kind() {
@ -933,13 +934,13 @@ where
) )
} }
} }
TokenKind::Identifier((Sym::CONSTRUCTOR, _)) if !r#static => { TokenKind::IdentifierName((Sym::CONSTRUCTOR, _)) if !r#static => {
return Err(Error::general( return Err(Error::general(
"class constructor may not be a getter method", "class constructor may not be a getter method",
token.span().start(), token.span().start(),
)) ))
} }
TokenKind::Identifier(_) TokenKind::IdentifierName(_)
| TokenKind::StringLiteral(_) | TokenKind::StringLiteral(_)
| TokenKind::NumericLiteral(_) | TokenKind::NumericLiteral(_)
| TokenKind::Keyword(_) | TokenKind::Keyword(_)
@ -1006,13 +1007,13 @@ where
} }
} }
} }
TokenKind::Identifier((Sym::SET, ContainsEscapeSequence(true))) if is_keyword => { TokenKind::IdentifierName((Sym::SET, ContainsEscapeSequence(true))) if is_keyword => {
return Err(Error::general( return Err(Error::general(
"keyword must not contain escaped characters", "keyword must not contain escaped characters",
token.span().start(), token.span().start(),
)) ))
} }
TokenKind::Identifier((Sym::SET, ContainsEscapeSequence(false))) if is_keyword => { TokenKind::IdentifierName((Sym::SET, ContainsEscapeSequence(false))) if is_keyword => {
cursor.advance(interner); cursor.advance(interner);
let token = cursor.peek(0, interner).or_abrupt()?; let token = cursor.peek(0, interner).or_abrupt()?;
match token.kind() { match token.kind() {
@ -1064,13 +1065,13 @@ where
) )
} }
} }
TokenKind::Identifier((Sym::CONSTRUCTOR, _)) if !r#static => { TokenKind::IdentifierName((Sym::CONSTRUCTOR, _)) if !r#static => {
return Err(Error::general( return Err(Error::general(
"class constructor may not be a setter method", "class constructor may not be a setter method",
token.span().start(), token.span().start(),
)) ))
} }
TokenKind::Identifier(_) TokenKind::IdentifierName(_)
| TokenKind::StringLiteral(_) | TokenKind::StringLiteral(_)
| TokenKind::NumericLiteral(_) | TokenKind::NumericLiteral(_)
| TokenKind::Keyword(_) | TokenKind::Keyword(_)
@ -1231,7 +1232,7 @@ where
} }
} }
} }
TokenKind::Identifier(_) TokenKind::IdentifierName(_)
| TokenKind::StringLiteral(_) | TokenKind::StringLiteral(_)
| TokenKind::NumericLiteral(_) | TokenKind::NumericLiteral(_)
| TokenKind::Keyword(_) | TokenKind::Keyword(_)

8
boa_parser/src/parser/statement/declaration/hoistable/class_decl/tests.rs

@ -1,4 +1,4 @@
use crate::parser::tests::check_parser; use crate::parser::tests::check_script_parser;
use boa_ast::{ use boa_ast::{
expression::literal::Literal, expression::literal::Literal,
function::{Class, ClassElement, FormalParameterList, Function}, function::{Class, ClassElement, FormalParameterList, Function},
@ -21,7 +21,7 @@ fn check_async_ordinary_method() {
)), )),
)]; )];
check_parser( check_script_parser(
"class A { "class A {
async() { } async() { }
} }
@ -47,7 +47,7 @@ fn check_async_field_initialization() {
Some(Literal::from(1).into()), Some(Literal::from(1).into()),
)]; )];
check_parser( check_script_parser(
"class A { "class A {
async async
= 1 = 1
@ -74,7 +74,7 @@ fn check_async_field() {
None, None,
)]; )];
check_parser( check_script_parser(
"class A { "class A {
async async
} }

24
boa_parser/src/parser/statement/declaration/hoistable/function_decl/tests.rs

@ -1,4 +1,4 @@
use crate::parser::tests::check_parser; use crate::parser::tests::check_script_parser;
use boa_ast::{ use boa_ast::{
function::{FormalParameterList, Function}, function::{FormalParameterList, Function},
Declaration, StatementList, Declaration, StatementList,
@ -10,7 +10,7 @@ use boa_macros::utf16;
#[test] #[test]
fn function_declaration() { fn function_declaration() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"function hello() {}", "function hello() {}",
vec![Declaration::Function(Function::new( vec![Declaration::Function(Function::new(
Some( Some(
@ -46,41 +46,41 @@ fn function_declaration_keywords() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
let ast = genast!("yield", interner); let ast = genast!("yield", interner);
check_parser("function yield() {}", ast, interner); check_script_parser("function yield() {}", ast, interner);
let interner = &mut Interner::default(); let interner = &mut Interner::default();
let ast = genast!("await", interner); let ast = genast!("await", interner);
check_parser("function await() {}", ast, interner); check_script_parser("function await() {}", ast, interner);
let interner = &mut Interner::default(); let interner = &mut Interner::default();
let ast = genast!("as", interner); let ast = genast!("as", interner);
check_parser("function as() {}", ast, interner); check_script_parser("function as() {}", ast, interner);
let interner = &mut Interner::default(); let interner = &mut Interner::default();
let ast = genast!("async", interner); let ast = genast!("async", interner);
check_parser("function async() {}", ast, interner); check_script_parser("function async() {}", ast, interner);
let interner = &mut Interner::default(); let interner = &mut Interner::default();
let ast = genast!("from", interner); let ast = genast!("from", interner);
check_parser("function from() {}", ast, interner); check_script_parser("function from() {}", ast, interner);
let interner = &mut Interner::default(); let interner = &mut Interner::default();
let ast = genast!("get", interner); let ast = genast!("get", interner);
check_parser("function get() {}", ast, interner); check_script_parser("function get() {}", ast, interner);
let interner = &mut Interner::default(); let interner = &mut Interner::default();
let ast = genast!("meta", interner); let ast = genast!("meta", interner);
check_parser("function meta() {}", ast, interner); check_script_parser("function meta() {}", ast, interner);
let interner = &mut Interner::default(); let interner = &mut Interner::default();
let ast = genast!("of", interner); let ast = genast!("of", interner);
check_parser("function of() {}", ast, interner); check_script_parser("function of() {}", ast, interner);
let interner = &mut Interner::default(); let interner = &mut Interner::default();
let ast = genast!("set", interner); let ast = genast!("set", interner);
check_parser("function set() {}", ast, interner); check_script_parser("function set() {}", ast, interner);
let interner = &mut Interner::default(); let interner = &mut Interner::default();
let ast = genast!("target", interner); let ast = genast!("target", interner);
check_parser("function target() {}", ast, interner); check_script_parser("function target() {}", ast, interner);
} }

4
boa_parser/src/parser/statement/declaration/hoistable/generator_decl/tests.rs

@ -1,4 +1,4 @@
use crate::parser::tests::check_parser; use crate::parser::tests::check_script_parser;
use boa_ast::{ use boa_ast::{
function::{FormalParameterList, Generator}, function::{FormalParameterList, Generator},
Declaration, StatementList, Declaration, StatementList,
@ -9,7 +9,7 @@ use boa_macros::utf16;
#[test] #[test]
fn generator_function_declaration() { fn generator_function_declaration() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"function* gen() {}", "function* gen() {}",
vec![Declaration::Generator(Generator::new( vec![Declaration::Generator(Generator::new(
Some(interner.get_or_intern_static("gen", utf16!("gen")).into()), Some(interner.get_or_intern_static("gen", utf16!("gen")).into()),

36
boa_parser/src/parser/statement/declaration/tests.rs

@ -1,6 +1,6 @@
use std::convert::TryInto; use std::convert::TryInto;
use crate::parser::tests::{check_invalid, check_parser}; use crate::parser::tests::{check_invalid, check_script_parser};
use boa_ast::{ use boa_ast::{
declaration::{LexicalDeclaration, VarDeclaration, Variable}, declaration::{LexicalDeclaration, VarDeclaration, Variable},
expression::literal::Literal, expression::literal::Literal,
@ -13,7 +13,7 @@ use boa_macros::utf16;
#[test] #[test]
fn var_declaration() { fn var_declaration() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"var a = 5;", "var a = 5;",
vec![Statement::Var(VarDeclaration( vec![Statement::Var(VarDeclaration(
vec![Variable::from_identifier( vec![Variable::from_identifier(
@ -32,7 +32,7 @@ fn var_declaration() {
#[test] #[test]
fn var_declaration_keywords() { fn var_declaration_keywords() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"var yield = 5;", "var yield = 5;",
vec![Statement::Var(VarDeclaration( vec![Statement::Var(VarDeclaration(
vec![Variable::from_identifier( vec![Variable::from_identifier(
@ -49,7 +49,7 @@ fn var_declaration_keywords() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"var await = 5;", "var await = 5;",
vec![Statement::Var(VarDeclaration( vec![Statement::Var(VarDeclaration(
vec![Variable::from_identifier( vec![Variable::from_identifier(
@ -70,7 +70,7 @@ fn var_declaration_keywords() {
#[test] #[test]
fn var_declaration_no_spaces() { fn var_declaration_no_spaces() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"var a=5;", "var a=5;",
vec![Statement::Var(VarDeclaration( vec![Statement::Var(VarDeclaration(
vec![Variable::from_identifier( vec![Variable::from_identifier(
@ -89,7 +89,7 @@ fn var_declaration_no_spaces() {
#[test] #[test]
fn empty_var_declaration() { fn empty_var_declaration() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"var a;", "var a;",
vec![Statement::Var(VarDeclaration( vec![Statement::Var(VarDeclaration(
vec![Variable::from_identifier( vec![Variable::from_identifier(
@ -108,7 +108,7 @@ fn empty_var_declaration() {
#[test] #[test]
fn multiple_var_declaration() { fn multiple_var_declaration() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"var a = 5, b, c = 6;", "var a = 5, b, c = 6;",
vec![Statement::Var(VarDeclaration( vec![Statement::Var(VarDeclaration(
vec![ vec![
@ -137,7 +137,7 @@ fn multiple_var_declaration() {
#[test] #[test]
fn let_declaration() { fn let_declaration() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"let a = 5;", "let a = 5;",
vec![Declaration::Lexical(LexicalDeclaration::Let( vec![Declaration::Lexical(LexicalDeclaration::Let(
vec![Variable::from_identifier( vec![Variable::from_identifier(
@ -156,7 +156,7 @@ fn let_declaration() {
#[test] #[test]
fn let_declaration_keywords() { fn let_declaration_keywords() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"let yield = 5;", "let yield = 5;",
vec![Declaration::Lexical(LexicalDeclaration::Let( vec![Declaration::Lexical(LexicalDeclaration::Let(
vec![Variable::from_identifier( vec![Variable::from_identifier(
@ -173,7 +173,7 @@ fn let_declaration_keywords() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"let await = 5;", "let await = 5;",
vec![Declaration::Lexical(LexicalDeclaration::Let( vec![Declaration::Lexical(LexicalDeclaration::Let(
vec![Variable::from_identifier( vec![Variable::from_identifier(
@ -194,7 +194,7 @@ fn let_declaration_keywords() {
#[test] #[test]
fn let_declaration_no_spaces() { fn let_declaration_no_spaces() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"let a=5;", "let a=5;",
vec![Declaration::Lexical(LexicalDeclaration::Let( vec![Declaration::Lexical(LexicalDeclaration::Let(
vec![Variable::from_identifier( vec![Variable::from_identifier(
@ -213,7 +213,7 @@ fn let_declaration_no_spaces() {
#[test] #[test]
fn empty_let_declaration() { fn empty_let_declaration() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"let a;", "let a;",
vec![Declaration::Lexical(LexicalDeclaration::Let( vec![Declaration::Lexical(LexicalDeclaration::Let(
vec![Variable::from_identifier( vec![Variable::from_identifier(
@ -232,7 +232,7 @@ fn empty_let_declaration() {
#[test] #[test]
fn multiple_let_declaration() { fn multiple_let_declaration() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"let a = 5, b, c = 6;", "let a = 5, b, c = 6;",
vec![Declaration::Lexical(LexicalDeclaration::Let( vec![Declaration::Lexical(LexicalDeclaration::Let(
vec![ vec![
@ -261,7 +261,7 @@ fn multiple_let_declaration() {
#[test] #[test]
fn const_declaration() { fn const_declaration() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"const a = 5;", "const a = 5;",
vec![Declaration::Lexical(LexicalDeclaration::Const( vec![Declaration::Lexical(LexicalDeclaration::Const(
vec![Variable::from_identifier( vec![Variable::from_identifier(
@ -280,7 +280,7 @@ fn const_declaration() {
#[test] #[test]
fn const_declaration_keywords() { fn const_declaration_keywords() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"const yield = 5;", "const yield = 5;",
vec![Declaration::Lexical(LexicalDeclaration::Const( vec![Declaration::Lexical(LexicalDeclaration::Const(
vec![Variable::from_identifier( vec![Variable::from_identifier(
@ -297,7 +297,7 @@ fn const_declaration_keywords() {
); );
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"const await = 5;", "const await = 5;",
vec![Declaration::Lexical(LexicalDeclaration::Const( vec![Declaration::Lexical(LexicalDeclaration::Const(
vec![Variable::from_identifier( vec![Variable::from_identifier(
@ -318,7 +318,7 @@ fn const_declaration_keywords() {
#[test] #[test]
fn const_declaration_no_spaces() { fn const_declaration_no_spaces() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"const a=5;", "const a=5;",
vec![Declaration::Lexical(LexicalDeclaration::Const( vec![Declaration::Lexical(LexicalDeclaration::Const(
vec![Variable::from_identifier( vec![Variable::from_identifier(
@ -343,7 +343,7 @@ fn empty_const_declaration() {
#[test] #[test]
fn multiple_const_declaration() { fn multiple_const_declaration() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"const a = 5, c = 6;", "const a = 5, c = 6;",
vec![Declaration::Lexical(LexicalDeclaration::Const( vec![Declaration::Lexical(LexicalDeclaration::Const(
vec![ vec![

6
boa_parser/src/parser/statement/if_stm/tests.rs

@ -1,4 +1,4 @@
use crate::parser::tests::check_parser; use crate::parser::tests::check_script_parser;
use boa_ast::{ use boa_ast::{
expression::literal::Literal, expression::literal::Literal,
statement::{Block, If}, statement::{Block, If},
@ -8,7 +8,7 @@ use boa_interner::Interner;
#[test] #[test]
fn if_without_else_block() { fn if_without_else_block() {
check_parser( check_script_parser(
"if (true) {}", "if (true) {}",
vec![Statement::If(If::new( vec![Statement::If(If::new(
Literal::from(true).into(), Literal::from(true).into(),
@ -22,7 +22,7 @@ fn if_without_else_block() {
#[test] #[test]
fn if_without_else_block_with_trailing_newline() { fn if_without_else_block_with_trailing_newline() {
check_parser( check_script_parser(
"if (true) {}\n", "if (true) {}\n",
vec![Statement::If(If::new( vec![Statement::If(If::new(
Literal::from(true).into(), Literal::from(true).into(),

12
boa_parser/src/parser/statement/iteration/tests.rs

@ -1,4 +1,4 @@
use crate::parser::tests::{check_invalid, check_parser}; use crate::parser::tests::{check_invalid, check_script_parser};
use boa_ast::{ use boa_ast::{
declaration::{VarDeclaration, Variable}, declaration::{VarDeclaration, Variable},
expression::{ expression::{
@ -17,7 +17,7 @@ use boa_macros::utf16;
#[test] #[test]
fn check_do_while() { fn check_do_while() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
r#"do { r#"do {
a += 1; a += 1;
} while (true)"#, } while (true)"#,
@ -43,7 +43,7 @@ fn check_do_while() {
#[test] #[test]
fn check_do_while_semicolon_insertion() { fn check_do_while_semicolon_insertion() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
r#"var i = 0; r#"var i = 0;
do {console.log("hello");} while(i++ < 10) console.log("end");"#, do {console.log("hello");} while(i++ < 10) console.log("end");"#,
vec![ vec![
@ -116,7 +116,7 @@ fn check_do_while_semicolon_insertion() {
#[test] #[test]
fn check_do_while_semicolon_insertion_no_space() { fn check_do_while_semicolon_insertion_no_space() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
r#"var i = 0; r#"var i = 0;
do {console.log("hello");} while(i++ < 10)console.log("end");"#, do {console.log("hello");} while(i++ < 10)console.log("end");"#,
vec![ vec![
@ -187,7 +187,7 @@ fn check_do_while_semicolon_insertion_no_space() {
/// Checks parsing of a while statement which is seperated out with line terminators. /// Checks parsing of a while statement which is seperated out with line terminators.
#[test] #[test]
fn while_spaces() { fn while_spaces() {
check_parser( check_script_parser(
r#" r#"
while while
@ -213,7 +213,7 @@ fn while_spaces() {
/// Checks parsing of a while statement which is seperated out with line terminators. /// Checks parsing of a while statement which is seperated out with line terminators.
#[test] #[test]
fn do_while_spaces() { fn do_while_spaces() {
check_parser( check_script_parser(
r#" r#"
do do

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

@ -190,7 +190,7 @@ where
cursor.advance(interner); cursor.advance(interner);
Ok(ast::Statement::Empty) Ok(ast::Statement::Empty)
} }
TokenKind::Identifier(_) => { TokenKind::IdentifierName(_) => {
// Labelled Statement check // Labelled Statement check
cursor.set_goal(InputElement::Div); cursor.set_goal(InputElement::Div);
let tok = cursor.peek(1, interner)?; let tok = cursor.peek(1, interner)?;
@ -504,7 +504,7 @@ where
TokenKind::Punctuator(Punctuator::OpenBracket) TokenKind::Punctuator(Punctuator::OpenBracket)
| TokenKind::StringLiteral(_) | TokenKind::StringLiteral(_)
| TokenKind::NumericLiteral(_) => true, | TokenKind::NumericLiteral(_) => true,
TokenKind::Identifier(_) if next_token_is_colon => true, TokenKind::IdentifierName(_) if next_token_is_colon => true,
TokenKind::Keyword(_) if next_token_is_colon => true, TokenKind::Keyword(_) if next_token_is_colon => true,
_ => false, _ => false,
}; };

4
boa_parser/src/parser/statement/switch/tests.rs

@ -1,4 +1,4 @@
use crate::parser::tests::{check_invalid, check_parser}; use crate::parser::tests::{check_invalid, check_script_parser};
use boa_ast::{ use boa_ast::{
declaration::{LexicalDeclaration, Variable}, declaration::{LexicalDeclaration, Variable},
expression::{access::SimplePropertyAccess, literal::Literal, Call, Identifier}, expression::{access::SimplePropertyAccess, literal::Literal, Call, Identifier},
@ -152,7 +152,7 @@ fn check_separated_switch() {
let console = interner.get_or_intern_static("console", utf16!("console")); let console = interner.get_or_intern_static("console", utf16!("console"));
let a = interner.get_or_intern_static("a", utf16!("a")); let a = interner.get_or_intern_static("a", utf16!("a"));
check_parser( check_script_parser(
s, s,
vec![ vec![
Declaration::Lexical(LexicalDeclaration::Let( Declaration::Lexical(LexicalDeclaration::Let(

4
boa_parser/src/parser/statement/throw/tests.rs

@ -1,4 +1,4 @@
use crate::parser::tests::check_parser; use crate::parser::tests::check_script_parser;
use boa_ast::{expression::literal::Literal, statement::Throw, Statement}; use boa_ast::{expression::literal::Literal, statement::Throw, Statement};
use boa_interner::Interner; use boa_interner::Interner;
use boa_macros::utf16; use boa_macros::utf16;
@ -6,7 +6,7 @@ use boa_macros::utf16;
#[test] #[test]
fn check_throw_parsing() { fn check_throw_parsing() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"throw 'error';", "throw 'error';",
vec![Statement::Throw(Throw::new( vec![Statement::Throw(Throw::new(
Literal::from(interner.get_or_intern_static("error", utf16!("error"))).into(), Literal::from(interner.get_or_intern_static("error", utf16!("error"))).into(),

2
boa_parser/src/parser/statement/try_stm/catch.rs

@ -168,7 +168,7 @@ where
.parse(cursor, interner)?; .parse(cursor, interner)?;
Ok(Binding::Pattern(pat.into())) Ok(Binding::Pattern(pat.into()))
} }
TokenKind::Identifier(_) => { TokenKind::IdentifierName(_) => {
let ident = BindingIdentifier::new(self.allow_yield, self.allow_await) let ident = BindingIdentifier::new(self.allow_yield, self.allow_await)
.parse(cursor, interner)?; .parse(cursor, interner)?;
Ok(Binding::Identifier(ident)) Ok(Binding::Identifier(ident))

22
boa_parser/src/parser/statement/try_stm/tests.rs

@ -1,6 +1,6 @@
use std::convert::TryInto; use std::convert::TryInto;
use crate::parser::tests::{check_invalid, check_parser}; use crate::parser::tests::{check_invalid, check_script_parser};
use boa_ast::{ use boa_ast::{
declaration::{VarDeclaration, Variable}, declaration::{VarDeclaration, Variable},
expression::{literal::Literal, Identifier}, expression::{literal::Literal, Identifier},
@ -15,7 +15,7 @@ use boa_macros::utf16;
#[test] #[test]
fn check_inline_with_empty_try_catch() { fn check_inline_with_empty_try_catch() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"try { } catch(e) {}", "try { } catch(e) {}",
vec![Statement::Try(Try::new( vec![Statement::Try(Try::new(
Block::default(), Block::default(),
@ -32,7 +32,7 @@ fn check_inline_with_empty_try_catch() {
#[test] #[test]
fn check_inline_with_var_decl_inside_try() { fn check_inline_with_var_decl_inside_try() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"try { var x = 1; } catch(e) {}", "try { var x = 1; } catch(e) {}",
vec![Statement::Try(Try::new( vec![Statement::Try(Try::new(
vec![Statement::Var(VarDeclaration( vec![Statement::Var(VarDeclaration(
@ -58,7 +58,7 @@ fn check_inline_with_var_decl_inside_try() {
#[test] #[test]
fn check_inline_with_var_decl_inside_catch() { fn check_inline_with_var_decl_inside_catch() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"try { var x = 1; } catch(e) { var x = 1; }", "try { var x = 1; } catch(e) { var x = 1; }",
vec![Statement::Try(Try::new( vec![Statement::Try(Try::new(
vec![Statement::Var(VarDeclaration( vec![Statement::Var(VarDeclaration(
@ -93,7 +93,7 @@ fn check_inline_with_var_decl_inside_catch() {
#[test] #[test]
fn check_inline_with_empty_try_catch_finally() { fn check_inline_with_empty_try_catch_finally() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"try {} catch(e) {} finally {}", "try {} catch(e) {} finally {}",
vec![Statement::Try(Try::new( vec![Statement::Try(Try::new(
Block::default(), Block::default(),
@ -112,7 +112,7 @@ fn check_inline_with_empty_try_catch_finally() {
#[test] #[test]
fn check_inline_with_empty_try_finally() { fn check_inline_with_empty_try_finally() {
check_parser( check_script_parser(
"try {} finally {}", "try {} finally {}",
vec![Statement::Try(Try::new( vec![Statement::Try(Try::new(
Block::default(), Block::default(),
@ -126,7 +126,7 @@ fn check_inline_with_empty_try_finally() {
#[test] #[test]
fn check_inline_with_empty_try_var_decl_in_finally() { fn check_inline_with_empty_try_var_decl_in_finally() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"try {} finally { var x = 1; }", "try {} finally { var x = 1; }",
vec![Statement::Try(Try::new( vec![Statement::Try(Try::new(
Block::default(), Block::default(),
@ -149,7 +149,7 @@ fn check_inline_with_empty_try_var_decl_in_finally() {
#[test] #[test]
fn check_inline_empty_try_paramless_catch() { fn check_inline_empty_try_paramless_catch() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"try {} catch { var x = 1; }", "try {} catch { var x = 1; }",
vec![Statement::Try(Try::new( vec![Statement::Try(Try::new(
Block::default(), Block::default(),
@ -176,7 +176,7 @@ fn check_inline_empty_try_paramless_catch() {
fn check_inline_with_binding_pattern_object() { fn check_inline_with_binding_pattern_object() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
let a = interner.get_or_intern_static("a", utf16!("a")); let a = interner.get_or_intern_static("a", utf16!("a"));
check_parser( check_script_parser(
"try {} catch ({ a, b: c }) {}", "try {} catch ({ a, b: c }) {}",
vec![Statement::Try(Try::new( vec![Statement::Try(Try::new(
Block::default(), Block::default(),
@ -209,7 +209,7 @@ fn check_inline_with_binding_pattern_object() {
#[test] #[test]
fn check_inline_with_binding_pattern_array() { fn check_inline_with_binding_pattern_array() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"try {} catch ([a, b]) {}", "try {} catch ([a, b]) {}",
vec![Statement::Try(Try::new( vec![Statement::Try(Try::new(
Block::from(vec![]), Block::from(vec![]),
@ -238,7 +238,7 @@ fn check_inline_with_binding_pattern_array() {
#[test] #[test]
fn check_catch_with_var_redeclaration() { fn check_catch_with_var_redeclaration() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"try {} catch(e) { var e = 'oh' }", "try {} catch(e) { var e = 'oh' }",
vec![Statement::Try(Try::new( vec![Statement::Try(Try::new(
Block::from(vec![]), Block::from(vec![]),

42
boa_parser/src/parser/tests/mod.rs

@ -31,7 +31,7 @@ use boa_macros::utf16;
/// Checks that the given JavaScript string gives the expected expression. /// Checks that the given JavaScript string gives the expected expression.
#[allow(clippy::unwrap_used)] #[allow(clippy::unwrap_used)]
#[track_caller] #[track_caller]
pub(super) fn check_parser<L>(js: &str, expr: L, interner: &mut Interner) pub(super) fn check_script_parser<L>(js: &str, expr: L, interner: &mut Interner)
where where
L: Into<Box<[StatementListItem]>>, L: Into<Box<[StatementListItem]>>,
{ {
@ -55,7 +55,7 @@ pub(super) fn check_invalid(js: &str) {
#[test] #[test]
fn check_construct_call_precedence() { fn check_construct_call_precedence() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"new Date().getTime()", "new Date().getTime()",
vec![Statement::Expression(Expression::from(Call::new( vec![Statement::Expression(Expression::from(Call::new(
Expression::PropertyAccess( Expression::PropertyAccess(
@ -80,7 +80,7 @@ fn check_construct_call_precedence() {
#[test] #[test]
fn assign_operator_precedence() { fn assign_operator_precedence() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
"a = a + 1", "a = a + 1",
vec![Statement::Expression(Expression::from(Assign::new( vec![Statement::Expression(Expression::from(Assign::new(
AssignOp::Assign, AssignOp::Assign,
@ -104,7 +104,7 @@ fn hoisting() {
.get_or_intern_static("hello", utf16!("hello")) .get_or_intern_static("hello", utf16!("hello"))
.into(); .into();
let a = interner.get_or_intern_static("a", utf16!("a")); let a = interner.get_or_intern_static("a", utf16!("a"));
check_parser( check_script_parser(
r" r"
var a = hello(); var a = hello();
a++; a++;
@ -137,7 +137,7 @@ fn hoisting() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
let a = interner.get_or_intern_static("a", utf16!("a")); let a = interner.get_or_intern_static("a", utf16!("a"));
check_parser( check_script_parser(
r" r"
a = 10; a = 10;
a++; a++;
@ -171,7 +171,7 @@ fn ambigous_regex_divide_expression() {
let s = "1 / a === 1 / b"; let s = "1 / a === 1 / b";
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
s, s,
vec![Statement::Expression(Expression::from(Binary::new( vec![Statement::Expression(Expression::from(Binary::new(
RelationalOp::StrictEqual.into(), RelationalOp::StrictEqual.into(),
@ -199,7 +199,7 @@ fn two_divisions_in_expression() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
let a = interner.get_or_intern_static("a", utf16!("a")); let a = interner.get_or_intern_static("a", utf16!("a"));
check_parser( check_script_parser(
s, s,
vec![Statement::Expression(Expression::from(Binary::new( vec![Statement::Expression(Expression::from(Binary::new(
LogicalOp::Or.into(), LogicalOp::Or.into(),
@ -239,7 +239,7 @@ fn comment_semi_colon_insertion() {
"#; "#;
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
s, s,
vec![ vec![
Declaration::Lexical(LexicalDeclaration::Let( Declaration::Lexical(LexicalDeclaration::Let(
@ -275,7 +275,7 @@ fn multiline_comment_semi_colon_insertion() {
"#; "#;
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
s, s,
vec![ vec![
Declaration::Lexical(LexicalDeclaration::Let( Declaration::Lexical(LexicalDeclaration::Let(
@ -308,7 +308,7 @@ fn multiline_comment_no_lineterminator() {
"#; "#;
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
s, s,
vec![ vec![
Declaration::Lexical(LexicalDeclaration::Let( Declaration::Lexical(LexicalDeclaration::Let(
@ -344,7 +344,7 @@ fn assignment_line_terminator() {
"#; "#;
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
s, s,
vec![ vec![
Declaration::Lexical(LexicalDeclaration::Let( Declaration::Lexical(LexicalDeclaration::Let(
@ -381,7 +381,7 @@ fn assignment_multiline_terminator() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
let a = interner.get_or_intern_static("a", utf16!("a")); let a = interner.get_or_intern_static("a", utf16!("a"));
check_parser( check_script_parser(
s, s,
vec![ vec![
Declaration::Lexical(LexicalDeclaration::Let( Declaration::Lexical(LexicalDeclaration::Let(
@ -409,7 +409,7 @@ fn bracketed_expr() {
let s = r#"(b)"#; let s = r#"(b)"#;
let interner = &mut Interner::default(); let interner = &mut Interner::default();
check_parser( check_script_parser(
s, s,
vec![Statement::Expression(Expression::from(Identifier::new( vec![Statement::Expression(Expression::from(Identifier::new(
interner.get_or_intern_static("b", utf16!("b")), interner.get_or_intern_static("b", utf16!("b")),
@ -425,7 +425,7 @@ fn increment_in_comma_op() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
let b = interner.get_or_intern_static("b", utf16!("b")); let b = interner.get_or_intern_static("b", utf16!("b"));
check_parser( check_script_parser(
s, s,
vec![Statement::Expression(Expression::from(Binary::new( vec![Statement::Expression(Expression::from(Binary::new(
BinaryOp::Comma, BinaryOp::Comma,
@ -458,7 +458,7 @@ fn spread_in_object() {
), ),
]; ];
check_parser( check_script_parser(
s, s,
vec![Declaration::Lexical(LexicalDeclaration::Let( vec![Declaration::Lexical(LexicalDeclaration::Let(
vec![Variable::from_identifier( vec![Variable::from_identifier(
@ -489,7 +489,7 @@ fn spread_in_arrow_function() {
)); ));
assert_eq!(params.flags(), FormalParameterListFlags::HAS_REST_PARAMETER); assert_eq!(params.flags(), FormalParameterListFlags::HAS_REST_PARAMETER);
assert_eq!(params.length(), 0); assert_eq!(params.length(), 0);
check_parser( check_script_parser(
s, s,
vec![Statement::Expression(Expression::from(ArrowFunction::new( vec![Statement::Expression(Expression::from(ArrowFunction::new(
None, None,
@ -505,7 +505,7 @@ fn spread_in_arrow_function() {
fn empty_statement() { fn empty_statement() {
let interner = &mut Interner::default(); let interner = &mut Interner::default();
let a = interner.get_or_intern_static("a", utf16!("a")); let a = interner.get_or_intern_static("a", utf16!("a"));
check_parser( check_script_parser(
r" r"
;;var a = 10; ;;var a = 10;
if(a) ; if(a) ;
@ -536,7 +536,7 @@ fn empty_statement_ends_directive_prologues() {
let public = interner let public = interner
.get_or_intern_static("public", utf16!("public")) .get_or_intern_static("public", utf16!("public"))
.into(); .into();
check_parser( check_script_parser(
r#" r#"
"a"; "a";
; ;
@ -563,7 +563,7 @@ fn empty_statement_ends_directive_prologues() {
#[test] #[test]
fn hashbang_use_strict_no_with() { fn hashbang_use_strict_no_with() {
check_parser( check_script_parser(
r#"#!\"use strict" r#"#!\"use strict"
"#, "#,
vec![], vec![],
@ -574,7 +574,7 @@ fn hashbang_use_strict_no_with() {
#[test] #[test]
#[ignore] #[ignore]
fn hashbang_use_strict_with_with_statement() { fn hashbang_use_strict_with_with_statement() {
check_parser( check_script_parser(
r#"#!\"use strict" r#"#!\"use strict"
with({}) {} with({}) {}
@ -586,5 +586,5 @@ fn hashbang_use_strict_with_with_statement() {
#[test] #[test]
fn hashbang_comment() { fn hashbang_comment() {
check_parser(r"#!Comment Here", vec![], &mut Interner::default()); check_script_parser(r"#!Comment Here", vec![], &mut Interner::default());
} }

Loading…
Cancel
Save