diff options
author | Jake Leahy <jake@leahy.dev> | 2023-02-14 18:14:19 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-14 08:14:19 +0100 |
commit | cac49694c011e851707cb3a86a3263c741559b3d (patch) | |
tree | 0655a6586ed1aa296da9088d9b739ce71b535e3f /lib/js | |
parent | 1d06c2b6cf84bcf65b67e88667dba4fd5e8ba519 (diff) | |
download | Nim-cac49694c011e851707cb3a86a3263c741559b3d.tar.gz |
`std/asyncjs` allow transforming proc types (#21356)
* Add test case * Implement JS async transform for nnkProcTy
Diffstat (limited to 'lib/js')
-rw-r--r-- | lib/js/asyncjs.nim | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/js/asyncjs.nim b/lib/js/asyncjs.nim index 364f7a21a..8e2f85156 100644 --- a/lib/js/asyncjs.nim +++ b/lib/js/asyncjs.nim @@ -100,10 +100,18 @@ proc isFutureVoid(node: NimNode): bool = node[1].kind == nnkIdent and $node[1] == "void" proc generateJsasync(arg: NimNode): NimNode = - if arg.kind notin {nnkProcDef, nnkLambda, nnkMethodDef, nnkDo}: + if arg.kind notin {nnkProcDef, nnkLambda, nnkMethodDef, nnkDo, nnkProcTy}: error("Cannot transform this node kind into an async proc." & " proc/method definition or lambda node expected.") + # Transform type X = proc (): something {.async.} + # into type X = proc (): Future[something] + if arg.kind == nnkProcTy: + result = arg + if arg[0][0].kind == nnkEmpty: + result[0][0] = quote do: Future[void] + return result + result = arg var isVoid = false let jsResolve = ident("jsResolve") |