@openelement/compiler 1.0.0-alpha.15 → 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 +3 -2
- package/src/compiler.d.ts +8 -6
- package/src/compiler.js +7 -6
- package/src/internal/compiler/compiled-artifact-class-candidates.d.ts +5 -30
- package/src/internal/compiler/compiled-artifact-class-candidates.js +18 -32
- package/src/internal/compiler/compiled-artifact-style-requests.d.ts +9 -7
- package/src/internal/compiler/compiled-artifact-style-requests.js +9 -7
- package/src/internal/compiler/plugin.d.ts +31 -50
- package/src/internal/compiler/plugin.js +41 -108
- package/src/internal/compiler/semantic-core/analyze-module.d.ts +1 -45
- package/src/internal/compiler/semantic-core/analyze-module.js +10 -405
- 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/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 +51 -0
- package/src/internal/compiler/semantic-core/lower-program.js +186 -90
- package/src/internal/compiler/semantic-core/module-analysis.d.ts +28 -5
- package/src/internal/compiler/semantic-core/module-analysis.js +16 -17
- 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 +22 -7
- package/src/internal/compiler/semantic-core/server-component.js +163 -57
- 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 +0 -8
- package/src/internal/compiler/style-requests.js +1 -14
- package/src/internal/compiler/semantic-core/compile.d.ts +0 -47
- package/src/internal/compiler/semantic-core/compile.js +0 -100
- package/src/internal/compiler/semantic-core/emit-module.js +0 -317
- package/src/internal/compiler/semantic-core/emit-program.js +0 -141
- package/src/internal/compiler/semantic-core/style-imports.js +0 -87
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//#region src/internal/compiler/semantic-ir/generated-leaf/codegen-literals.ts
|
|
2
|
+
/**
|
|
3
|
+
* M09-2c — the generated-leaf code-literal boundary.
|
|
4
|
+
*
|
|
5
|
+
* CodeQL's `js/bad-code-sanitization` rule (CWE-79/94/116) treats a
|
|
6
|
+
* `JSON.stringify` result inserted into generated JavaScript as code
|
|
7
|
+
* construction: a literal containing `<`, `>`, U+2028 or U+2029 can break out
|
|
8
|
+
* of an inline-script context even though it is a valid JavaScript string. The
|
|
9
|
+
* rule's own remediation is the post-stringify escape set below, which the
|
|
10
|
+
* router already implements as
|
|
11
|
+
* `packages/router/src/vite/internal/ssg/codegen-literals.ts`.
|
|
12
|
+
*
|
|
13
|
+
* The generator cannot import that helper: the router depends on the compiler,
|
|
14
|
+
* not the other way round. This module is the compiler-side mirror at the one
|
|
15
|
+
* codegen boundary in this lane (event/ref names and their authored-location
|
|
16
|
+
* error details); it is deliberately the same implementation, not a new
|
|
17
|
+
* sanitizer policy.
|
|
18
|
+
*/
|
|
19
|
+
const UNSAFE_JS_LITERAL_CHARS_RE = /[<>\u2028\u2029]/g;
|
|
20
|
+
const UNSAFE_JS_LITERAL_CHAR_ESCAPES = {
|
|
21
|
+
"<": "\\u003C",
|
|
22
|
+
">": "\\u003E",
|
|
23
|
+
"\u2028": "\\u2028",
|
|
24
|
+
"\u2029": "\\u2029"
|
|
25
|
+
};
|
|
26
|
+
/** Serialize any JSON-serializable value for safe embedding in generated JS. */
|
|
27
|
+
function quoteGeneratedJavaScriptValue(value, space) {
|
|
28
|
+
return JSON.stringify(value, null, space).replace(UNSAFE_JS_LITERAL_CHARS_RE, (char) => UNSAFE_JS_LITERAL_CHAR_ESCAPES[char]);
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { quoteGeneratedJavaScriptValue };
|
|
@@ -0,0 +1,647 @@
|
|
|
1
|
+
import { CLAIM_SUFFIX, ERROR_REPORT_PROPERTY, IDENTIFIER_PATTERN, INTERNAL_PREFIX, MOUNT_HOST, MOUNT_PROPS, MOUNT_SCOPE, MOUNT_SUFFIX, TRANSACTION_VAR, declareReads, diag, fragmentLineCount, moduleUsesErrorBoundary, push, pushParts, recordFor, toIrSpan } from "./emission.js";
|
|
2
|
+
import { assertTextBoundaryContext, componentClaimable, componentProjectsChildren, emissionNodes, staticElementDirectory, textSlotOrdinals } from "./structure.js";
|
|
3
|
+
import { CONTEXT_SCOPE_PROPERTY, ERROR_HANDLER_PROPERTY, GENERATED_CONTEXT_SCOPE_RECORD, GENERATED_ROOT_CONNECT_ENV_RECORD, GENERATED_ROOT_CONNECT_RECORD, GENERATED_ROOT_INSTANCE_NAME, HOST_ELEMENT_PROPERTY, LEAF_SETUP_HOST_PROPERTY, LEAF_SETUP_SUFFIX, PROPERTY_CHANGE_PROPERTY, ROOT_SETUP_HOST_PROPERTY, ROOT_SETUP_RECORD, ROOT_SETUP_REQUIRE, STATES_PROPERTY, TEARDOWN_SIGNAL_VAR, componentUsesContextIntrinsic, emitContextProviders, emitContextScopeDeclaration, emitJoinTransaction, emitLifecycleEnvReplay, emitLifecycleReplay, emitSetupAlias, emitSetupBinding, moduleUsesContext, moduleUsesHostAccess, moduleUsesLifecycleEnv, moduleUsesPropertyChange } from "./instance-emission.js";
|
|
4
|
+
import { appendSinkToArray, emitMountedDirectory, emitNode, emitRecipes } from "./mount-emission.js";
|
|
5
|
+
import { emitClaimFunction } from "./claim-emission.js";
|
|
6
|
+
import { emitSsrFunction } from "./server-emission.js";
|
|
7
|
+
//#region src/internal/compiler/semantic-ir/generated-leaf/component-emission.ts
|
|
8
|
+
function emitDisposeHook(state, hook) {
|
|
9
|
+
if (hook.receivesEnv) {
|
|
10
|
+
pushParts(state, [
|
|
11
|
+
`${INTERNAL_PREFIX}owner.add(() => (`,
|
|
12
|
+
{ record: hook.record },
|
|
13
|
+
`)({ host: ${MOUNT_HOST}.${HOST_ELEMENT_PROPERTY}, signal: ${TEARDOWN_SIGNAL_VAR}, states: ${MOUNT_HOST}.${STATES_PROPERTY} }));`
|
|
14
|
+
], hook.span);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
pushParts(state, [
|
|
18
|
+
`${INTERNAL_PREFIX}owner.add((`,
|
|
19
|
+
{ record: hook.record },
|
|
20
|
+
"));"
|
|
21
|
+
], hook.span);
|
|
22
|
+
}
|
|
23
|
+
function prepareDisposeHooks(state, hooks) {
|
|
24
|
+
if (hooks.some((hook) => hook.receivesEnv)) push(state, `const ${TEARDOWN_SIGNAL_VAR} = ${INTERNAL_PREFIX}owner.signal;`);
|
|
25
|
+
}
|
|
26
|
+
function setupOrder(span) {
|
|
27
|
+
return span.line * 1e5 + span.column;
|
|
28
|
+
}
|
|
29
|
+
/** Register a disposer before any later initializer that might throw. */
|
|
30
|
+
function emitSetupSteps(state, declarations, hooks) {
|
|
31
|
+
const last = declarations.at(-1);
|
|
32
|
+
if (last === void 0 || hooks.every((hook) => setupOrder(hook.span) >= last.order)) {
|
|
33
|
+
for (const declaration of declarations) declaration.emit();
|
|
34
|
+
return hooks;
|
|
35
|
+
}
|
|
36
|
+
prepareDisposeHooks(state, hooks);
|
|
37
|
+
const steps = [...declarations, ...hooks.map((hook) => ({
|
|
38
|
+
order: setupOrder(hook.span),
|
|
39
|
+
emit: () => emitDisposeHook(state, hook)
|
|
40
|
+
}))];
|
|
41
|
+
steps.sort((left, right) => left.order - right.order);
|
|
42
|
+
for (const step of steps) step.emit();
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
function emitComponent(file, component, records, componentByName, sharedClaimCursor, rootInstance, retention, claimStyleLinkPrefix, lightRoot) {
|
|
46
|
+
const propsName = component.propsParam;
|
|
47
|
+
const projectsChildren = componentProjectsChildren(component);
|
|
48
|
+
const declaredRecipeIds = /* @__PURE__ */ new Set();
|
|
49
|
+
const recipeNames = /* @__PURE__ */ new Set();
|
|
50
|
+
for (const resource of component.resources) {
|
|
51
|
+
if (resource.recipeId === null) continue;
|
|
52
|
+
declaredRecipeIds.add(resource.recipeId);
|
|
53
|
+
recipeNames.add(resource.name);
|
|
54
|
+
}
|
|
55
|
+
const claimable = componentClaimable(component, {
|
|
56
|
+
componentByName,
|
|
57
|
+
stack: /* @__PURE__ */ new Set()
|
|
58
|
+
});
|
|
59
|
+
const state = {
|
|
60
|
+
component,
|
|
61
|
+
lines: [],
|
|
62
|
+
physicalLine: 0,
|
|
63
|
+
indent: 1,
|
|
64
|
+
diagnostics: [],
|
|
65
|
+
requiredBindings: /* @__PURE__ */ new Set(),
|
|
66
|
+
requiredProps: /* @__PURE__ */ new Set(),
|
|
67
|
+
hostBindings: /* @__PURE__ */ new Set(),
|
|
68
|
+
localResources: /* @__PURE__ */ new Set(),
|
|
69
|
+
counter: { value: 0 },
|
|
70
|
+
propsName,
|
|
71
|
+
requiresPropsChanged: false,
|
|
72
|
+
segments: [],
|
|
73
|
+
placements: [],
|
|
74
|
+
segmentKeys: /* @__PURE__ */ new Set(),
|
|
75
|
+
scopeVar: MOUNT_SCOPE,
|
|
76
|
+
hostVar: MOUNT_HOST,
|
|
77
|
+
componentByName,
|
|
78
|
+
declaredRecipeIds,
|
|
79
|
+
recipeNames,
|
|
80
|
+
recipeVars: /* @__PURE__ */ new Map(),
|
|
81
|
+
entryNames: /* @__PURE__ */ new Set(),
|
|
82
|
+
refreshStack: [],
|
|
83
|
+
listDepth: 0,
|
|
84
|
+
recipeDepth: 0,
|
|
85
|
+
childrenRecipeVar: projectsChildren ? `${INTERNAL_PREFIX}childrenRecipe` : null,
|
|
86
|
+
ssrRecipeVars: /* @__PURE__ */ new Map(),
|
|
87
|
+
ssrChildrenRenderVar: null,
|
|
88
|
+
directorySource: `${file}#${component.name}`,
|
|
89
|
+
usesStaticSiblingDirectoryConsumer: false,
|
|
90
|
+
claimCursorShared: false,
|
|
91
|
+
claimStyleLinkPrefix: false,
|
|
92
|
+
claimAdoptedVar: null,
|
|
93
|
+
claimActivationVar: null,
|
|
94
|
+
usesClaimRecipe: false,
|
|
95
|
+
emitDirectoryMarkers: claimable,
|
|
96
|
+
emitTextBoundaries: claimable,
|
|
97
|
+
textOrdinals: textSlotOrdinals(component.roots),
|
|
98
|
+
claimEntry: null,
|
|
99
|
+
usesLeafClaimMismatch: false,
|
|
100
|
+
retention,
|
|
101
|
+
retainBody: retention !== null && retention.rootName === component.name,
|
|
102
|
+
leafBody: retention?.leafBodies.has(component.name) === true,
|
|
103
|
+
retainsChildren: retention?.retainingBodies.has(component.name) === true,
|
|
104
|
+
claimTimeRecipeDepth: 0
|
|
105
|
+
};
|
|
106
|
+
if (claimable && !assertTextBoundaryContext(state, component.roots)) return {
|
|
107
|
+
lines: [],
|
|
108
|
+
diagnostics: state.diagnostics,
|
|
109
|
+
requiredBindings: [],
|
|
110
|
+
requiredProps: [],
|
|
111
|
+
requiresPropsChanged: false,
|
|
112
|
+
rootInstanceFactory: null,
|
|
113
|
+
segments: [],
|
|
114
|
+
placements: []
|
|
115
|
+
};
|
|
116
|
+
if (propsName !== null && (!IDENTIFIER_PATTERN.test(propsName) || propsName.startsWith("__oe_"))) diag(state, "OEIR_LEAF_INVALID_BINDING", `props parameter '${propsName}' is not usable`, {
|
|
117
|
+
file,
|
|
118
|
+
start: 0,
|
|
119
|
+
end: 0,
|
|
120
|
+
line: 1,
|
|
121
|
+
column: 1
|
|
122
|
+
});
|
|
123
|
+
const localLines = [];
|
|
124
|
+
for (const resource of component.resources) {
|
|
125
|
+
if (!IDENTIFIER_PATTERN.test(resource.name) || resource.name.startsWith("__oe_")) {
|
|
126
|
+
diag(state, "OEIR_LEAF_INVALID_BINDING", `resource '${resource.name}' is not usable`, resource.span);
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (resource.kind === "ref") {
|
|
130
|
+
if (resource.expression === null) {
|
|
131
|
+
localLines.push({
|
|
132
|
+
name: resource.name,
|
|
133
|
+
kind: "ref",
|
|
134
|
+
record: null,
|
|
135
|
+
span: resource.span
|
|
136
|
+
});
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
const record = recordFor(state, resource.expression, records);
|
|
140
|
+
if (record === null || !declareReads(state, record)) continue;
|
|
141
|
+
state.localResources.add(resource.name);
|
|
142
|
+
localLines.push({
|
|
143
|
+
name: resource.name,
|
|
144
|
+
kind: "ref",
|
|
145
|
+
record,
|
|
146
|
+
span: resource.span
|
|
147
|
+
});
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (resource.kind === "host") {
|
|
151
|
+
state.localResources.add(resource.name);
|
|
152
|
+
localLines.push({
|
|
153
|
+
name: resource.name,
|
|
154
|
+
kind: "host",
|
|
155
|
+
record: null,
|
|
156
|
+
span: resource.span
|
|
157
|
+
});
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
if (resource.kind === "context") {
|
|
161
|
+
if (resource.expression === null) continue;
|
|
162
|
+
const record = recordFor(state, resource.expression, records);
|
|
163
|
+
if (record === null || !declareReads(state, record)) continue;
|
|
164
|
+
state.localResources.add(resource.name);
|
|
165
|
+
localLines.push({
|
|
166
|
+
name: resource.name,
|
|
167
|
+
kind: "context",
|
|
168
|
+
record,
|
|
169
|
+
span: resource.span
|
|
170
|
+
});
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
if (resource.kind === "local") {
|
|
174
|
+
if (resource.recipeId !== null || resource.expression === null) continue;
|
|
175
|
+
const record = recordFor(state, resource.expression, records);
|
|
176
|
+
if (record === null) continue;
|
|
177
|
+
if (!declareReads(state, record)) continue;
|
|
178
|
+
state.localResources.add(resource.name);
|
|
179
|
+
localLines.push({
|
|
180
|
+
name: resource.name,
|
|
181
|
+
kind: "local",
|
|
182
|
+
record,
|
|
183
|
+
span: resource.span
|
|
184
|
+
});
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
state.hostBindings.add(resource.name);
|
|
188
|
+
state.requiredBindings.add(resource.name);
|
|
189
|
+
}
|
|
190
|
+
if (state.diagnostics.length > 0) return {
|
|
191
|
+
lines: [],
|
|
192
|
+
diagnostics: state.diagnostics,
|
|
193
|
+
requiredBindings: [],
|
|
194
|
+
requiredProps: [],
|
|
195
|
+
requiresPropsChanged: false,
|
|
196
|
+
rootInstanceFactory: null,
|
|
197
|
+
segments: [],
|
|
198
|
+
placements: []
|
|
199
|
+
};
|
|
200
|
+
if (!IDENTIFIER_PATTERN.test(component.name) || component.name.startsWith("__oe_")) {
|
|
201
|
+
diag(state, "OEIR_LEAF_INVALID_COMPONENT", `component '${component.name}' is not usable`, component.span);
|
|
202
|
+
return {
|
|
203
|
+
lines: [],
|
|
204
|
+
diagnostics: state.diagnostics,
|
|
205
|
+
requiredBindings: [],
|
|
206
|
+
requiredProps: [],
|
|
207
|
+
requiresPropsChanged: false,
|
|
208
|
+
rootInstanceFactory: null,
|
|
209
|
+
segments: [],
|
|
210
|
+
placements: []
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
const rootBindingResources = rootInstance === component.name ? component.resources.filter((resource) => (resource.kind === "signal" || resource.kind === "computed") && resource.expression !== null) : [];
|
|
214
|
+
const rootBindingNames = new Set(rootBindingResources.map((resource) => resource.name));
|
|
215
|
+
const rootSetupCaptures = rootBindingNames;
|
|
216
|
+
const hookReadsHostBinding = (record) => record.reads.some((read) => !rootSetupCaptures.has(read.name) && !rootSetupCaptures.has(read.binding.name) && (state.hostBindings.has(read.name) || state.hostBindings.has(read.binding.name) || state.requiredBindings.has(read.name) || state.requiredBindings.has(read.binding.name)));
|
|
217
|
+
const carriedByOwner = rootInstance === component.name || state.leafBody && state.retention?.setupBodies.has(component.name) === true;
|
|
218
|
+
if (componentUsesContextIntrinsic(component) && !carriedByOwner) {
|
|
219
|
+
const span = componentUsesContextIntrinsic(component) ? component.contextProviders[0]?.span ?? component.resources.find((resource) => resource.kind === "context")?.span ?? component.span : component.span;
|
|
220
|
+
diag(state, "OEIR_LEAF_INVALID_ARTIFACT", "a context intrinsic needs an owner scope: context is carried only by the generated element ROOT setup or a RETAINED hostless body setup (any depth, direct hostless references only); recipe/list bodies and a component no retained body references fail closed", toIrSpan({
|
|
221
|
+
id: "context",
|
|
222
|
+
mode: "setup",
|
|
223
|
+
span
|
|
224
|
+
}));
|
|
225
|
+
}
|
|
226
|
+
const admittedHooks = [];
|
|
227
|
+
for (const hook of component.lifecycle) {
|
|
228
|
+
const record = recordFor(state, hook.callback, records);
|
|
229
|
+
if (record === null || !declareReads(state, record, rootSetupCaptures)) continue;
|
|
230
|
+
if (hookReadsHostBinding(record)) continue;
|
|
231
|
+
const carriedByRoot = rootInstance === component.name;
|
|
232
|
+
const carriedByLeaf = state.leafBody && state.retention?.setupBodies.has(component.name) === true;
|
|
233
|
+
if (!carriedByRoot && !carriedByLeaf) {
|
|
234
|
+
diag(state, "OEIR_LEAF_INVALID_ARTIFACT", `the '${hook.kind}' lifecycle hook has no lifecycle owner: nested hooks are carried only by a RETAINED hostless body setup (any depth, direct hostless references only); recipe/list bodies and a component no retained body references fail closed`, hook.span);
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
admittedHooks.push({
|
|
238
|
+
kind: hook.kind,
|
|
239
|
+
record,
|
|
240
|
+
receivesEnv: hook.receivesEnv,
|
|
241
|
+
span: hook.span
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
if (state.diagnostics.length > 0) return {
|
|
245
|
+
lines: [],
|
|
246
|
+
diagnostics: state.diagnostics,
|
|
247
|
+
requiredBindings: [],
|
|
248
|
+
requiredProps: [],
|
|
249
|
+
requiresPropsChanged: false,
|
|
250
|
+
rootInstanceFactory: null,
|
|
251
|
+
segments: [],
|
|
252
|
+
placements: []
|
|
253
|
+
};
|
|
254
|
+
const connectHooks = admittedHooks.filter((hook) => hook.kind === "connect");
|
|
255
|
+
const disposeHooks = admittedHooks.filter((hook) => hook.kind === "dispose");
|
|
256
|
+
const changeHooks = admittedHooks.filter((hook) => hook.kind === "property-change");
|
|
257
|
+
const errorHooks = admittedHooks.filter((hook) => hook.kind === "error");
|
|
258
|
+
const setupReadsHostBinding = localLines.some((line) => (line.record?.reads ?? []).some((read) => !rootBindingNames.has(read.name) && !rootBindingNames.has(read.binding.name) && (state.hostBindings.has(read.name) || state.hostBindings.has(read.binding.name) || state.requiredBindings.has(read.name) || state.requiredBindings.has(read.binding.name))));
|
|
259
|
+
const providersOnRoot = rootInstance === component.name && componentUsesContextIntrinsic(component);
|
|
260
|
+
const hooksOnRoot = rootInstance === component.name && admittedHooks.length > 0;
|
|
261
|
+
const rootSetup = rootInstance === component.name && (localLines.length > 0 || hooksOnRoot || providersOnRoot || rootBindingResources.length > 0) && !setupReadsHostBinding;
|
|
262
|
+
const aliasesSetupRecord = localLines.length > 0 || componentUsesContextIntrinsic(component);
|
|
263
|
+
if ((hooksOnRoot || providersOnRoot) && !rootSetup) return {
|
|
264
|
+
lines: [],
|
|
265
|
+
diagnostics: [...state.diagnostics, {
|
|
266
|
+
severity: "error",
|
|
267
|
+
code: "OEIR_LEAF_UNSUPPORTED_BINDING",
|
|
268
|
+
message: "the root setup reads a host binding, so the admitted lifecycle hooks and context providers cannot be carried by the retained instance factory; the generated element lane has no binding channel",
|
|
269
|
+
span: {
|
|
270
|
+
file: "",
|
|
271
|
+
start: 0,
|
|
272
|
+
end: 0,
|
|
273
|
+
line: 1,
|
|
274
|
+
column: 1
|
|
275
|
+
},
|
|
276
|
+
origin: "module"
|
|
277
|
+
}],
|
|
278
|
+
requiredBindings: [],
|
|
279
|
+
requiredProps: [],
|
|
280
|
+
requiresPropsChanged: false,
|
|
281
|
+
rootInstanceFactory: null,
|
|
282
|
+
segments: [],
|
|
283
|
+
placements: []
|
|
284
|
+
};
|
|
285
|
+
let setupLines = [];
|
|
286
|
+
let setupSegments = [];
|
|
287
|
+
let setupPlacements = [];
|
|
288
|
+
if (rootSetup) {
|
|
289
|
+
const fixedNames = [
|
|
290
|
+
GENERATED_ROOT_INSTANCE_NAME,
|
|
291
|
+
GENERATED_ROOT_CONNECT_RECORD,
|
|
292
|
+
ROOT_SETUP_RECORD,
|
|
293
|
+
ROOT_SETUP_REQUIRE
|
|
294
|
+
];
|
|
295
|
+
const authoredNames = /* @__PURE__ */ new Set([component.name, ...component.resources.map((resource) => resource.name)]);
|
|
296
|
+
const collision = fixedNames.find((name) => authoredNames.has(name));
|
|
297
|
+
if (collision !== void 0) diag(state, "OEIR_LEAF_INVALID_ARTIFACT", `the root instance setup name '${collision}' collides with an authored identifier`, component.span);
|
|
298
|
+
else if (localLines.some((line) => line.name === propsName)) diag(state, "OEIR_LEAF_INVALID_BINDING", `the root setup local collides with the props parameter '${String(propsName)}'`, component.span);
|
|
299
|
+
if (state.diagnostics.length > 0) return {
|
|
300
|
+
lines: [],
|
|
301
|
+
diagnostics: state.diagnostics,
|
|
302
|
+
requiredBindings: [],
|
|
303
|
+
requiredProps: [],
|
|
304
|
+
requiresPropsChanged: false,
|
|
305
|
+
rootInstanceFactory: null,
|
|
306
|
+
segments: [],
|
|
307
|
+
placements: []
|
|
308
|
+
};
|
|
309
|
+
const setupReadsProps = rootBindingResources.some((resource) => (records.get(resource.expression?.id ?? "")?.reads ?? []).some((read) => read.name === "props" || read.binding.name === "props")) || localLines.some((line) => (line.record?.reads ?? []).some((read) => read.name === "props" || read.binding.name === "props")) || admittedHooks.some((hook) => hook.record.reads.some((read) => read.name === "props" || read.binding.name === "props")) || component.contextProviders.some((provider) => [records.get(provider.token.id), records.get(provider.value.id)].some((record) => (record?.reads ?? []).some((read) => read.name === "props" || read.binding.name === "props"))) || component.resources.some((resource) => resource.kind === "context" && (records.get(resource.expression?.id ?? "")?.reads.some((read) => read.name === "props" || read.binding.name === "props") ?? false));
|
|
310
|
+
const setupPrologue = [`function ${GENERATED_ROOT_INSTANCE_NAME}(${INTERNAL_PREFIX}owner, ${MOUNT_HOST}) {`];
|
|
311
|
+
if (setupReadsProps && propsName !== null) setupPrologue.push(` const ${propsName} = ${MOUNT_HOST}.props;`);
|
|
312
|
+
const setupState = {
|
|
313
|
+
...state,
|
|
314
|
+
lines: [],
|
|
315
|
+
physicalLine: 0,
|
|
316
|
+
segments: [],
|
|
317
|
+
placements: [],
|
|
318
|
+
segmentKeys: /* @__PURE__ */ new Set()
|
|
319
|
+
};
|
|
320
|
+
emitContextScopeDeclaration(setupState, component, false);
|
|
321
|
+
emitContextProviders(setupState, component.contextProviders, records);
|
|
322
|
+
const factoryDecls = [];
|
|
323
|
+
for (const resource of rootBindingResources) {
|
|
324
|
+
const record = recordFor(setupState, resource.expression, records);
|
|
325
|
+
if (record === null || !declareReads(setupState, record)) return {
|
|
326
|
+
lines: [],
|
|
327
|
+
diagnostics: state.diagnostics,
|
|
328
|
+
requiredBindings: [],
|
|
329
|
+
requiredProps: [],
|
|
330
|
+
requiresPropsChanged: false,
|
|
331
|
+
rootInstanceFactory: null,
|
|
332
|
+
segments: [],
|
|
333
|
+
placements: []
|
|
334
|
+
};
|
|
335
|
+
factoryDecls.push({
|
|
336
|
+
name: resource.name,
|
|
337
|
+
order: setupOrder(resource.span),
|
|
338
|
+
emit: () => {
|
|
339
|
+
pushParts(setupState, [
|
|
340
|
+
resource.kind === "computed" ? `const ${resource.name} = computed(` : `const ${resource.name} = signal((`,
|
|
341
|
+
{ record },
|
|
342
|
+
resource.kind === "computed" ? ");" : "));"
|
|
343
|
+
], resource.span);
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
for (const line of localLines) factoryDecls.push({
|
|
348
|
+
name: line.name,
|
|
349
|
+
order: setupOrder(line.span),
|
|
350
|
+
emit: () => emitSetupBinding(setupState, line)
|
|
351
|
+
});
|
|
352
|
+
factoryDecls.sort((left, right) => left.order - right.order);
|
|
353
|
+
const lateDisposeHooks = emitSetupSteps(setupState, factoryDecls, disposeHooks);
|
|
354
|
+
if (connectHooks.length > 0) {
|
|
355
|
+
const legacyConnectHooks = connectHooks.filter((hook) => !hook.receivesEnv);
|
|
356
|
+
const envConnectHooks = connectHooks.filter((hook) => hook.receivesEnv);
|
|
357
|
+
if (legacyConnectHooks.length > 0) push(setupState, `const ${GENERATED_ROOT_CONNECT_RECORD} = [];`);
|
|
358
|
+
for (const hook of legacyConnectHooks) pushParts(setupState, [
|
|
359
|
+
`${GENERATED_ROOT_CONNECT_RECORD}.push((`,
|
|
360
|
+
{ record: hook.record },
|
|
361
|
+
"));"
|
|
362
|
+
], hook.span);
|
|
363
|
+
if (envConnectHooks.length > 0) push(setupState, `const ${GENERATED_ROOT_CONNECT_ENV_RECORD} = [];`);
|
|
364
|
+
for (const hook of envConnectHooks) pushParts(setupState, [
|
|
365
|
+
`${GENERATED_ROOT_CONNECT_ENV_RECORD}.push((`,
|
|
366
|
+
{ record: hook.record },
|
|
367
|
+
"));"
|
|
368
|
+
], hook.span);
|
|
369
|
+
}
|
|
370
|
+
prepareDisposeHooks(setupState, lateDisposeHooks);
|
|
371
|
+
for (const hook of lateDisposeHooks) emitDisposeHook(setupState, hook);
|
|
372
|
+
for (const hook of changeHooks) pushParts(setupState, [
|
|
373
|
+
`if (${MOUNT_HOST}.${PROPERTY_CHANGE_PROPERTY} !== undefined) ${MOUNT_HOST}.${PROPERTY_CHANGE_PROPERTY}((`,
|
|
374
|
+
{ record: hook.record },
|
|
375
|
+
"));"
|
|
376
|
+
], hook.span);
|
|
377
|
+
for (const hook of errorHooks) pushParts(setupState, [
|
|
378
|
+
`if (${MOUNT_HOST}.${ERROR_HANDLER_PROPERTY} !== undefined) ${MOUNT_HOST}.${ERROR_HANDLER_PROPERTY}((`,
|
|
379
|
+
{ record: hook.record },
|
|
380
|
+
"));"
|
|
381
|
+
], hook.span);
|
|
382
|
+
const recordFields = factoryDecls.map((declaration) => declaration.name);
|
|
383
|
+
if (componentUsesContextIntrinsic(component)) recordFields.push(GENERATED_CONTEXT_SCOPE_RECORD);
|
|
384
|
+
if (connectHooks.some((hook) => !hook.receivesEnv)) recordFields.push(GENERATED_ROOT_CONNECT_RECORD);
|
|
385
|
+
if (connectHooks.some((hook) => hook.receivesEnv)) recordFields.push(GENERATED_ROOT_CONNECT_ENV_RECORD);
|
|
386
|
+
const setupReturn = recordFields.length === 0 ? " return {};" : ` return { ${recordFields.join(", ")} };`;
|
|
387
|
+
setupLines = [
|
|
388
|
+
...setupPrologue,
|
|
389
|
+
...setupState.lines,
|
|
390
|
+
setupReturn,
|
|
391
|
+
"}",
|
|
392
|
+
""
|
|
393
|
+
];
|
|
394
|
+
const setupShift = fragmentLineCount(setupPrologue);
|
|
395
|
+
setupSegments = setupState.segments.map((segment) => ({
|
|
396
|
+
...segment,
|
|
397
|
+
generatedLine: segment.generatedLine + setupShift
|
|
398
|
+
}));
|
|
399
|
+
setupPlacements = setupState.placements.map((placement) => ({
|
|
400
|
+
...placement,
|
|
401
|
+
generatedLine: placement.generatedLine + setupShift
|
|
402
|
+
}));
|
|
403
|
+
}
|
|
404
|
+
const leafSetup = state.leafBody && (localLines.length > 0 || admittedHooks.length > 0 || componentUsesContextIntrinsic(component));
|
|
405
|
+
if (leafSetup) {
|
|
406
|
+
const fixedNames = [
|
|
407
|
+
ROOT_SETUP_RECORD,
|
|
408
|
+
ROOT_SETUP_REQUIRE,
|
|
409
|
+
GENERATED_ROOT_CONNECT_RECORD
|
|
410
|
+
];
|
|
411
|
+
const authoredNames = /* @__PURE__ */ new Set([component.name, ...component.resources.map((resource) => resource.name)]);
|
|
412
|
+
const collision = fixedNames.find((name) => authoredNames.has(name));
|
|
413
|
+
if (collision !== void 0) diag(state, "OEIR_LEAF_INVALID_ARTIFACT", `the leaf instance setup name '${collision}' collides with an authored identifier`, component.span);
|
|
414
|
+
else if (propsName !== null && localLines.some((line) => line.name === propsName)) diag(state, "OEIR_LEAF_INVALID_BINDING", `the leaf setup local collides with the props parameter '${String(propsName)}'`, component.span);
|
|
415
|
+
if (state.diagnostics.length > 0) return {
|
|
416
|
+
lines: [],
|
|
417
|
+
diagnostics: state.diagnostics,
|
|
418
|
+
requiredBindings: [],
|
|
419
|
+
requiredProps: [],
|
|
420
|
+
requiresPropsChanged: false,
|
|
421
|
+
rootInstanceFactory: null,
|
|
422
|
+
segments: [],
|
|
423
|
+
placements: []
|
|
424
|
+
};
|
|
425
|
+
const setupReadsProps = localLines.some((line) => (line.record?.reads ?? []).some((read) => read.name === "props" || read.binding.name === "props")) || admittedHooks.some((hook) => hook.record.reads.some((read) => read.name === "props" || read.binding.name === "props")) || component.contextProviders.some((provider) => [records.get(provider.token.id), records.get(provider.value.id)].some((record) => (record?.reads ?? []).some((read) => read.name === "props" || read.binding.name === "props"))) || component.resources.some((resource) => resource.kind === "context" && (records.get(resource.expression?.id ?? "")?.reads.some((read) => read.name === "props" || read.binding.name === "props") ?? false));
|
|
426
|
+
const setupPrologue = [`function ${component.name}${LEAF_SETUP_SUFFIX}(${INTERNAL_PREFIX}owner, ${MOUNT_PROPS}, ${MOUNT_HOST}) {`];
|
|
427
|
+
if (setupReadsProps && propsName !== null) setupPrologue.push(` const ${propsName} = ${MOUNT_PROPS};`);
|
|
428
|
+
const setupState = {
|
|
429
|
+
...state,
|
|
430
|
+
lines: [],
|
|
431
|
+
physicalLine: 0,
|
|
432
|
+
segments: [],
|
|
433
|
+
placements: [],
|
|
434
|
+
segmentKeys: /* @__PURE__ */ new Set()
|
|
435
|
+
};
|
|
436
|
+
emitContextScopeDeclaration(setupState, component, true);
|
|
437
|
+
emitContextProviders(setupState, component.contextProviders, records);
|
|
438
|
+
const lateDisposeHooks = emitSetupSteps(setupState, localLines.map((line) => ({
|
|
439
|
+
order: setupOrder(line.span),
|
|
440
|
+
emit: () => emitSetupBinding(setupState, line)
|
|
441
|
+
})), disposeHooks);
|
|
442
|
+
if (connectHooks.some((hook) => !hook.receivesEnv)) push(setupState, `const ${GENERATED_ROOT_CONNECT_RECORD} = [];`);
|
|
443
|
+
for (const hook of connectHooks) {
|
|
444
|
+
if (hook.receivesEnv) continue;
|
|
445
|
+
pushParts(setupState, [
|
|
446
|
+
`${GENERATED_ROOT_CONNECT_RECORD}.push((`,
|
|
447
|
+
{ record: hook.record },
|
|
448
|
+
"));"
|
|
449
|
+
], hook.span);
|
|
450
|
+
}
|
|
451
|
+
if (connectHooks.some((hook) => hook.receivesEnv)) push(setupState, `const ${GENERATED_ROOT_CONNECT_ENV_RECORD} = [];`);
|
|
452
|
+
for (const hook of connectHooks) {
|
|
453
|
+
if (!hook.receivesEnv) continue;
|
|
454
|
+
pushParts(setupState, [
|
|
455
|
+
`${GENERATED_ROOT_CONNECT_ENV_RECORD}.push((`,
|
|
456
|
+
{ record: hook.record },
|
|
457
|
+
"));"
|
|
458
|
+
], hook.span);
|
|
459
|
+
}
|
|
460
|
+
prepareDisposeHooks(setupState, lateDisposeHooks);
|
|
461
|
+
for (const hook of lateDisposeHooks) emitDisposeHook(setupState, hook);
|
|
462
|
+
for (const hook of changeHooks) pushParts(setupState, [
|
|
463
|
+
`if (${MOUNT_HOST}.${PROPERTY_CHANGE_PROPERTY} !== undefined) ${MOUNT_HOST}.${PROPERTY_CHANGE_PROPERTY}((`,
|
|
464
|
+
{ record: hook.record },
|
|
465
|
+
"));"
|
|
466
|
+
], hook.span);
|
|
467
|
+
for (const hook of errorHooks) pushParts(setupState, [
|
|
468
|
+
`if (${MOUNT_HOST}.${ERROR_HANDLER_PROPERTY} !== undefined) ${MOUNT_HOST}.${ERROR_HANDLER_PROPERTY}((`,
|
|
469
|
+
{ record: hook.record },
|
|
470
|
+
"));"
|
|
471
|
+
], hook.span);
|
|
472
|
+
const setupFields = localLines.map((line) => line.name);
|
|
473
|
+
if (componentUsesContextIntrinsic(component)) setupFields.push(GENERATED_CONTEXT_SCOPE_RECORD);
|
|
474
|
+
if (connectHooks.some((hook) => !hook.receivesEnv)) setupFields.push(GENERATED_ROOT_CONNECT_RECORD);
|
|
475
|
+
if (connectHooks.some((hook) => hook.receivesEnv)) setupFields.push(GENERATED_ROOT_CONNECT_ENV_RECORD);
|
|
476
|
+
const setupReturn = setupFields.length === 0 ? " return {};" : ` return { ${setupFields.join(", ")} };`;
|
|
477
|
+
setupLines = [
|
|
478
|
+
...setupPrologue,
|
|
479
|
+
...setupState.lines,
|
|
480
|
+
setupReturn,
|
|
481
|
+
"}",
|
|
482
|
+
""
|
|
483
|
+
];
|
|
484
|
+
const setupShift = fragmentLineCount(setupPrologue);
|
|
485
|
+
setupSegments = setupState.segments.map((segment) => ({
|
|
486
|
+
...segment,
|
|
487
|
+
generatedLine: segment.generatedLine + setupShift
|
|
488
|
+
}));
|
|
489
|
+
setupPlacements = setupState.placements.map((placement) => ({
|
|
490
|
+
...placement,
|
|
491
|
+
generatedLine: placement.generatedLine + setupShift
|
|
492
|
+
}));
|
|
493
|
+
}
|
|
494
|
+
if (state.retainBody) {
|
|
495
|
+
const beginCall = `beginInstancePass(${MOUNT_HOST}.instance)`;
|
|
496
|
+
push(state, state.retention?.transaction === true ? `const ${TRANSACTION_VAR} = ${beginCall};` : `${beginCall};`);
|
|
497
|
+
}
|
|
498
|
+
push(state, `const ${INTERNAL_PREFIX}nodes = [];`);
|
|
499
|
+
if (rootSetup && aliasesSetupRecord) emitSetupAlias(state, localLines, ROOT_SETUP_HOST_PROPERTY);
|
|
500
|
+
else if (leafSetup && (localLines.length > 0 || componentUsesContextIntrinsic(component))) emitSetupAlias(state, localLines, LEAF_SETUP_HOST_PROPERTY);
|
|
501
|
+
else for (const line of localLines) emitSetupBinding(state, line);
|
|
502
|
+
emitJoinTransaction(state);
|
|
503
|
+
if (state.childrenRecipeVar !== null) {
|
|
504
|
+
push(state, `const ${state.childrenRecipeVar} = ${MOUNT_PROPS}.children;`);
|
|
505
|
+
push(state, `if (${state.childrenRecipeVar} == null || typeof ${state.childrenRecipeVar} !== "object" || typeof ${state.childrenRecipeVar}.mount !== "function" || ${state.childrenRecipeVar}.definitionOwner == null) throw new Error("OEIR_LEAF_MISSING_CHILDREN: component '<${component.name}>' projects props.children but the mounted instance was given no children recipe");`);
|
|
506
|
+
}
|
|
507
|
+
emitRecipes(state, file, records);
|
|
508
|
+
if (state.diagnostics.length > 0) return {
|
|
509
|
+
lines: [],
|
|
510
|
+
diagnostics: state.diagnostics,
|
|
511
|
+
requiredBindings: [],
|
|
512
|
+
requiredProps: [],
|
|
513
|
+
requiresPropsChanged: false,
|
|
514
|
+
rootInstanceFactory: null,
|
|
515
|
+
segments: [],
|
|
516
|
+
placements: []
|
|
517
|
+
};
|
|
518
|
+
const rootDirectory = state.emitDirectoryMarkers ? staticElementDirectory(component.roots) : null;
|
|
519
|
+
if (rootDirectory !== null) emitMountedDirectory(state, rootDirectory, records, {
|
|
520
|
+
kind: "array",
|
|
521
|
+
name: `${INTERNAL_PREFIX}nodes`
|
|
522
|
+
});
|
|
523
|
+
else for (const root of emissionNodes(state, component.roots)) {
|
|
524
|
+
const sink = [];
|
|
525
|
+
emitNode(state, root, sink, records);
|
|
526
|
+
appendSinkToArray(state, sink, `${INTERNAL_PREFIX}nodes`);
|
|
527
|
+
}
|
|
528
|
+
if (state.retainBody) push(state, `endInstancePass(${MOUNT_HOST}.instance);`);
|
|
529
|
+
push(state, `return ${INTERNAL_PREFIX}nodes;`);
|
|
530
|
+
const mountPrologue = [`function ${component.name}${MOUNT_SUFFIX}(${MOUNT_SCOPE}, ${MOUNT_PROPS}, ${MOUNT_HOST}) {`];
|
|
531
|
+
if (propsName !== null) {
|
|
532
|
+
mountPrologue.push(` const ${propsName} = ${MOUNT_PROPS};`);
|
|
533
|
+
state.requiredProps.add(propsName);
|
|
534
|
+
}
|
|
535
|
+
if (state.requiredBindings.size > 0) {
|
|
536
|
+
mountPrologue.push(` const ${INTERNAL_PREFIX}requireBinding = (name) => { const value = ${MOUNT_HOST}.bindings[name]; if (value === undefined) throw new Error("OEIR_LEAF_MISSING_VALUE: " + name); return value; };`);
|
|
537
|
+
for (const binding of [...state.requiredBindings].sort()) mountPrologue.push(` const ${binding} = ${INTERNAL_PREFIX}requireBinding(${JSON.stringify(binding)});`);
|
|
538
|
+
}
|
|
539
|
+
if (connectHooks.some((hook) => !hook.receivesEnv)) for (const line of emitLifecycleReplay(rootSetup ? "bindings" : "setup")) mountPrologue.push(line);
|
|
540
|
+
if (connectHooks.some((hook) => hook.receivesEnv)) for (const line of emitLifecycleEnvReplay(rootSetup ? "bindings" : "setup")) mountPrologue.push(line);
|
|
541
|
+
const mountHostVar = `${INTERNAL_PREFIX}mountHost`;
|
|
542
|
+
const factoryLines = [`export function create${component.name}Recipe(${INTERNAL_PREFIX}owner, ${INTERNAL_PREFIX}host) {`];
|
|
543
|
+
const forwardedInstance = state.retainBody ? `, instance: ${INTERNAL_PREFIX}host.instance` : "";
|
|
544
|
+
const forwardedHostElement = moduleUsesLifecycleEnv(state) || moduleUsesHostAccess(state) ? `, ${HOST_ELEMENT_PROPERTY}: ${INTERNAL_PREFIX}host.${HOST_ELEMENT_PROPERTY}, ${STATES_PROPERTY}: ${INTERNAL_PREFIX}host.${STATES_PROPERTY}` : "";
|
|
545
|
+
const forwardedPropertyChange = moduleUsesPropertyChange(state) ? `, ${PROPERTY_CHANGE_PROPERTY}: ${INTERNAL_PREFIX}host.${PROPERTY_CHANGE_PROPERTY}` : "";
|
|
546
|
+
const forwardedErrorBoundary = moduleUsesErrorBoundary(state) ? `, ${ERROR_HANDLER_PROPERTY}: ${INTERNAL_PREFIX}host.${ERROR_HANDLER_PROPERTY}, ${ERROR_REPORT_PROPERTY}: ${INTERNAL_PREFIX}host.${ERROR_REPORT_PROPERTY}` : "";
|
|
547
|
+
const forwardedContext = moduleUsesContext(state) ? `, ${CONTEXT_SCOPE_PROPERTY}: ${INTERNAL_PREFIX}host.${CONTEXT_SCOPE_PROPERTY}` : "";
|
|
548
|
+
if (state.requiresPropsChanged) {
|
|
549
|
+
factoryLines.push(` const ${INTERNAL_PREFIX}propsChanged = ${INTERNAL_PREFIX}host.propsChanged; if (${INTERNAL_PREFIX}propsChanged === undefined) throw new Error("OEIR_LEAF_MISSING_VALUE: propsChanged");`);
|
|
550
|
+
factoryLines.push(` const ${mountHostVar} = { bindings: ${INTERNAL_PREFIX}host.bindings, propDeps: [${INTERNAL_PREFIX}propsChanged]${forwardedInstance}${forwardedHostElement}${forwardedPropertyChange}${forwardedErrorBoundary}${forwardedContext} };`);
|
|
551
|
+
} else factoryLines.push(` const ${mountHostVar} = { bindings: ${INTERNAL_PREFIX}host.bindings, propDeps: []${forwardedInstance}${forwardedHostElement}${forwardedPropertyChange}${forwardedErrorBoundary}${forwardedContext} };`);
|
|
552
|
+
const claim = state.diagnostics.length === 0 ? emitClaimFunction(file, component, records, componentByName, sharedClaimCursor, rootSetup, aliasesSetupRecord, rootInstance === component.name, connectHooks.some((hook) => !hook.receivesEnv) ? rootSetup ? "bindings" : "setup" : null, connectHooks.some((hook) => hook.receivesEnv) ? rootSetup ? "bindings" : "setup" : null, retention, claimStyleLinkPrefix) : null;
|
|
553
|
+
if (claim !== null && claim.diagnostics.length > 0) return {
|
|
554
|
+
lines: [],
|
|
555
|
+
diagnostics: [...state.diagnostics, ...claim.diagnostics],
|
|
556
|
+
requiredBindings: [...state.requiredBindings].sort(),
|
|
557
|
+
requiredProps: [...state.requiredProps].sort(),
|
|
558
|
+
requiresPropsChanged: state.requiresPropsChanged,
|
|
559
|
+
rootInstanceFactory: null,
|
|
560
|
+
segments: [],
|
|
561
|
+
placements: []
|
|
562
|
+
};
|
|
563
|
+
const recipeFields = [
|
|
564
|
+
" return createRecipe({",
|
|
565
|
+
` definitionOwner: ${INTERNAL_PREFIX}owner,`,
|
|
566
|
+
` source: ${JSON.stringify(`${file}#${component.name}`)},`,
|
|
567
|
+
" mount(__oe_scope) {",
|
|
568
|
+
` return ${component.name}${MOUNT_SUFFIX}(${MOUNT_SCOPE}, ${INTERNAL_PREFIX}host.props, ${mountHostVar});`,
|
|
569
|
+
" },"
|
|
570
|
+
];
|
|
571
|
+
if (claim !== null) recipeFields.push(" claim(__oe_scope, __oe_props, __oe_parent) {", ` return ${component.name}${CLAIM_SUFFIX}(${MOUNT_SCOPE}, ${INTERNAL_PREFIX}host.props, ${mountHostVar}, __oe_parent);`, " },");
|
|
572
|
+
recipeFields.push(" });", "}", "");
|
|
573
|
+
factoryLines.push(...recipeFields);
|
|
574
|
+
const mountLines = [
|
|
575
|
+
...mountPrologue,
|
|
576
|
+
...state.lines,
|
|
577
|
+
"}",
|
|
578
|
+
""
|
|
579
|
+
];
|
|
580
|
+
const claimLines = claim?.lines ?? [];
|
|
581
|
+
const ssr = claim === null ? null : emitSsrFunction(file, component, rootDirectory, records, componentByName, lightRoot, rootInstance ?? null);
|
|
582
|
+
if (ssr !== null && ssr.diagnostics.length > 0) return {
|
|
583
|
+
lines: [],
|
|
584
|
+
diagnostics: [...state.diagnostics, ...ssr.diagnostics],
|
|
585
|
+
requiredBindings: [...state.requiredBindings].sort(),
|
|
586
|
+
requiredProps: [...state.requiredProps].sort(),
|
|
587
|
+
requiresPropsChanged: state.requiresPropsChanged,
|
|
588
|
+
rootInstanceFactory: null,
|
|
589
|
+
segments: [],
|
|
590
|
+
placements: []
|
|
591
|
+
};
|
|
592
|
+
const ssrLines = ssr?.lines ?? [];
|
|
593
|
+
const setupShift = fragmentLineCount(setupLines);
|
|
594
|
+
const claimShift = setupShift + fragmentLineCount(mountLines) + fragmentLineCount(factoryLines);
|
|
595
|
+
const ssrShift = claimShift + fragmentLineCount(claimLines);
|
|
596
|
+
const shift = setupShift + fragmentLineCount(mountPrologue);
|
|
597
|
+
return {
|
|
598
|
+
lines: [
|
|
599
|
+
...setupLines,
|
|
600
|
+
...mountLines,
|
|
601
|
+
...factoryLines,
|
|
602
|
+
...claimLines,
|
|
603
|
+
...ssrLines
|
|
604
|
+
],
|
|
605
|
+
diagnostics: state.diagnostics,
|
|
606
|
+
requiredBindings: [...state.requiredBindings].sort(),
|
|
607
|
+
requiredProps: [...state.requiredProps].sort(),
|
|
608
|
+
requiresPropsChanged: state.requiresPropsChanged,
|
|
609
|
+
rootInstanceFactory: rootSetup ? GENERATED_ROOT_INSTANCE_NAME : null,
|
|
610
|
+
usesStaticSiblingDirectoryConsumer: claim?.usesStaticSiblingDirectoryConsumer === true,
|
|
611
|
+
usesClaimRecipe: claim?.usesClaimRecipe === true,
|
|
612
|
+
hasClaim: claim !== null,
|
|
613
|
+
usesLeafClaimMismatch: claim?.usesLeafClaimMismatch === true,
|
|
614
|
+
segments: [
|
|
615
|
+
...setupSegments,
|
|
616
|
+
...state.segments.map((segment) => ({
|
|
617
|
+
...segment,
|
|
618
|
+
generatedLine: segment.generatedLine + shift
|
|
619
|
+
})),
|
|
620
|
+
...(claim?.segments ?? []).map((segment) => ({
|
|
621
|
+
...segment,
|
|
622
|
+
generatedLine: segment.generatedLine + claimShift
|
|
623
|
+
})),
|
|
624
|
+
...(ssr?.segments ?? []).map((segment) => ({
|
|
625
|
+
...segment,
|
|
626
|
+
generatedLine: segment.generatedLine + ssrShift
|
|
627
|
+
}))
|
|
628
|
+
],
|
|
629
|
+
placements: [
|
|
630
|
+
...setupPlacements,
|
|
631
|
+
...state.placements.map((placement) => ({
|
|
632
|
+
...placement,
|
|
633
|
+
generatedLine: placement.generatedLine + shift
|
|
634
|
+
})),
|
|
635
|
+
...(claim?.placements ?? []).map((placement) => ({
|
|
636
|
+
...placement,
|
|
637
|
+
generatedLine: placement.generatedLine + claimShift
|
|
638
|
+
})),
|
|
639
|
+
...(ssr?.placements ?? []).map((placement) => ({
|
|
640
|
+
...placement,
|
|
641
|
+
generatedLine: placement.generatedLine + ssrShift
|
|
642
|
+
}))
|
|
643
|
+
]
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
//#endregion
|
|
647
|
+
export { emitComponent };
|