@tamagui/compiler-core 0.0.0-bootstrap.0 → 3.0.0-beta.1093.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 +108 -0
  4. package/dist/cjs/contracts.cjs +61 -0
  5. package/dist/cjs/diagnostics.cjs +68 -0
  6. package/dist/cjs/evaluate.cjs +602 -0
  7. package/dist/cjs/graph.cjs +335 -0
  8. package/dist/cjs/hash.cjs +48 -0
  9. package/dist/cjs/index.cjs +43 -0
  10. package/dist/cjs/ir.cjs +32 -0
  11. package/dist/cjs/lower.cjs +232 -0
  12. package/dist/cjs/materialize.cjs +222 -0
  13. package/dist/cjs/normalize.cjs +628 -0
  14. package/dist/cjs/output.cjs +148 -0
  15. package/dist/cjs/planCache.cjs +262 -0
  16. package/dist/cjs/session.cjs +127 -0
  17. package/dist/cjs/yuku.cjs +166 -0
  18. package/dist/cjs/zero.cjs +389 -0
  19. package/dist/esm/ast.mjs +79 -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 +576 -0
  26. package/dist/esm/evaluate.mjs.map +1 -0
  27. package/dist/esm/graph.mjs +313 -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 +210 -0
  35. package/dist/esm/lower.mjs.map +1 -0
  36. package/dist/esm/materialize.mjs +203 -0
  37. package/dist/esm/materialize.mjs.map +1 -0
  38. package/dist/esm/normalize.mjs +604 -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 +232 -0
  43. package/dist/esm/planCache.mjs.map +1 -0
  44. package/dist/esm/session.mjs +108 -0
  45. package/dist/esm/session.mjs.map +1 -0
  46. package/dist/esm/yuku.mjs +144 -0
  47. package/dist/esm/yuku.mjs.map +1 -0
  48. package/dist/esm/zero.mjs +354 -0
  49. package/dist/esm/zero.mjs.map +1 -0
  50. package/package.json +42 -4
  51. package/src/ast.ts +106 -0
  52. package/src/contracts.ts +150 -0
  53. package/src/diagnostics.ts +96 -0
  54. package/src/evaluate.ts +875 -0
  55. package/src/graph.ts +425 -0
  56. package/src/hash.ts +36 -0
  57. package/src/index.ts +15 -0
  58. package/src/ir.ts +156 -0
  59. package/src/lower.ts +435 -0
  60. package/src/materialize.ts +383 -0
  61. package/src/normalize.ts +834 -0
  62. package/src/output.ts +175 -0
  63. package/src/planCache.ts +362 -0
  64. package/src/session.ts +192 -0
  65. package/src/yuku.ts +197 -0
  66. package/src/zero.ts +609 -0
  67. package/types/ast.d.ts +11 -0
  68. package/types/ast.d.ts.map +1 -0
  69. package/types/contracts.d.ts +99 -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 +48 -0
  74. package/types/evaluate.d.ts.map +1 -0
  75. package/types/graph.d.ts +51 -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 +120 -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 +121 -0
  86. package/types/materialize.d.ts.map +1 -0
  87. package/types/normalize.d.ts +7 -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 +123 -0
  92. package/types/planCache.d.ts.map +1 -0
  93. package/types/session.d.ts +52 -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 +99 -0
  98. package/types/zero.d.ts.map +1 -0
@@ -0,0 +1,335 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: () => from[key],
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+ var graph_exports = {};
22
+ __export(graph_exports, {
23
+ ProjectGraph: () => ProjectGraph,
24
+ moduleContentHash: () => moduleContentHash
25
+ });
26
+ module.exports = __toCommonJS(graph_exports);
27
+ var import_node_crypto = require("node:crypto");
28
+ var import_contracts = require("./contracts.cjs");
29
+ var import_ast = require("./ast.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
+ /** resolved ids a module imports that the graph does not own (package entries) */
94
+ externalImportsOf(id) {
95
+ const record = this.#modules.get(id);
96
+ if (!record) return [];
97
+ const ids = /* @__PURE__ */ new Set();
98
+ for (const dependency of record.input.imports) {
99
+ if (dependency.external) ids.add(dependency.resolvedId);
100
+ }
101
+ return [...ids].sort(compareIds);
102
+ }
103
+ affectedBy(id) {
104
+ const affected = /* @__PURE__ */ new Set([id]);
105
+ const queue = [id];
106
+ while (queue.length) {
107
+ const current = queue.shift();
108
+ for (const dependent of this.#dependents.get(current) ?? []) {
109
+ if (affected.has(dependent)) continue;
110
+ affected.add(dependent);
111
+ queue.push(dependent);
112
+ }
113
+ }
114
+ return [...affected].sort(compareIds);
115
+ }
116
+ parseCount(id) {
117
+ return this.#candidate.parseCount(id);
118
+ }
119
+ resolveBinding(id, localName) {
120
+ const definition = this.#candidate.definitionOf(id, localName);
121
+ if (!definition) return null;
122
+ return {
123
+ id: definition.id,
124
+ name: definition.name,
125
+ span: {
126
+ id: definition.id,
127
+ start: definition.start,
128
+ end: definition.end
129
+ },
130
+ initializer: definition.initializer ? (0, import_contracts.expressionReference)(definition.id, definition.initializer) : null,
131
+ constant: definition.constant
132
+ };
133
+ }
134
+ resolveReference(reference) {
135
+ const definition = this.#candidate.definitionAt(reference.id, reference.start, reference.end);
136
+ if (!definition) return null;
137
+ return {
138
+ id: definition.id,
139
+ name: definition.name,
140
+ span: {
141
+ id: definition.id,
142
+ start: definition.start,
143
+ end: definition.end
144
+ },
145
+ initializer: definition.initializer ? (0, import_contracts.expressionReference)(definition.id, definition.initializer) : null,
146
+ constant: definition.constant
147
+ };
148
+ }
149
+ expressionNode(reference) {
150
+ if (!this.#modules.has(reference.id)) return null;
151
+ return (0, import_normalize.nodeAtSpan)(this.#candidate.programOf(reference.id), reference.start, reference.end);
152
+ }
153
+ /**
154
+ * The members of a plain object literal, each as its own expression:
155
+ * `{ width: expr, height: 10 }`. Null for anything else, and for an object
156
+ * that spreads, computes a key, or defines a method or accessor.
157
+ */
158
+ objectMembers(reference) {
159
+ const node = this.expressionNode(reference);
160
+ if (!node) return null;
161
+ const object = (0, import_ast.unwrapExpression)(node);
162
+ if (object.type !== "ObjectExpression") return null;
163
+ const members = [];
164
+ for (const property of (0, import_ast.childNodes)(object, "properties")) {
165
+ if (property.type !== "Property" && property.type !== "ObjectProperty" || property.computed === true || property.method === true || property.kind !== void 0 && property.kind !== "init") {
166
+ return null;
167
+ }
168
+ const key = (0, import_ast.childNode)(property, "key");
169
+ const value = (0, import_ast.childNode)(property, "value");
170
+ if (!key || !value) return null;
171
+ const name = (0, import_ast.identifierName)(key) ?? (typeof key.value === "string" ? key.value : null);
172
+ if (name === null) return null;
173
+ members.push({
174
+ name,
175
+ span: (0, import_contracts.spanOf)(reference.id, property),
176
+ value: (0, import_contracts.expressionReference)(reference.id, value)
177
+ });
178
+ }
179
+ return members;
180
+ }
181
+ evaluate(reference) {
182
+ return (0, import_evaluate.evaluateExpression)(this, reference);
183
+ }
184
+ evaluateBranches(reference) {
185
+ return (0, import_evaluate.evaluateBranches)(this, reference);
186
+ }
187
+ evaluateDynamic(reference) {
188
+ return (0, import_evaluate.evaluateDynamicExpression)(this, reference);
189
+ }
190
+ evaluateBinding(id, localName) {
191
+ return (0, import_evaluate.evaluateBinding)(this, id, localName);
192
+ }
193
+ elementsOf(id) {
194
+ const record = this.#modules.get(id);
195
+ if (!record) throw new Error(`Unknown host module ${id}`);
196
+ const cached = this.#elementCache.get(id);
197
+ if (cached?.hash === record.hash) return cached.result;
198
+ const result = (0, import_normalize.normalizeElements)(this.#candidate, id, record.input.imports);
199
+ this.#elementCache.set(id, {
200
+ hash: record.hash,
201
+ result
202
+ });
203
+ return result;
204
+ }
205
+ diagnostics() {
206
+ const diagnostics = this.#candidate.diagnostics().map((diagnostic) => diagnostic.kind === "parse" ? (0, import_diagnostics.localBailout)("local/parse-error", {
207
+ id: diagnostic.id,
208
+ start: 0,
209
+ end: 0
210
+ }, diagnostic.message) : (0, import_diagnostics.linkedBailout)("linked/unresolved-binding", {
211
+ id: diagnostic.id,
212
+ start: 0,
213
+ end: 0
214
+ }, diagnostic.message));
215
+ for (const [id, record] of this.#modules) {
216
+ for (const dependency of record.input.imports) {
217
+ if (dependency.external) continue;
218
+ if (this.#modules.has(dependency.resolvedId)) continue;
219
+ diagnostics.push((0, import_diagnostics.linkedBailout)("linked/unresolved-import", {
220
+ id,
221
+ start: 0,
222
+ end: 0
223
+ }, `Host-resolved import ${dependency.specifier} points outside the project graph`, dependency.resolvedId));
224
+ }
225
+ }
226
+ return diagnostics.sort((left, right) => {
227
+ const byId = compareCodeUnits(left.span.id, right.span.id);
228
+ return byId || left.span.start - right.span.start || compareCodeUnits(left.code, right.code);
229
+ });
230
+ }
231
+ updateModule(input) {
232
+ const previous = this.#modules.get(input.id);
233
+ const nextHash = moduleContentHash(input);
234
+ if (previous?.hash === nextHash) {
235
+ return {
236
+ changed: false,
237
+ id: input.id,
238
+ previousHash: previous.hash,
239
+ contentHash: previous.hash,
240
+ invalidatedIds: []
241
+ };
242
+ }
243
+ const invalidatedIds = this.affectedBy(input.id);
244
+ const previousHash = previous?.hash ?? null;
245
+ if (previous) this.#candidate.removeFile(input.id);
246
+ this.#installHostRecord(input);
247
+ this.#candidate.addFile(input.id, input.source);
248
+ this.#candidate.link();
249
+ for (const id of invalidatedIds) this.#elementCache.delete(id);
250
+ return {
251
+ changed: true,
252
+ id: input.id,
253
+ previousHash,
254
+ contentHash: nextHash,
255
+ invalidatedIds
256
+ };
257
+ }
258
+ removeModule(id) {
259
+ const previous = this.#modules.get(id);
260
+ if (!previous) {
261
+ return {
262
+ changed: false,
263
+ id,
264
+ previousHash: null,
265
+ contentHash: null,
266
+ invalidatedIds: []
267
+ };
268
+ }
269
+ const invalidatedIds = this.affectedBy(id);
270
+ this.#candidate.removeFile(id);
271
+ this.#removeOutgoingEdges(id);
272
+ this.#removeResolutions(id);
273
+ this.#modules.delete(id);
274
+ this.#files.delete(id);
275
+ this.#candidate.link();
276
+ for (const invalidated of invalidatedIds) this.#elementCache.delete(invalidated);
277
+ return {
278
+ changed: true,
279
+ id,
280
+ previousHash: previous.hash,
281
+ contentHash: null,
282
+ invalidatedIds
283
+ };
284
+ }
285
+ #installHostRecord(input) {
286
+ (0, import_contracts.resolvedModuleId)(input.id);
287
+ const seenSpecifiers = /* @__PURE__ */ new Set();
288
+ for (const dependency of input.imports) {
289
+ (0, import_contracts.resolvedModuleId)(dependency.resolvedId);
290
+ if (seenSpecifiers.has(dependency.specifier)) {
291
+ throw new Error(`Duplicate host resolution for ${input.id}:${dependency.specifier}`);
292
+ }
293
+ seenSpecifiers.add(dependency.specifier);
294
+ }
295
+ this.#removeOutgoingEdges(input.id);
296
+ this.#removeResolutions(input.id);
297
+ const dependencies = new Set(input.imports.filter(({ external }) => !external).map(({ resolvedId }) => resolvedId));
298
+ this.#dependencies.set(input.id, dependencies);
299
+ for (const dependency of dependencies) {
300
+ let reverse = this.#dependents.get(dependency);
301
+ if (!reverse) {
302
+ reverse = /* @__PURE__ */ new Set();
303
+ this.#dependents.set(dependency, reverse);
304
+ }
305
+ reverse.add(input.id);
306
+ }
307
+ for (const dependency of input.imports) {
308
+ if (dependency.external) continue;
309
+ this.#resolutions.set((0, import_contracts.resolutionKey)(input.id, dependency.specifier), dependency.resolvedId);
310
+ }
311
+ const installedInput = {
312
+ ...input,
313
+ imports: input.imports.map((dependency) => ({ ...dependency }))
314
+ };
315
+ this.#files.set(installedInput.id, installedInput.source);
316
+ this.#modules.set(installedInput.id, {
317
+ input: installedInput,
318
+ hash: moduleContentHash(installedInput)
319
+ });
320
+ }
321
+ #removeOutgoingEdges(id) {
322
+ for (const dependency of this.#dependencies.get(id) ?? []) {
323
+ const reverse = this.#dependents.get(dependency);
324
+ reverse?.delete(id);
325
+ if (reverse?.size === 0) this.#dependents.delete(dependency);
326
+ }
327
+ this.#dependencies.delete(id);
328
+ }
329
+ #removeResolutions(id) {
330
+ const prefix = `${id}\0`;
331
+ for (const key of this.#resolutions.keys()) {
332
+ if (key.startsWith(prefix)) this.#resolutions.delete(key);
333
+ }
334
+ }
335
+ };
@@ -0,0 +1,48 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: () => from[key],
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+ var hash_exports = {};
22
+ __export(hash_exports, {
23
+ contentHash: () => contentHash,
24
+ stableStringify: () => stableStringify
25
+ });
26
+ module.exports = __toCommonJS(hash_exports);
27
+ var import_node_crypto = require("node:crypto");
28
+ function contentHash(value) {
29
+ return (0, import_node_crypto.createHash)("sha256").update(value).digest("hex");
30
+ }
31
+ function compareCodeUnits(left, right) {
32
+ return left < right ? -1 : left > right ? 1 : 0;
33
+ }
34
+ function stringify(value) {
35
+ if (Array.isArray(value)) {
36
+ return `[${value.map((child) => stringify(child) ?? "null").join(",")}]`;
37
+ }
38
+ if (value && typeof value === "object") {
39
+ const entries = Object.entries(value).sort(([left], [right]) => compareCodeUnits(left, right)).map(([key, child]) => [key, stringify(child)]).filter((entry) => entry[1] !== void 0);
40
+ return `{${entries.map(([key, child]) => `${JSON.stringify(key)}:${child}`).join(",")}}`;
41
+ }
42
+ return JSON.stringify(value);
43
+ }
44
+ function stableStringify(value) {
45
+ const serialized = stringify(value);
46
+ if (serialized === void 0) throw new Error("Cannot serialize undefined cache root");
47
+ return serialized;
48
+ }
@@ -0,0 +1,43 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: () => from[key],
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
+ };
20
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
+ var index_exports = {};
23
+ __export(index_exports, {
24
+ normalizeElements: () => import_normalize.normalizeElements,
25
+ parseModuleAst: () => import_yuku.parseModuleAst,
26
+ yukuFactory: () => import_yuku.yukuFactory
27
+ });
28
+ module.exports = __toCommonJS(index_exports);
29
+ __reExport(index_exports, require("./ast.cjs"), module.exports);
30
+ __reExport(index_exports, require("./contracts.cjs"), module.exports);
31
+ __reExport(index_exports, require("./diagnostics.cjs"), module.exports);
32
+ __reExport(index_exports, require("./evaluate.cjs"), module.exports);
33
+ __reExport(index_exports, require("./graph.cjs"), module.exports);
34
+ __reExport(index_exports, require("./hash.cjs"), module.exports);
35
+ __reExport(index_exports, require("./ir.cjs"), module.exports);
36
+ __reExport(index_exports, require("./lower.cjs"), module.exports);
37
+ __reExport(index_exports, require("./materialize.cjs"), module.exports);
38
+ __reExport(index_exports, require("./output.cjs"), module.exports);
39
+ __reExport(index_exports, require("./planCache.cjs"), module.exports);
40
+ __reExport(index_exports, require("./session.cjs"), module.exports);
41
+ var import_normalize = require("./normalize.cjs");
42
+ __reExport(index_exports, require("./zero.cjs"), module.exports);
43
+ var import_yuku = require("./yuku.cjs");
@@ -0,0 +1,32 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: () => from[key],
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+ var ir_exports = {};
22
+ __export(ir_exports, { hostImportProvenance: () => hostImportProvenance });
23
+ module.exports = __toCommonJS(ir_exports);
24
+ function hostImportProvenance(imports, specifier, importedName) {
25
+ const resolution = imports.find((candidate) => candidate.specifier === specifier);
26
+ return resolution ? {
27
+ specifier,
28
+ importedName,
29
+ resolvedId: resolution.resolvedId,
30
+ external: resolution.external === true
31
+ } : null;
32
+ }
@@ -0,0 +1,232 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: () => from[key],
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+ var lower_exports = {};
22
+ __export(lower_exports, {
23
+ LOWERED_MODULE_PLAN_VERSION: () => LOWERED_MODULE_PLAN_VERSION,
24
+ lowerModule: () => lowerModule
25
+ });
26
+ module.exports = __toCommonJS(lower_exports);
27
+ var import_diagnostics = require("./diagnostics.cjs");
28
+ var import_output = require("./output.cjs");
29
+ const LOWERED_MODULE_PLAN_VERSION = 3;
30
+ function compareCodeUnits(left, right) {
31
+ return left < right ? -1 : left > right ? 1 : 0;
32
+ }
33
+ function blocking(reason) {
34
+ return {
35
+ ...reason,
36
+ blocking: true
37
+ };
38
+ }
39
+ function diagnostic(code, element, message, prop) {
40
+ return {
41
+ ...(0, import_diagnostics.localBailout)(code, element.span, message),
42
+ component: element.component.name,
43
+ specifier: element.component.provenance?.specifier,
44
+ prop
45
+ };
46
+ }
47
+ function styledDefinitionFor(module2, element) {
48
+ const definition = element.component.definition;
49
+ if (!definition) return null;
50
+ return module2.styledDefinitions.find((candidate) => candidate.id === definition.id && candidate.name === definition.name) ?? null;
51
+ }
52
+ function unsafeEntry(element, entry, component, host) {
53
+ if (entry.kind === "spread" && entry.value.kind !== "static") {
54
+ return diagnostic("local/unsafe-style-spread", element, "Unevaluated spread may change style and duplicate-prop precedence");
55
+ }
56
+ 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)) {
57
+ return diagnostic("local/dynamic-style-value", element, `Style prop ${entry.name} could not be evaluated`, entry.name);
58
+ }
59
+ if (entry.kind === "prop" && entry.value.kind === "object") {
60
+ for (const member of entry.value.members) {
61
+ if (member.value.kind !== "bailout" && member.value.kind !== "conditional") continue;
62
+ if (!host.isStyleProp(member.name, component) || !host.canLowerDynamicStyleProp?.(member.name, component, member.value.kind)) {
63
+ return diagnostic("local/dynamic-style-value", element, `Style prop ${member.name} could not be evaluated`, member.name);
64
+ }
65
+ }
66
+ }
67
+ return null;
68
+ }
69
+ function editsAreCandidateLocal(element, edits) {
70
+ return edits.every((edit) => edit.origin.id === element.id && edit.start >= element.span.start && edit.end <= element.span.end);
71
+ }
72
+ function overlapsCommitted(edits, committed) {
73
+ return edits.some((edit) => committed.some((existing) => {
74
+ if (edit.start === edit.end) {
75
+ return edit.start > existing.start && edit.start < existing.end;
76
+ }
77
+ if (existing.start === existing.end) {
78
+ return existing.start > edit.start && existing.start < edit.end;
79
+ }
80
+ return edit.start < existing.end && existing.start < edit.end;
81
+ }));
82
+ }
83
+ function lowerModule({ module: module2, source, target, host, options, structuralPass }) {
84
+ const stats = {
85
+ found: 0,
86
+ lowered: 0,
87
+ flattened: 0,
88
+ styled: 0,
89
+ bailed: 0
90
+ };
91
+ const structural = structuralPass ? structuralPass.transform({
92
+ module: module2,
93
+ source,
94
+ target
95
+ }) : {
96
+ module: module2,
97
+ edits: [],
98
+ imports: [],
99
+ diagnostics: [],
100
+ dependencies: []
101
+ };
102
+ if (structural.module.id !== module2.id) {
103
+ throw new Error(`Structural pass changed module identity from ${module2.id} to ${structural.module.id}`);
104
+ }
105
+ if (structuralPass && !structuralPass.versionHash) {
106
+ throw new Error("Structural pass must provide a non-empty version hash");
107
+ }
108
+ module2 = structural.module;
109
+ (0, import_output.validateSourceEdits)(source, structural.edits);
110
+ const edits = [...structural.edits];
111
+ const css = /* @__PURE__ */ new Set();
112
+ const diagnostics = [...module2.diagnostics, ...structural.diagnostics];
113
+ const dependencies = /* @__PURE__ */ new Set([...module2.dependencies, ...structural.dependencies]);
114
+ const imports = new Map(structural.imports.map((candidateImport) => [candidateImport.content, candidateImport]));
115
+ for (const element of module2.elements) {
116
+ const styledDefinition = styledDefinitionFor(module2, element);
117
+ const component = host.resolveComponent(element, styledDefinition);
118
+ if (!component) continue;
119
+ stats.found++;
120
+ const input = {
121
+ id: module2.id,
122
+ source,
123
+ target,
124
+ module: module2,
125
+ element,
126
+ styledDefinition,
127
+ component
128
+ };
129
+ const commitDevelopmentDebug = (result2) => {
130
+ const debugEdits = host.developmentDebugInstrumentation?.(input, result2);
131
+ if (!debugEdits) return;
132
+ (0, import_output.validateSourceEdits)(source, debugEdits);
133
+ if (!editsAreCandidateLocal(element, debugEdits) || overlapsCommitted(debugEdits, edits)) {
134
+ throw new Error("Development debug instrumentation must stay candidate-local");
135
+ }
136
+ edits.push(...debugEdits);
137
+ };
138
+ if (!element.complete || styledDefinition && !styledDefinition.complete) {
139
+ const reasons = [...element.bailouts.map(blocking), ...(styledDefinition?.bailouts ?? []).map(blocking)];
140
+ diagnostics.push(...reasons);
141
+ const reason = reasons[0];
142
+ if (reason) commitDevelopmentDebug({
143
+ ok: false,
144
+ bailout: reason
145
+ });
146
+ stats.bailed++;
147
+ continue;
148
+ }
149
+ const unsafe = element.entries.map((entry) => unsafeEntry(element, entry, component, host)).find((result2) => result2 !== null);
150
+ if (unsafe) {
151
+ diagnostics.push(blocking(unsafe));
152
+ commitDevelopmentDebug({
153
+ ok: false,
154
+ bailout: blocking(unsafe)
155
+ });
156
+ stats.bailed++;
157
+ continue;
158
+ }
159
+ let result;
160
+ try {
161
+ result = host.lowerCandidate(input);
162
+ } catch (error) {
163
+ result = {
164
+ ok: false,
165
+ bailout: diagnostic("local/style-resolution-failed", element, `Style resolution failed: ${error instanceof Error ? error.message : String(error)}`)
166
+ };
167
+ }
168
+ if (!result.ok) {
169
+ diagnostics.push(blocking(result.bailout));
170
+ commitDevelopmentDebug(result);
171
+ stats.bailed++;
172
+ continue;
173
+ }
174
+ try {
175
+ (0, import_output.validateSourceEdits)(source, result.edits);
176
+ } catch (error) {
177
+ const reason = blocking(diagnostic("local/overlapping-edit", element, error instanceof Error ? error.message : String(error)));
178
+ diagnostics.push(reason);
179
+ commitDevelopmentDebug({
180
+ ok: false,
181
+ bailout: reason
182
+ });
183
+ stats.bailed++;
184
+ continue;
185
+ }
186
+ if (!editsAreCandidateLocal(element, result.edits) || overlapsCommitted(result.edits, edits)) {
187
+ const reason = blocking(diagnostic("local/overlapping-edit", element, "Candidate edits overlap another candidate or escape the element span"));
188
+ diagnostics.push(reason);
189
+ commitDevelopmentDebug({
190
+ ok: false,
191
+ bailout: reason
192
+ });
193
+ stats.bailed++;
194
+ continue;
195
+ }
196
+ diagnostics.push(...result.diagnostics ?? []);
197
+ edits.push(...result.edits);
198
+ commitDevelopmentDebug(result);
199
+ for (const rule of result.css) css.add(rule);
200
+ for (const candidateImport of result.imports) {
201
+ if (!imports.has(candidateImport.content)) {
202
+ imports.set(candidateImport.content, candidateImport);
203
+ }
204
+ }
205
+ for (const dependency of result.dependencies ?? []) dependencies.add(dependency);
206
+ stats.lowered++;
207
+ if (result.flattened) stats.flattened++;
208
+ if (styledDefinition) stats.styled++;
209
+ }
210
+ for (const candidateImport of imports.values()) {
211
+ edits.push({
212
+ start: source.length,
213
+ end: source.length,
214
+ content: candidateImport.content,
215
+ origin: candidateImport.origin
216
+ });
217
+ }
218
+ return {
219
+ version: LOWERED_MODULE_PLAN_VERSION,
220
+ id: module2.id,
221
+ target,
222
+ inputHash: module2.inputHash,
223
+ sourceHash: (0, import_output.sourceContentHash)(source),
224
+ projectGeneration: options.projectGeneration,
225
+ structuralPassHash: structuralPass?.versionHash ?? `${target}-noop-v1`,
226
+ edits,
227
+ css: [...css].join(""),
228
+ diagnostics,
229
+ dependencies: [...dependencies].sort(compareCodeUnits),
230
+ stats
231
+ };
232
+ }