From aadbdd6b066bc7251c6d24bb5ef5ce3f940825ec Mon Sep 17 00:00:00 2001 From: Alexander Ivanov Date: Sun, 30 Dec 2018 03:48:37 +0200 Subject: Support undefined in isNil (#9960) --- compiler/jsgen.nim | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'compiler') diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim index daaa145e1..83d205bc2 100644 --- a/compiler/jsgen.nim +++ b/compiler/jsgen.nim @@ -1884,12 +1884,13 @@ proc genMagic(p: PProc, n: PNode, r: var TCompRes) = of mLtStr: binaryExpr(p, n, r, "cmpStrings", "(cmpStrings($1, $2) < 0)") of mIsNil: + # we want to accept undefined, so we == if mapType(n[1].typ) != etyBaseIndex: - unaryExpr(p, n, r, "", "($1 === null)") + unaryExpr(p, n, r, "", "($1 == null)") else: var x: TCompRes gen(p, n[1], x) - r.res = "($# === null && $# === 0)" % [x.address, x.res] + r.res = "($# == null && $# === 0)" % [x.address, x.res] of mEnumToStr: genRepr(p, n, r) of mNew, mNewFinalize: genNew(p, n) of mChr: gen(p, n.sons[1], r) @@ -1922,7 +1923,7 @@ proc genMagic(p: PProc, n: PNode, r: var TCompRes) = if optOverflowCheck notin p.options: binaryExpr(p, n, r, "", "$1 -= $2") else: binaryExpr(p, n, r, "subInt", "$1 = subInt($3, $2)") of mSetLengthStr: - binaryExpr(p, n, r, "mnewString", "($1 === null ? $3 = mnewString($2) : $3.length = $2)") + binaryExpr(p, n, r, "mnewString", "($1 == null ? $3 = mnewString($2) : $3.length = $2)") of mSetLengthSeq: var x, y: TCompRes gen(p, n.sons[1], x) -- cgit 1.4.1-2-gfad0