diff --git a/calcit/snapshots/test-js.cirru b/calcit/snapshots/test-js.cirru index d5452560..67795837 100644 --- a/calcit/snapshots/test-js.cirru +++ b/calcit/snapshots/test-js.cirru @@ -50,6 +50,14 @@ assert-detect identity $ instance? js/Number (new js/Number 1) assert-detect not $ instance? js/String (new js/Number 1) + assert= + [] 1 ([] 2 3) (:: :quote ([] 'a 'b)) + to-calcit-data $ js-array 1 ([] 2 3) (:: :quote ([] 'a 'b)) + + assert= + &{} |a 1 :b 2 |c $ [] 3 4 + to-calcit-data $ &js-object |a 1 |:b 2 :c $ [] 3 4 + |test-let-example $ quote fn () log-title "|Testing code emitting of using let" diff --git a/ts-src/js-cirru.ts b/ts-src/js-cirru.ts index 8725446d..8a427f9d 100644 --- a/ts-src/js-cirru.ts +++ b/ts-src/js-cirru.ts @@ -6,7 +6,7 @@ import { CalcitList } from "./js-list"; import { CalcitRecord } from "./js-record"; import { CalcitMap } from "./js-map"; import { CalcitSet } from "./js-set"; -import { CalcitKeyword, CalcitSymbol, kwd } from "./calcit-data"; +import { CalcitKeyword, CalcitSymbol, CalcitRecur, CalcitRef, kwd } from "./calcit-data"; import { CalcitTuple } from "./js-tuple"; type CirruEdnFormat = string | CirruEdnFormat[]; @@ -200,24 +200,20 @@ export let format_cirru_edn = (data: CalcitValue, useInline: boolean = true): st }; export let to_calcit_data = (x: any, noKeyword: boolean = false): CalcitValue => { - if (x == null) { - return null; - } - if (typeof x === "number") { - return x; - } + if (x == null) return null; + + if (typeof x === "number") return x; + if (typeof x === "string") { if (!noKeyword && x[0] === ":" && x.slice(1).match(/^[\w\d_\?\!\-]+$/)) { return kwd(x.slice(1)); } return x; } - if (x === true || x === false) { - return x; - } - if (typeof x === "function") { - return x; - } + if (x === true || x === false) return x; + + if (typeof x === "function") return x; + if (Array.isArray(x)) { var result: any[] = []; x.forEach((v) => { @@ -232,6 +228,17 @@ export let to_calcit_data = (x: any, noKeyword: boolean = false): CalcitValue => }); return new CalcitSet(result); } + + if (x instanceof CalcitList) return x; + if (x instanceof CalcitMap) return x; + if (x instanceof CalcitSet) return x; + if (x instanceof CalcitRecord) return x; + if (x instanceof CalcitRecur) return x; + if (x instanceof CalcitRef) return x; + if (x instanceof CalcitKeyword) return x; + if (x instanceof CalcitSymbol) return x; + if (x instanceof CalcitTuple) return x; + // detects object if (x === Object(x)) { let result: Array<[CalcitValue, CalcitValue]> = [];