Skip to content

Commit

Permalink
add generator support for StaticBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Sep 28, 2020
1 parent 52d9663 commit 300415d
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/babel-generator/src/generators/classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Foo {
static {}
}

class A1 {
static{
foo;
}
}

class A2 {
static {
foo;
bar;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"minified": true,
"plugins": ["classStaticBlock"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class Foo{static{}}class A1{static{foo}}class A2{static{foo;bar}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Foo {
static {}
}

class A1 {
static{
foo;
}
}

class A2 {
static {
foo;bar;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "plugins": ["classStaticBlock"] }
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Foo {
static {}
}

class A1 {
static {
foo;
}
}

class A2 {
static {
foo;
bar;
}
}

0 comments on commit 300415d

Please sign in to comment.