feat(es/parser): Add tests for static blocks (#2180)

swc_ecma_parser:
 - Add tests for multiple static blocks in a class.
This commit is contained in:
Sosuke Suzuki 2021-08-30 12:45:41 +09:00 committed by GitHub
parent c0b0337d1d
commit b2c99719fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1926,6 +1926,47 @@ export default function waitUntil(callback, options = {}) {
);
}
#[test]
fn multiple_class_static_blocks() {
let src = "class Foo { static { 1 + 1; } static { 1 + 1; } }";
assert_eq_ignore_span!(
test_parser(
src,
Syntax::Es(EsConfig {
static_blocks: true,
..Default::default()
}),
|p| p.parse_expr()
),
Box::new(Expr::Class(ClassExpr {
ident: Some(Ident {
span,
sym: "Foo".into(),
optional: false,
}),
class: Class {
span,
decorators: Vec::new(),
super_class: None,
type_params: None,
super_type_params: None,
is_abstract: false,
implements: Vec::new(),
body: vec!(
ClassMember::StaticBlock(StaticBlock {
span,
body: vec!(stmt("1 + 1;"))
}),
ClassMember::StaticBlock(StaticBlock {
span,
body: vec!(stmt("1 + 1;"))
})
)
}
}))
);
}
#[test]
fn class_static_blocks_in_ts() {
let src = "class Foo { static { 1 + 1 }; }";