summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorflywind <xzsflywind@gmail.com>2021-02-21 04:17:25 -0600
committerGitHub <noreply@github.com>2021-02-21 11:17:25 +0100
commit146beb2797982e2b80ab83c227b7279cad4e0943 (patch)
tree0817133ac411fd4677c40e334e47fd450a2ee2fc
parent70ec17eede74f4216aee3b0bfb11e789bcbf0e54 (diff)
downloadNim-146beb2797982e2b80ab83c227b7279cad4e0943.tar.gz
remove unnecessary when statement (#17135)
-rw-r--r--lib/pure/json.nim19
-rw-r--r--tests/stdlib/tjson.nim11
2 files changed, 17 insertions, 13 deletions
diff --git a/lib/pure/json.nim b/lib/pure/json.nim
index ac3c3b194..d610edcbf 100644
--- a/lib/pure/json.nim
+++ b/lib/pure/json.nim
@@ -152,9 +152,9 @@ runnableExamples:
   doAssert $(%* Foo()) == """{"a1":0,"a2":0,"a0":0,"a3":0,"a4":0}"""
 
 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
 
 export
@@ -682,13 +682,10 @@ proc toPretty(result: var string, node: JsonNode, indent = 2, ml = true,
       escapeJson(node.str, result)
   of JInt:
     if lstArr: result.indent(currIndent)
-    when defined(js): result.add($node.num)
-    else: result.addInt(node.num)
+    result.addInt(node.num)
   of JFloat:
     if lstArr: result.indent(currIndent)
-    # Fixme: implement new system.add ops for the JS target
-    when defined(js): result.add($node.fnum)
-    else: result.addFloat(node.fnum)
+    result.addFloat(node.fnum)
   of JBool:
     if lstArr: result.indent(currIndent)
     result.add(if node.bval: "true" else: "false")
@@ -766,11 +763,9 @@ proc toUgly*(result: var string, node: JsonNode) =
     else:
       node.str.escapeJson(result)
   of JInt:
-    when defined(js): result.add($node.num)
-    else: result.addInt(node.num)
+    result.addInt(node.num)
   of JFloat:
-    when defined(js): result.add($node.fnum)
-    else: result.addFloat(node.fnum)
+    result.addFloat(node.fnum)
   of JBool:
     result.add(if node.bval: "true" else: "false")
   of JNull:
@@ -912,7 +907,7 @@ proc parseJson*(s: Stream, filename: string = ""; rawIntegers = false, rawFloats
     p.close()
 
 when defined(js):
-  from math import `mod`
+  from std/math import `mod`
   type
     JSObject = object
 
diff --git a/tests/stdlib/tjson.nim b/tests/stdlib/tjson.nim
index 78f284abb..b71961554 100644
--- a/tests/stdlib/tjson.nim
+++ b/tests/stdlib/tjson.nim
@@ -1,3 +1,8 @@
+discard """
+  targets: "c cpp js"
+"""
+
+
 #[
 Note: Macro tests are in tests/stdlib/tjsonmacro.nim
 ]#
@@ -234,4 +239,8 @@ doAssert isRefSkipDistinct(MyDistinct)
 doAssert isRefSkipDistinct(MyOtherDistinct)
 
 let x = parseJson("9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999")
-doAssert x.kind == JString
+
+when defined(js): # xxx fixme
+  doAssert x.kind == JInt
+else:
+  doAssert x.kind == JString