Skip to content

Commit

Permalink
feat(es/parser): Add tests for static blocks (#2180)
Browse files Browse the repository at this point in the history
swc_ecma_parser:
 - Add tests for multiple static blocks in a class.
  • Loading branch information
sosukesuzuki authored Aug 30, 2021
1 parent c0b0337 commit b2c9971
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions ecmascript/parser/src/parser/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }; }";
Expand Down

0 comments on commit b2c9971

Please sign in to comment.