remove unnecessary when statement (#17135)
This commit is contained in:
parent
70ec17eede
commit
146beb2797
2 changed files with 17 additions and 13 deletions
|
|
@ -152,9 +152,9 @@ runnableExamples:
|
||||||
doAssert $(%* Foo()) == """{"a1":0,"a2":0,"a0":0,"a3":0,"a4":0}"""
|
doAssert $(%* Foo()) == """{"a1":0,"a2":0,"a0":0,"a3":0,"a4":0}"""
|
||||||
|
|
||||||
import
|
import
|
||||||
hashes, tables, strutils, lexbase, streams, macros, parsejson
|
std/[hashes, tables, strutils, lexbase, streams, macros, parsejson]
|
||||||
|
|
||||||
import options # xxx remove this dependency using same approach as https://github.com/nim-lang/Nim/pull/14563
|
import std/options # xxx remove this dependency using same approach as https://github.com/nim-lang/Nim/pull/14563
|
||||||
import std/private/since
|
import std/private/since
|
||||||
|
|
||||||
export
|
export
|
||||||
|
|
@ -682,13 +682,10 @@ proc toPretty(result: var string, node: JsonNode, indent = 2, ml = true,
|
||||||
escapeJson(node.str, result)
|
escapeJson(node.str, result)
|
||||||
of JInt:
|
of JInt:
|
||||||
if lstArr: result.indent(currIndent)
|
if lstArr: result.indent(currIndent)
|
||||||
when defined(js): result.add($node.num)
|
result.addInt(node.num)
|
||||||
else: result.addInt(node.num)
|
|
||||||
of JFloat:
|
of JFloat:
|
||||||
if lstArr: result.indent(currIndent)
|
if lstArr: result.indent(currIndent)
|
||||||
# Fixme: implement new system.add ops for the JS target
|
result.addFloat(node.fnum)
|
||||||
when defined(js): result.add($node.fnum)
|
|
||||||
else: result.addFloat(node.fnum)
|
|
||||||
of JBool:
|
of JBool:
|
||||||
if lstArr: result.indent(currIndent)
|
if lstArr: result.indent(currIndent)
|
||||||
result.add(if node.bval: "true" else: "false")
|
result.add(if node.bval: "true" else: "false")
|
||||||
|
|
@ -766,11 +763,9 @@ proc toUgly*(result: var string, node: JsonNode) =
|
||||||
else:
|
else:
|
||||||
node.str.escapeJson(result)
|
node.str.escapeJson(result)
|
||||||
of JInt:
|
of JInt:
|
||||||
when defined(js): result.add($node.num)
|
result.addInt(node.num)
|
||||||
else: result.addInt(node.num)
|
|
||||||
of JFloat:
|
of JFloat:
|
||||||
when defined(js): result.add($node.fnum)
|
result.addFloat(node.fnum)
|
||||||
else: result.addFloat(node.fnum)
|
|
||||||
of JBool:
|
of JBool:
|
||||||
result.add(if node.bval: "true" else: "false")
|
result.add(if node.bval: "true" else: "false")
|
||||||
of JNull:
|
of JNull:
|
||||||
|
|
@ -912,7 +907,7 @@ proc parseJson*(s: Stream, filename: string = ""; rawIntegers = false, rawFloats
|
||||||
p.close()
|
p.close()
|
||||||
|
|
||||||
when defined(js):
|
when defined(js):
|
||||||
from math import `mod`
|
from std/math import `mod`
|
||||||
type
|
type
|
||||||
JSObject = object
|
JSObject = object
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,8 @@
|
||||||
|
discard """
|
||||||
|
targets: "c cpp js"
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
#[
|
#[
|
||||||
Note: Macro tests are in tests/stdlib/tjsonmacro.nim
|
Note: Macro tests are in tests/stdlib/tjsonmacro.nim
|
||||||
]#
|
]#
|
||||||
|
|
@ -234,4 +239,8 @@ doAssert isRefSkipDistinct(MyDistinct)
|
||||||
doAssert isRefSkipDistinct(MyOtherDistinct)
|
doAssert isRefSkipDistinct(MyOtherDistinct)
|
||||||
|
|
||||||
let x = parseJson("9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999")
|
let x = parseJson("9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999")
|
||||||
|
|
||||||
|
when defined(js): # xxx fixme
|
||||||
|
doAssert x.kind == JInt
|
||||||
|
else:
|
||||||
doAssert x.kind == JString
|
doAssert x.kind == JString
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue