@tamagui/compiler-core 0.0.0-bootstrap.0 → 3.0.0-beta.643.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
@@ -0,0 +1,279 @@
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 graph_exports = {};
23
+ __export(graph_exports, {
24
+ ProjectGraph: () => ProjectGraph,
25
+ moduleContentHash: () => moduleContentHash
26
+ });
27
+ module.exports = __toCommonJS(graph_exports);
28
+ var import_node_crypto = require("node:crypto");
29
+ var import_contracts = require("./contracts.cjs");
30
+ var import_diagnostics = require("./diagnostics.cjs");
31
+ var import_evaluate = require("./evaluate.cjs");
32
+ var import_normalize = require("./normalize.cjs");
33
+ function compareIds(left, right) {
34
+ return compareCodeUnits(left, right);
35
+ }
36
+ function compareCodeUnits(left, right) {
37
+ return left < right ? -1 : left > right ? 1 : 0;
38
+ }
39
+ function stableImports(imports) {
40
+ return [...imports].sort((left, right) => {
41
+ const bySpecifier = compareCodeUnits(left.specifier, right.specifier);
42
+ return bySpecifier || compareCodeUnits(left.resolvedId, right.resolvedId);
43
+ });
44
+ }
45
+ function moduleContentHash(input) {
46
+ const hash = (0, import_node_crypto.createHash)("sha256");
47
+ hash.update(input.source);
48
+ hash.update("\0");
49
+ for (const dependency of stableImports(input.imports)) {
50
+ hash.update(dependency.specifier);
51
+ hash.update("\0");
52
+ hash.update(dependency.resolvedId);
53
+ hash.update("\0");
54
+ hash.update(dependency.external ? "external" : "internal");
55
+ hash.update("\0");
56
+ }
57
+ return hash.digest("hex");
58
+ }
59
+ var ProjectGraph = class {
60
+ #files = /* @__PURE__ */ new Map();
61
+ #resolutions = /* @__PURE__ */ new Map();
62
+ #modules = /* @__PURE__ */ new Map();
63
+ #dependencies = /* @__PURE__ */ new Map();
64
+ #dependents = /* @__PURE__ */ new Map();
65
+ #elementCache = /* @__PURE__ */ new Map();
66
+ #candidate;
67
+ constructor(factory, project) {
68
+ for (const input of project.modules) this.#installHostRecord(input);
69
+ const candidateProject = {
70
+ files: this.#files,
71
+ resolutions: this.#resolutions
72
+ };
73
+ this.#candidate = factory.create(candidateProject);
74
+ this.#candidate.link();
75
+ }
76
+ moduleIds() {
77
+ return [...this.#modules.keys()].sort(compareIds);
78
+ }
79
+ contentHash(id) {
80
+ return this.#modules.get(id)?.hash ?? null;
81
+ }
82
+ sourceOf(id) {
83
+ const source = this.#modules.get(id)?.input.source;
84
+ if (source === void 0) throw new Error(`Unknown host module ${id}`);
85
+ return source;
86
+ }
87
+ dependenciesOf(id) {
88
+ return [...this.#dependencies.get(id) ?? []].sort(compareIds);
89
+ }
90
+ dependentsOf(id) {
91
+ return [...this.#dependents.get(id) ?? []].sort(compareIds);
92
+ }
93
+ affectedBy(id) {
94
+ const affected = /* @__PURE__ */ new Set([id]);
95
+ const queue = [id];
96
+ while (queue.length) {
97
+ const current = queue.shift();
98
+ for (const dependent of this.#dependents.get(current) ?? []) {
99
+ if (affected.has(dependent)) continue;
100
+ affected.add(dependent);
101
+ queue.push(dependent);
102
+ }
103
+ }
104
+ return [...affected].sort(compareIds);
105
+ }
106
+ parseCount(id) {
107
+ return this.#candidate.parseCount(id);
108
+ }
109
+ resolveBinding(id, localName) {
110
+ const definition = this.#candidate.definitionOf(id, localName);
111
+ if (!definition) return null;
112
+ return {
113
+ id: definition.id,
114
+ name: definition.name,
115
+ span: {
116
+ id: definition.id,
117
+ start: definition.start,
118
+ end: definition.end
119
+ },
120
+ initializer: definition.initializer ? (0, import_contracts.expressionReference)(definition.id, definition.initializer) : null,
121
+ constant: definition.constant
122
+ };
123
+ }
124
+ expressionNode(reference) {
125
+ if (!this.#modules.has(reference.id)) return null;
126
+ return (0, import_normalize.nodeAtSpan)(this.#candidate.programOf(reference.id), reference.start, reference.end);
127
+ }
128
+ evaluate(reference) {
129
+ return (0, import_evaluate.evaluateExpression)(this, reference);
130
+ }
131
+ evaluateConditional(reference) {
132
+ return (0, import_evaluate.evaluateConditionalExpression)(this, reference);
133
+ }
134
+ evaluateBinding(id, localName) {
135
+ return (0, import_evaluate.evaluateBinding)(this, id, localName);
136
+ }
137
+ elementsOf(id) {
138
+ const record = this.#modules.get(id);
139
+ if (!record) throw new Error(`Unknown host module ${id}`);
140
+ const cached = this.#elementCache.get(id);
141
+ if (cached?.hash === record.hash) return cached.result;
142
+ const result = (0, import_normalize.normalizeElements)(this.#candidate, id, record.input.imports);
143
+ this.#elementCache.set(id, {
144
+ hash: record.hash,
145
+ result
146
+ });
147
+ return result;
148
+ }
149
+ diagnostics() {
150
+ const diagnostics = this.#candidate.diagnostics().map((diagnostic) => diagnostic.kind === "parse" ? (0, import_diagnostics.localBailout)("local/parse-error", {
151
+ id: diagnostic.id,
152
+ start: 0,
153
+ end: 0
154
+ }, diagnostic.message) : (0, import_diagnostics.linkedBailout)("linked/unresolved-binding", {
155
+ id: diagnostic.id,
156
+ start: 0,
157
+ end: 0
158
+ }, diagnostic.message));
159
+ for (const [id, record] of this.#modules) {
160
+ for (const dependency of record.input.imports) {
161
+ if (dependency.external) continue;
162
+ if (this.#modules.has(dependency.resolvedId)) continue;
163
+ diagnostics.push((0, import_diagnostics.linkedBailout)("linked/unresolved-import", {
164
+ id,
165
+ start: 0,
166
+ end: 0
167
+ }, `Host-resolved import ${dependency.specifier} points outside the project graph`, dependency.resolvedId));
168
+ }
169
+ }
170
+ return diagnostics.sort((left, right) => {
171
+ const byId = compareCodeUnits(left.span.id, right.span.id);
172
+ return byId || left.span.start - right.span.start || compareCodeUnits(left.code, right.code);
173
+ });
174
+ }
175
+ updateModule(input) {
176
+ const previous = this.#modules.get(input.id);
177
+ const nextHash = moduleContentHash(input);
178
+ if (previous?.hash === nextHash) {
179
+ return {
180
+ changed: false,
181
+ id: input.id,
182
+ previousHash: previous.hash,
183
+ contentHash: previous.hash,
184
+ invalidatedIds: []
185
+ };
186
+ }
187
+ const invalidatedIds = this.affectedBy(input.id);
188
+ const previousHash = previous?.hash ?? null;
189
+ if (previous) this.#candidate.removeFile(input.id);
190
+ this.#installHostRecord(input);
191
+ this.#candidate.addFile(input.id, input.source);
192
+ this.#candidate.link();
193
+ for (const id of invalidatedIds) this.#elementCache.delete(id);
194
+ return {
195
+ changed: true,
196
+ id: input.id,
197
+ previousHash,
198
+ contentHash: nextHash,
199
+ invalidatedIds
200
+ };
201
+ }
202
+ removeModule(id) {
203
+ const previous = this.#modules.get(id);
204
+ if (!previous) {
205
+ return {
206
+ changed: false,
207
+ id,
208
+ previousHash: null,
209
+ contentHash: null,
210
+ invalidatedIds: []
211
+ };
212
+ }
213
+ const invalidatedIds = this.affectedBy(id);
214
+ this.#candidate.removeFile(id);
215
+ this.#removeOutgoingEdges(id);
216
+ this.#removeResolutions(id);
217
+ this.#modules.delete(id);
218
+ this.#files.delete(id);
219
+ this.#candidate.link();
220
+ for (const invalidated of invalidatedIds) this.#elementCache.delete(invalidated);
221
+ return {
222
+ changed: true,
223
+ id,
224
+ previousHash: previous.hash,
225
+ contentHash: null,
226
+ invalidatedIds
227
+ };
228
+ }
229
+ #installHostRecord(input) {
230
+ (0, import_contracts.resolvedModuleId)(input.id);
231
+ const seenSpecifiers = /* @__PURE__ */ new Set();
232
+ for (const dependency of input.imports) {
233
+ (0, import_contracts.resolvedModuleId)(dependency.resolvedId);
234
+ if (seenSpecifiers.has(dependency.specifier)) {
235
+ throw new Error(`Duplicate host resolution for ${input.id}:${dependency.specifier}`);
236
+ }
237
+ seenSpecifiers.add(dependency.specifier);
238
+ }
239
+ this.#removeOutgoingEdges(input.id);
240
+ this.#removeResolutions(input.id);
241
+ const dependencies = new Set(input.imports.filter(({ external }) => !external).map(({ resolvedId }) => resolvedId));
242
+ this.#dependencies.set(input.id, dependencies);
243
+ for (const dependency of dependencies) {
244
+ let reverse = this.#dependents.get(dependency);
245
+ if (!reverse) {
246
+ reverse = /* @__PURE__ */ new Set();
247
+ this.#dependents.set(dependency, reverse);
248
+ }
249
+ reverse.add(input.id);
250
+ }
251
+ for (const dependency of input.imports) {
252
+ if (dependency.external) continue;
253
+ this.#resolutions.set((0, import_contracts.resolutionKey)(input.id, dependency.specifier), dependency.resolvedId);
254
+ }
255
+ const installedInput = {
256
+ ...input,
257
+ imports: input.imports.map((dependency) => ({ ...dependency }))
258
+ };
259
+ this.#files.set(installedInput.id, installedInput.source);
260
+ this.#modules.set(installedInput.id, {
261
+ input: installedInput,
262
+ hash: moduleContentHash(installedInput)
263
+ });
264
+ }
265
+ #removeOutgoingEdges(id) {
266
+ for (const dependency of this.#dependencies.get(id) ?? []) {
267
+ const reverse = this.#dependents.get(dependency);
268
+ reverse?.delete(id);
269
+ if (reverse?.size === 0) this.#dependents.delete(dependency);
270
+ }
271
+ this.#dependencies.delete(id);
272
+ }
273
+ #removeResolutions(id) {
274
+ const prefix = `${id}\0`;
275
+ for (const key of this.#resolutions.keys()) {
276
+ if (key.startsWith(prefix)) this.#resolutions.delete(key);
277
+ }
278
+ }
279
+ };
@@ -0,0 +1,49 @@
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 hash_exports = {};
23
+ __export(hash_exports, {
24
+ contentHash: () => contentHash,
25
+ stableStringify: () => stableStringify
26
+ });
27
+ module.exports = __toCommonJS(hash_exports);
28
+ var import_node_crypto = require("node:crypto");
29
+ function contentHash(value) {
30
+ return (0, import_node_crypto.createHash)("sha256").update(value).digest("hex");
31
+ }
32
+ function compareCodeUnits(left, right) {
33
+ return left < right ? -1 : left > right ? 1 : 0;
34
+ }
35
+ function stringify(value) {
36
+ if (Array.isArray(value)) {
37
+ return `[${value.map((child) => stringify(child) ?? "null").join(",")}]`;
38
+ }
39
+ if (value && typeof value === "object") {
40
+ const entries = Object.entries(value).sort(([left], [right]) => compareCodeUnits(left, right)).map(([key, child]) => [key, stringify(child)]).filter((entry) => entry[1] !== void 0);
41
+ return `{${entries.map(([key, child]) => `${JSON.stringify(key)}:${child}`).join(",")}}`;
42
+ }
43
+ return JSON.stringify(value);
44
+ }
45
+ function stableStringify(value) {
46
+ const serialized = stringify(value);
47
+ if (serialized === void 0) throw new Error("Cannot serialize undefined cache root");
48
+ return serialized;
49
+ }
@@ -0,0 +1,44 @@
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
22
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
+ var index_exports = {};
24
+ __export(index_exports, {
25
+ normalizeElements: () => import_normalize.normalizeElements,
26
+ parseModuleAst: () => import_yuku.parseModuleAst,
27
+ yukuFactory: () => import_yuku.yukuFactory
28
+ });
29
+ module.exports = __toCommonJS(index_exports);
30
+ __reExport(index_exports, require("./ast.cjs"), module.exports);
31
+ __reExport(index_exports, require("./contracts.cjs"), module.exports);
32
+ __reExport(index_exports, require("./diagnostics.cjs"), module.exports);
33
+ __reExport(index_exports, require("./evaluate.cjs"), module.exports);
34
+ __reExport(index_exports, require("./graph.cjs"), module.exports);
35
+ __reExport(index_exports, require("./hash.cjs"), module.exports);
36
+ __reExport(index_exports, require("./ir.cjs"), module.exports);
37
+ __reExport(index_exports, require("./lower.cjs"), module.exports);
38
+ __reExport(index_exports, require("./materialize.cjs"), module.exports);
39
+ __reExport(index_exports, require("./output.cjs"), module.exports);
40
+ __reExport(index_exports, require("./planCache.cjs"), module.exports);
41
+ __reExport(index_exports, require("./session.cjs"), module.exports);
42
+ var import_normalize = require("./normalize.cjs");
43
+ __reExport(index_exports, require("./zero.cjs"), module.exports);
44
+ var import_yuku = require("./yuku.cjs");
@@ -0,0 +1,33 @@
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 ir_exports = {};
23
+ __export(ir_exports, { hostImportProvenance: () => hostImportProvenance });
24
+ module.exports = __toCommonJS(ir_exports);
25
+ function hostImportProvenance(imports, specifier, importedName) {
26
+ const resolution = imports.find((candidate) => candidate.specifier === specifier);
27
+ return resolution ? {
28
+ specifier,
29
+ importedName,
30
+ resolvedId: resolution.resolvedId,
31
+ external: resolution.external === true
32
+ } : null;
33
+ }
@@ -0,0 +1,225 @@
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 lower_exports = {};
23
+ __export(lower_exports, {
24
+ LOWERED_MODULE_PLAN_VERSION: () => LOWERED_MODULE_PLAN_VERSION,
25
+ lowerModule: () => lowerModule
26
+ });
27
+ module.exports = __toCommonJS(lower_exports);
28
+ var import_diagnostics = require("./diagnostics.cjs");
29
+ var import_output = require("./output.cjs");
30
+ const LOWERED_MODULE_PLAN_VERSION = 2;
31
+ function compareCodeUnits(left, right) {
32
+ return left < right ? -1 : left > right ? 1 : 0;
33
+ }
34
+ function blocking(reason) {
35
+ return {
36
+ ...reason,
37
+ blocking: true
38
+ };
39
+ }
40
+ function diagnostic(code, element, message, prop) {
41
+ return {
42
+ ...(0, import_diagnostics.localBailout)(code, element.span, message),
43
+ component: element.component.name,
44
+ specifier: element.component.provenance?.specifier,
45
+ prop
46
+ };
47
+ }
48
+ function styledDefinitionFor(module2, element) {
49
+ const definition = element.component.definition;
50
+ if (!definition) return null;
51
+ return module2.styledDefinitions.find((candidate) => candidate.id === definition.id && candidate.name === definition.name) ?? null;
52
+ }
53
+ function unsafeEntry(element, entry, component, host) {
54
+ if (entry.kind === "spread" && entry.value.kind !== "static") {
55
+ return diagnostic("local/unsafe-style-spread", element, "Unevaluated spread may change style and duplicate-prop precedence");
56
+ }
57
+ if (entry.kind === "prop" && host.isStyleProp(entry.name, component) && (entry.value.kind === "bailout" || entry.value.kind === "conditional") && !host.canLowerDynamicStyleProp?.(entry.name, component, entry.value.kind)) {
58
+ return diagnostic("local/dynamic-style-value", element, `Style prop ${entry.name} could not be evaluated`, entry.name);
59
+ }
60
+ return null;
61
+ }
62
+ function editsAreCandidateLocal(element, edits) {
63
+ return edits.every((edit) => edit.origin.id === element.id && edit.start >= element.span.start && edit.end <= element.span.end);
64
+ }
65
+ function overlapsCommitted(edits, committed) {
66
+ return edits.some((edit) => committed.some((existing) => {
67
+ if (edit.start === edit.end) {
68
+ return edit.start > existing.start && edit.start < existing.end;
69
+ }
70
+ if (existing.start === existing.end) {
71
+ return existing.start > edit.start && existing.start < edit.end;
72
+ }
73
+ return edit.start < existing.end && existing.start < edit.end;
74
+ }));
75
+ }
76
+ function lowerModule({ module: module2, source, target, host, options, structuralPass }) {
77
+ const stats = {
78
+ found: 0,
79
+ lowered: 0,
80
+ flattened: 0,
81
+ styled: 0,
82
+ bailed: 0
83
+ };
84
+ const structural = structuralPass ? structuralPass.transform({
85
+ module: module2,
86
+ source,
87
+ target
88
+ }) : {
89
+ module: module2,
90
+ edits: [],
91
+ imports: [],
92
+ diagnostics: [],
93
+ dependencies: []
94
+ };
95
+ if (structural.module.id !== module2.id) {
96
+ throw new Error(`Structural pass changed module identity from ${module2.id} to ${structural.module.id}`);
97
+ }
98
+ if (structuralPass && !structuralPass.versionHash) {
99
+ throw new Error("Structural pass must provide a non-empty version hash");
100
+ }
101
+ module2 = structural.module;
102
+ (0, import_output.validateSourceEdits)(source, structural.edits);
103
+ const edits = [...structural.edits];
104
+ const css = /* @__PURE__ */ new Set();
105
+ const diagnostics = [...module2.diagnostics, ...structural.diagnostics];
106
+ const dependencies = /* @__PURE__ */ new Set([...module2.dependencies, ...structural.dependencies]);
107
+ const imports = new Map(structural.imports.map((candidateImport) => [candidateImport.content, candidateImport]));
108
+ for (const element of module2.elements) {
109
+ const styledDefinition = styledDefinitionFor(module2, element);
110
+ const component = host.resolveComponent(element, styledDefinition);
111
+ if (!component) continue;
112
+ stats.found++;
113
+ const input = {
114
+ id: module2.id,
115
+ source,
116
+ target,
117
+ module: module2,
118
+ element,
119
+ styledDefinition,
120
+ component
121
+ };
122
+ const commitDevelopmentDebug = (result2) => {
123
+ const debugEdits = host.developmentDebugInstrumentation?.(input, result2);
124
+ if (!debugEdits) return;
125
+ (0, import_output.validateSourceEdits)(source, debugEdits);
126
+ if (!editsAreCandidateLocal(element, debugEdits) || overlapsCommitted(debugEdits, edits)) {
127
+ throw new Error("Development debug instrumentation must stay candidate-local");
128
+ }
129
+ edits.push(...debugEdits);
130
+ };
131
+ if (!element.complete || styledDefinition && !styledDefinition.complete) {
132
+ const reasons = [...element.bailouts.map(blocking), ...(styledDefinition?.bailouts ?? []).map(blocking)];
133
+ diagnostics.push(...reasons);
134
+ const reason = reasons[0];
135
+ if (reason) commitDevelopmentDebug({
136
+ ok: false,
137
+ bailout: reason
138
+ });
139
+ stats.bailed++;
140
+ continue;
141
+ }
142
+ const unsafe = element.entries.map((entry) => unsafeEntry(element, entry, component, host)).find((result2) => result2 !== null);
143
+ if (unsafe) {
144
+ diagnostics.push(blocking(unsafe));
145
+ commitDevelopmentDebug({
146
+ ok: false,
147
+ bailout: blocking(unsafe)
148
+ });
149
+ stats.bailed++;
150
+ continue;
151
+ }
152
+ let result;
153
+ try {
154
+ result = host.lowerCandidate(input);
155
+ } catch (error) {
156
+ result = {
157
+ ok: false,
158
+ bailout: diagnostic("local/style-resolution-failed", element, `Style resolution failed: ${error instanceof Error ? error.message : String(error)}`)
159
+ };
160
+ }
161
+ if (!result.ok) {
162
+ diagnostics.push(blocking(result.bailout));
163
+ commitDevelopmentDebug(result);
164
+ stats.bailed++;
165
+ continue;
166
+ }
167
+ try {
168
+ (0, import_output.validateSourceEdits)(source, result.edits);
169
+ } catch (error) {
170
+ const reason = blocking(diagnostic("local/overlapping-edit", element, error instanceof Error ? error.message : String(error)));
171
+ diagnostics.push(reason);
172
+ commitDevelopmentDebug({
173
+ ok: false,
174
+ bailout: reason
175
+ });
176
+ stats.bailed++;
177
+ continue;
178
+ }
179
+ if (!editsAreCandidateLocal(element, result.edits) || overlapsCommitted(result.edits, edits)) {
180
+ const reason = blocking(diagnostic("local/overlapping-edit", element, "Candidate edits overlap another candidate or escape the element span"));
181
+ diagnostics.push(reason);
182
+ commitDevelopmentDebug({
183
+ ok: false,
184
+ bailout: reason
185
+ });
186
+ stats.bailed++;
187
+ continue;
188
+ }
189
+ diagnostics.push(...result.diagnostics ?? []);
190
+ edits.push(...result.edits);
191
+ commitDevelopmentDebug(result);
192
+ for (const rule of result.css) css.add(rule);
193
+ for (const candidateImport of result.imports) {
194
+ if (!imports.has(candidateImport.content)) {
195
+ imports.set(candidateImport.content, candidateImport);
196
+ }
197
+ }
198
+ for (const dependency of result.dependencies ?? []) dependencies.add(dependency);
199
+ stats.lowered++;
200
+ if (result.flattened) stats.flattened++;
201
+ if (styledDefinition) stats.styled++;
202
+ }
203
+ for (const candidateImport of imports.values()) {
204
+ edits.push({
205
+ start: source.length,
206
+ end: source.length,
207
+ content: candidateImport.content,
208
+ origin: candidateImport.origin
209
+ });
210
+ }
211
+ return {
212
+ version: LOWERED_MODULE_PLAN_VERSION,
213
+ id: module2.id,
214
+ target,
215
+ inputHash: module2.inputHash,
216
+ sourceHash: (0, import_output.sourceContentHash)(source),
217
+ projectGeneration: options.projectGeneration,
218
+ structuralPassHash: structuralPass?.versionHash ?? `${target}-noop-v1`,
219
+ edits,
220
+ css: [...css].join(""),
221
+ diagnostics,
222
+ dependencies: [...dependencies].sort(compareCodeUnits),
223
+ stats
224
+ };
225
+ }