diff --git a/core/src/main/java/org/teavm/javascript/Renderer.java b/core/src/main/java/org/teavm/javascript/Renderer.java index 289fca789..1d7f4867c 100644 --- a/core/src/main/java/org/teavm/javascript/Renderer.java +++ b/core/src/main/java/org/teavm/javascript/Renderer.java @@ -1245,12 +1245,21 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext List nameList = new ArrayList<>(names); Collections.sort(nameList); for (String name : nameList) { - sb.append('_').append(name); + sb.append('_').append(escapeName(name)); } } return sb.toString(); } + private static String escapeName(String name) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < name.length(); ++i) { + char c = name.charAt(i); + sb.append(Character.isJavaIdentifierPart(c) ? c : '_'); + } + return sb.toString(); + } + private String pointerName() { return minifying ? "$p" : "$ptr"; }