Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public static boolean generatesCode(IdeDeclaration primaryDeclaration) {
private boolean needsCompanionInterface;
private List<ClassDeclaration> mixinClasses;
private boolean hasOwnConfigClass;
private List<BlockStatement> staticCodeBlocks;

TypeScriptCodeGenerator(TypeScriptModuleResolver typeScriptModuleResolver, JsWriter out, CompilationUnitResolver compilationUnitModelResolver) {
super(out, compilationUnitModelResolver);
Expand Down Expand Up @@ -2131,7 +2132,15 @@ public void visitClassBodyDirectives(List<Directive> classBodyDirectives) throws
}
}
}
staticCodeBlocks = new ArrayList<>();
super.visitClassBodyDirectives(classBodyDirectives);
if (!companionInterfaceMode) {
for (BlockStatement staticCodeBlock : staticCodeBlocks) {
out.writeSymbolWhitespace(staticCodeBlock.getSymbol());
out.writeToken("static ");
staticCodeBlock.visit(this);
}
}
}

private void generateRestResourceUriTemplateConstant(Annotation restResourceAnnotation) throws IOException {
Expand All @@ -2157,35 +2166,26 @@ private void setIndentationToTwo(JooSymbol symbol) {
}
}

private int staticCodeCounter = 0;

@Override
void generateStaticInitializer(List<Directive> directives) throws IOException {
if (directives.isEmpty() || companionInterfaceMode) {
if (directives.isEmpty()) {
return;
}
Directive firstDirective = directives.get(0);
out.writeSymbolWhitespace(firstDirective.getSymbol());
String uniqueName = "";
if (staticCodeCounter > 0) {
uniqueName = String.valueOf(staticCodeCounter);
}
++staticCodeCounter;
out.writeToken(String.format("static #static%s = (() =>", uniqueName));

// is static code already wrapped in a block?
if (directives.size() == 1 && firstDirective instanceof BlockStatement) {
// static block already has curly braces: reuse these!
firstDirective.visit(this);
staticCodeBlocks.add((BlockStatement) firstDirective);
} else {
// surround statements by curly braces:
out.writeToken(" {\n ");
for (Directive directive : directives) {
directive.visit(this);
}
out.writeToken("\n }");
JooSymbol firstSymbol = firstDirective.getSymbol();
JooSymbol lastSymbol = directives.get(directives.size() - 1).getSymbol();
staticCodeBlocks.add(new BlockStatement(
new JooSymbol(sym.LBRACE, firstSymbol.getFileName(), firstSymbol.getLine(), firstSymbol.getColumn(), firstSymbol.getWhitespace(), "{"),
directives,
new JooSymbol(sym.RBRACE, lastSymbol.getFileName(), lastSymbol.getLine(), lastSymbol.getColumn(), lastSymbol.getWhitespace(), "}")
));
}
out.writeToken(")();");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
*/
class StaticAndNonStatic {

static #static = (() => {
new StaticAndNonStatic();
})();

StaticAndNonStatic:string = null;

static {

new StaticAndNonStatic();

}

static {

new StaticAndNonStatic();

static #static1 = (() => {
new StaticAndNonStatic();
})();
}
}
export default StaticAndNonStatic;
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,6 @@ class SimpleMxmlClass extends ConfigClass{

#blub:any;

static #static = (() =>{
if(1 < 0 && 0 > 1) {
throw "plain wrong!";
}
})();

#list:any = null;

get list():any { return this.#list; }
Expand Down Expand Up @@ -193,5 +187,11 @@ class SimpleMxmlClass extends ConfigClass{
#no_config:SomeOtherClass = null;

get no_config():SomeOtherClass { return this.#no_config; }
set no_config(value:SomeOtherClass) { this.#no_config = value; }}
set no_config(value:SomeOtherClass) { this.#no_config = value; }

static {
if(1 < 0 && 0 > 1) {
throw "plain wrong!";
}
}}
export default SimpleMxmlClass;