Skip to content
Draft
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 @@ -26,8 +26,8 @@ class Client {
});
trace("TestStuff.doSomething(): " + testStuff.doSomething("pre", "text", "pos"));

if (untyped __js__("typeof(document)") != "undefined") {
var canvas = untyped __js__("document.getElementById('canvas')");
if (js.Syntax.code("typeof(document)") != "undefined") {
var canvas = js.Syntax.code("document.getElementById('canvas')");
testStuff.drawSomething(canvas);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ class TestModule {
}

public static function getExternalDependencyVersion(): String {
return untyped __js__('libWithVersion.version');
return js.Syntax.code('libWithVersion.version');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class HaxeModuleAccessorGeneratorVisitor extends AbstractHaxeGeneratorVisitor {
return \
"""@:final class ${node.alias} {

static var __module:Dynamic = untyped __js__('${GeneratorUtils.createModuleAccessor(node.name, format)}');
static var __module:Dynamic = js.Syntax.code('${GeneratorUtils.createModuleAccessor(node.name, format)}');

${node.methods*.accept(new MethodVisitor(node)).join("")}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ class HaxeModuleProxyGeneratorVisitor extends AbstractHaxeGeneratorVisitor {
String visitModuleNode(ModuleNode node) {
return \
"""@:final class __${node.alias}Proxy {
public function new() {}
public var ${node.alias}: __${node.alias}Proxy;
public function new() {
${node.alias} = this;
}
${
node.methods*.accept(new MethodVisitor(node)).join("") +
node.accept(new QualifiedConstVisitor(node)) +
node.accept(new QualifiedEnumVisitor(node)) +
"\tpublic var ${node.alias} = this;\n"
node.accept(new QualifiedEnumVisitor(node))
}}
"""
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ ${node.entries*.accept(new ConstEntryVisitor(node.name)).join("")}
String value = HaxeUtils.toPrimitiveString(node.value)
// TODO [knuton] Enable after migratory period
// String moduleAccessor = GeneratorUtils.createModuleAccessor(foreignModuleName, format)
// String value = "untyped __js__('${moduleAccessor}[\"${constName}\"][\"${node.name}\"]')"
// String value = "js.Syntax.code('${moduleAccessor}[\"${constName}\"][\"${node.name}\"]')"
return "\tpublic static inline var ${node.name}:${type} = ${value};\n"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class HaxeDependentEnumGeneratorVisitor extends HaxeEnumGeneratorVisitor {
return new HaxeEnumGeneratorVisitor.EnumValueVisitor(enumName) {
@Override
String generateValueExpression(EnumValueNode node) {
return "untyped __js__('${GeneratorUtils.createModuleAccessor(foreignModuleName, format)}[\"${enumName}\"][\"${node.name}\"]')"
return "js.Syntax.code('${GeneratorUtils.createModuleAccessor(foreignModuleName, format)}[\"${enumName}\"][\"${node.name}\"]')"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ class HaxeEnumGeneratorVisitor extends StringModuleVisitorBase {
def enumName = node.name

return \
"""abstract ${enumName}(Int) {
"""
@:runtimeValue
enum abstract ${enumName}(Int) {
${node.values*.accept(createEnumValueVisitor(node.name)).join("\n")}

static var _values = {
#if js
var thisValue = ${enumName};
${node.values.collect { entry -> "untyped __js__(\"thisValue[thisValue.${entry.name}] = '${entry.name}'\");" }.join("\n\t\t")}
${node.values.collect { entry -> "js.Syntax.code(\"thisValue[thisValue.${entry.name}] = '${entry.name}'\");" }.join("\n\t\t")}
#end
[${node.values.collect { entry -> "Std.string(${entry.name}) => ${entry.name}" }.join(", ")}];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module com.example.test {
expect:
result == """@:final class TestModule {

static var __module:Dynamic = untyped __js__('Spaghetti["dependencies"]["com.example.test"]["module"]');
static var __module:Dynamic = js.Syntax.code('Spaghetti["dependencies"]["com.example.test"]["module"]');

/**
* Initializes module.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ class HaxeEnumGeneratorVisitorTest extends EnumGeneratorSpecification {

expect:
result == expectedWith(
"untyped __js__('Spaghetti[\"dependencies\"][\"test\"][\"MyEnum\"][\"ALMA\"]')",
"untyped __js__('Spaghetti[\"dependencies\"][\"test\"][\"MyEnum\"][\"BELA\"]')",
"untyped __js__('Spaghetti[\"dependencies\"][\"test\"][\"MyEnum\"][\"GEZA\"]')")
"js.Syntax.code('Spaghetti[\"dependencies\"][\"test\"][\"MyEnum\"][\"ALMA\"]')",
"js.Syntax.code('Spaghetti[\"dependencies\"][\"test\"][\"MyEnum\"][\"BELA\"]')",
"js.Syntax.code('Spaghetti[\"dependencies\"][\"test\"][\"MyEnum\"][\"GEZA\"]')")
}

def "generate dependent definition for wrapperless format"() {
def result = parseAndVisitEnum(definition, new HaxeDependentEnumGeneratorVisitor("test", ModuleFormat.Wrapperless))

expect:
result == expectedWith(
"untyped __js__('Spaghetti[\"dependencies\"][\"test\"][\"module\"][\"MyEnum\"][\"ALMA\"]')",
"untyped __js__('Spaghetti[\"dependencies\"][\"test\"][\"module\"][\"MyEnum\"][\"BELA\"]')",
"untyped __js__('Spaghetti[\"dependencies\"][\"test\"][\"module\"][\"MyEnum\"][\"GEZA\"]')")
"js.Syntax.code('Spaghetti[\"dependencies\"][\"test\"][\"module\"][\"MyEnum\"][\"ALMA\"]')",
"js.Syntax.code('Spaghetti[\"dependencies\"][\"test\"][\"module\"][\"MyEnum\"][\"BELA\"]')",
"js.Syntax.code('Spaghetti[\"dependencies\"][\"test\"][\"module\"][\"MyEnum\"][\"GEZA\"]')")
}

private static String expectedWith(String first, String second, String third) {
Expand All @@ -56,9 +56,9 @@ class HaxeEnumGeneratorVisitorTest extends EnumGeneratorSpecification {
static var _values = {
#if js
var thisValue = MyEnum;
untyped __js__("thisValue[thisValue.ALMA] = 'ALMA'");
untyped __js__("thisValue[thisValue.BELA] = 'BELA'");
untyped __js__("thisValue[thisValue.GEZA] = 'GEZA'");
js.Syntax.code("thisValue[thisValue.ALMA] = 'ALMA'");
js.Syntax.code("thisValue[thisValue.BELA] = 'BELA'");
js.Syntax.code("thisValue[thisValue.GEZA] = 'GEZA'");
#end
[Std.string(ALMA) => ALMA, Std.string(BELA) => BELA, Std.string(GEZA) => GEZA];
}
Expand Down