@invinite-org/chartlang-compiler 1.0.1

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.
Files changed (88) hide show
  1. package/CHANGELOG.md +683 -0
  2. package/LICENSE +21 -0
  3. package/README.md +53 -0
  4. package/dist/analysis/extractAlertConditions.d.ts +33 -0
  5. package/dist/analysis/extractAlertConditions.d.ts.map +1 -0
  6. package/dist/analysis/extractAlertConditions.js +118 -0
  7. package/dist/analysis/extractAlertConditions.js.map +1 -0
  8. package/dist/analysis/extractCapabilities.d.ts +22 -0
  9. package/dist/analysis/extractCapabilities.d.ts.map +1 -0
  10. package/dist/analysis/extractCapabilities.js +44 -0
  11. package/dist/analysis/extractCapabilities.js.map +1 -0
  12. package/dist/analysis/extractInputs.d.ts +44 -0
  13. package/dist/analysis/extractInputs.d.ts.map +1 -0
  14. package/dist/analysis/extractInputs.js +306 -0
  15. package/dist/analysis/extractInputs.js.map +1 -0
  16. package/dist/analysis/extractMaxLookback.d.ts +37 -0
  17. package/dist/analysis/extractMaxLookback.d.ts.map +1 -0
  18. package/dist/analysis/extractMaxLookback.js +90 -0
  19. package/dist/analysis/extractMaxLookback.js.map +1 -0
  20. package/dist/analysis/extractRequestedIntervals.d.ts +19 -0
  21. package/dist/analysis/extractRequestedIntervals.d.ts.map +1 -0
  22. package/dist/analysis/extractRequestedIntervals.js +85 -0
  23. package/dist/analysis/extractRequestedIntervals.js.map +1 -0
  24. package/dist/analysis/extractRequiresIntervals.d.ts +16 -0
  25. package/dist/analysis/extractRequiresIntervals.d.ts.map +1 -0
  26. package/dist/analysis/extractRequiresIntervals.js +71 -0
  27. package/dist/analysis/extractRequiresIntervals.js.map +1 -0
  28. package/dist/analysis/forbiddenConstructs.d.ts +22 -0
  29. package/dist/analysis/forbiddenConstructs.d.ts.map +1 -0
  30. package/dist/analysis/forbiddenConstructs.js +214 -0
  31. package/dist/analysis/forbiddenConstructs.js.map +1 -0
  32. package/dist/analysis/index.d.ts +15 -0
  33. package/dist/analysis/index.d.ts.map +1 -0
  34. package/dist/analysis/index.js +13 -0
  35. package/dist/analysis/index.js.map +1 -0
  36. package/dist/analysis/statefulCallInLoop.d.ts +26 -0
  37. package/dist/analysis/statefulCallInLoop.d.ts.map +1 -0
  38. package/dist/analysis/statefulCallInLoop.js +64 -0
  39. package/dist/analysis/statefulCallInLoop.js.map +1 -0
  40. package/dist/analysis/structuralChecks.d.ts +73 -0
  41. package/dist/analysis/structuralChecks.d.ts.map +1 -0
  42. package/dist/analysis/structuralChecks.js +243 -0
  43. package/dist/analysis/structuralChecks.js.map +1 -0
  44. package/dist/analysis/validateLowerTfIntervals.d.ts +26 -0
  45. package/dist/analysis/validateLowerTfIntervals.d.ts.map +1 -0
  46. package/dist/analysis/validateLowerTfIntervals.js +91 -0
  47. package/dist/analysis/validateLowerTfIntervals.js.map +1 -0
  48. package/dist/api.d.ts +205 -0
  49. package/dist/api.d.ts.map +1 -0
  50. package/dist/api.js +354 -0
  51. package/dist/api.js.map +1 -0
  52. package/dist/bundle.d.ts +75 -0
  53. package/dist/bundle.d.ts.map +1 -0
  54. package/dist/bundle.js +90 -0
  55. package/dist/bundle.js.map +1 -0
  56. package/dist/diagnostics.d.ts +88 -0
  57. package/dist/diagnostics.d.ts.map +1 -0
  58. package/dist/diagnostics.js +95 -0
  59. package/dist/diagnostics.js.map +1 -0
  60. package/dist/index.d.ts +9 -0
  61. package/dist/index.d.ts.map +1 -0
  62. package/dist/index.js +7 -0
  63. package/dist/index.js.map +1 -0
  64. package/dist/manifest.d.ts +40 -0
  65. package/dist/manifest.d.ts.map +1 -0
  66. package/dist/manifest.js +57 -0
  67. package/dist/manifest.js.map +1 -0
  68. package/dist/program.d.ts +68 -0
  69. package/dist/program.d.ts.map +1 -0
  70. package/dist/program.js +1391 -0
  71. package/dist/program.js.map +1 -0
  72. package/dist/transformers/callsiteIdInjection.d.ts +48 -0
  73. package/dist/transformers/callsiteIdInjection.d.ts.map +1 -0
  74. package/dist/transformers/callsiteIdInjection.js +91 -0
  75. package/dist/transformers/callsiteIdInjection.js.map +1 -0
  76. package/dist/transformers/index.d.ts +4 -0
  77. package/dist/transformers/index.d.ts.map +1 -0
  78. package/dist/transformers/index.js +5 -0
  79. package/dist/transformers/index.js.map +1 -0
  80. package/dist/transformers/resolveCallee.d.ts +39 -0
  81. package/dist/transformers/resolveCallee.d.ts.map +1 -0
  82. package/dist/transformers/resolveCallee.js +136 -0
  83. package/dist/transformers/resolveCallee.js.map +1 -0
  84. package/dist/typesEmit.d.ts +35 -0
  85. package/dist/typesEmit.d.ts.map +1 -0
  86. package/dist/typesEmit.js +27 -0
  87. package/dist/typesEmit.js.map +1 -0
  88. package/package.json +48 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"program.js","sourceRoot":"","sources":["../src/program.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAE/D,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,0BAA0B,CAAC;AAE3D;;;;;;;;;GASG;AACH,MAAM,iBAAiB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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N,CAAC;QACD,UAAU,CAAC,QAAQ;YACf,OAAO,gBAAgB,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,YAAY,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QAC/E,CAAC;KACJ,CAAC;IAEF,MAAM,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC;QAC7B,SAAS,EAAE,CAAC,UAAU,EAAE,gBAAgB,CAAC;QACzC,OAAO,EAAE,gBAAgB;QACzB,IAAI;KACP,CAAC,CAAC;IACH,OAAO,MAAM,CAAC,MAAM,CAAC;QACjB,OAAO;QACP,UAAU;QACV,OAAO,EAAE,OAAO,CAAC,cAAc,EAAE;KACpC,CAAC,CAAC;AACP,CAAC;AAED,SAAS,aAAa,CAAC,CAAS;IAC5B,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;AACtD,CAAC"}
@@ -0,0 +1,48 @@
1
+ import type { StatefulPrimitiveEntry } from "@invinite-org/chartlang-core";
2
+ import ts from "typescript";
3
+ import { type CompileDiagnostic } from "../diagnostics.js";
4
+ /**
5
+ * Output of `injectCallsiteIds` — the rewritten source file plus any
6
+ * diagnostics produced during the rewrite. Only `callsite-id-conflict`
7
+ * surfaces here; every other transformer-related check lives in the
8
+ * `analysis/` modules.
9
+ *
10
+ * @since 0.1
11
+ * @example
12
+ * // const { transformed, diagnostics } = injectCallsiteIds(src, checker, opts);
13
+ * const shape: { transformed: unknown; diagnostics: ReadonlyArray<unknown> } = {
14
+ * transformed: null,
15
+ * diagnostics: [],
16
+ * };
17
+ * void shape;
18
+ */
19
+ export type InjectCallsiteIdsResult = Readonly<{
20
+ transformed: ts.SourceFile;
21
+ diagnostics: ReadonlyArray<CompileDiagnostic>;
22
+ }>;
23
+ /**
24
+ * Inject a `__slot` string-literal first argument into every stateful
25
+ * primitive call. Slot id format per PLAN.md §5.5:
26
+ * `<sourcePath>:<line>:<col>#<callIndex>`. `callIndex` is hardcoded to `0`
27
+ * for hand-written code (Phase 1 reserves non-zero for future macros).
28
+ *
29
+ * The transformer is a pure rewrite — input nodes are never mutated. Lines
30
+ * and columns are 1-based and read from the **input** source file before
31
+ * any rewrite happens. Duplicate ids at the same `(line, col)` (impossible
32
+ * in hand-written TS but reachable by future macros) trigger a
33
+ * `callsite-id-conflict` diagnostic; only the first call at the duplicated
34
+ * position gets the slot.
35
+ *
36
+ * @since 0.1
37
+ * @example
38
+ * // Input: ta.ema(close, 20)
39
+ * // Output: ta.ema("demo.chart.ts:5:13#0", close, 20)
40
+ * const fn: typeof injectCallsiteIds = injectCallsiteIds;
41
+ * void fn;
42
+ */
43
+ export declare function injectCallsiteIds(sourceFile: ts.SourceFile, checker: ts.TypeChecker, opts: {
44
+ readonly sourcePath: string;
45
+ readonly statefulByName: ReadonlyMap<string, StatefulPrimitiveEntry>;
46
+ readonly slotsSeen?: Map<string, ts.CallExpression>;
47
+ }): InjectCallsiteIdsResult;
48
+ //# sourceMappingURL=callsiteIdInjection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callsiteIdInjection.d.ts","sourceRoot":"","sources":["../../src/transformers/callsiteIdInjection.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,EAAE,KAAK,iBAAiB,EAAoB,MAAM,mBAAmB,CAAC;AAG7E;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,uBAAuB,GAAG,QAAQ,CAAC;IAC3C,WAAW,EAAE,EAAE,CAAC,UAAU,CAAC;IAC3B,WAAW,EAAE,aAAa,CAAC,iBAAiB,CAAC,CAAC;CACjD,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,iBAAiB,CAC7B,UAAU,EAAE,EAAE,CAAC,UAAU,EACzB,OAAO,EAAE,EAAE,CAAC,WAAW,EACvB,IAAI,EAAE;IACF,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,cAAc,EAAE,WAAW,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;IACrE,QAAQ,CAAC,SAAS,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC,cAAc,CAAC,CAAC;CACvD,GACF,uBAAuB,CAiFzB"}
@@ -0,0 +1,91 @@
1
+ // Copyright (c) 2026 Invinite. Licensed under the MIT License.
2
+ // See the LICENSE file in the repo root for full license text.
3
+ import ts from "typescript";
4
+ import { createDiagnostic } from "../diagnostics.js";
5
+ import { resolveCalleeName, resolveCoreSymbolForElementAccess } from "./resolveCallee.js";
6
+ /**
7
+ * Inject a `__slot` string-literal first argument into every stateful
8
+ * primitive call. Slot id format per PLAN.md §5.5:
9
+ * `<sourcePath>:<line>:<col>#<callIndex>`. `callIndex` is hardcoded to `0`
10
+ * for hand-written code (Phase 1 reserves non-zero for future macros).
11
+ *
12
+ * The transformer is a pure rewrite — input nodes are never mutated. Lines
13
+ * and columns are 1-based and read from the **input** source file before
14
+ * any rewrite happens. Duplicate ids at the same `(line, col)` (impossible
15
+ * in hand-written TS but reachable by future macros) trigger a
16
+ * `callsite-id-conflict` diagnostic; only the first call at the duplicated
17
+ * position gets the slot.
18
+ *
19
+ * @since 0.1
20
+ * @example
21
+ * // Input: ta.ema(close, 20)
22
+ * // Output: ta.ema("demo.chart.ts:5:13#0", close, 20)
23
+ * const fn: typeof injectCallsiteIds = injectCallsiteIds;
24
+ * void fn;
25
+ */
26
+ export function injectCallsiteIds(sourceFile, checker, opts) {
27
+ const { sourcePath, statefulByName } = opts;
28
+ const slotsSeen = opts.slotsSeen ?? new Map();
29
+ const diagnostics = [];
30
+ const factory = (context) => {
31
+ const visit = (node) => {
32
+ if (ts.isCallExpression(node)) {
33
+ // Element-access calls (`ta["ema"](...)`, `alert?.[chan](...)`)
34
+ // bypass slot-id injection because the property name is not
35
+ // statically known. Detecting these explicitly turns the
36
+ // silent-state-corruption footgun into a compile-time error.
37
+ if (ts.isElementAccessExpression(node.expression)) {
38
+ const coreName = resolveCoreSymbolForElementAccess(node.expression, checker);
39
+ if (coreName !== null) {
40
+ diagnostics.push(createDiagnostic({
41
+ severity: "error",
42
+ code: "stateful-call-element-access",
43
+ message: `Element-access calls on the \`${coreName}\` namespace bypass callsite-id injection. Use the property-access form (\`${coreName}.<name>(...)\`).`,
44
+ file: sourcePath,
45
+ node,
46
+ sourceFile,
47
+ }));
48
+ return ts.visitEachChild(node, visit, context);
49
+ }
50
+ }
51
+ const calleeName = resolveCalleeName(node, checker);
52
+ const entry = calleeName === null ? undefined : statefulByName.get(calleeName);
53
+ if (entry?.slot) {
54
+ const start = node.getStart(sourceFile);
55
+ const { line, character } = sourceFile.getLineAndCharacterOfPosition(start);
56
+ const slotId = `${sourcePath}:${line + 1}:${character + 1}#0`;
57
+ const existing = slotsSeen.get(slotId);
58
+ if (existing !== undefined) {
59
+ diagnostics.push(createDiagnostic({
60
+ severity: "error",
61
+ code: "callsite-id-conflict",
62
+ message: `Two stateful calls share the same slot id "${slotId}".`,
63
+ file: sourcePath,
64
+ node,
65
+ sourceFile,
66
+ }));
67
+ return ts.visitEachChild(node, visit, context);
68
+ }
69
+ slotsSeen.set(slotId, node);
70
+ const visitedArguments = node.arguments.map((argument) => ts.visitNode(argument, visit, ts.isExpression));
71
+ const updatedArguments = ts.factory.createNodeArray([
72
+ ts.factory.createStringLiteral(slotId),
73
+ ...visitedArguments,
74
+ ]);
75
+ const visitedCallee = ts.visitNode(node.expression, visit, ts.isExpression);
76
+ return ts.factory.updateCallExpression(node, visitedCallee, node.typeArguments, updatedArguments);
77
+ }
78
+ }
79
+ return ts.visitEachChild(node, visit, context);
80
+ };
81
+ return (file) => ts.visitNode(file, visit, ts.isSourceFile);
82
+ };
83
+ const result = ts.transform(sourceFile, [factory]);
84
+ const transformed = result.transformed[0];
85
+ result.dispose();
86
+ return Object.freeze({
87
+ transformed,
88
+ diagnostics: Object.freeze(diagnostics.slice()),
89
+ });
90
+ }
91
+ //# sourceMappingURL=callsiteIdInjection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callsiteIdInjection.js","sourceRoot":"","sources":["../../src/transformers/callsiteIdInjection.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAG/D,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,EAA0B,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC7E,OAAO,EAAE,iBAAiB,EAAE,iCAAiC,EAAE,MAAM,oBAAoB,CAAC;AAsB1F;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,iBAAiB,CAC7B,UAAyB,EACzB,OAAuB,EACvB,IAIC;IAED,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC;IAC5C,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,IAAI,GAAG,EAA6B,CAAC;IACzE,MAAM,WAAW,GAAwB,EAAE,CAAC;IAE5C,MAAM,OAAO,GAAyC,CAAC,OAAO,EAAE,EAAE;QAC9D,MAAM,KAAK,GAAe,CAAC,IAAI,EAAE,EAAE;YAC/B,IAAI,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC5B,gEAAgE;gBAChE,4DAA4D;gBAC5D,yDAAyD;gBACzD,6DAA6D;gBAC7D,IAAI,EAAE,CAAC,yBAAyB,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;oBAChD,MAAM,QAAQ,GAAG,iCAAiC,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;oBAC7E,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;wBACpB,WAAW,CAAC,IAAI,CACZ,gBAAgB,CAAC;4BACb,QAAQ,EAAE,OAAO;4BACjB,IAAI,EAAE,8BAA8B;4BACpC,OAAO,EAAE,iCAAiC,QAAQ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InjectCallsiteIdsResult } from "./callsiteIdInjection.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transformers/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,YAAY,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC"}
@@ -0,0 +1,5 @@
1
+ // Copyright (c) 2026 Invinite. Licensed under the MIT License.
2
+ // See the LICENSE file in the repo root for full license text.
3
+ export { resolveCalleeName } from "./resolveCallee.js";
4
+ export { injectCallsiteIds } from "./callsiteIdInjection.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/transformers/index.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAE/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC"}
@@ -0,0 +1,39 @@
1
+ import ts from "typescript";
2
+ /**
3
+ * Resolve a `CallExpression`'s callee to its fully-qualified name. Returns
4
+ * one of `"ta.<method>"`, `"plot"`, `"hline"`, `"alert"`,
5
+ * `"defineIndicator"`, `"defineAlert"` for calls whose target comes from
6
+ * `@invinite-org/chartlang-core`; returns `null` for everything else
7
+ * (user-shadowed identifiers, computed access, optional chains, calls on
8
+ * call results).
9
+ *
10
+ * Identifier callees are gated on the symbol's declaration source file
11
+ * matching the core ambient module path so a user's `const plot = (x) => x;
12
+ * plot(42);` is not mistaken for the core `plot` primitive.
13
+ *
14
+ * @since 0.1
15
+ * @example
16
+ * // const fqn = resolveCalleeName(callNode, checker);
17
+ * // fqn === "ta.ema" | "plot" | "alert" | ... | null
18
+ * const fn: typeof resolveCalleeName = resolveCalleeName;
19
+ * void fn;
20
+ */
21
+ export declare function resolveCalleeName(node: ts.CallExpression, checker: ts.TypeChecker): string | null;
22
+ /**
23
+ * Resolve the canonical core-export name for the *object* of an
24
+ * `ElementAccessExpression` (`obj[...]`). Used by the callsite-id
25
+ * transformer to detect element-access calls on core namespaces
26
+ * (`ta["ema"](...)`, `state["foo"]?.()`) that would otherwise silently
27
+ * skip slot-id injection. Returns the canonical name (e.g. `"ta"`) when
28
+ * the object identifier resolves to a core symbol, or `null` when it
29
+ * does not (user-shadowed identifier, non-core object, computed receiver).
30
+ *
31
+ * @since 0.1
32
+ * @example
33
+ * // const name = resolveCoreSymbolForElementAccess(node, checker);
34
+ * // name === "ta" | null
35
+ * const fn: typeof resolveCoreSymbolForElementAccess = resolveCoreSymbolForElementAccess;
36
+ * void fn;
37
+ */
38
+ export declare function resolveCoreSymbolForElementAccess(node: ts.ElementAccessExpression, checker: ts.TypeChecker): string | null;
39
+ //# sourceMappingURL=resolveCallee.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveCallee.d.ts","sourceRoot":"","sources":["../../src/transformers/resolveCallee.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,YAAY,CAAC;AAI5B;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,EAAE,CAAC,cAAc,EAAE,OAAO,EAAE,EAAE,CAAC,WAAW,GAAG,MAAM,GAAG,IAAI,CAWjG;AAkBD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,iCAAiC,CAC7C,IAAI,EAAE,EAAE,CAAC,uBAAuB,EAChC,OAAO,EAAE,EAAE,CAAC,WAAW,GACxB,MAAM,GAAG,IAAI,CAIf"}
@@ -0,0 +1,136 @@
1
+ // Copyright (c) 2026 Invinite. Licensed under the MIT License.
2
+ // See the LICENSE file in the repo root for full license text.
3
+ import ts from "typescript";
4
+ import { CORE_MODULE_PATH } from "../program.js";
5
+ /**
6
+ * Resolve a `CallExpression`'s callee to its fully-qualified name. Returns
7
+ * one of `"ta.<method>"`, `"plot"`, `"hline"`, `"alert"`,
8
+ * `"defineIndicator"`, `"defineAlert"` for calls whose target comes from
9
+ * `@invinite-org/chartlang-core`; returns `null` for everything else
10
+ * (user-shadowed identifiers, computed access, optional chains, calls on
11
+ * call results).
12
+ *
13
+ * Identifier callees are gated on the symbol's declaration source file
14
+ * matching the core ambient module path so a user's `const plot = (x) => x;
15
+ * plot(42);` is not mistaken for the core `plot` primitive.
16
+ *
17
+ * @since 0.1
18
+ * @example
19
+ * // const fqn = resolveCalleeName(callNode, checker);
20
+ * // fqn === "ta.ema" | "plot" | "alert" | ... | null
21
+ * const fn: typeof resolveCalleeName = resolveCalleeName;
22
+ * void fn;
23
+ */
24
+ export function resolveCalleeName(node, checker) {
25
+ const expression = node.expression;
26
+ if (ts.isPropertyAccessExpression(expression)) {
27
+ return resolvePropertyAccessName(expression, checker);
28
+ }
29
+ if (ts.isIdentifier(expression)) {
30
+ const canonical = resolveCoreSymbolName(checker, expression);
31
+ if (canonical === null)
32
+ return null;
33
+ return canonical;
34
+ }
35
+ return null;
36
+ }
37
+ function resolvePropertyAccessName(expression, checker) {
38
+ const segments = [expression.name.text];
39
+ let current = expression.expression;
40
+ while (ts.isPropertyAccessExpression(current)) {
41
+ segments.unshift(current.name.text);
42
+ current = current.expression;
43
+ }
44
+ if (!ts.isIdentifier(current))
45
+ return null;
46
+ const canonical = resolveCoreSymbolName(checker, current);
47
+ if (canonical === null)
48
+ return null;
49
+ return [canonical, ...segments].join(".");
50
+ }
51
+ /**
52
+ * Resolve the canonical core-export name for the *object* of an
53
+ * `ElementAccessExpression` (`obj[...]`). Used by the callsite-id
54
+ * transformer to detect element-access calls on core namespaces
55
+ * (`ta["ema"](...)`, `state["foo"]?.()`) that would otherwise silently
56
+ * skip slot-id injection. Returns the canonical name (e.g. `"ta"`) when
57
+ * the object identifier resolves to a core symbol, or `null` when it
58
+ * does not (user-shadowed identifier, non-core object, computed receiver).
59
+ *
60
+ * @since 0.1
61
+ * @example
62
+ * // const name = resolveCoreSymbolForElementAccess(node, checker);
63
+ * // name === "ta" | null
64
+ * const fn: typeof resolveCoreSymbolForElementAccess = resolveCoreSymbolForElementAccess;
65
+ * void fn;
66
+ */
67
+ export function resolveCoreSymbolForElementAccess(node, checker) {
68
+ const obj = node.expression;
69
+ if (!ts.isIdentifier(obj))
70
+ return null;
71
+ return resolveCoreSymbolName(checker, obj);
72
+ }
73
+ /**
74
+ * Return the canonical core-export name for `identifier`, or `null` if
75
+ * the identifier does not resolve to a `@invinite-org/chartlang-core`
76
+ * symbol. Renamed imports (`import { ta as TA } from "core"; TA.ema(...)`)
77
+ * map back to their export name (`"ta"`) so the resulting slot-id
78
+ * matches what `STATEFUL_PRIMITIVES` expects.
79
+ */
80
+ function resolveCoreSymbolName(checker, identifier) {
81
+ const localSymbol = checker.getSymbolAtLocation(identifier);
82
+ if (!localSymbol)
83
+ return null;
84
+ const target = localSymbol.flags & ts.SymbolFlags.Alias
85
+ ? checker.getAliasedSymbol(localSymbol)
86
+ : localSymbol;
87
+ const declarations = target.declarations ?? [];
88
+ if (declarations.some((d) => d.getSourceFile().fileName === CORE_MODULE_PATH)) {
89
+ return target.getName();
90
+ }
91
+ // Destructured `compute({ ta, plot, ... })` binding: the symbol's
92
+ // declaration is the binding element, not the core module. The
93
+ // identifier's *type*, however, comes from `ComputeContext` (core)
94
+ // — so a binding element whose type declaration originates in core
95
+ // counts as a core symbol for the callsite-id transformer. The
96
+ // canonical name is the binding's property name (or, when the
97
+ // binding is renamed `{ ta: TA }`, the original property name).
98
+ for (const declaration of declarations) {
99
+ if (!ts.isBindingElement(declaration))
100
+ continue;
101
+ // `{ ta }` → propertyName is undefined, fall back to identifier.
102
+ // `{ ta: TA }` → propertyName is `ta`, identifier is `TA`.
103
+ const propertyName = declaration.propertyName;
104
+ const canonicalName = propertyName !== undefined && ts.isIdentifier(propertyName)
105
+ ? propertyName.text
106
+ : identifier.text;
107
+ if (bindingElementComesFromCoreContext(checker, declaration, canonicalName)) {
108
+ return canonicalName;
109
+ }
110
+ const type = checker.getTypeAtLocation(identifier);
111
+ const typeSymbol = type.getSymbol();
112
+ /* v8 ignore next */
113
+ if (typeSymbol === undefined)
114
+ continue;
115
+ /* v8 ignore next */
116
+ const typeDecls = typeSymbol.declarations ?? [];
117
+ if (!typeDecls.some((d) => d.getSourceFile().fileName === CORE_MODULE_PATH))
118
+ continue;
119
+ if (propertyName !== undefined && ts.isIdentifier(propertyName)) {
120
+ return propertyName.text;
121
+ }
122
+ return identifier.text;
123
+ }
124
+ return null;
125
+ }
126
+ function bindingElementComesFromCoreContext(checker, declaration, canonicalName) {
127
+ const bindingPattern = declaration.parent;
128
+ const bindingOwner = bindingPattern.parent;
129
+ if (!ts.isObjectBindingPattern(bindingPattern) || !ts.isParameter(bindingOwner))
130
+ return false;
131
+ const parameterType = checker.getTypeAtLocation(bindingOwner);
132
+ const property = parameterType.getProperty(canonicalName);
133
+ const propertyDecls = property?.declarations ?? [];
134
+ return propertyDecls.some((d) => d.getSourceFile().fileName === CORE_MODULE_PATH);
135
+ }
136
+ //# sourceMappingURL=resolveCallee.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveCallee.js","sourceRoot":"","sources":["../../src/transformers/resolveCallee.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAE/D,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEjD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAuB,EAAE,OAAuB;IAC9E,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;IACnC,IAAI,EAAE,CAAC,0BAA0B,CAAC,UAAU,CAAC,EAAE,CAAC;QAC5C,OAAO,yBAAyB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAC1D,CAAC;IACD,IAAI,EAAE,C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frozen script manifest
4
+ * the runtime will consume; `sourcePath` is reserved so a future generator can
5
+ * embed it into the declarations as a comment when source navigation surfaces
6
+ * land. Phase 1 emits the same minimal `.d.ts` for every script.
7
+ *
8
+ * @since 0.1
9
+ * @example
10
+ * const opts: EmitTypesOptions = {
11
+ * manifest: { } as never,
12
+ * sourcePath: "demo.chart.ts",
13
+ * };
14
+ * void opts;
15
+ */
16
+ export type EmitTypesOptions = Readonly<{
17
+ manifest: ScriptManifest;
18
+ sourcePath: string;
19
+ }>;
20
+ /**
21
+ * Generate the Phase-1 minimal `.d.ts` sibling for a compiled script. The
22
+ * declarations mirror the runtime expectation in §5.2 — a default-exported
23
+ * `CompiledScriptObject` plus the `__manifest` symbol the bundler emits at
24
+ * the bottom of the JS. Identical content for every script in Phase 1;
25
+ * Phase 4+ specialises per-script inputs / outputs.
26
+ *
27
+ * @since 0.1
28
+ * @example
29
+ * // const dts = emitTypes({ manifest, sourcePath: "demo.chart.ts" });
30
+ * // dts.includes("export default script");
31
+ * const fn: typeof emitTypes = emitTypes;
32
+ * void fn;
33
+ */
34
+ export declare function emitTypes(_opts: EmitTypesOptions): string;
35
+ //# sourceMappingURL=typesEmit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typesEmit.d.ts","sourceRoot":"","sources":["../src/typesEmit.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAEnE;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CAAC;IACpC,QAAQ,EAAE,cAAc,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;CACtB,CAAC,CAAC;AAEH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,gBAAgB,GAAG,MAAM,CASzD"}
@@ -0,0 +1,27 @@
1
+ // Copyright (c) 2026 Invinite. Licensed under the MIT License.
2
+ // See the LICENSE file in the repo root for full license text.
3
+ /**
4
+ * Generate the Phase-1 minimal `.d.ts` sibling for a compiled script. The
5
+ * declarations mirror the runtime expectation in §5.2 — a default-exported
6
+ * `CompiledScriptObject` plus the `__manifest` symbol the bundler emits at
7
+ * the bottom of the JS. Identical content for every script in Phase 1;
8
+ * Phase 4+ specialises per-script inputs / outputs.
9
+ *
10
+ * @since 0.1
11
+ * @example
12
+ * // const dts = emitTypes({ manifest, sourcePath: "demo.chart.ts" });
13
+ * // dts.includes("export default script");
14
+ * const fn: typeof emitTypes = emitTypes;
15
+ * void fn;
16
+ */
17
+ export function emitTypes(_opts) {
18
+ return `// auto-generated by @invinite-org/chartlang-compiler
19
+ import type { CompiledScriptObject, ScriptManifest } from "@invinite-org/chartlang-core";
20
+
21
+ declare const script: CompiledScriptObject;
22
+ export default script;
23
+
24
+ export declare const __manifest: ScriptManifest;
25
+ `;
26
+ }
27
+ //# sourceMappingURL=typesEmit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typesEmit.js","sourceRoot":"","sources":["../src/typesEmit.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAuB/D;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,SAAS,CAAC,KAAuB;IAC7C,OAAO;;;;;;;CAOV,CAAC;AACF,CAAC"}
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@invinite-org/chartlang-compiler",
3
+ "version": "1.0.1",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "description": "TypeScript transformer + bundler for .chart.ts files",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md",
18
+ "CHANGELOG.md",
19
+ "LICENSE"
20
+ ],
21
+ "dependencies": {
22
+ "esbuild": "^0.24.0",
23
+ "typescript": "^5.6.0",
24
+ "@invinite-org/chartlang-core": "1.0.1"
25
+ },
26
+ "devDependencies": {
27
+ "@types/node": "^20.0.0",
28
+ "fast-check": "^3.20.0"
29
+ },
30
+ "publishConfig": {
31
+ "access": "public",
32
+ "provenance": true
33
+ },
34
+ "engines": {
35
+ "node": ">=20"
36
+ },
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "https://github.com/outraday-org/chartlang.git",
40
+ "directory": "packages/compiler"
41
+ },
42
+ "scripts": {
43
+ "build": "tsc -p tsconfig.json",
44
+ "typecheck": "tsc -p tsconfig.json --noEmit",
45
+ "test": "vitest run --coverage",
46
+ "bench": "vitest bench --run"
47
+ }
48
+ }