Fix generation of JS aliases for Java objects

This commit is contained in:
Alexey Andreev 2015-10-21 21:56:08 +03:00
parent 3f7b142d6e
commit fb3412b4c0

View File

@ -57,8 +57,12 @@ class JSAliasRenderer implements RendererListener {
} }
writer.append("c").ws().append("=").ws().appendClass(entry.getKey()).append(".prototype;").softNewLine(); writer.append("c").ws().append("=").ws().appendClass(entry.getKey()).append(".prototype;").softNewLine();
for (Map.Entry<MethodDescriptor, String> aliasEntry : cls.methods.entrySet()) { for (Map.Entry<MethodDescriptor, String> aliasEntry : cls.methods.entrySet()) {
writer.append("c.").append(aliasEntry.getValue()).ws().append("=").ws().append("c.") if (isKeyword(aliasEntry.getValue())) {
.appendMethod(aliasEntry.getKey()).append(";").softNewLine(); writer.append("c[\"").append(aliasEntry.getValue()).append("\"]");
} else {
writer.append("c.").append(aliasEntry.getValue());
}
writer.ws().append("=").ws().append("c.").appendMethod(aliasEntry.getKey()).append(";").softNewLine();
} }
if (cls.functorField != null) { if (cls.functorField != null) {
@ -68,6 +72,25 @@ class JSAliasRenderer implements RendererListener {
writer.outdent().append("})();").newLine(); writer.outdent().append("})();").newLine();
} }
private boolean isKeyword(String id) {
switch (id) {
case "with":
case "delete":
case "in":
case "undefined":
case "debugger":
case "export":
case "function":
case "let":
case "var":
case "typeof":
case "yield":
return true;
default:
return false;
}
}
private void writeFunctor(ExposedClass cls) throws IOException { private void writeFunctor(ExposedClass cls) throws IOException {
String alias = cls.methods.get(cls.functorMethod); String alias = cls.methods.get(cls.functorMethod);
if (alias == null) { if (alias == null) {