summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorZahary Karadjov <zahary@gmail.com>2017-04-10 21:28:11 +0300
committerZahary Karadjov <zahary@gmail.com>2017-04-10 23:58:05 +0300
commita3f19c87fb2134db25543f1e15b96144df5638dc (patch)
treeeeb93b47e30ac8add3ead8255be97c3b3b1c1d44 /lib
parentf7b10e213b81588d560e37aa5f7c8b0d10ea5689 (diff)
downloadNim-a3f19c87fb2134db25543f1e15b96144df5638dc.tar.gz
lift parameter-less do block to lambdas
Diffstat (limited to 'lib')
-rw-r--r--lib/js/jsffi.nim10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/js/jsffi.nim b/lib/js/jsffi.nim
index 7aa80b39b..e0310e33a 100644
--- a/lib/js/jsffi.nim
+++ b/lib/js/jsffi.nim
@@ -112,6 +112,12 @@ proc toJs*[T](val: T): JsObject {. importcpp: "(#)" .}
 
 template toJs*(s: string): JsObject = cstring(s).toJs
 
+macro jsFromAst*(n: untyped): untyped =
+  result = n
+  if n.kind == nnkStmtList:
+    result = newProc(procType = nnkDo, body = result)
+  return quote: toJs(`result`)
+
 proc `&`*(a, b: cstring): cstring {.importcpp: "(# + #)".}
   ## Concatenation operator for JavaScript strings
 
@@ -220,7 +226,7 @@ macro `.=`*(obj: JsObject, field: static[cstring], value: untyped): untyped =
 
 macro `.()`*(obj: JsObject,
              field: static[cstring],
-             args: varargs[JsObject, toJs]): JsObject =
+             args: varargs[JsObject, jsFromAst]): JsObject =
   ## Experimental "method call" operator for type JsObject.
   ## Takes the name of a method of the JavaScript object (`field`) and calls
   ## it with `args` as arguments, returning a JsObject (which may be discarded,
@@ -244,7 +250,7 @@ macro `.()`*(obj: JsObject,
     if not mangledNames.hasKey($field):
       mangledNames[$field] = $mangleJsName(field)
     importString = "#." & mangledNames[$field] & "(@)"
-  result = quote do:
+  result = quote:
     proc helper(o: JsObject): JsObject
       {. importcpp: `importString`, gensym, discardable .}
     helper(`obj`)