diff options
-rw-r--r-- | changelog.md | 5 | ||||
-rw-r--r-- | compiler/pragmas.nim | 17 |
2 files changed, 9 insertions, 13 deletions
diff --git a/changelog.md b/changelog.md index 6f8a32bff..bbcd6d970 100644 --- a/changelog.md +++ b/changelog.md @@ -100,7 +100,10 @@ iterator myitems[T](x: openarray[T]): lent T iterator mypairs[T](x: openarray[T]): tuple[idx: int, val: lent T] ``` -- `importjs` can now be used to import for ffi on the JS target +- Added an `importjs` pragma that can now be used instead of `importcpp` + and `importc` to import symbols from JavaScript. `importjs` for routines always + takes a "pattern" for maximum flexibility. + ## Language changes diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index 56f5ea126..f8f6a1a23 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -805,20 +805,13 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, processImportCpp(c, sym, getOptionalStr(c, it, "$1"), it.info) of wImportJs: if c.config.cmd != cmdCompileToJS: - localError(c.config, it.info, "importjs pragma only supported when compiling to js.") - var strArg: PNode = nil - if it.kind in nkPragmaCallKinds: - strArg = it[1] - if strArg.kind notin {nkStrLit..nkTripleStrLit}: - localError(c.config, it.info, errStringLiteralExpected) + localError(c.config, it.info, "`importjs` pragma requires the JavaScript target") + let name = getOptionalStr(c, it, "$1") incl(sym.flags, sfImportc) incl(sym.flags, sfInfixCall) - if strArg == nil: - if sym.kind in skProcKinds: - message(c.config, n.info, warnDeprecated, "procedure import should have an import pattern") - setExternName(c, sym, sym.name.s, it.info) - else: - setExternName(c, sym, strArg.strVal, it.info) + if sym.kind in skProcKinds and {'(', '#', '@'} notin name: + localError(c.config, n.info, "`importjs` for routines requires a pattern") + setExternName(c, sym, name, it.info) of wImportObjC: processImportObjC(c, sym, getOptionalStr(c, it, "$1"), it.info) of wAlign: |