diff options
Diffstat (limited to 'compiler/jsgen.nim')
-rw-r--r-- | compiler/jsgen.nim | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim index 8b91ada8a..766e6a80d 100644 --- a/compiler/jsgen.nim +++ b/compiler/jsgen.nim @@ -1736,6 +1736,7 @@ proc genVarInit(p: PProc, v: PSym, n: PNode) = varCode: string varName = mangleName(p.module, v) useReloadingGuard = sfGlobal in v.flags and p.config.hcrOn + useGlobalPragmas = sfGlobal in v.flags and ({sfPure, sfThread} * v.flags != {}) if v.constraint.isNil: if useReloadingGuard: @@ -1743,6 +1744,10 @@ proc genVarInit(p: PProc, v: PSym, n: PNode) = lineF(p, "if ($1 === undefined) {$n", varName) varCode = $varName inc p.extraIndent + elif useGlobalPragmas: + lineF(p, "if (globalThis.$1 === undefined) {$n", varName) + varCode = $varName + inc p.extraIndent else: varCode = "var $2" else: @@ -1795,7 +1800,7 @@ proc genVarInit(p: PProc, v: PSym, n: PNode) = else: line(p, runtimeFormat(varCode & " = $3;$n", [returnType, v.loc.r, s])) - if useReloadingGuard: + if useReloadingGuard or useGlobalPragmas: dec p.extraIndent lineF(p, "}$n") |