@invinite-org/chartlang-compiler 1.2.1 → 1.4.0
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/CHANGELOG.md +310 -0
- package/dist/analysis/extractDependencyGraph.d.ts.map +1 -1
- package/dist/analysis/extractDependencyGraph.js +9 -1
- package/dist/analysis/extractDependencyGraph.js.map +1 -1
- package/dist/analysis/extractInputs.d.ts.map +1 -1
- package/dist/analysis/extractInputs.js +2 -0
- package/dist/analysis/extractInputs.js.map +1 -1
- package/dist/analysis/extractMaxLookback.d.ts +2 -1
- package/dist/analysis/extractMaxLookback.d.ts.map +1 -1
- package/dist/analysis/extractMaxLookback.js +90 -6
- package/dist/analysis/extractMaxLookback.js.map +1 -1
- package/dist/analysis/extractRequestedIntervals.d.ts +63 -1
- package/dist/analysis/extractRequestedIntervals.d.ts.map +1 -1
- package/dist/analysis/extractRequestedIntervals.js +245 -29
- package/dist/analysis/extractRequestedIntervals.js.map +1 -1
- package/dist/analysis/forbiddenConstructs.d.ts.map +1 -1
- package/dist/analysis/forbiddenConstructs.js +2 -41
- package/dist/analysis/forbiddenConstructs.js.map +1 -1
- package/dist/analysis/index.d.ts +4 -1
- package/dist/analysis/index.d.ts.map +1 -1
- package/dist/analysis/index.js +3 -1
- package/dist/analysis/index.js.map +1 -1
- package/dist/analysis/loopBounds.d.ts +91 -0
- package/dist/analysis/loopBounds.d.ts.map +1 -0
- package/dist/analysis/loopBounds.js +132 -0
- package/dist/analysis/loopBounds.js.map +1 -0
- package/dist/analysis/resolveIndexBound.d.ts +73 -0
- package/dist/analysis/resolveIndexBound.d.ts.map +1 -0
- package/dist/analysis/resolveIndexBound.js +336 -0
- package/dist/analysis/resolveIndexBound.js.map +1 -0
- package/dist/analysis/stateArrayCapacity.d.ts +58 -0
- package/dist/analysis/stateArrayCapacity.d.ts.map +1 -0
- package/dist/analysis/stateArrayCapacity.js +108 -0
- package/dist/analysis/stateArrayCapacity.js.map +1 -0
- package/dist/analysis/validateSecurityExpr.d.ts +25 -0
- package/dist/analysis/validateSecurityExpr.d.ts.map +1 -0
- package/dist/analysis/validateSecurityExpr.js +154 -0
- package/dist/analysis/validateSecurityExpr.js.map +1 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +22 -3
- package/dist/api.js.map +1 -1
- package/dist/diagnostics.d.ts +8 -2
- package/dist/diagnostics.d.ts.map +1 -1
- package/dist/diagnostics.js.map +1 -1
- package/dist/manifest.d.ts +3 -1
- package/dist/manifest.d.ts.map +1 -1
- package/dist/manifest.js +11 -0
- package/dist/manifest.js.map +1 -1
- package/dist/program.d.ts.map +1 -1
- package/dist/program.js +148 -15
- package/dist/program.js.map +1 -1
- package/dist/transformers/callsiteIdInjection.d.ts +21 -0
- package/dist/transformers/callsiteIdInjection.d.ts.map +1 -1
- package/dist/transformers/callsiteIdInjection.js +34 -4
- package/dist/transformers/callsiteIdInjection.js.map +1 -1
- package/dist/transformers/plotKindFromCallsite.d.ts +3 -0
- package/dist/transformers/plotKindFromCallsite.d.ts.map +1 -1
- package/dist/transformers/plotKindFromCallsite.js +7 -0
- package/dist/transformers/plotKindFromCallsite.js.map +1 -1
- package/dist/transformers/resolveCallee.d.ts +21 -0
- package/dist/transformers/resolveCallee.d.ts.map +1 -1
- package/dist/transformers/resolveCallee.js +14 -1
- package/dist/transformers/resolveCallee.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +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"}
|
|
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;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,qBAAqB,CACjC,OAAO,EAAE,EAAE,CAAC,WAAW,EACvB,UAAU,EAAE,EAAE,CAAC,UAAU,GAC1B,MAAM,GAAG,IAAI,CA2Cf"}
|
|
@@ -76,8 +76,21 @@ export function resolveCoreSymbolForElementAccess(node, checker) {
|
|
|
76
76
|
* symbol. Renamed imports (`import { ta as TA } from "core"; TA.ema(...)`)
|
|
77
77
|
* map back to their export name (`"ta"`) so the resulting slot-id
|
|
78
78
|
* matches what `STATEFUL_PRIMITIVES` expects.
|
|
79
|
+
*
|
|
80
|
+
* Reused by the `request.security` expression capture check
|
|
81
|
+
* (`validateSecurityExpr`) to decide whether a free identifier inside the
|
|
82
|
+
* HTF callback resolves to the ambient `ta` / `inputs` namespaces (allowed)
|
|
83
|
+
* versus an outer-scope binding (rejected).
|
|
84
|
+
*
|
|
85
|
+
* @since 0.7
|
|
86
|
+
* @stable
|
|
87
|
+
* @example
|
|
88
|
+
* // const name = resolveCoreSymbolName(checker, identifier);
|
|
89
|
+
* // name === "ta" | "inputs" | null
|
|
90
|
+
* const fn: typeof resolveCoreSymbolName = resolveCoreSymbolName;
|
|
91
|
+
* void fn;
|
|
79
92
|
*/
|
|
80
|
-
function resolveCoreSymbolName(checker, identifier) {
|
|
93
|
+
export function resolveCoreSymbolName(checker, identifier) {
|
|
81
94
|
const localSymbol = checker.getSymbolAtLocation(identifier);
|
|
82
95
|
if (!localSymbol)
|
|
83
96
|
return null;
|
|
@@ -1 +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,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE,CAAC;QAC9B,MAAM,SAAS,GAAG,qBAAqB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QAC7D,IAAI,SAAS,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC;QACpC,OAAO,SAAS,CAAC;IACrB,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,SAAS,yBAAyB,CAC9B,UAAuC,EACvC,OAAuB;IAEvB,MAAM,QAAQ,GAAa,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClD,IAAI,OAAO,GAAkB,UAAU,CAAC,UAAU,CAAC;IACnD,OAAO,EAAE,CAAC,0BAA0B,CAAC,OAAO,CAAC,EAAE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AC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,SAAS,kCAAkC,CACvC,OAAuB,EACvB,WAA8B,EAC9B,aAAqB;IAErB,MAAM,cAAc,GAAG,WAAW,CAAC,MAAM,CAAC;IAC1C,MAAM,YAAY,GAAG,cAAc,CAAC,MAAM,CAAC;IAC3C,IAAI,CAAC,EAAE,CAAC,sBAAsB,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,YAAY,CAAC;QAAE,OAAO,KAAK,CAAC;IAC9F,MAAM,aAAa,GAAG,OAAO,CAAC,iBAAiB,CAAC,YAAY,CAAC,CAAC;IAC9D,MAAM,QAAQ,GAAG,aAAa,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;IAC1D,MAAM,aAAa,GAAG,QAAQ,EAAE,YAAY,IAAI,EAAE,CAAC;IACnD,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC,QAAQ,KAAK,gBAAgB,CAAC,CAAC;AACtF,CAAC","sourcesContent":["// Copyright (c) 2026 Invinite. Licensed under the MIT License.\n// See the LICENSE file in the repo root for full license text.\n\nimport ts from \"typescript\";\n\nimport { CORE_MODULE_PATH } from \"../program.js\";\n\n/**\n * Resolve a `CallExpression`'s callee to its fully-qualified name. Returns\n * one of `\"ta.<method>\"`, `\"plot\"`, `\"hline\"`, `\"alert\"`,\n * `\"defineIndicator\"`, `\"defineAlert\"` for calls whose target comes from\n * `@invinite-org/chartlang-core`; returns `null` for everything else\n * (user-shadowed identifiers, computed access, optional chains, calls on\n * call results).\n *\n * Identifier callees are gated on the symbol's declaration source file\n * matching the core ambient module path so a user's `const plot = (x) => x;\n * plot(42);` is not mistaken for the core `plot` primitive.\n *\n * @since 0.1\n * @example\n * // const fqn = resolveCalleeName(callNode, checker);\n * // fqn === \"ta.ema\" | \"plot\" | \"alert\" | ... | null\n * const fn: typeof resolveCalleeName = resolveCalleeName;\n * void fn;\n */\nexport function resolveCalleeName(node: ts.CallExpression, checker: ts.TypeChecker): string | null {\n const expression = node.expression;\n if (ts.isPropertyAccessExpression(expression)) {\n return resolvePropertyAccessName(expression, checker);\n }\n if (ts.isIdentifier(expression)) {\n const canonical = resolveCoreSymbolName(checker, expression);\n if (canonical === null) return null;\n return canonical;\n }\n return null;\n}\n\nfunction resolvePropertyAccessName(\n expression: ts.PropertyAccessExpression,\n checker: ts.TypeChecker,\n): string | null {\n const segments: string[] = [expression.name.text];\n let current: ts.Expression = expression.expression;\n while (ts.isPropertyAccessExpression(current)) {\n segments.unshift(current.name.text);\n current = current.expression;\n }\n if (!ts.isIdentifier(current)) return null;\n const canonical = resolveCoreSymbolName(checker, current);\n if (canonical === null) return null;\n return [canonical, ...segments].join(\".\");\n}\n\n/**\n * Resolve the canonical core-export name for the *object* of an\n * `ElementAccessExpression` (`obj[...]`). Used by the callsite-id\n * transformer to detect element-access calls on core namespaces\n * (`ta[\"ema\"](...)`, `state[\"foo\"]?.()`) that would otherwise silently\n * skip slot-id injection. Returns the canonical name (e.g. `\"ta\"`) when\n * the object identifier resolves to a core symbol, or `null` when it\n * does not (user-shadowed identifier, non-core object, computed receiver).\n *\n * @since 0.1\n * @example\n * // const name = resolveCoreSymbolForElementAccess(node, checker);\n * // name === \"ta\" | null\n * const fn: typeof resolveCoreSymbolForElementAccess = resolveCoreSymbolForElementAccess;\n * void fn;\n */\nexport function resolveCoreSymbolForElementAccess(\n node: ts.ElementAccessExpression,\n checker: ts.TypeChecker,\n): string | null {\n const obj = node.expression;\n if (!ts.isIdentifier(obj)) return null;\n return resolveCoreSymbolName(checker, obj);\n}\n\n/**\n * Return the canonical core-export name for `identifier`, or `null` if\n * the identifier does not resolve to a `@invinite-org/chartlang-core`\n * symbol. Renamed imports (`import { ta as TA } from \"core\"; TA.ema(...)`)\n * map back to their export name (`\"ta\"`) so the resulting slot-id\n * matches what `STATEFUL_PRIMITIVES` expects.\n */\nfunction resolveCoreSymbolName(checker: ts.TypeChecker, identifier: ts.Identifier): string | null {\n const localSymbol = checker.getSymbolAtLocation(identifier);\n if (!localSymbol) return null;\n const target =\n localSymbol.flags & ts.SymbolFlags.Alias\n ? checker.getAliasedSymbol(localSymbol)\n : localSymbol;\n const declarations = target.declarations ?? [];\n if (declarations.some((d) => d.getSourceFile().fileName === CORE_MODULE_PATH)) {\n return target.getName();\n }\n // Destructured `compute({ ta, plot, ... })` binding: the symbol's\n // declaration is the binding element, not the core module. The\n // identifier's *type*, however, comes from `ComputeContext` (core)\n // — so a binding element whose type declaration originates in core\n // counts as a core symbol for the callsite-id transformer. The\n // canonical name is the binding's property name (or, when the\n // binding is renamed `{ ta: TA }`, the original property name).\n for (const declaration of declarations) {\n if (!ts.isBindingElement(declaration)) continue;\n // `{ ta }` → propertyName is undefined, fall back to identifier.\n // `{ ta: TA }` → propertyName is `ta`, identifier is `TA`.\n const propertyName = declaration.propertyName;\n const canonicalName =\n propertyName !== undefined && ts.isIdentifier(propertyName)\n ? propertyName.text\n : identifier.text;\n if (bindingElementComesFromCoreContext(checker, declaration, canonicalName)) {\n return canonicalName;\n }\n const type = checker.getTypeAtLocation(identifier);\n const typeSymbol = type.getSymbol();\n /* v8 ignore next */\n if (typeSymbol === undefined) continue;\n /* v8 ignore next */\n const typeDecls = typeSymbol.declarations ?? [];\n if (!typeDecls.some((d) => d.getSourceFile().fileName === CORE_MODULE_PATH)) continue;\n if (propertyName !== undefined && ts.isIdentifier(propertyName)) {\n return propertyName.text;\n }\n return identifier.text;\n }\n return null;\n}\n\nfunction bindingElementComesFromCoreContext(\n checker: ts.TypeChecker,\n declaration: ts.BindingElement,\n canonicalName: string,\n): boolean {\n const bindingPattern = declaration.parent;\n const bindingOwner = bindingPattern.parent;\n if (!ts.isObjectBindingPattern(bindingPattern) || !ts.isParameter(bindingOwner)) return false;\n const parameterType = checker.getTypeAtLocation(bindingOwner);\n const property = parameterType.getProperty(canonicalName);\n const propertyDecls = property?.declarations ?? [];\n return propertyDecls.some((d) => d.getSourceFile().fileName === CORE_MODULE_PATH);\n}\n"]}
|
|
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,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE,CAAC;QAC9B,MAAM,SAAS,GAAG,qBAAqB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QAC7D,IAAI,SAAS,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC;QACpC,OAAO,SAAS,CAAC;IACrB,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,SAAS,yBAAyB,CAC9B,UAAuC,EACvC,OAAuB;IAEvB,MAAM,QAAQ,GAAa,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClD,IAAI,OAAO,GAAkB,UAAU,CAAC,UAAU,CAAC;IACnD,OAAO,EAAE,CAAC,0BAA0B,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5C,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACpC,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC;IACjC,CAAC;IACD,IAAI,CAAC,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC;QAAE,OAAO,IAAI,CAAC;IAC3C,MA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3C,IAAI,CAAC,EAAE,CAAC,sBAAsB,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,YAAY,CAAC;QAAE,OAAO,KAAK,CAAC;IAC9F,MAAM,aAAa,GAAG,OAAO,CAAC,iBAAiB,CAAC,YAAY,CAAC,CAAC;IAC9D,MAAM,QAAQ,GAAG,aAAa,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;IAC1D,MAAM,aAAa,GAAG,QAAQ,EAAE,YAAY,IAAI,EAAE,CAAC;IACnD,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC,QAAQ,KAAK,gBAAgB,CAAC,CAAC;AACtF,CAAC","sourcesContent":["// Copyright (c) 2026 Invinite. Licensed under the MIT License.\n// See the LICENSE file in the repo root for full license text.\n\nimport ts from \"typescript\";\n\nimport { CORE_MODULE_PATH } from \"../program.js\";\n\n/**\n * Resolve a `CallExpression`'s callee to its fully-qualified name. Returns\n * one of `\"ta.<method>\"`, `\"plot\"`, `\"hline\"`, `\"alert\"`,\n * `\"defineIndicator\"`, `\"defineAlert\"` for calls whose target comes from\n * `@invinite-org/chartlang-core`; returns `null` for everything else\n * (user-shadowed identifiers, computed access, optional chains, calls on\n * call results).\n *\n * Identifier callees are gated on the symbol's declaration source file\n * matching the core ambient module path so a user's `const plot = (x) => x;\n * plot(42);` is not mistaken for the core `plot` primitive.\n *\n * @since 0.1\n * @example\n * // const fqn = resolveCalleeName(callNode, checker);\n * // fqn === \"ta.ema\" | \"plot\" | \"alert\" | ... | null\n * const fn: typeof resolveCalleeName = resolveCalleeName;\n * void fn;\n */\nexport function resolveCalleeName(node: ts.CallExpression, checker: ts.TypeChecker): string | null {\n const expression = node.expression;\n if (ts.isPropertyAccessExpression(expression)) {\n return resolvePropertyAccessName(expression, checker);\n }\n if (ts.isIdentifier(expression)) {\n const canonical = resolveCoreSymbolName(checker, expression);\n if (canonical === null) return null;\n return canonical;\n }\n return null;\n}\n\nfunction resolvePropertyAccessName(\n expression: ts.PropertyAccessExpression,\n checker: ts.TypeChecker,\n): string | null {\n const segments: string[] = [expression.name.text];\n let current: ts.Expression = expression.expression;\n while (ts.isPropertyAccessExpression(current)) {\n segments.unshift(current.name.text);\n current = current.expression;\n }\n if (!ts.isIdentifier(current)) return null;\n const canonical = resolveCoreSymbolName(checker, current);\n if (canonical === null) return null;\n return [canonical, ...segments].join(\".\");\n}\n\n/**\n * Resolve the canonical core-export name for the *object* of an\n * `ElementAccessExpression` (`obj[...]`). Used by the callsite-id\n * transformer to detect element-access calls on core namespaces\n * (`ta[\"ema\"](...)`, `state[\"foo\"]?.()`) that would otherwise silently\n * skip slot-id injection. Returns the canonical name (e.g. `\"ta\"`) when\n * the object identifier resolves to a core symbol, or `null` when it\n * does not (user-shadowed identifier, non-core object, computed receiver).\n *\n * @since 0.1\n * @example\n * // const name = resolveCoreSymbolForElementAccess(node, checker);\n * // name === \"ta\" | null\n * const fn: typeof resolveCoreSymbolForElementAccess = resolveCoreSymbolForElementAccess;\n * void fn;\n */\nexport function resolveCoreSymbolForElementAccess(\n node: ts.ElementAccessExpression,\n checker: ts.TypeChecker,\n): string | null {\n const obj = node.expression;\n if (!ts.isIdentifier(obj)) return null;\n return resolveCoreSymbolName(checker, obj);\n}\n\n/**\n * Return the canonical core-export name for `identifier`, or `null` if\n * the identifier does not resolve to a `@invinite-org/chartlang-core`\n * symbol. Renamed imports (`import { ta as TA } from \"core\"; TA.ema(...)`)\n * map back to their export name (`\"ta\"`) so the resulting slot-id\n * matches what `STATEFUL_PRIMITIVES` expects.\n *\n * Reused by the `request.security` expression capture check\n * (`validateSecurityExpr`) to decide whether a free identifier inside the\n * HTF callback resolves to the ambient `ta` / `inputs` namespaces (allowed)\n * versus an outer-scope binding (rejected).\n *\n * @since 0.7\n * @stable\n * @example\n * // const name = resolveCoreSymbolName(checker, identifier);\n * // name === \"ta\" | \"inputs\" | null\n * const fn: typeof resolveCoreSymbolName = resolveCoreSymbolName;\n * void fn;\n */\nexport function resolveCoreSymbolName(\n checker: ts.TypeChecker,\n identifier: ts.Identifier,\n): string | null {\n const localSymbol = checker.getSymbolAtLocation(identifier);\n if (!localSymbol) return null;\n const target =\n localSymbol.flags & ts.SymbolFlags.Alias\n ? checker.getAliasedSymbol(localSymbol)\n : localSymbol;\n const declarations = target.declarations ?? [];\n if (declarations.some((d) => d.getSourceFile().fileName === CORE_MODULE_PATH)) {\n return target.getName();\n }\n // Destructured `compute({ ta, plot, ... })` binding: the symbol's\n // declaration is the binding element, not the core module. The\n // identifier's *type*, however, comes from `ComputeContext` (core)\n // — so a binding element whose type declaration originates in core\n // counts as a core symbol for the callsite-id transformer. The\n // canonical name is the binding's property name (or, when the\n // binding is renamed `{ ta: TA }`, the original property name).\n for (const declaration of declarations) {\n if (!ts.isBindingElement(declaration)) continue;\n // `{ ta }` → propertyName is undefined, fall back to identifier.\n // `{ ta: TA }` → propertyName is `ta`, identifier is `TA`.\n const propertyName = declaration.propertyName;\n const canonicalName =\n propertyName !== undefined && ts.isIdentifier(propertyName)\n ? propertyName.text\n : identifier.text;\n if (bindingElementComesFromCoreContext(checker, declaration, canonicalName)) {\n return canonicalName;\n }\n const type = checker.getTypeAtLocation(identifier);\n const typeSymbol = type.getSymbol();\n /* v8 ignore next */\n if (typeSymbol === undefined) continue;\n /* v8 ignore next */\n const typeDecls = typeSymbol.declarations ?? [];\n if (!typeDecls.some((d) => d.getSourceFile().fileName === CORE_MODULE_PATH)) continue;\n if (propertyName !== undefined && ts.isIdentifier(propertyName)) {\n return propertyName.text;\n }\n return identifier.text;\n }\n return null;\n}\n\nfunction bindingElementComesFromCoreContext(\n checker: ts.TypeChecker,\n declaration: ts.BindingElement,\n canonicalName: string,\n): boolean {\n const bindingPattern = declaration.parent;\n const bindingOwner = bindingPattern.parent;\n if (!ts.isObjectBindingPattern(bindingPattern) || !ts.isParameter(bindingOwner)) return false;\n const parameterType = checker.getTypeAtLocation(bindingOwner);\n const property = parameterType.getProperty(canonicalName);\n const propertyDecls = property?.declarations ?? [];\n return propertyDecls.some((d) => d.getSourceFile().fileName === CORE_MODULE_PATH);\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@invinite-org/chartlang-compiler",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "TypeScript transformer + bundler for .chart.ts files",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"esbuild": "^0.24.0",
|
|
23
23
|
"typescript": "^5.6.0",
|
|
24
|
-
"@invinite-org/chartlang-core": "1.
|
|
24
|
+
"@invinite-org/chartlang-core": "1.3.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/node": "^20.0.0",
|