summary refs log tree commit diff stats
path: root/tests/js/tthismangle.nim
diff options
context:
space:
mode:
authorLemonBoy <LemonBoy@users.noreply.github.com>2018-09-03 17:51:30 +0200
committerAndreas Rumpf <rumpf_a@web.de>2018-09-03 17:51:30 +0200
commit1a60ffcf1dc265c6b92dfd757e1bfd5e904c1f3d (patch)
tree2f70738c3379cc3fc54d2f56bb6d9a20ea09488d /tests/js/tthismangle.nim
parent0694c9080f85b59e86ddfb0bd3c799fe9d9e30ae (diff)
downloadNim-1a60ffcf1dc265c6b92dfd757e1bfd5e904c1f3d.tar.gz
Correctly mangle `this` in the JS backend (#8853)
As shown in pragmagic/karax#67 using `this` as parameter name made the
codegen output wrong code (and the user didn't notice the errors in the
browser console).
Diffstat (limited to 'tests/js/tthismangle.nim')
-rw-r--r--tests/js/tthismangle.nim23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/js/tthismangle.nim b/tests/js/tthismangle.nim
new file mode 100644
index 000000000..880abcc83
--- /dev/null
+++ b/tests/js/tthismangle.nim
@@ -0,0 +1,23 @@
+proc moo1(this: int) =
+  doAssert this == 42
+
+proc moo2(x: int) =
+  var this = x
+  doAssert this == 42
+
+proc moo3() =
+  for this in [1,1,1]:
+    doAssert this == 1
+
+proc moo4() =
+  type
+    X = object
+      this: int
+
+  var q = X(this: 42)
+  doAssert q.this == 42
+
+moo1(42)
+moo2(42)
+moo3()
+moo4()