@elaraai/east 1.0.67 → 1.0.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/ast.d.ts +2 -0
- package/dist/src/ast.d.ts.map +1 -1
- package/dist/src/ast_to_ir.d.ts +7 -3
- package/dist/src/ast_to_ir.d.ts.map +1 -1
- package/dist/src/ast_to_ir.js +62 -15
- package/dist/src/ast_to_ir.js.map +1 -1
- package/dist/src/codegen/codegen.spec.d.ts +6 -0
- package/dist/src/codegen/codegen.spec.d.ts.map +1 -0
- package/dist/src/codegen/codegen.spec.js +763 -0
- package/dist/src/codegen/codegen.spec.js.map +1 -0
- package/dist/src/codegen/doc.d.ts +111 -0
- package/dist/src/codegen/doc.d.ts.map +1 -0
- package/dist/src/codegen/doc.js +350 -0
- package/dist/src/codegen/doc.js.map +1 -0
- package/dist/src/codegen/doc.spec.d.ts +6 -0
- package/dist/src/codegen/doc.spec.d.ts.map +1 -0
- package/dist/src/codegen/doc.spec.js +86 -0
- package/dist/src/codegen/doc.spec.js.map +1 -0
- package/dist/src/codegen/index.d.ts +15 -0
- package/dist/src/codegen/index.d.ts.map +1 -0
- package/dist/src/codegen/index.js +15 -0
- package/dist/src/codegen/index.js.map +1 -0
- package/dist/src/codegen/printer.d.ts +63 -0
- package/dist/src/codegen/printer.d.ts.map +1 -0
- package/dist/src/codegen/printer.js +1529 -0
- package/dist/src/codegen/printer.js.map +1 -0
- package/dist/src/codegen/spellings.d.ts +73 -0
- package/dist/src/codegen/spellings.d.ts.map +1 -0
- package/dist/src/codegen/spellings.js +298 -0
- package/dist/src/codegen/spellings.js.map +1 -0
- package/dist/src/codegen/spellings.spec.d.ts +6 -0
- package/dist/src/codegen/spellings.spec.d.ts.map +1 -0
- package/dist/src/codegen/spellings.spec.js +191 -0
- package/dist/src/codegen/spellings.spec.js.map +1 -0
- package/dist/src/codegen/types.d.ts +67 -0
- package/dist/src/codegen/types.d.ts.map +1 -0
- package/dist/src/codegen/types.js +173 -0
- package/dist/src/codegen/types.js.map +1 -0
- package/dist/src/compile.js +10 -10
- package/dist/src/compile.js.map +1 -1
- package/dist/src/expr/block.d.ts +148 -0
- package/dist/src/expr/block.d.ts.map +1 -1
- package/dist/src/expr/block.js +168 -4
- package/dist/src/expr/block.js.map +1 -1
- package/dist/src/expr/index.d.ts +155 -2
- package/dist/src/expr/index.d.ts.map +1 -1
- package/dist/src/expr/index.js +155 -2
- package/dist/src/expr/index.js.map +1 -1
- package/dist/src/functions.crossimport.spec.d.ts +6 -0
- package/dist/src/functions.crossimport.spec.d.ts.map +1 -0
- package/dist/src/functions.crossimport.spec.js +45 -0
- package/dist/src/functions.crossimport.spec.js.map +1 -0
- package/dist/src/functions.d.ts +4103 -0
- package/dist/src/functions.d.ts.map +1 -0
- package/dist/src/functions.js +443 -0
- package/dist/src/functions.js.map +1 -0
- package/dist/src/functions.spec.d.ts +6 -0
- package/dist/src/functions.spec.d.ts.map +1 -0
- package/dist/src/functions.spec.js +123 -0
- package/dist/src/functions.spec.js.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/naming.d.ts +50 -0
- package/dist/src/naming.d.ts.map +1 -0
- package/dist/src/naming.js +194 -0
- package/dist/src/naming.js.map +1 -0
- package/dist/src/naming.spec.d.ts +6 -0
- package/dist/src/naming.spec.d.ts.map +1 -0
- package/dist/src/naming.spec.js +154 -0
- package/dist/src/naming.spec.js.map +1 -0
- package/dist/src/serialization/beast2/index.spec.js +25 -0
- package/dist/src/serialization/beast2/index.spec.js.map +1 -1
- package/dist/src/serialization/beast2/shared.d.ts +1 -1
- package/dist/src/serialization/beast2/shared.d.ts.map +1 -1
- package/dist/src/serialization/beast2/shared.js +9 -1
- package/dist/src/serialization/beast2/shared.js.map +1 -1
- package/package.json +11 -2
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* The layout document algebra (#639): the fits-or-breaks rule, hard lines,
|
|
7
|
+
* hugging, member chains — each pinned on a small document, so the
|
|
8
|
+
* printers' layout rests on stated semantics rather than on their output.
|
|
9
|
+
*/
|
|
10
|
+
import { describe, test } from "node:test";
|
|
11
|
+
import assert from "node:assert/strict";
|
|
12
|
+
import { bracket, callArgs, choice, flat, fn, group, hardline, hug, ifBreak, indent, join, line, render, softline, willBreak, } from "./doc.js";
|
|
13
|
+
describe("codegen doc: the layout algebra", () => {
|
|
14
|
+
test("a group is flat when it fits the remaining width and breaks otherwise", () => {
|
|
15
|
+
const items = ["aaaa", "bbbb", "cccc"];
|
|
16
|
+
assert.equal(render(bracket("[", items, "]"), 40), "[aaaa, bbbb, cccc]");
|
|
17
|
+
assert.equal(render(bracket("[", items, "]"), 10), "[\n aaaa,\n bbbb,\n cccc,\n]");
|
|
18
|
+
// what follows the group on its line counts: the same list breaks when a tail no longer fits
|
|
19
|
+
assert.equal(render([bracket("[", items, "]"), " + tail"], 20), "[\n aaaa,\n bbbb,\n cccc,\n] + tail");
|
|
20
|
+
assert.equal(render(bracket("{", ["a: 1"], "}", " "), 80), "{ a: 1 }");
|
|
21
|
+
assert.equal(render(bracket("{", [], "}", " "), 80), "{}");
|
|
22
|
+
assert.equal(flat(bracket("[", items, "]")), "[aaaa, bbbb, cccc]");
|
|
23
|
+
});
|
|
24
|
+
test("nested groups take their own turn: the outer breaks, an inner that fits stays flat", () => {
|
|
25
|
+
const inner = bracket("[", ["1n", "2n"], "]");
|
|
26
|
+
const outer = bracket("(", ["first", inner, "third"], ")");
|
|
27
|
+
assert.equal(render(["f", outer], 14), "f(\n first,\n [1n, 2n],\n third,\n)");
|
|
28
|
+
});
|
|
29
|
+
test("a hard line breaks every group around it, and a block body renders in break mode", () => {
|
|
30
|
+
const body = group(["{", indent([hardline, bracket("(", ["a", "b"], ")")]), hardline, "}"]);
|
|
31
|
+
assert.equal(render(["x = ", bracket("[", [body], "]")], 80), "x = [\n {\n (a, b)\n },\n]");
|
|
32
|
+
assert.ok(willBreak(body));
|
|
33
|
+
assert.ok(!willBreak(bracket("[", ["a"], "]")));
|
|
34
|
+
});
|
|
35
|
+
test("a choice takes the first option that fits up to its first line break, else the last", () => {
|
|
36
|
+
const block = fn(group(["() => {", indent([hardline, "body;"]), hardline, "}"]));
|
|
37
|
+
// the hug: the head fits, so the block stays on the line and breaks inside
|
|
38
|
+
assert.equal(render(["f", callArgs(["a", block])], 20), "f(a, () => {\n body;\n})");
|
|
39
|
+
// the head does not fit: every argument on its own line
|
|
40
|
+
assert.equal(render(["f", callArgs(["a-long-argument", block])], 20), "f(\n a-long-argument,\n () => {\n body;\n },\n)");
|
|
41
|
+
// a plain choice
|
|
42
|
+
const c = choice("short", "a much longer fallback");
|
|
43
|
+
assert.equal(render(c, 10), "short");
|
|
44
|
+
assert.equal(render(["0123456789", c], 12), "0123456789a much longer fallback");
|
|
45
|
+
});
|
|
46
|
+
test("a hug never hides a block from the plain groups around the call: they break out", () => {
|
|
47
|
+
const block = fn(group(["($, x) => {", indent([hardline, "body;"]), hardline, "}"]));
|
|
48
|
+
const call = ["xs.map", callArgs([block])];
|
|
49
|
+
assert.equal(render(["const y = $.const", callArgs([call]), ";"], 80), "const y = $.const(\n xs.map(($, x) => {\n body;\n }),\n);");
|
|
50
|
+
// the call itself hugs
|
|
51
|
+
assert.equal(render(["return ", call, ";"], 80), "return xs.map(($, x) => {\n body;\n});");
|
|
52
|
+
});
|
|
53
|
+
test("a sole literal argument is hugged; a trailing literal after other arguments is too", () => {
|
|
54
|
+
const lit = hug(bracket("{", ["a: 1", "b: 2"], "}", " "));
|
|
55
|
+
assert.equal(render(["f", callArgs([lit])], 12), "f({\n a: 1,\n b: 2,\n})");
|
|
56
|
+
assert.equal(render(["f", callArgs(["x", lit])], 15), "f(x, {\n a: 1,\n b: 2,\n})");
|
|
57
|
+
// a trailing non-literal is not: the call breaks out, the literal then fitting its own line
|
|
58
|
+
assert.equal(render(["f", callArgs([lit, "T"])], 19), "f(\n { a: 1, b: 2 },\n T,\n)");
|
|
59
|
+
});
|
|
60
|
+
test("a choice's fallback options never break the groups around it: a chain that fits stays on its line", () => {
|
|
61
|
+
const chain = choice(["x", ".a()", ".b()", ".c()"], group(["x", indent([hardline, ".a()", hardline, ".b()", hardline, ".c()"])]));
|
|
62
|
+
assert.equal(render(["const y = $.let", callArgs([chain]), ";"], 80), "const y = $.let(x.a().b().c());");
|
|
63
|
+
assert.equal(render(["const y = $.let", callArgs([chain]), ";"], 20), "const y = $.let(\n x.a().b().c(),\n);");
|
|
64
|
+
assert.equal(render(["const y = $.let", callArgs([chain]), ";"], 12), "const y = $.let(\n x\n .a()\n .b()\n .c(),\n);");
|
|
65
|
+
assert.ok(!willBreak(chain));
|
|
66
|
+
});
|
|
67
|
+
test("a hugged concise arrow that does not fit breaks after its arrow, the close on its own line; two trailing callbacks hug neither", () => {
|
|
68
|
+
const concise = (names, body) => fn(group([`(${names}) =>`, indent([line, body])]), group([`(${names}) =>`, indent([line, body]), ifBreak(","), softline]));
|
|
69
|
+
const long = "East.equal(_f1(v, k), 4n).ifElse(a, b)";
|
|
70
|
+
assert.equal(render(["return a.firstMap", callArgs([concise("$, v, k", long)]), ";"], 40), "return a.firstMap(($, v, k) =>\n East.equal(_f1(v, k), 4n).ifElse(a, b),\n);");
|
|
71
|
+
assert.equal(render(["x.ifElse", callArgs([concise("$", "aaaaaaaaaaaaaaaa"), concise("$", "bbbbbbbbbbbbbbbb")]), ";"], 40), "x.ifElse(\n ($) => aaaaaaaaaaaaaaaa,\n ($) => bbbbbbbbbbbbbbbb,\n);");
|
|
72
|
+
});
|
|
73
|
+
test("a leading block before one short argument is hugged (reduce(fn, init))", () => {
|
|
74
|
+
const block = fn(group(["($, acc, x) => {", indent([hardline, "body;"]), hardline, "}"]));
|
|
75
|
+
assert.equal(render(["xs.reduce", callArgs([block, "0n"])], 80), "xs.reduce(($, acc, x) => {\n body;\n}, 0n)");
|
|
76
|
+
});
|
|
77
|
+
test("lines: line is a space or a newline, softline nothing or a newline, and trailing spaces are trimmed", () => {
|
|
78
|
+
const g = group(["a", line, "b", softline, "c"]);
|
|
79
|
+
assert.equal(render(g, 80), "a bc");
|
|
80
|
+
assert.equal(render(g, 2), "a\nb\nc");
|
|
81
|
+
assert.equal(render(["x ", hardline, "y"], 80), "x\ny");
|
|
82
|
+
assert.equal(render(indent(["a", hardline, "b"]), 80, " "), "a\n b");
|
|
83
|
+
assert.equal(render(join(", ", ["1", "2", "3"]), 80), "1, 2, 3");
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
//# sourceMappingURL=doc.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doc.spec.js","sourceRoot":"","sources":["../../../src/codegen/doc.spec.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,MAAM,MAAM,oBAAoB,CAAC;AAExC,OAAO,EACK,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAClH,SAAS,GACV,MAAM,UAAU,CAAC;AAElB,QAAQ,CAAC,iCAAiC,EAAE,GAAG,EAAE;IAC/C,IAAI,CAAC,uEAAuE,EAAE,GAAG,EAAE;QACjF,MAAM,KAAK,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QACvC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,CAAC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,EAAE,CAAC,EAAE,6CAA6C,CAAC,CAAC;IAClH,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,qGAAqG,EAAE,GAAG,EAAE;QAC/G,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC;QACjD,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC;QACpC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;QACtC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC;QACxD,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,UAAU,CAAC,CAAC;QAC3E,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,SAAS,CAAC,CAAC;IACnE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* The IR → TypeScript printer (#628) — the TypeScript half of East's
|
|
7
|
+
* bidirectional codegen: `toSource` renders any East IR as the
|
|
8
|
+
* `East.function` builder source that rebuilds it, the python half
|
|
9
|
+
* (`east.codegen.to_python_source`) renders it as python, and the
|
|
10
|
+
* three-way sweep pins `IR₁ ≡ IR₂ ≡ IR₃` across both.
|
|
11
|
+
*/
|
|
12
|
+
export { toSource, Unprintable, type ToSourceOptions } from "./printer.js";
|
|
13
|
+
export { SPELLINGS, RAW_ONLY, spellingFor, type Spelling } from "./spellings.js";
|
|
14
|
+
export { typeSource, typeKey, TYPE_IMPORTS } from "./types.js";
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/codegen/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;GAMG;AAEH,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* The IR → TypeScript printer (#628) — the TypeScript half of East's
|
|
7
|
+
* bidirectional codegen: `toSource` renders any East IR as the
|
|
8
|
+
* `East.function` builder source that rebuilds it, the python half
|
|
9
|
+
* (`east.codegen.to_python_source`) renders it as python, and the
|
|
10
|
+
* three-way sweep pins `IR₁ ≡ IR₂ ≡ IR₃` across both.
|
|
11
|
+
*/
|
|
12
|
+
export { toSource, Unprintable } from "./printer.js";
|
|
13
|
+
export { SPELLINGS, RAW_ONLY, spellingFor } from "./spellings.js";
|
|
14
|
+
export { typeSource, typeKey, TYPE_IMPORTS } from "./types.js";
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/codegen/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;GAMG;AAEH,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAwB,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAiB,MAAM,gBAAgB,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Thrown for an IR shape the TypeScript surface cannot spell.
|
|
7
|
+
*
|
|
8
|
+
* The message names the node kind (and builtin) and where it sits — a
|
|
9
|
+
* statement in expression position, a jump to no loop, a `NewVector` of
|
|
10
|
+
* expressions, a `finally` on an expression `TryCatch`, an unknown node
|
|
11
|
+
* kind. Builtins without a spelling row print raw and are never unprintable.
|
|
12
|
+
*/
|
|
13
|
+
export declare class Unprintable extends Error {
|
|
14
|
+
constructor(message: string);
|
|
15
|
+
}
|
|
16
|
+
/** Options for {@link toSource}. */
|
|
17
|
+
export interface ToSourceOptions {
|
|
18
|
+
/** The module-level export bound to the rebuilt function (default `"main"`). */
|
|
19
|
+
name?: string;
|
|
20
|
+
/** The module specifier the printed module imports from (default `"@elaraai/east"`). */
|
|
21
|
+
importFrom?: string;
|
|
22
|
+
/** The line width the layout keeps to (default {@link LINE_WIDTH}); `Infinity` prints every construct on one line. */
|
|
23
|
+
width?: number;
|
|
24
|
+
/**
|
|
25
|
+
* The library modules the program uses, by the specifier the printed
|
|
26
|
+
* module should import them from: `{ "@elaraai/east-node-io": await
|
|
27
|
+
* import("@elaraai/east-node-io") }`. A platform call whose declaration
|
|
28
|
+
* handle a module exports prints as that export — `Compression.Tar.create(
|
|
29
|
+
* entries)` with `import { Compression } from "@elaraai/east-node-io"` —
|
|
30
|
+
* rather than as a hoisted declaration; the library's own structure is the
|
|
31
|
+
* spelling, read from its exports.
|
|
32
|
+
*/
|
|
33
|
+
libraries?: Record<string, object>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Prints East IR as a TypeScript module that rebuilds it.
|
|
37
|
+
*
|
|
38
|
+
* @param fnOrIr - A built `East.function` / `East.asyncFunction` expression,
|
|
39
|
+
* its `toIR()` result, or a homoiconic IR value (a Function / AsyncFunction
|
|
40
|
+
* node, or the `Block[Let…, Function]` a python build with hoisted
|
|
41
|
+
* constants emits — its constants become the body's first `$.const`s)
|
|
42
|
+
* @param options - The export name (default `main`), the module the
|
|
43
|
+
* printed source imports from (default `@elaraai/east`), the line width,
|
|
44
|
+
* and the library modules whose exported declarations spell the platform
|
|
45
|
+
* calls (`libraries`)
|
|
46
|
+
* @returns The module source: importing it binds `name` to an
|
|
47
|
+
* `East.function(...)` whose IR normalizes equal to the input's
|
|
48
|
+
* @throws {Unprintable} For a shape the TypeScript surface cannot spell — a
|
|
49
|
+
* statement in expression position, a jump to no loop, a `NewVector` of
|
|
50
|
+
* expressions, a `finally` on an expression `TryCatch`. Builtins without a
|
|
51
|
+
* spelling print through `East.builtin(...)` and are never unprintable.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* const double = East.function([IntegerType], IntegerType, ($, x) => x.multiply(2n));
|
|
56
|
+
* console.log(East.toSource(double));
|
|
57
|
+
* // import { East, Expr, ... } from "@elaraai/east";
|
|
58
|
+
* //
|
|
59
|
+
* // export const main = East.function([IntegerType], IntegerType, ($, x) => x.multiply(2n));
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare function toSource(fnOrIr: unknown, options?: ToSourceOptions): string;
|
|
63
|
+
//# sourceMappingURL=printer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"printer.d.ts","sourceRoot":"","sources":["../../../src/codegen/printer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAqGH;;;;;;;GAOG;AACH,qBAAa,WAAY,SAAQ,KAAK;gBACxB,OAAO,EAAE,MAAM;CAI5B;AA+RD,oCAAoC;AACpC,MAAM,WAAW,eAAe;IAC9B,gFAAgF;IAChF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wFAAwF;IACxF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,sHAAsH;IACtH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;;;;OAQG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACpC;AAwhCD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,GAAE,eAAoB,GAAG,MAAM,CAG/E"}
|