Parse class static block (#12079)
Co-authored-by: Brian Ng <bng412@gmail.com>
This commit is contained in:
committed by
Nicolò Ribaudo
parent
6830c90ac9
commit
3ccca88178
@@ -134,3 +134,18 @@ export function _classMethodHead(node) {
|
||||
this.tsPrintClassMemberModifiers(node, /* isField */ false);
|
||||
this._methodHead(node);
|
||||
}
|
||||
|
||||
export function StaticBlock(node) {
|
||||
this.word("static");
|
||||
this.space();
|
||||
this.token("{");
|
||||
if (node.body.length === 0) {
|
||||
this.token("}");
|
||||
} else {
|
||||
this.newline();
|
||||
this.printSequence(node.body, node, {
|
||||
indent: true,
|
||||
});
|
||||
this.rightBrace();
|
||||
}
|
||||
}
|
||||
|
||||
16
packages/babel-generator/test/fixtures/minified/static-block/input.js
vendored
Normal file
16
packages/babel-generator/test/fixtures/minified/static-block/input.js
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
class Foo {
|
||||
static {}
|
||||
}
|
||||
|
||||
class A1 {
|
||||
static{
|
||||
foo;
|
||||
}
|
||||
}
|
||||
|
||||
class A2 {
|
||||
static {
|
||||
foo;
|
||||
bar;
|
||||
}
|
||||
}
|
||||
4
packages/babel-generator/test/fixtures/minified/static-block/options.json
vendored
Normal file
4
packages/babel-generator/test/fixtures/minified/static-block/options.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"minified": true,
|
||||
"plugins": ["classStaticBlock"]
|
||||
}
|
||||
1
packages/babel-generator/test/fixtures/minified/static-block/output.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/minified/static-block/output.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
class Foo{static{}}class A1{static{foo}}class A2{static{foo;bar}}
|
||||
15
packages/babel-generator/test/fixtures/types/ClassBody-StaticBlock/input.js
vendored
Normal file
15
packages/babel-generator/test/fixtures/types/ClassBody-StaticBlock/input.js
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
class Foo {
|
||||
static {}
|
||||
}
|
||||
|
||||
class A1 {
|
||||
static{
|
||||
foo;
|
||||
}
|
||||
}
|
||||
|
||||
class A2 {
|
||||
static {
|
||||
foo;bar;
|
||||
}
|
||||
}
|
||||
1
packages/babel-generator/test/fixtures/types/ClassBody-StaticBlock/options.json
vendored
Normal file
1
packages/babel-generator/test/fixtures/types/ClassBody-StaticBlock/options.json
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{ "plugins": ["classStaticBlock"] }
|
||||
16
packages/babel-generator/test/fixtures/types/ClassBody-StaticBlock/output.js
vendored
Normal file
16
packages/babel-generator/test/fixtures/types/ClassBody-StaticBlock/output.js
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
class Foo {
|
||||
static {}
|
||||
}
|
||||
|
||||
class A1 {
|
||||
static {
|
||||
foo;
|
||||
}
|
||||
}
|
||||
|
||||
class A2 {
|
||||
static {
|
||||
foo;
|
||||
bar;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user