@sprlab/wccompiler 0.5.8 → 0.5.10
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/lib/codegen.js +12 -2
- package/lib/compiler.js +21 -4
- package/lib/tree-walker.js +4 -2
- package/package.json +1 -1
package/lib/codegen.js
CHANGED
|
@@ -1000,6 +1000,7 @@ export function generateComponent(parseResult, options = {}) {
|
|
|
1000
1000
|
lines.push(' const clone = tpl.content.cloneNode(true);');
|
|
1001
1001
|
lines.push(' const node = clone.firstChild;');
|
|
1002
1002
|
lines.push(` this.${vn}_anchor.parentNode.insertBefore(node, this.${vn}_anchor);`);
|
|
1003
|
+
lines.push(' customElements.upgrade(node);');
|
|
1003
1004
|
lines.push(` this.${vn}_current = node;`);
|
|
1004
1005
|
// Setup bindings/events for active branch (only if any branch has bindings/events)
|
|
1005
1006
|
const hasSetup = ifBlock.branches.some(b =>
|
|
@@ -1066,7 +1067,7 @@ export function generateComponent(parseResult, options = {}) {
|
|
|
1066
1067
|
lines.push(' for (const n of __oldMap.values()) n.remove();');
|
|
1067
1068
|
lines.push('');
|
|
1068
1069
|
lines.push(' // Reorder: insert all nodes in correct order before anchor');
|
|
1069
|
-
lines.push(` for (const n of __newNodes) this.${vn}_anchor.parentNode.insertBefore(n, this.${vn}_anchor)
|
|
1070
|
+
lines.push(` for (const n of __newNodes) { this.${vn}_anchor.parentNode.insertBefore(n, this.${vn}_anchor); customElements.upgrade(n); }`);
|
|
1070
1071
|
lines.push('');
|
|
1071
1072
|
lines.push(` this.${vn}_nodes = __newNodes;`);
|
|
1072
1073
|
lines.push(` this.${vn}_keyMap = __newMap;`);
|
|
@@ -1083,6 +1084,7 @@ export function generateComponent(parseResult, options = {}) {
|
|
|
1083
1084
|
generateItemSetup(lines, forBlock, itemVar, indexVar, propNames, signalNamesSet, computedNamesSet);
|
|
1084
1085
|
|
|
1085
1086
|
lines.push(` this.${vn}_anchor.parentNode.insertBefore(node, this.${vn}_anchor);`);
|
|
1087
|
+
lines.push(' customElements.upgrade(node);');
|
|
1086
1088
|
lines.push(` this.${vn}_nodes.push(node);`);
|
|
1087
1089
|
lines.push(' });');
|
|
1088
1090
|
lines.push(' }));');
|
|
@@ -1254,7 +1256,15 @@ export function generateComponent(parseResult, options = {}) {
|
|
|
1254
1256
|
} else if (b.type === 'computed') {
|
|
1255
1257
|
lines.push(` __effect(() => { ${b.varName}.textContent = this._c_${b.name}() ?? ''; });`);
|
|
1256
1258
|
} else {
|
|
1257
|
-
|
|
1259
|
+
// method/expression type — check for props.x pattern
|
|
1260
|
+
let ref;
|
|
1261
|
+
if (propsObjectName && b.name.startsWith(propsObjectName + '.')) {
|
|
1262
|
+
const propName = b.name.slice(propsObjectName.length + 1);
|
|
1263
|
+
ref = `this._s_${propName}()`;
|
|
1264
|
+
} else {
|
|
1265
|
+
ref = transformExpr(b.name, signalNames, computedNames, propsObjectName, propNames, emitsObjectName, constantNames, methodNames);
|
|
1266
|
+
}
|
|
1267
|
+
lines.push(` __effect(() => { ${b.varName}.textContent = ${ref} ?? ''; });`);
|
|
1258
1268
|
}
|
|
1259
1269
|
}
|
|
1260
1270
|
|
package/lib/compiler.js
CHANGED
|
@@ -291,14 +291,31 @@ async function compileSFC(filePath, config) {
|
|
|
291
291
|
}
|
|
292
292
|
}
|
|
293
293
|
|
|
294
|
-
// 18. Resolve child component imports
|
|
294
|
+
// 18. Resolve child component imports (from main template + if branches + each blocks)
|
|
295
295
|
/** @type {import('./types.js').ChildComponentImport[]} */
|
|
296
296
|
const childImports = [];
|
|
297
|
-
|
|
298
|
-
|
|
297
|
+
const allChildTags = new Set(childComponents.map(c => c.tag));
|
|
298
|
+
|
|
299
|
+
// Collect child tags from if branches
|
|
300
|
+
for (const ifBlock of ifBlocks) {
|
|
301
|
+
for (const branch of ifBlock.branches) {
|
|
302
|
+
if (branch.childComponents) {
|
|
303
|
+
for (const cc of branch.childComponents) allChildTags.add(cc.tag);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// Collect child tags from each blocks
|
|
309
|
+
for (const forBlock of forBlocks) {
|
|
310
|
+
if (forBlock.childComponents) {
|
|
311
|
+
for (const cc of forBlock.childComponents) allChildTags.add(cc.tag);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if (allChildTags.size > 0) {
|
|
299
316
|
const sourceDir = dirname(filePath);
|
|
300
317
|
|
|
301
|
-
for (const tag of
|
|
318
|
+
for (const tag of allChildTags) {
|
|
302
319
|
const resolved = resolveChildComponent(tag, sourceDir, config);
|
|
303
320
|
if (resolved) {
|
|
304
321
|
childImports.push({ tag, importPath: resolved });
|
package/lib/tree-walker.js
CHANGED
|
@@ -432,7 +432,7 @@ function buildIfBlock(chain, parent, parentPath, idx, signalNames, computedNames
|
|
|
432
432
|
const templateHtml = clone.outerHTML;
|
|
433
433
|
|
|
434
434
|
// Process internal bindings/events via partial walk
|
|
435
|
-
const { bindings, events, showBindings, attrBindings, modelBindings, slots, processedHtml } = walkBranch(templateHtml, signalNames, computedNames, propNames);
|
|
435
|
+
const { bindings, events, showBindings, attrBindings, modelBindings, slots, childComponents, processedHtml } = walkBranch(templateHtml, signalNames, computedNames, propNames);
|
|
436
436
|
|
|
437
437
|
return {
|
|
438
438
|
type: branch.type,
|
|
@@ -444,6 +444,7 @@ function buildIfBlock(chain, parent, parentPath, idx, signalNames, computedNames
|
|
|
444
444
|
attrBindings,
|
|
445
445
|
modelBindings,
|
|
446
446
|
slots,
|
|
447
|
+
childComponents,
|
|
447
448
|
};
|
|
448
449
|
});
|
|
449
450
|
|
|
@@ -762,7 +763,7 @@ export function processForBlocks(parent, parentPath, signalNames, computedNames,
|
|
|
762
763
|
const templateHtml = clone.outerHTML;
|
|
763
764
|
|
|
764
765
|
// Process internal bindings/events via partial walk
|
|
765
|
-
const { bindings, events, showBindings, attrBindings, modelBindings, slots, processedHtml } = walkBranch(templateHtml, signalNames, computedNames, propNames);
|
|
766
|
+
const { bindings, events, showBindings, attrBindings, modelBindings, slots, childComponents: forChildComponents, processedHtml } = walkBranch(templateHtml, signalNames, computedNames, propNames);
|
|
766
767
|
|
|
767
768
|
// Replace the original element with a comment node <!-- each -->
|
|
768
769
|
const doc = node.ownerDocument;
|
|
@@ -790,6 +791,7 @@ export function processForBlocks(parent, parentPath, signalNames, computedNames,
|
|
|
790
791
|
attrBindings,
|
|
791
792
|
modelBindings,
|
|
792
793
|
slots,
|
|
794
|
+
childComponents: forChildComponents,
|
|
793
795
|
});
|
|
794
796
|
} else {
|
|
795
797
|
// Recurse into non-each elements to find nested each
|
package/package.json
CHANGED