mirror of https://github.com/boa-dev/boa.git
Browse Source
This PR fixes #2275 There are keywords that are allowed as identifiers. https://tc39.es/ecma262/#sec-keywords-and-reserved-words > Those that are always allowed as identifiers, but also appear as keywords within certain syntactic productions, at places where Identifier is not allowed: as, async, from, get, meta, of, set, and target. This PR adds test cases for them, and fixes some cases such as `class A { set(a, b) { } }` `function of() { }` `let obj = {async: true}` `async()`pull/2277/head
Choongwoo Han
2 years ago
14 changed files with 392 additions and 173 deletions
@ -0,0 +1,95 @@ |
|||||||
|
use crate::syntax::{ |
||||||
|
ast::{ |
||||||
|
node::{ |
||||||
|
declaration::class_decl::ClassElement as ClassElementNode, |
||||||
|
object::{MethodDefinition, PropertyName}, |
||||||
|
Class, FormalParameterList, FunctionExpr, Node, |
||||||
|
}, |
||||||
|
Const, |
||||||
|
}, |
||||||
|
parser::tests::check_parser, |
||||||
|
}; |
||||||
|
use boa_interner::Interner; |
||||||
|
|
||||||
|
#[test] |
||||||
|
fn check_async_ordinary_method() { |
||||||
|
let mut interner = Interner::default(); |
||||||
|
|
||||||
|
let elements = vec![ClassElementNode::MethodDefinition( |
||||||
|
PropertyName::Computed(Node::Const(Const::from( |
||||||
|
interner.get_or_intern_static("async"), |
||||||
|
))), |
||||||
|
MethodDefinition::Ordinary(FunctionExpr::new( |
||||||
|
None, |
||||||
|
FormalParameterList::default(), |
||||||
|
vec![], |
||||||
|
)), |
||||||
|
)]; |
||||||
|
|
||||||
|
check_parser( |
||||||
|
"class A { |
||||||
|
async() { } |
||||||
|
} |
||||||
|
", |
||||||
|
[Node::ClassDecl(Class::new( |
||||||
|
interner.get_or_intern_static("A"), |
||||||
|
None, |
||||||
|
None, |
||||||
|
elements, |
||||||
|
))], |
||||||
|
interner, |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
#[test] |
||||||
|
fn check_async_field_initialization() { |
||||||
|
let mut interner = Interner::default(); |
||||||
|
|
||||||
|
let elements = vec![ClassElementNode::FieldDefinition( |
||||||
|
PropertyName::Computed(Node::Const(Const::from( |
||||||
|
interner.get_or_intern_static("async"), |
||||||
|
))), |
||||||
|
Some(Node::Const(Const::from(1))), |
||||||
|
)]; |
||||||
|
|
||||||
|
check_parser( |
||||||
|
"class A { |
||||||
|
async |
||||||
|
= 1 |
||||||
|
} |
||||||
|
", |
||||||
|
[Node::ClassDecl(Class::new( |
||||||
|
interner.get_or_intern_static("A"), |
||||||
|
None, |
||||||
|
None, |
||||||
|
elements, |
||||||
|
))], |
||||||
|
interner, |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
#[test] |
||||||
|
fn check_async_field() { |
||||||
|
let mut interner = Interner::default(); |
||||||
|
|
||||||
|
let elements = vec![ClassElementNode::FieldDefinition( |
||||||
|
PropertyName::Computed(Node::Const(Const::from( |
||||||
|
interner.get_or_intern_static("async"), |
||||||
|
))), |
||||||
|
None, |
||||||
|
)]; |
||||||
|
|
||||||
|
check_parser( |
||||||
|
"class A { |
||||||
|
async |
||||||
|
} |
||||||
|
", |
||||||
|
[Node::ClassDecl(Class::new( |
||||||
|
interner.get_or_intern_static("A"), |
||||||
|
None, |
||||||
|
None, |
||||||
|
elements, |
||||||
|
))], |
||||||
|
interner, |
||||||
|
); |
||||||
|
} |
Loading…
Reference in new issue