mirror of
https://github.com/cincheo/jsweet.git
synced 2025-12-15 15:29:22 +00:00
fix for static imports with @Root annotation + associated test cases
This commit is contained in:
parent
bfd3d32276
commit
fbc32b0f6f
@ -136,12 +136,13 @@ public class Java2TypeScriptAdapter extends AbstractPrinterAdapter {
|
||||
}
|
||||
// function belong to the current package (no need to
|
||||
// import)
|
||||
String current = Util.getRootRelativeJavaName(getPrinter().getCompilationUnit().packge);
|
||||
if (getPrinter().getContext().useModules) {
|
||||
if (getPrinter().getCompilationUnit().packge.getQualifiedName().toString().equals(name)) {
|
||||
if (current.equals(name)) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
if (getPrinter().getCompilationUnit().packge.getQualifiedName().toString().startsWith(name)) {
|
||||
if (current.startsWith(name)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,6 +44,8 @@ import org.jsweet.test.transpiler.source.structural.globalclasses.c.GlobalFuncti
|
||||
import org.jsweet.test.transpiler.source.structural.globalclasses.d.GlobalFunctionAccessFromMain;
|
||||
import org.jsweet.test.transpiler.source.structural.globalclasses.f.GlobalFunctionStaticDelete;
|
||||
import org.jsweet.test.transpiler.source.structural.globalclasses.g.GlobalFunctionDelete;
|
||||
import org.jsweet.test.transpiler.source.structural.globalclasses.noroot.a.GlobalsInNoRoot;
|
||||
import org.jsweet.test.transpiler.source.structural.globalclasses.root.a.GlobalsInRoot;
|
||||
import org.jsweet.transpiler.JSweetProblem;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@ -204,6 +206,24 @@ public class StructuralTests extends AbstractTest {
|
||||
getSourceFile(GlobalFunctionAccessFromMain.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGlobalsInRoot() {
|
||||
eval((logHandler, r) -> {
|
||||
assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
Assert.assertEquals(true, r.get("m1"));
|
||||
Assert.assertEquals(true, r.get("m2"));
|
||||
} , getSourceFile(GlobalsInRoot.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGlobalsInNoRoot() {
|
||||
eval((logHandler, r) -> {
|
||||
assertEquals("There should be no errors", 0, logHandler.reportedProblems.size());
|
||||
Assert.assertEquals(true, r.get("m1"));
|
||||
Assert.assertEquals(true, r.get("m2"));
|
||||
} , getSourceFile(GlobalsInNoRoot.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutoImportClassesInSamePackage() {
|
||||
eval((logHandler, r) -> {
|
||||
|
||||
@ -0,0 +1,33 @@
|
||||
package org.jsweet.test.transpiler.source.structural.globalclasses.noroot.a;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static org.jsweet.test.transpiler.source.structural.globalclasses.noroot.a.Globals.m2;
|
||||
|
||||
public class GlobalsInNoRoot {
|
||||
|
||||
public void f1() {
|
||||
Globals.m1();
|
||||
}
|
||||
|
||||
public void f2() {
|
||||
m2();
|
||||
}
|
||||
}
|
||||
|
||||
class Globals {
|
||||
|
||||
public static void m1() {
|
||||
$export("m1", true);
|
||||
}
|
||||
|
||||
public static void m2() {
|
||||
$export("m2", true);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
GlobalsInNoRoot o = new GlobalsInNoRoot();
|
||||
o.f1();
|
||||
o.f2();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
package org.jsweet.test.transpiler.source.structural.globalclasses.root.a;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static org.jsweet.test.transpiler.source.structural.globalclasses.root.a.Globals.m2;
|
||||
|
||||
public class GlobalsInRoot {
|
||||
|
||||
public void f1() {
|
||||
Globals.m1();
|
||||
}
|
||||
|
||||
public void f2() {
|
||||
m2();
|
||||
}
|
||||
}
|
||||
|
||||
class Globals {
|
||||
|
||||
public static void m1() {
|
||||
$export("m1", true);
|
||||
}
|
||||
|
||||
public static void m2() {
|
||||
$export("m2", true);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
GlobalsInRoot o = new GlobalsInRoot();
|
||||
o.f1();
|
||||
o.f2();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,2 @@
|
||||
@jsweet.lang.Root
|
||||
package org.jsweet.test.transpiler.source.structural.globalclasses.root;
|
||||
Loading…
x
Reference in New Issue
Block a user