@openelement/compiler 1.0.0-alpha.14 → 1.0.0-alpha.16
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/package.json +4 -2
- package/src/compiler.d.ts +12 -6
- package/src/compiler.js +11 -6
- package/src/internal/compiler/compiled-artifact-class-candidates.d.ts +11 -0
- package/src/internal/compiler/compiled-artifact-class-candidates.js +46 -0
- package/src/internal/compiler/compiled-artifact-style-requests.d.ts +26 -7
- package/src/internal/compiler/compiled-artifact-style-requests.js +57 -9
- package/src/internal/compiler/plugin.d.ts +68 -49
- package/src/internal/compiler/plugin.js +93 -82
- package/src/internal/compiler/semantic-core/analyze-module.d.ts +73 -0
- package/src/internal/compiler/semantic-core/analyze-module.js +29 -379
- package/src/internal/compiler/semantic-core/attribute-classification.js +92 -0
- package/src/internal/compiler/semantic-core/compiler-diagnostics.js +2 -16
- package/src/internal/compiler/semantic-core/diagnostics/index.d.ts +21 -1
- package/src/internal/compiler/semantic-core/diagnostics/index.js +32 -1
- package/src/internal/compiler/semantic-core/expression-lowering.js +469 -0
- package/src/internal/compiler/semantic-core/expression-registry.js +165 -0
- package/src/internal/compiler/semantic-core/function-frontend.js +1229 -0
- package/src/internal/compiler/semantic-core/island-policy-statement.js +52 -0
- package/src/internal/compiler/semantic-core/jsx-module-id.d.ts +4 -0
- package/src/internal/compiler/semantic-core/jsx-module-id.js +7 -0
- package/src/internal/compiler/semantic-core/lower-program.d.ts +220 -0
- package/src/internal/compiler/semantic-core/lower-program.js +350 -142
- package/src/internal/compiler/semantic-core/module-analysis.d.ts +82 -4
- package/src/internal/compiler/semantic-core/module-analysis.js +88 -19
- package/src/internal/compiler/semantic-core/parse-module.js +16 -16
- package/src/internal/compiler/semantic-core/scope-resolution.d.ts +208 -0
- package/src/internal/compiler/semantic-core/scope-resolution.js +1121 -0
- package/src/internal/compiler/semantic-core/server-component.d.ts +129 -0
- package/src/internal/compiler/semantic-core/server-component.js +587 -0
- package/src/internal/compiler/semantic-core/type-check.js +1 -1
- package/src/internal/compiler/semantic-core/type-erasure.js +156 -0
- package/src/internal/compiler/semantic-ir/generated-element/compile.d.ts +61 -0
- package/src/internal/compiler/semantic-ir/generated-element/compile.js +137 -0
- package/src/internal/compiler/semantic-ir/generated-element/contract.d.ts +201 -0
- package/src/internal/compiler/semantic-ir/generated-element/contract.js +147 -0
- package/src/internal/compiler/semantic-ir/generated-element/emit.js +452 -0
- package/src/internal/compiler/semantic-ir/generated-element/site.js +1195 -0
- package/src/internal/compiler/semantic-ir/generated-leaf/claim-emission.js +1372 -0
- package/src/internal/compiler/semantic-ir/generated-leaf/codegen-literals.js +31 -0
- package/src/internal/compiler/semantic-ir/generated-leaf/component-emission.js +647 -0
- package/src/internal/compiler/semantic-ir/generated-leaf/emission.js +388 -0
- package/src/internal/compiler/semantic-ir/generated-leaf/generate.js +395 -0
- package/src/internal/compiler/semantic-ir/generated-leaf/instance-emission.js +865 -0
- package/src/internal/compiler/semantic-ir/generated-leaf/mount-emission.js +960 -0
- package/src/internal/compiler/semantic-ir/generated-leaf/server-emission.js +1011 -0
- package/src/internal/compiler/semantic-ir/generated-leaf/structure.js +714 -0
- package/src/internal/compiler/style-requests.d.ts +35 -7
- package/src/internal/compiler/style-requests.js +57 -11
- package/src/internal/compiler/tailwind-candidates.d.ts +84 -0
- package/src/internal/compiler/tailwind-candidates.js +54 -0
- package/src/internal/compiler/semantic-core/compile.d.ts +0 -39
- package/src/internal/compiler/semantic-core/compile.js +0 -98
- package/src/internal/compiler/semantic-core/emit-module.js +0 -313
- package/src/internal/compiler/semantic-core/emit-program.js +0 -121
- package/src/internal/compiler/semantic-core/style-imports.js +0 -87
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
//#region src/internal/compiler/semantic-ir/generated-leaf/emission.ts
|
|
2
|
+
const INTERNAL_PREFIX = "__oe_";
|
|
3
|
+
/**
|
|
4
|
+
* 16b-LC depth >= 2 (2026-11-21): the transaction token local of a retaining
|
|
5
|
+
* body. The root body captures `beginInstancePass`'s return in it; a retained
|
|
6
|
+
* body reads the token from its compiler-private host literal and joins. The
|
|
7
|
+
* `__oe_` prefix is refused for authored identifiers, so it cannot collide.
|
|
8
|
+
*/
|
|
9
|
+
const TRANSACTION_VAR = `${INTERNAL_PREFIX}txn`;
|
|
10
|
+
/** The namespace URI an `<svg>` subtree is created and claimed in. */
|
|
11
|
+
const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
|
|
12
|
+
const HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
|
|
13
|
+
/**
|
|
14
|
+
* `16b-EB`: the compiler-private host-record property that carries the
|
|
15
|
+
* update-phase error sink into `guardUpdate`. A GETTER on the shell side, so
|
|
16
|
+
* registration order cannot matter; generated code only reads it where a refresh
|
|
17
|
+
* subscription is opened.
|
|
18
|
+
*/
|
|
19
|
+
const ERROR_REPORT_PROPERTY = `${INTERNAL_PREFIX}reportError`;
|
|
20
|
+
/**
|
|
21
|
+
* Whether any component in the module registers an `onError` handler
|
|
22
|
+
* (`16b-EB`). The registration AND the update-phase sink ride the host-record
|
|
23
|
+
* literals only for such a module, so every other module keeps its exact bytes
|
|
24
|
+
* (including every `guardUpdate` call, which stays a two-name call).
|
|
25
|
+
*/
|
|
26
|
+
function moduleUsesErrorBoundary(state) {
|
|
27
|
+
for (const component of state.componentByName.values()) if (component.lifecycle.some((hook) => hook.kind === "error")) return true;
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The M02 marked-printer placeholder for a JSX value lowered inside an
|
|
32
|
+
* expression (`__oe_recipe_ref("id")`). The function model keeps the recipe
|
|
33
|
+
* identity for the M02 §recipe model, but the generated leaf module can only
|
|
34
|
+
* execute recipes created by a direct component-local JSX initializer, so any
|
|
35
|
+
* lowered record carrying this placeholder fails closed.
|
|
36
|
+
*/
|
|
37
|
+
const RECIPE_REFERENCE_CALLEE = "__oe_recipe_ref";
|
|
38
|
+
/**
|
|
39
|
+
* Module-level component mount (M06b1a-1): `<Name>__mount(scope, props, host)`.
|
|
40
|
+
* The mount builds one detached instance and returns its top-level nodes; both
|
|
41
|
+
* the exported root factory and every component-reference call site delegate to
|
|
42
|
+
* it, so one component body is emitted exactly once per module.
|
|
43
|
+
*/
|
|
44
|
+
const MOUNT_SUFFIX = "__mount";
|
|
45
|
+
/** Fixed module-level mount parameters; they define the emitted host record shape. */
|
|
46
|
+
const MOUNT_SCOPE = `${INTERNAL_PREFIX}scope`;
|
|
47
|
+
const MOUNT_PROPS = `${INTERNAL_PREFIX}props`;
|
|
48
|
+
const MOUNT_HOST = `${INTERNAL_PREFIX}host`;
|
|
49
|
+
/**
|
|
50
|
+
* Module-level claim (M07a): `<Name>__claim(scope, props, host, parent)` adopts
|
|
51
|
+
* the existing children of `parent`. Emitted only for the static leaf shape.
|
|
52
|
+
*/
|
|
53
|
+
const CLAIM_SUFFIX = "__claim";
|
|
54
|
+
/** Static SSR producer (M08-1a): `<Name>__ssr()` returns the mount HTML. */
|
|
55
|
+
const SSR_SUFFIX = "__ssr";
|
|
56
|
+
/**
|
|
57
|
+
* M08 composition SSR: the third parameter of the module-local
|
|
58
|
+
* `__oe_ssrComponent_<Component>` helper. It renders the children recipe a
|
|
59
|
+
* `<Frame>…</Frame>` reference passed, once per `{props.children}` projection.
|
|
60
|
+
* The exported `<Name>__ssr(props, host)` wrapper passes null, so a root
|
|
61
|
+
* instance of a children-projecting component still fails closed.
|
|
62
|
+
*/
|
|
63
|
+
const SSR_CHILDREN_RENDER = `${INTERNAL_PREFIX}renderChildren`;
|
|
64
|
+
/** Module-local helper name prefix for a composition component (`__oe_ssrComponent_<Name>`). */
|
|
65
|
+
const SSR_HELPER_PREFIX = `${INTERNAL_PREFIX}ssrComponent_`;
|
|
66
|
+
const CLAIM_PARENT = `${INTERNAL_PREFIX}parent`;
|
|
67
|
+
/**
|
|
68
|
+
* The module-level mount's host record: the parent-provided host bindings plus
|
|
69
|
+
* the defining-scope signals a child instance refreshes props reads through.
|
|
70
|
+
* The root factory supplies `[host.propsChanged]`; a component-reference call
|
|
71
|
+
* site supplies the parent bindings its prop expressions depend on.
|
|
72
|
+
*/
|
|
73
|
+
const MOUNT_DEP_LOOP = `${INTERNAL_PREFIX}propDep`;
|
|
74
|
+
const IDENTIFIER_PATTERN = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
75
|
+
const TAG_PATTERN = /^[a-z][a-z0-9-]*$/;
|
|
76
|
+
const ATTRIBUTE_PATTERN = /^[A-Za-z_:][A-Za-z0-9_:.-]*$/;
|
|
77
|
+
/**
|
|
78
|
+
* Dynamic intrinsic-element channels the generated leaf can install. `event`
|
|
79
|
+
* and `ref` are client-only attachment channels: they never become DOM
|
|
80
|
+
* attributes and never render SSR bytes.
|
|
81
|
+
*/
|
|
82
|
+
const ADMITTED_ATTRIBUTE_CHANNELS = /* @__PURE__ */ new Set([
|
|
83
|
+
"attribute",
|
|
84
|
+
"boolean",
|
|
85
|
+
"property",
|
|
86
|
+
"event",
|
|
87
|
+
"ref"
|
|
88
|
+
]);
|
|
89
|
+
/**
|
|
90
|
+
* The channels a component REFERENCE may pass as props. Event/ref stay refused
|
|
91
|
+
* here: a child callback prop would be a second callback API, not the
|
|
92
|
+
* intrinsic DOM-handler/ref channel this slice admits.
|
|
93
|
+
*/
|
|
94
|
+
const COMPONENT_PROP_ATTRIBUTE_CHANNELS = /* @__PURE__ */ new Set([
|
|
95
|
+
"attribute",
|
|
96
|
+
"boolean",
|
|
97
|
+
"property"
|
|
98
|
+
]);
|
|
99
|
+
/** Attributes the compiler consumes as identity (never a DOM write). */
|
|
100
|
+
const CONSUMED_ATTRIBUTE_CHANNELS = /* @__PURE__ */ new Set(["key"]);
|
|
101
|
+
/**
|
|
102
|
+
* Client-only attachment channels: installed as listeners/handlers on the
|
|
103
|
+
* created/adopted element, excluded from SSR bytes and from the claim's
|
|
104
|
+
* attribute seed, and never DOM attributes. They are event handlers (called
|
|
105
|
+
* with the native event) and ref handlers (called with the element on attach,
|
|
106
|
+
* with the returned cleanup on detach, then with null).
|
|
107
|
+
*/
|
|
108
|
+
const CLIENT_ONLY_ATTRIBUTE_CHANNELS = /* @__PURE__ */ new Set(["event", "ref"]);
|
|
109
|
+
const importContexts = /* @__PURE__ */ new WeakMap();
|
|
110
|
+
function importContextOf(component) {
|
|
111
|
+
return importContexts.get(component);
|
|
112
|
+
}
|
|
113
|
+
function diag(state, code, message, span) {
|
|
114
|
+
state.diagnostics.push({
|
|
115
|
+
severity: "error",
|
|
116
|
+
code,
|
|
117
|
+
message,
|
|
118
|
+
span,
|
|
119
|
+
origin: "ir-object"
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
function currentColumn(state) {
|
|
123
|
+
return state.indent * 2;
|
|
124
|
+
}
|
|
125
|
+
/** Real newlines in one emitted line element (a multi-line lowered expression). */
|
|
126
|
+
function countLineBreaks(line) {
|
|
127
|
+
let count = 0;
|
|
128
|
+
for (const character of line) if (character === "\n") count += 1;
|
|
129
|
+
return count;
|
|
130
|
+
}
|
|
131
|
+
/** Physical lines a generated fragment occupies (elements may contain newlines). */
|
|
132
|
+
function fragmentLineCount(lines) {
|
|
133
|
+
let count = 0;
|
|
134
|
+
for (const line of lines) count += 1 + countLineBreaks(line);
|
|
135
|
+
return count;
|
|
136
|
+
}
|
|
137
|
+
function addSegment(state, generatedLine, generatedColumn, sourceLine, sourceColumn, name) {
|
|
138
|
+
const key = `${generatedLine}:${generatedColumn}`;
|
|
139
|
+
if (state.segmentKeys.has(key)) return;
|
|
140
|
+
state.segmentKeys.add(key);
|
|
141
|
+
state.segments.push({
|
|
142
|
+
generatedLine,
|
|
143
|
+
generatedColumn,
|
|
144
|
+
sourceLine,
|
|
145
|
+
sourceColumn,
|
|
146
|
+
...name === void 0 ? {} : { name }
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
/** Append one generated line; an authored anchor maps its start position. */
|
|
150
|
+
function push(state, text, anchor) {
|
|
151
|
+
const lineNumber = state.physicalLine + 1;
|
|
152
|
+
if (anchor !== void 0) addSegment(state, lineNumber, 0, anchor.line, anchor.column - 1);
|
|
153
|
+
const line = `${" ".repeat(state.indent)}${text}`;
|
|
154
|
+
state.lines.push(line);
|
|
155
|
+
state.physicalLine += 1 + countLineBreaks(line);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Append one generated line containing lowered expression text: the placement
|
|
159
|
+
* is recorded and the A2 expression segments are rebased into module
|
|
160
|
+
* coordinates (multi-line lowering keeps later lines at their own columns).
|
|
161
|
+
*/
|
|
162
|
+
function pushParts(state, parts, anchor) {
|
|
163
|
+
const lineNumber = state.physicalLine + 1;
|
|
164
|
+
let column = currentColumn(state);
|
|
165
|
+
let text = " ".repeat(state.indent);
|
|
166
|
+
if (anchor !== void 0) addSegment(state, lineNumber, column, anchor.line, anchor.column - 1);
|
|
167
|
+
for (const part of parts) {
|
|
168
|
+
if (typeof part === "string") {
|
|
169
|
+
text += part;
|
|
170
|
+
column += part.length;
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
const record = part.record;
|
|
174
|
+
const lowered = record.lowered.trim();
|
|
175
|
+
const startLine = lineNumber;
|
|
176
|
+
const startColumn = column;
|
|
177
|
+
addSegment(state, startLine, startColumn, record.authoredSpan.line, record.authoredSpan.column - 1);
|
|
178
|
+
state.placements.push({
|
|
179
|
+
exprId: record.id,
|
|
180
|
+
generatedLine: startLine,
|
|
181
|
+
generatedColumn: startColumn,
|
|
182
|
+
authoredLine: record.authoredSpan.line,
|
|
183
|
+
authoredColumn: record.authoredSpan.column - 1
|
|
184
|
+
});
|
|
185
|
+
for (const segment of record.segments) addSegment(state, startLine + segment.generatedLine - 1, segment.generatedLine === 1 ? startColumn + segment.generatedColumn : segment.generatedColumn, segment.sourceLine, segment.sourceColumn, segment.name);
|
|
186
|
+
text += lowered;
|
|
187
|
+
const lines = lowered.split("\n");
|
|
188
|
+
column = lines.length === 1 ? startColumn + lowered.length : lines[lines.length - 1].length;
|
|
189
|
+
}
|
|
190
|
+
state.lines.push(text);
|
|
191
|
+
state.physicalLine += 1 + countLineBreaks(text);
|
|
192
|
+
}
|
|
193
|
+
/** Register one generated refresh function with the enclosing entry builder. */
|
|
194
|
+
function registerRefresh(state, name) {
|
|
195
|
+
const collector = state.refreshStack[state.refreshStack.length - 1];
|
|
196
|
+
if (collector !== void 0) collector.push(name);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* True when the record reads a name bound by an enclosing list-entry builder
|
|
200
|
+
* (the mapper parameter). Such a read has no reactive dependency: a keyed reuse
|
|
201
|
+
* or an unkeyed positional reuse re-binds the parameter through
|
|
202
|
+
* `update(next)`. A zero-dependency slot that reads an entry-local name must
|
|
203
|
+
* therefore still register a refresh closure, otherwise it keeps the first
|
|
204
|
+
* snapshot (the M06b2c defect).
|
|
205
|
+
*/
|
|
206
|
+
function readsEntryLocal(state, record) {
|
|
207
|
+
if (state.refreshStack.length === 0) return false;
|
|
208
|
+
return record.reads.some((read) => state.entryNames.has(read.name) || state.entryNames.has(read.binding.name));
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Emit `function <refresh>() { <write> } <refresh>();` and return the refresh
|
|
212
|
+
* name. The caller decides whether it registers with the enclosing entry builder
|
|
213
|
+
* and whether dependency subscriptions are added (zero-dependency vs tracked).
|
|
214
|
+
*/
|
|
215
|
+
function emitLocalRefresh(state, anchor, write) {
|
|
216
|
+
const refresh = nextName(state, "refresh");
|
|
217
|
+
push(state, `function ${refresh}() {`, anchor);
|
|
218
|
+
state.indent += 1;
|
|
219
|
+
write();
|
|
220
|
+
state.indent -= 1;
|
|
221
|
+
push(state, `}`);
|
|
222
|
+
push(state, `${refresh}();`);
|
|
223
|
+
return refresh;
|
|
224
|
+
}
|
|
225
|
+
function nextName(state, prefix) {
|
|
226
|
+
return `${INTERNAL_PREFIX}${prefix}${state.counter.value++}`;
|
|
227
|
+
}
|
|
228
|
+
function toIrSpan(ref) {
|
|
229
|
+
return ref.span;
|
|
230
|
+
}
|
|
231
|
+
function bindingKey(id) {
|
|
232
|
+
return `${id.scope.path}#${id.name}#${id.declarationOrder}`;
|
|
233
|
+
}
|
|
234
|
+
function recordFor(state, ref, records) {
|
|
235
|
+
const record = records.get(ref.id);
|
|
236
|
+
if (record === void 0) {
|
|
237
|
+
diag(state, "OEIR_LEAF_MISSING_EXPRESSION", `expression ${ref.id} is not in the registry`, {
|
|
238
|
+
file: "",
|
|
239
|
+
start: 0,
|
|
240
|
+
end: 0,
|
|
241
|
+
line: 1,
|
|
242
|
+
column: 1
|
|
243
|
+
});
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
if (record.lowered.includes("__oe_recipe_ref")) {
|
|
247
|
+
diag(state, "OEIR_LEAF_UNSUPPORTED_RECIPE", "a JSX value inside an expression lowers to a recipe reference, but this slice only admits direct component-local JSX initializers (`const x = <div/>;` + `{x}`); move the JSX to a direct initializer or keep it as a JSX child", toIrSpan(ref));
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
return record;
|
|
251
|
+
}
|
|
252
|
+
/** Declare the host bindings an expression reads (prologue) and validate names. */
|
|
253
|
+
function declareReads(state, record, localCaptures) {
|
|
254
|
+
for (const read of record.reads) {
|
|
255
|
+
if (localCaptures?.has(read.name) || localCaptures?.has(read.binding.name)) continue;
|
|
256
|
+
if (state.entryNames.has(read.name) || state.entryNames.has(read.binding.name)) continue;
|
|
257
|
+
if (read.name === "props" || read.binding.name === "props") {
|
|
258
|
+
if (state.propsName === null) {
|
|
259
|
+
diag(state, "OEIR_LEAF_UNSUPPORTED_PROPS", "the leaf slice needs a named props parameter", toIrSpan({
|
|
260
|
+
id: record.id,
|
|
261
|
+
mode: record.mode,
|
|
262
|
+
span: record.authoredSpan
|
|
263
|
+
}));
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
state.requiredProps.add(state.propsName);
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
if (state.localResources.has(read.name) || state.hostBindings.has(read.name)) continue;
|
|
270
|
+
if (state.recipeNames.has(read.name)) {
|
|
271
|
+
diag(state, "OEIR_LEAF_UNSUPPORTED_RECIPE", `'${read.name}' is a reusable JSX value; it can only be projected with {${read.name}} in JSX child position, not read as an expression value`, toIrSpan({
|
|
272
|
+
id: record.id,
|
|
273
|
+
mode: record.mode,
|
|
274
|
+
span: record.authoredSpan
|
|
275
|
+
}));
|
|
276
|
+
return false;
|
|
277
|
+
}
|
|
278
|
+
if (!IDENTIFIER_PATTERN.test(read.name) || read.name.startsWith("__oe_")) {
|
|
279
|
+
diag(state, "OEIR_LEAF_INVALID_BINDING", `binding '${read.name}' is not a usable identifier`, toIrSpan({
|
|
280
|
+
id: record.id,
|
|
281
|
+
mode: record.mode,
|
|
282
|
+
span: record.authoredSpan
|
|
283
|
+
}));
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
const imported = importContextOf(state.component)?.byLocal.get(read.name);
|
|
287
|
+
if (imported !== void 0) {
|
|
288
|
+
importContextOf(state.component).used.set(`${imported.specifier}#${imported.imported}#${imported.local}`, imported);
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
const resource = state.component.resources.find((candidate) => candidate.name === read.name);
|
|
292
|
+
if (resource !== void 0 && resource.kind === "ref") {
|
|
293
|
+
state.localResources.add(read.name);
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
if (resource !== void 0 && resource.kind === "context") {
|
|
297
|
+
state.localResources.add(read.name);
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
if (resource !== void 0 && resource.kind !== "local") {
|
|
301
|
+
state.hostBindings.add(read.name);
|
|
302
|
+
state.requiredBindings.add(read.name);
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
if (resource !== void 0 && resource.kind === "local") {
|
|
306
|
+
state.localResources.add(read.name);
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
309
|
+
if (read.value === "plain" && read.binding.name === read.name && read.binding.scope.path === "global") continue;
|
|
310
|
+
state.hostBindings.add(read.name);
|
|
311
|
+
state.requiredBindings.add(read.name);
|
|
312
|
+
}
|
|
313
|
+
return true;
|
|
314
|
+
}
|
|
315
|
+
function dependencyNames(state, record) {
|
|
316
|
+
const byKey = new Map(record.reads.map((read) => [bindingKey(read.binding), read]));
|
|
317
|
+
const names = [];
|
|
318
|
+
for (const id of record.dependencies) {
|
|
319
|
+
const read = byKey.get(bindingKey(id));
|
|
320
|
+
if (read === void 0) {
|
|
321
|
+
diag(state, "OEIR_LEAF_UNSUPPORTED_BINDING", `tracked expression ${record.id} has a dependency outside its reads`, toIrSpan({
|
|
322
|
+
id: record.id,
|
|
323
|
+
mode: record.mode,
|
|
324
|
+
span: record.authoredSpan
|
|
325
|
+
}));
|
|
326
|
+
return null;
|
|
327
|
+
}
|
|
328
|
+
if (state.entryNames.has(read.name) || state.entryNames.has(read.binding.name)) continue;
|
|
329
|
+
const fromProps = read.name === "props" || read.binding.name === "props";
|
|
330
|
+
const local = state.component.resources.some((resource) => resource.kind === "context" && resource.name === read.name);
|
|
331
|
+
if (local) {} else if (fromProps) state.requiresPropsChanged = true;
|
|
332
|
+
else if (!state.hostBindings.has(read.name)) {
|
|
333
|
+
state.hostBindings.add(read.name);
|
|
334
|
+
state.requiredBindings.add(read.name);
|
|
335
|
+
}
|
|
336
|
+
if (!names.some((entry) => entry.name === read.name)) names.push({
|
|
337
|
+
name: read.name,
|
|
338
|
+
fromProps,
|
|
339
|
+
local
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
return names;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Subscribe one generated refresh closure to the signals a slot's expression
|
|
346
|
+
* reads. Props reads refresh through the mount host's `propDeps` (the defining
|
|
347
|
+
* scope's signals: `host.propsChanged` for a root instance, the parent bindings
|
|
348
|
+
* behind the passed prop expressions for a component-reference instance); every
|
|
349
|
+
* other read binds its named host binding directly.
|
|
350
|
+
*/
|
|
351
|
+
function emitDependencySubscriptions(state, dependencies, refreshVar, anchor, options) {
|
|
352
|
+
const handler = options?.ignoreSignalValue === true ? `() => ${refreshVar}()` : refreshVar;
|
|
353
|
+
const guarded = moduleUsesErrorBoundary(state) ? `guardUpdate(${handler}, ${state.hostVar}.${ERROR_REPORT_PROPERTY})` : handler;
|
|
354
|
+
for (const dependency of dependencies) {
|
|
355
|
+
if (dependency.fromProps) {
|
|
356
|
+
push(state, `for (const ${MOUNT_DEP_LOOP} of ${state.hostVar}.propDeps) bindSignalWrites(${state.scopeVar}, ${MOUNT_DEP_LOOP}, ${JSON.stringify(dependency.name)}, ${guarded});`, anchor);
|
|
357
|
+
continue;
|
|
358
|
+
}
|
|
359
|
+
push(state, `bindSignalWrites(${state.scopeVar}, ${dependency.name}, ${JSON.stringify(dependency.name)}, ${guarded});`, anchor);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
/** Validate one prop of a component reference; `key` is consumed before this. */
|
|
363
|
+
function componentPropAdmitted(state, attribute, componentName, span) {
|
|
364
|
+
if (attribute.kind === "static") {
|
|
365
|
+
if (!ATTRIBUTE_PATTERN.test(attribute.name)) {
|
|
366
|
+
diag(state, "OEIR_LEAF_UNSUPPORTED_ATTRIBUTE", `prop name '${attribute.name}' on component '<${componentName}>' is invalid`, span);
|
|
367
|
+
return false;
|
|
368
|
+
}
|
|
369
|
+
return true;
|
|
370
|
+
}
|
|
371
|
+
if (!COMPONENT_PROP_ATTRIBUTE_CHANNELS.has(attribute.channel)) {
|
|
372
|
+
diag(state, "OEIR_LEAF_UNSUPPORTED_ATTRIBUTE", `prop channel '${attribute.channel}' on component '<${componentName}>' is outside the M06b1 slice (class/style/innerHTML/event/ref stay refused)`, span);
|
|
373
|
+
return false;
|
|
374
|
+
}
|
|
375
|
+
return true;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* The optional trailing origin argument: `, { file, line, column }` or empty
|
|
379
|
+
* when the emitter has no authored anchor. Both values are compile-time
|
|
380
|
+
* constants; the runtime never parses a source map. `line`/`column` are the
|
|
381
|
+
* 1-based `SpanLike` values, used as-is.
|
|
382
|
+
*/
|
|
383
|
+
function originArgs(anchor) {
|
|
384
|
+
if (anchor === void 0) return "";
|
|
385
|
+
return `, { file: ${JSON.stringify(anchor.file)}, line: ${anchor.line}, column: ${anchor.column} }`;
|
|
386
|
+
}
|
|
387
|
+
//#endregion
|
|
388
|
+
export { ADMITTED_ATTRIBUTE_CHANNELS, ATTRIBUTE_PATTERN, CLAIM_PARENT, CLAIM_SUFFIX, CLIENT_ONLY_ATTRIBUTE_CHANNELS, CONSUMED_ATTRIBUTE_CHANNELS, ERROR_REPORT_PROPERTY, HTML_NAMESPACE, IDENTIFIER_PATTERN, INTERNAL_PREFIX, MOUNT_HOST, MOUNT_PROPS, MOUNT_SCOPE, MOUNT_SUFFIX, RECIPE_REFERENCE_CALLEE, SSR_CHILDREN_RENDER, SSR_HELPER_PREFIX, SSR_SUFFIX, SVG_NAMESPACE, TAG_PATTERN, TRANSACTION_VAR, componentPropAdmitted, declareReads, dependencyNames, diag, emitDependencySubscriptions, emitLocalRefresh, fragmentLineCount, importContextOf, importContexts, moduleUsesErrorBoundary, nextName, originArgs, push, pushParts, readsEntryLocal, recordFor, registerRefresh, toIrSpan };
|