@tamagui/compiler-core 0.0.0-bootstrap.0 → 3.0.0-beta.637.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 (98) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +57 -1
  3. package/dist/cjs/ast.cjs +95 -0
  4. package/dist/cjs/contracts.cjs +62 -0
  5. package/dist/cjs/diagnostics.cjs +69 -0
  6. package/dist/cjs/evaluate.cjs +351 -0
  7. package/dist/cjs/graph.cjs +279 -0
  8. package/dist/cjs/hash.cjs +49 -0
  9. package/dist/cjs/index.cjs +44 -0
  10. package/dist/cjs/ir.cjs +33 -0
  11. package/dist/cjs/lower.cjs +225 -0
  12. package/dist/cjs/materialize.cjs +200 -0
  13. package/dist/cjs/normalize.cjs +622 -0
  14. package/dist/cjs/output.cjs +149 -0
  15. package/dist/cjs/planCache.cjs +224 -0
  16. package/dist/cjs/session.cjs +119 -0
  17. package/dist/cjs/yuku.cjs +159 -0
  18. package/dist/cjs/zero.cjs +387 -0
  19. package/dist/esm/ast.mjs +65 -0
  20. package/dist/esm/ast.mjs.map +1 -0
  21. package/dist/esm/contracts.mjs +34 -0
  22. package/dist/esm/contracts.mjs.map +1 -0
  23. package/dist/esm/diagnostics.mjs +44 -0
  24. package/dist/esm/diagnostics.mjs.map +1 -0
  25. package/dist/esm/evaluate.mjs +327 -0
  26. package/dist/esm/evaluate.mjs.map +1 -0
  27. package/dist/esm/graph.mjs +256 -0
  28. package/dist/esm/graph.mjs.map +1 -0
  29. package/dist/esm/hash.mjs +26 -0
  30. package/dist/esm/hash.mjs.map +1 -0
  31. package/dist/esm/index.mjs +30 -0
  32. package/dist/esm/ir.mjs +12 -0
  33. package/dist/esm/ir.mjs.map +1 -0
  34. package/dist/esm/lower.mjs +202 -0
  35. package/dist/esm/lower.mjs.map +1 -0
  36. package/dist/esm/materialize.mjs +179 -0
  37. package/dist/esm/materialize.mjs.map +1 -0
  38. package/dist/esm/normalize.mjs +596 -0
  39. package/dist/esm/normalize.mjs.map +1 -0
  40. package/dist/esm/output.mjs +119 -0
  41. package/dist/esm/output.mjs.map +1 -0
  42. package/dist/esm/planCache.mjs +194 -0
  43. package/dist/esm/planCache.mjs.map +1 -0
  44. package/dist/esm/session.mjs +99 -0
  45. package/dist/esm/session.mjs.map +1 -0
  46. package/dist/esm/yuku.mjs +136 -0
  47. package/dist/esm/yuku.mjs.map +1 -0
  48. package/dist/esm/zero.mjs +352 -0
  49. package/dist/esm/zero.mjs.map +1 -0
  50. package/package.json +42 -4
  51. package/src/ast.ts +86 -0
  52. package/src/contracts.ts +148 -0
  53. package/src/diagnostics.ts +96 -0
  54. package/src/evaluate.ts +497 -0
  55. package/src/graph.ts +347 -0
  56. package/src/hash.ts +36 -0
  57. package/src/index.ts +15 -0
  58. package/src/ir.ts +154 -0
  59. package/src/lower.ts +418 -0
  60. package/src/materialize.ts +330 -0
  61. package/src/normalize.ts +846 -0
  62. package/src/output.ts +175 -0
  63. package/src/planCache.ts +327 -0
  64. package/src/session.ts +172 -0
  65. package/src/yuku.ts +189 -0
  66. package/src/zero.ts +598 -0
  67. package/types/ast.d.ts +10 -0
  68. package/types/ast.d.ts.map +1 -0
  69. package/types/contracts.d.ts +97 -0
  70. package/types/contracts.d.ts.map +1 -0
  71. package/types/diagnostics.d.ts +31 -0
  72. package/types/diagnostics.d.ts.map +1 -0
  73. package/types/evaluate.d.ts +36 -0
  74. package/types/evaluate.d.ts.map +1 -0
  75. package/types/graph.d.ts +37 -0
  76. package/types/graph.d.ts.map +1 -0
  77. package/types/hash.d.ts +8 -0
  78. package/types/hash.d.ts.map +1 -0
  79. package/types/index.d.ts +16 -0
  80. package/types/index.d.ts.map +1 -0
  81. package/types/ir.d.ts +118 -0
  82. package/types/ir.d.ts.map +1 -0
  83. package/types/lower.d.ts +99 -0
  84. package/types/lower.d.ts.map +1 -0
  85. package/types/materialize.d.ts +104 -0
  86. package/types/materialize.d.ts.map +1 -0
  87. package/types/normalize.d.ts +8 -0
  88. package/types/normalize.d.ts.map +1 -0
  89. package/types/output.d.ts +32 -0
  90. package/types/output.d.ts.map +1 -0
  91. package/types/planCache.d.ts +113 -0
  92. package/types/planCache.d.ts.map +1 -0
  93. package/types/session.d.ts +44 -0
  94. package/types/session.d.ts.map +1 -0
  95. package/types/yuku.d.ts +4 -0
  96. package/types/yuku.d.ts.map +1 -0
  97. package/types/zero.d.ts +98 -0
  98. package/types/zero.d.ts.map +1 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Nate Wienert
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1 +1,57 @@
1
- # @tamagui/compiler-core
1
+ # `@tamagui/compiler-core`
2
+
3
+ `CompilerSession` is Tamagui's bundler-neutral compiler API. It owns parsing,
4
+ the module graph, invalidation, lowering, and source-map-aware output. The host
5
+ owns resolution and loading.
6
+
7
+ ```ts
8
+ import {
9
+ CompilerSession,
10
+ resolvedModuleId,
11
+ type CompilerAdapter,
12
+ type HostModuleInput,
13
+ } from '@tamagui/compiler-core'
14
+
15
+ const session = new CompilerSession()
16
+ const entry: HostModuleInput = {
17
+ id: resolvedModuleId('/app/Button.tsx'),
18
+ source: buttonSource,
19
+ imports: [
20
+ {
21
+ specifier: './tokens',
22
+ resolvedId: resolvedModuleId('/app/tokens.ts'),
23
+ },
24
+ ],
25
+ }
26
+
27
+ const adapter: CompilerAdapter = {
28
+ target: 'web',
29
+ projectGeneration: configHash,
30
+ host: createYourLoweringHost(),
31
+ async load(id) {
32
+ return modules.get(id) ?? null
33
+ },
34
+ }
35
+
36
+ const result = await session.compile({ module: entry, adapter })
37
+ ```
38
+
39
+ Every `HostModuleInput` must contain a canonical id and every import must
40
+ already be resolved by the host. Mark package or runtime boundaries with
41
+ `external: true`. Call `update()` or `remove()` on watch changes and use the
42
+ returned ids to invalidate the host's module graph. Change
43
+ `projectGeneration` whenever Tamagui config or component metadata changes.
44
+
45
+ Adapters should pass the output source map back to their bundler and watch the
46
+ dependencies they loaded. Native adapters must reject CSS output rather than
47
+ silently dropping it.
48
+
49
+ The maintained adapters are:
50
+
51
+ - `@tamagui/vite-plugin` for Vite web and One's iOS/Android Rolldown pipeline
52
+ through its Vite config provider API
53
+ - `@tamagui/metro-plugin` for Metro's main-process graph and worker cache
54
+ - `tamagui build` for explicit precompilation, including Next.js Turbopack
55
+
56
+ The legacy `@tamagui/next-plugin` and `tamagui-loader` packages only support
57
+ webpack and are outside the v3 compiler path.
@@ -0,0 +1,95 @@
1
+
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all) __defProp(target, name, {
8
+ get: all[name],
9
+ enumerable: true
10
+ });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
15
+ get: () => from[key],
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ }
19
+ return to;
20
+ };
21
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
+ var ast_exports = {};
23
+ __export(ast_exports, {
24
+ childNode: () => childNode,
25
+ childNodes: () => childNodes,
26
+ findAstNode: () => findAstNode,
27
+ identifierName: () => identifierName,
28
+ isAstNode: () => isAstNode,
29
+ literalValue: () => literalValue,
30
+ unwrapExpression: () => unwrapExpression,
31
+ walkAst: () => walkAst
32
+ });
33
+ module.exports = __toCommonJS(ast_exports);
34
+ const ignoredKeys = /* @__PURE__ */ new Set([
35
+ "loc",
36
+ "range",
37
+ "parent",
38
+ "comments",
39
+ "tokens"
40
+ ]);
41
+ function isAstNode(value) {
42
+ return typeof value === "object" && value !== null && typeof value.type === "string" && typeof value.start === "number" && typeof value.end === "number";
43
+ }
44
+ function walkAst(node, visitor, parent = null, key = null) {
45
+ visitor(node, parent, key);
46
+ for (const [childKey, value] of Object.entries(node)) {
47
+ if (ignoredKeys.has(childKey)) continue;
48
+ if (isAstNode(value)) {
49
+ walkAst(value, visitor, node, childKey);
50
+ } else if (Array.isArray(value)) {
51
+ for (const child of value) {
52
+ if (isAstNode(child)) {
53
+ walkAst(child, visitor, node, childKey);
54
+ }
55
+ }
56
+ }
57
+ }
58
+ }
59
+ function findAstNode(root, predicate) {
60
+ let found = null;
61
+ walkAst(root, (node, parent, key) => {
62
+ if (!found && predicate(node, parent, key)) {
63
+ found = node;
64
+ }
65
+ });
66
+ return found;
67
+ }
68
+ function childNode(node, key) {
69
+ const value = node[key];
70
+ return isAstNode(value) ? value : null;
71
+ }
72
+ function childNodes(node, key) {
73
+ const value = node[key];
74
+ return Array.isArray(value) ? value.filter(isAstNode) : [];
75
+ }
76
+ function identifierName(node) {
77
+ if (!node || node.type !== "Identifier" && node.type !== "JSXIdentifier") return null;
78
+ return typeof node.name === "string" ? node.name : null;
79
+ }
80
+ function literalValue(node) {
81
+ if (!node) return void 0;
82
+ if (node.type === "Literal" || node.type.endsWith("Literal")) {
83
+ return node.value;
84
+ }
85
+ return void 0;
86
+ }
87
+ function unwrapExpression(node) {
88
+ let current = node;
89
+ while (current.type === "TSAsExpression" || current.type === "TSSatisfiesExpression" || current.type === "TSNonNullExpression" || current.type === "ParenthesizedExpression") {
90
+ const expression = childNode(current, "expression");
91
+ if (!expression) break;
92
+ current = expression;
93
+ }
94
+ return current;
95
+ }
@@ -0,0 +1,62 @@
1
+
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all) __defProp(target, name, {
8
+ get: all[name],
9
+ enumerable: true
10
+ });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
15
+ get: () => from[key],
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ }
19
+ return to;
20
+ };
21
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
+ var contracts_exports = {};
23
+ __export(contracts_exports, {
24
+ expressionReference: () => expressionReference,
25
+ resolutionKey: () => resolutionKey,
26
+ resolveFromHost: () => resolveFromHost,
27
+ resolvedModuleId: () => resolvedModuleId,
28
+ spanOf: () => spanOf,
29
+ textOfSpan: () => textOfSpan
30
+ });
31
+ module.exports = __toCommonJS(contracts_exports);
32
+ function resolutionKey(importer, specifier) {
33
+ return `${importer}\0${specifier}`;
34
+ }
35
+ function resolveFromHost(resolutions, specifier, importer) {
36
+ return resolutions.get(resolutionKey(importer, specifier)) ?? null;
37
+ }
38
+ function resolvedModuleId(id) {
39
+ const isAbsolute = id.startsWith("/") || id.startsWith("\\") || id.startsWith("\0") || /^[A-Za-z]:[\\/]/.test(id) || /^[A-Za-z][A-Za-z\d+.-]*:\/\//.test(id);
40
+ if (!isAbsolute) {
41
+ throw new Error(`Host module id must be canonical and already resolved: ${id}`);
42
+ }
43
+ return id;
44
+ }
45
+ function expressionReference(id, node) {
46
+ return {
47
+ kind: "expression",
48
+ id,
49
+ start: node.start,
50
+ end: node.end
51
+ };
52
+ }
53
+ function spanOf(id, node) {
54
+ return {
55
+ id,
56
+ start: node.start,
57
+ end: node.end
58
+ };
59
+ }
60
+ function textOfSpan(source, span) {
61
+ return source.slice(span.start, span.end);
62
+ }
@@ -0,0 +1,69 @@
1
+
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all) __defProp(target, name, {
8
+ get: all[name],
9
+ enumerable: true
10
+ });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
15
+ get: () => from[key],
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ }
19
+ return to;
20
+ };
21
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
+ var diagnostics_exports = {};
23
+ __export(diagnostics_exports, {
24
+ linkedBailout: () => linkedBailout,
25
+ localBailout: () => localBailout,
26
+ zeroRuleForBailout: () => zeroRuleForBailout
27
+ });
28
+ module.exports = __toCommonJS(diagnostics_exports);
29
+ const ZERO_RULE_BY_CODE = {
30
+ "local/invalid-element-call": 2,
31
+ "local/unsupported-element-name": 2,
32
+ "local/unsupported-prop-key": 3,
33
+ "local/unsupported-child": 3,
34
+ "local/unsupported-expression": 3,
35
+ "local/unsupported-styled-definition": 3,
36
+ "local/dynamic-style-value": 3,
37
+ "local/unsafe-style-spread": 1,
38
+ "local/unsupported-target": 6,
39
+ "local/style-resolution-failed": 3,
40
+ "local/overlapping-edit": 6,
41
+ "local/non-object-spread": 1,
42
+ "local/static-evaluation-cycle": 3,
43
+ "local/parse-error": 3,
44
+ "linked/unresolved-component-binding": 2,
45
+ "linked/unresolved-binding": 2,
46
+ "linked/missing-initializer": 3,
47
+ "linked/unresolved-import": 2,
48
+ "linked/unresolved-component-config": 2
49
+ };
50
+ function zeroRuleForBailout(reason) {
51
+ return reason.zeroRule ?? ZERO_RULE_BY_CODE[reason.code];
52
+ }
53
+ function localBailout(code, span, message) {
54
+ return {
55
+ code,
56
+ kind: "local",
57
+ message,
58
+ span
59
+ };
60
+ }
61
+ function linkedBailout(code, span, message, dependencyId) {
62
+ return {
63
+ code,
64
+ kind: "linked",
65
+ message,
66
+ span,
67
+ dependencyId
68
+ };
69
+ }
@@ -0,0 +1,351 @@
1
+
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all) __defProp(target, name, {
8
+ get: all[name],
9
+ enumerable: true
10
+ });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
15
+ get: () => from[key],
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ }
19
+ return to;
20
+ };
21
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
+ var evaluate_exports = {};
23
+ __export(evaluate_exports, {
24
+ evaluateBinding: () => evaluateBinding,
25
+ evaluateConditionalExpression: () => evaluateConditionalExpression,
26
+ evaluateExpression: () => evaluateExpression
27
+ });
28
+ module.exports = __toCommonJS(evaluate_exports);
29
+ var import_ast = require("./ast.cjs");
30
+ var import_contracts = require("./contracts.cjs");
31
+ var import_diagnostics = require("./diagnostics.cjs");
32
+ function success(value) {
33
+ return {
34
+ ok: true,
35
+ value
36
+ };
37
+ }
38
+ function literal(node) {
39
+ if (node.type === "NullLiteral") return null;
40
+ if (node.type === "Literal" || node.type.endsWith("Literal")) {
41
+ const value = node.value;
42
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value === null) {
43
+ return value;
44
+ }
45
+ }
46
+ return void 0;
47
+ }
48
+ function unsupported(id, node, detail = `Expression ${node.type} is not statically supported`) {
49
+ return {
50
+ ok: false,
51
+ bailout: (0, import_diagnostics.localBailout)("local/unsupported-expression", (0, import_contracts.spanOf)(id, node), detail)
52
+ };
53
+ }
54
+ function evaluateDefinition(resolver, definition, useSpan, state) {
55
+ const key = `${definition.id}:${definition.span.start}`;
56
+ if (state.activeDefinitions.has(key)) {
57
+ return {
58
+ ok: false,
59
+ bailout: (0, import_diagnostics.localBailout)("local/static-evaluation-cycle", useSpan, `Static evaluation cycle reached ${definition.name}`)
60
+ };
61
+ }
62
+ if (!definition.initializer) {
63
+ return {
64
+ ok: false,
65
+ bailout: (0, import_diagnostics.linkedBailout)("linked/missing-initializer", useSpan, `Binding ${definition.name} has no static initializer`, definition.id)
66
+ };
67
+ }
68
+ if (!definition.constant) {
69
+ return {
70
+ ok: false,
71
+ bailout: (0, import_diagnostics.linkedBailout)("linked/unresolved-binding", useSpan, `Binding ${definition.name} is mutable and cannot be statically evaluated`, definition.id)
72
+ };
73
+ }
74
+ const initializer = resolver.expressionNode(definition.initializer);
75
+ if (!initializer) {
76
+ return {
77
+ ok: false,
78
+ bailout: (0, import_diagnostics.linkedBailout)("linked/missing-initializer", useSpan, `Binding ${definition.name} initializer is outside the linked graph`, definition.id)
79
+ };
80
+ }
81
+ state.dependencies.add(definition.id);
82
+ state.activeDefinitions.add(key);
83
+ try {
84
+ return evaluateNode(resolver, definition.id, initializer, state);
85
+ } finally {
86
+ state.activeDefinitions.delete(key);
87
+ }
88
+ }
89
+ function evaluateObject(resolver, id, node, state) {
90
+ const output = {};
91
+ for (const property of (0, import_ast.childNodes)(node, "properties")) {
92
+ if (property.type === "SpreadElement") {
93
+ const argument = (0, import_ast.childNode)(property, "argument");
94
+ if (!argument) return unsupported(id, property);
95
+ const spread = evaluateNode(resolver, id, argument, state);
96
+ if (!spread.ok) return spread;
97
+ if (!spread.value || typeof spread.value !== "object" || Array.isArray(spread.value)) {
98
+ return {
99
+ ok: false,
100
+ bailout: (0, import_diagnostics.localBailout)("local/non-object-spread", (0, import_contracts.spanOf)(id, property), "Static object spread did not evaluate to an object")
101
+ };
102
+ }
103
+ Object.assign(output, spread.value);
104
+ continue;
105
+ }
106
+ if (property.type !== "Property" && property.type !== "ObjectProperty") {
107
+ return unsupported(id, property);
108
+ }
109
+ const keyNode = (0, import_ast.childNode)(property, "key");
110
+ const valueNode = (0, import_ast.childNode)(property, "value");
111
+ if (!keyNode || !valueNode) return unsupported(id, property);
112
+ let key = (0, import_ast.identifierName)(keyNode) ?? void 0;
113
+ if (property.computed === true || key === void 0) {
114
+ const evaluatedKey = evaluateNode(resolver, id, keyNode, state);
115
+ if (!evaluatedKey.ok) return evaluatedKey;
116
+ key = evaluatedKey.value;
117
+ }
118
+ if (typeof key !== "string" && typeof key !== "number") {
119
+ return unsupported(id, keyNode, "Static object key is not a string or number");
120
+ }
121
+ const value = evaluateNode(resolver, id, valueNode, state);
122
+ if (!value.ok) return value;
123
+ output[String(key)] = value.value;
124
+ }
125
+ return success(output);
126
+ }
127
+ function evaluateArray(resolver, id, node, state) {
128
+ const output = [];
129
+ const rawElements = node.elements;
130
+ if (!Array.isArray(rawElements) || rawElements.some((element) => element === null || !(0, import_ast.isAstNode)(element))) {
131
+ return unsupported(id, node, "Sparse arrays are not statically supported");
132
+ }
133
+ for (const element of rawElements.filter(import_ast.isAstNode)) {
134
+ if (element.type === "SpreadElement") {
135
+ const argument = (0, import_ast.childNode)(element, "argument");
136
+ if (!argument) return unsupported(id, element);
137
+ const spread = evaluateNode(resolver, id, argument, state);
138
+ if (!spread.ok) return spread;
139
+ if (!Array.isArray(spread.value)) {
140
+ return unsupported(id, element, "Static array spread did not evaluate to an array");
141
+ }
142
+ output.push(...spread.value);
143
+ continue;
144
+ }
145
+ const value = evaluateNode(resolver, id, element, state);
146
+ if (!value.ok) return value;
147
+ output.push(value.value);
148
+ }
149
+ return success(output);
150
+ }
151
+ function evaluateNode(resolver, id, input, state) {
152
+ const node = (0, import_ast.unwrapExpression)(input);
153
+ const literalValue = literal(node);
154
+ if (literalValue !== void 0) return success(literalValue);
155
+ switch (node.type) {
156
+ case "Identifier": {
157
+ const name = (0, import_ast.identifierName)(node);
158
+ if (!name) return unsupported(id, node);
159
+ const definition = resolver.resolveBinding(id, name);
160
+ if (!definition) {
161
+ return {
162
+ ok: false,
163
+ bailout: (0, import_diagnostics.linkedBailout)("linked/unresolved-binding", (0, import_contracts.spanOf)(id, node), `Binding ${name} has no host-linked definition`)
164
+ };
165
+ }
166
+ return evaluateDefinition(resolver, definition, (0, import_contracts.spanOf)(id, node), state);
167
+ }
168
+ case "ObjectExpression": return evaluateObject(resolver, id, node, state);
169
+ case "ArrayExpression": return evaluateArray(resolver, id, node, state);
170
+ case "MemberExpression": {
171
+ const objectNode = (0, import_ast.childNode)(node, "object");
172
+ const propertyNode = (0, import_ast.childNode)(node, "property");
173
+ if (!objectNode || !propertyNode) return unsupported(id, node);
174
+ const object = evaluateNode(resolver, id, objectNode, state);
175
+ if (!object.ok) return object;
176
+ let property = (0, import_ast.identifierName)(propertyNode);
177
+ if (node.computed === true || property === null) {
178
+ const evaluatedProperty = evaluateNode(resolver, id, propertyNode, state);
179
+ if (!evaluatedProperty.ok) return evaluatedProperty;
180
+ property = evaluatedProperty.value;
181
+ }
182
+ if ((typeof object.value !== "object" || object.value === null) && typeof object.value !== "string") {
183
+ return unsupported(id, node, "Static member target is not indexable");
184
+ }
185
+ if (typeof property !== "string" && typeof property !== "number") {
186
+ return unsupported(id, propertyNode, "Static member key is not a string or number");
187
+ }
188
+ const value = object.value[String(property)];
189
+ return value === void 0 ? unsupported(id, node, `Static member ${String(property)} does not exist`) : success(value);
190
+ }
191
+ case "UnaryExpression": {
192
+ const argument = (0, import_ast.childNode)(node, "argument");
193
+ if (!argument) return unsupported(id, node);
194
+ const value = evaluateNode(resolver, id, argument, state);
195
+ if (!value.ok) return value;
196
+ if (node.operator === "-" && typeof value.value === "number") {
197
+ return success(-value.value);
198
+ }
199
+ if (node.operator === "+" && typeof value.value === "number") {
200
+ return success(value.value);
201
+ }
202
+ if (node.operator === "!") return success(!value.value);
203
+ return unsupported(id, node, `Unary operator ${String(node.operator)} is unsupported`);
204
+ }
205
+ case "BinaryExpression":
206
+ case "LogicalExpression": {
207
+ const leftNode = (0, import_ast.childNode)(node, "left");
208
+ const rightNode = (0, import_ast.childNode)(node, "right");
209
+ if (!leftNode || !rightNode) return unsupported(id, node);
210
+ const left = evaluateNode(resolver, id, leftNode, state);
211
+ if (!left.ok) return left;
212
+ if (node.type === "LogicalExpression") {
213
+ if (node.operator === "&&" && !left.value) return left;
214
+ if (node.operator === "||" && left.value) return left;
215
+ if (node.operator === "??" && left.value !== null) return left;
216
+ }
217
+ const right = evaluateNode(resolver, id, rightNode, state);
218
+ if (!right.ok) return right;
219
+ switch (node.operator) {
220
+ case "+":
221
+ if (typeof left.value === "number" && typeof right.value === "number") {
222
+ return success(left.value + right.value);
223
+ }
224
+ if (typeof left.value === "string" || typeof right.value === "string") {
225
+ return success(String(left.value) + String(right.value));
226
+ }
227
+ break;
228
+ case "-":
229
+ if (typeof left.value === "number" && typeof right.value === "number") {
230
+ return success(left.value - right.value);
231
+ }
232
+ break;
233
+ case "*":
234
+ if (typeof left.value === "number" && typeof right.value === "number") {
235
+ return success(left.value * right.value);
236
+ }
237
+ break;
238
+ case "/":
239
+ if (typeof left.value === "number" && typeof right.value === "number") {
240
+ return success(left.value / right.value);
241
+ }
242
+ break;
243
+ case "&&":
244
+ case "||":
245
+ case "??": return right;
246
+ }
247
+ return unsupported(id, node, `Binary operator ${String(node.operator)} is unsupported`);
248
+ }
249
+ case "ConditionalExpression": {
250
+ const testNode = (0, import_ast.childNode)(node, "test");
251
+ const consequent = (0, import_ast.childNode)(node, "consequent");
252
+ const alternate = (0, import_ast.childNode)(node, "alternate");
253
+ if (!testNode || !consequent || !alternate) return unsupported(id, node);
254
+ const test = evaluateNode(resolver, id, testNode, state);
255
+ if (!test.ok) return test;
256
+ return evaluateNode(resolver, id, test.value ? consequent : alternate, state);
257
+ }
258
+ case "TemplateLiteral": {
259
+ const quasis = (0, import_ast.childNodes)(node, "quasis");
260
+ const expressions = (0, import_ast.childNodes)(node, "expressions");
261
+ let output = "";
262
+ for (let index = 0; index < quasis.length; index++) {
263
+ const quasi = quasis[index];
264
+ const cooked = quasi?.value?.cooked;
265
+ const raw = quasi?.value?.raw;
266
+ output += typeof cooked === "string" ? cooked : typeof raw === "string" ? raw : "";
267
+ const expression = expressions[index];
268
+ if (expression) {
269
+ const value = evaluateNode(resolver, id, expression, state);
270
+ if (!value.ok) return value;
271
+ output += String(value.value);
272
+ }
273
+ }
274
+ return success(output);
275
+ }
276
+ default: return unsupported(id, node);
277
+ }
278
+ }
279
+ function evaluateConditionalExpression(resolver, reference) {
280
+ const node = resolver.expressionNode(reference);
281
+ if (!node) return null;
282
+ const expression = (0, import_ast.unwrapExpression)(node);
283
+ if (!(0, import_ast.isAstNode)(expression) || expression.type !== "ConditionalExpression") return null;
284
+ const testNode = (0, import_ast.childNode)(expression, "test");
285
+ const consequent = (0, import_ast.childNode)(expression, "consequent");
286
+ const alternate = (0, import_ast.childNode)(expression, "alternate");
287
+ if (!testNode || !consequent || !alternate) return null;
288
+ const trueState = {
289
+ activeDefinitions: /* @__PURE__ */ new Set(),
290
+ dependencies: /* @__PURE__ */ new Set()
291
+ };
292
+ const whenTrue = evaluateNode(resolver, reference.id, consequent, trueState);
293
+ if (!whenTrue.ok) return null;
294
+ const falseState = {
295
+ activeDefinitions: /* @__PURE__ */ new Set(),
296
+ dependencies: /* @__PURE__ */ new Set()
297
+ };
298
+ const whenFalse = evaluateNode(resolver, reference.id, alternate, falseState);
299
+ if (!whenFalse.ok) return null;
300
+ return {
301
+ test: (0, import_contracts.spanOf)(reference.id, testNode),
302
+ whenTrue: {
303
+ value: whenTrue.value,
304
+ dependencies: [...trueState.dependencies].sort()
305
+ },
306
+ whenFalse: {
307
+ value: whenFalse.value,
308
+ dependencies: [...falseState.dependencies].sort()
309
+ }
310
+ };
311
+ }
312
+ function evaluateExpression(resolver, reference) {
313
+ const node = resolver.expressionNode(reference);
314
+ if (!node) {
315
+ return {
316
+ ok: false,
317
+ bailout: (0, import_diagnostics.linkedBailout)("linked/missing-initializer", reference, "Expression is outside the linked project graph", reference.id)
318
+ };
319
+ }
320
+ const state = {
321
+ activeDefinitions: /* @__PURE__ */ new Set(),
322
+ dependencies: /* @__PURE__ */ new Set()
323
+ };
324
+ const result = evaluateNode(resolver, reference.id, node, state);
325
+ return result.ok ? {
326
+ ok: true,
327
+ value: result.value,
328
+ dependencies: [...state.dependencies].sort()
329
+ } : result;
330
+ }
331
+ function evaluateBinding(resolver, id, localName) {
332
+ const definition = resolver.resolveBinding(id, localName);
333
+ if (!definition) {
334
+ const emptySpan = {
335
+ id,
336
+ start: 0,
337
+ end: 0
338
+ };
339
+ return {
340
+ ok: false,
341
+ bailout: (0, import_diagnostics.linkedBailout)("linked/unresolved-binding", emptySpan, `Binding ${localName} has no host-linked definition`)
342
+ };
343
+ }
344
+ if (!definition.initializer) {
345
+ return {
346
+ ok: false,
347
+ bailout: (0, import_diagnostics.linkedBailout)("linked/missing-initializer", definition.span, `Binding ${localName} has no static initializer`, definition.id)
348
+ };
349
+ }
350
+ return evaluateExpression(resolver, (0, import_contracts.expressionReference)(definition.id, definition.initializer));
351
+ }