diff --git a/deno.json b/deno.json index ff1f8e6..2dfc35e 100644 --- a/deno.json +++ b/deno.json @@ -1,5 +1,5 @@ { "name": "@luaneko/lstd", - "version": "0.1.6", + "version": "0.2.0", "exports": "./mod.ts" } diff --git a/jit.ts b/jit.ts index 394bc27..68d8f1d 100644 --- a/jit.ts +++ b/jit.ts @@ -18,6 +18,21 @@ export class JitCompiler { } enclose(x: unknown) { + switch (typeof x) { + case "boolean": + case "number": + return this.write(`${x}`); + case "bigint": + return this.write(`${x}n`); + case "string": + return this.write(JSON.stringify(x)); + case "object": + if (x === null) return this.write(`null`); + break; + case "undefined": + return this.write(`undefined`); + } + let name = this.#args.get(x); if (!name) this.#args.set(x, (name = `__x${this.#args.size}`)); this.write(name); @@ -52,7 +67,6 @@ export function jit( jit.compiled = compiled; jit.raw = raw; jit.fragment = fragment; -jit.literal = literal; jit.map = map; jit.if = condition; @@ -92,10 +106,6 @@ export function fragment( }; } -export function literal(x: unknown) { - return raw(typeof x === "undefined" ? "undefined" : JSON.stringify(x)); -} - export function map( sep: string | JitFragment, xs: Iterable,