From 146beb2797982e2b80ab83c227b7279cad4e0943 Mon Sep 17 00:00:00 2001 From: flywind Date: Sun, 21 Feb 2021 04:17:25 -0600 Subject: [PATCH] remove unnecessary when statement (#17135) --- lib/pure/json.nim | 19 +++++++------------ tests/stdlib/tjson.nim | 11 ++++++++++- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/lib/pure/json.nim b/lib/pure/json.nim index ac3c3b1943..d610edcbf6 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 78f284abba..b71961554b 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