summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2016-01-21 15:30:21 +0100
committerAndreas Rumpf <rumpf_a@web.de>2016-01-21 15:30:21 +0100
commit263ee143f103e86daef167a04ec1886130701334 (patch)
tree3009e1d44ee7452c8556f0a994baa0ac8e79fa77 /compiler
parent72b975d1ff232a26aa48952387d4bb4a5d51e065 (diff)
parent8fab2f81e3c7bd2630bd53d8c530165808b564c2 (diff)
downloadNim-263ee143f103e86daef167a04ec1886130701334.tar.gz
Merge pull request #3733 from yglukhov/js-unicode
Fixed unicode handling in JS. Fixes #3714.
Diffstat (limited to 'compiler')
-rw-r--r--compiler/jsgen.nim20
1 files changed, 19 insertions, 1 deletions
diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim
index 14cdf0174..16a03a4ec 100644
--- a/compiler/jsgen.nim
+++ b/compiler/jsgen.nim
@@ -163,8 +163,26 @@ proc mangleName(s: PSym): Rope =
     add(result, rope(s.id))
     s.loc.r = result
 
+proc escapeJSString(s: string): string =
+  result = newStringOfCap(s.len + s.len shr 2)
+  result.add("\"")
+  for c in items(s):
+    case c
+    of '\l': result.add("\\n")
+    of '\r': result.add("\\r")
+    of '\t': result.add("\\t")
+    of '\b': result.add("\\b")
+    of '\a': result.add("\\a")
+    of '\e': result.add("\\e")
+    of '\v': result.add("\\v")
+    of '\\': result.add("\\\\")
+    of '\'': result.add("\\'")
+    of '\"': result.add("\\\"")
+    else: add(result, c)
+  result.add("\"")
+
 proc makeJSString(s: string): Rope =
-  (if s.isNil: "null".rope else: strutils.escape(s).rope)
+  (if s.isNil: "null".rope else: escapeJSString(s).rope)
 
 include jstypes