From d471066b08c9c05ff4b2865fc94f069a743fc1db Mon Sep 17 00:00:00 2001 From: flywind Date: Sun, 21 Feb 2021 15:02:09 +0800 Subject: [PATCH 1/6] remove unnecessary when statement --- 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 ac3c3b19430de..d610edcbf6809 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 78f284abba454..b71961554b928 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 From 0824e3df8893769b660a0652700573e2f76919a7 Mon Sep 17 00:00:00 2001 From: flywind Date: Mon, 22 Feb 2021 09:41:57 +0800 Subject: [PATCH 2/6] remove outdated codes --- lib/pure/collections/sequtils.nim | 1 - lib/pure/strtabs.nim | 1 - 2 files changed, 2 deletions(-) diff --git a/lib/pure/collections/sequtils.nim b/lib/pure/collections/sequtils.nim index 70ecff4932947..0872257f453b3 100644 --- a/lib/pure/collections/sequtils.nim +++ b/lib/pure/collections/sequtils.nim @@ -326,7 +326,6 @@ func distribute*[T](s: seq[T], num: Positive, spread = true): seq[seq[T]] = if num < 2: result = @[s] return - let num = int(num) # XXX probably only needed because of .. bug # Create the result and calculate the stride size and the remainder if any. result = newSeq[seq[T]](num) diff --git a/lib/pure/strtabs.nim b/lib/pure/strtabs.nim index 9047841a6113a..3b90fea509e9c 100644 --- a/lib/pure/strtabs.nim +++ b/lib/pure/strtabs.nim @@ -300,7 +300,6 @@ proc raiseFormatException(s: string) = proc getValue(t: StringTableRef, flags: set[FormatFlag], key: string): string = if hasKey(t, key): return t.getOrDefault(key) - # hm difficult: assume safety in taint mode here. XXX This is dangerous! when defined(js) or defined(nimscript) or defined(Standalone): result = "" else: From 0d734710c66599c451e2806d6c02262eb09e1514 Mon Sep 17 00:00:00 2001 From: flywind Date: Tue, 2 Mar 2021 14:45:09 +0800 Subject: [PATCH 3/6] re-enable fidget --- testament/important_packages.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testament/important_packages.nim b/testament/important_packages.nim index 10e24f6cc8663..9a066b4b5bbb0 100644 --- a/testament/important_packages.nim +++ b/testament/important_packages.nim @@ -54,7 +54,7 @@ pkg1 "delaunay" pkg1 "docopt" pkg1 "easygl", "nim c -o:egl -r src/easygl.nim", "https://github.com/jackmott/easygl" pkg1 "elvis" -# pkg1 "fidget" # pending https://github.com/treeform/fidget/issues/133 +pkg1 "fidget" pkg1 "fragments", "nim c -r fragments/dsl.nim" pkg1 "fusion" pkg1 "gara" From 3203ee5d7994b13f8b0823c2904364a0e1d007d1 Mon Sep 17 00:00:00 2001 From: flywind Date: Sun, 7 Mar 2021 12:42:23 +0800 Subject: [PATCH 4/6] Update testament/important_packages.nim Co-authored-by: Timothee Cour --- testament/important_packages.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testament/important_packages.nim b/testament/important_packages.nim index 9a066b4b5bbb0..84b927297d505 100644 --- a/testament/important_packages.nim +++ b/testament/important_packages.nim @@ -54,7 +54,7 @@ pkg1 "delaunay" pkg1 "docopt" pkg1 "easygl", "nim c -o:egl -r src/easygl.nim", "https://github.com/jackmott/easygl" pkg1 "elvis" -pkg1 "fidget" +pkg1 "fidget", useHead = false pkg1 "fragments", "nim c -r fragments/dsl.nim" pkg1 "fusion" pkg1 "gara" From f09bf1a4ca48dbe18b75eb2fc66dbbb0e09e61fa Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Sat, 6 Mar 2021 20:53:34 -0800 Subject: [PATCH 5/6] Update testament/important_packages.nim --- testament/important_packages.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testament/important_packages.nim b/testament/important_packages.nim index 84b927297d505..8b667ff740dad 100644 --- a/testament/important_packages.nim +++ b/testament/important_packages.nim @@ -54,7 +54,7 @@ pkg1 "delaunay" pkg1 "docopt" pkg1 "easygl", "nim c -o:egl -r src/easygl.nim", "https://github.com/jackmott/easygl" pkg1 "elvis" -pkg1 "fidget", useHead = false +pkg1 "fidget", useHead = false # refs https://github.com/treeform/fidget/issues/133 pkg1 "fragments", "nim c -r fragments/dsl.nim" pkg1 "fusion" pkg1 "gara" From f723c8c0b68ae1c3bfc8f19078f38d994fcb4e03 Mon Sep 17 00:00:00 2001 From: flywind Date: Wed, 24 Mar 2021 16:21:29 +0800 Subject: [PATCH 6/6] Update testament/important_packages.nim --- testament/important_packages.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testament/important_packages.nim b/testament/important_packages.nim index 8babdb6197081..66a2fa09e39d1 100644 --- a/testament/important_packages.nim +++ b/testament/important_packages.nim @@ -60,7 +60,7 @@ pkg "delaunay" pkg "docopt" pkg "easygl", "nim c -o:egl -r src/easygl.nim", "https://github.com/jackmott/easygl" pkg "elvis" -pkg "fidget" # pending https://github.com/treeform/fidget/issues/133 +pkg "fidget" pkg "fragments", "nim c -r fragments/dsl.nim" pkg "fusion" pkg "gara"