summary refs log tree commit diff stats
path: root/tests/js
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
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')
-rw-r--r--tests/js/tjsffi.nim4
-rw-r--r--tests/js/tthismangle.nim23
2 files changed, 25 insertions, 2 deletions
diff --git a/tests/js/tjsffi.nim b/tests/js/tjsffi.nim
index 156ca89e3..213d05964 100644
--- a/tests/js/tjsffi.nim
+++ b/tests/js/tjsffi.nim
@@ -267,8 +267,8 @@ block:
   type TestObject = object
     a: int
     onWhatever: proc(e: int): int
-  proc handleWhatever(that: TestObject, e: int): int =
-    e + that.a
+  proc handleWhatever(this: TestObject, e: int): int =
+    e + this.a
   proc test(): bool =
     let obj = TestObject(a: 9, onWhatever: bindMethod(handleWhatever))
     obj.onWhatever(1) == 10
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()