summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authormetagn <metagngn@gmail.com>2023-05-24 18:55:09 +0300
committerGitHub <noreply@github.com>2023-05-24 17:55:09 +0200
commit4d6be458a00a642555e95055ff640daba59513f7 (patch)
tree72c5c98f26d6e75c98b1129642cf7e415a89266f /compiler
parentc7f25419149d6b4b0723f0ef177bbaad72d7bc3e (diff)
downloadNim-4d6be458a00a642555e95055ff640daba59513f7.tar.gz
js -r defines nodejs & program result undeclared if unavailable (#21849)
* js -r defines nodejs & program result undefined if unavailable

fixes #16985, fixes #16074

* fix

* add changelog too

* minor word change
Diffstat (limited to 'compiler')
-rw-r--r--compiler/commands.nim6
1 files changed, 6 insertions, 0 deletions
diff --git a/compiler/commands.nim b/compiler/commands.nim
index 93a36e714..4980ff268 100644
--- a/compiler/commands.nim
+++ b/compiler/commands.nim
@@ -654,6 +654,9 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
     if backend == TBackend.default: localError(conf, info, "invalid backend: '$1'" % arg)
     if backend == backendJs: # bug #21209
       conf.globalOptions.excl {optThreadAnalysis, optThreads}
+      if optRun in conf.globalOptions:
+        # for now, -r uses nodejs, so define nodejs
+        defineSymbol(conf.symbols, "nodejs")
     conf.backend = backend
   of "doccmd": conf.docCmd = arg
   of "define", "d":
@@ -864,6 +867,9 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
       setTarget(conf.target, conf.target.targetOS, cpu)
   of "run", "r":
     processOnOffSwitchG(conf, {optRun}, arg, pass, info)
+    if conf.backend == backendJs:
+      # for now, -r uses nodejs, so define nodejs
+      defineSymbol(conf.symbols, "nodejs")
   of "maxloopiterationsvm":
     expectArg(conf, switch, arg, pass, info)
     conf.maxLoopIterationsVM = parseInt(arg)