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