mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-13 06:43:52 +00:00
cleanup importjs implementation
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user