@sprlab/wccompiler 0.5.9 → 0.5.11
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/compiler.js +37 -4
- package/lib/tree-walker.js +4 -2
- package/package.json +1 -1
package/lib/compiler.js
CHANGED
|
@@ -86,6 +86,15 @@ async function compileSFC(filePath, config) {
|
|
|
86
86
|
// 2. Process script block — mirrors parser.js logic
|
|
87
87
|
let source = stripMacroImport(descriptor.script);
|
|
88
88
|
|
|
89
|
+
// 2b. Extract manual .wcc imports (e.g. import './child.wcc') and strip them from source
|
|
90
|
+
const manualImports = [];
|
|
91
|
+
const wccImportRe = /import\s+['"]([^'"]+\.wcc)['"]\s*;?/g;
|
|
92
|
+
let wccImportMatch;
|
|
93
|
+
while ((wccImportMatch = wccImportRe.exec(source)) !== null) {
|
|
94
|
+
manualImports.push(wccImportMatch[1].replace(/\.wcc$/, '.js'));
|
|
95
|
+
}
|
|
96
|
+
source = source.replace(wccImportRe, '');
|
|
97
|
+
|
|
89
98
|
// 3. Extract props/emits from generic forms BEFORE type stripping
|
|
90
99
|
const propsFromGeneric = extractPropsGeneric(source);
|
|
91
100
|
const propsObjectNameFromGeneric = extractPropsObjectName(source);
|
|
@@ -291,14 +300,31 @@ async function compileSFC(filePath, config) {
|
|
|
291
300
|
}
|
|
292
301
|
}
|
|
293
302
|
|
|
294
|
-
// 18. Resolve child component imports
|
|
303
|
+
// 18. Resolve child component imports (from main template + if branches + each blocks)
|
|
295
304
|
/** @type {import('./types.js').ChildComponentImport[]} */
|
|
296
305
|
const childImports = [];
|
|
297
|
-
|
|
298
|
-
|
|
306
|
+
const allChildTags = new Set(childComponents.map(c => c.tag));
|
|
307
|
+
|
|
308
|
+
// Collect child tags from if branches
|
|
309
|
+
for (const ifBlock of ifBlocks) {
|
|
310
|
+
for (const branch of ifBlock.branches) {
|
|
311
|
+
if (branch.childComponents) {
|
|
312
|
+
for (const cc of branch.childComponents) allChildTags.add(cc.tag);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// Collect child tags from each blocks
|
|
318
|
+
for (const forBlock of forBlocks) {
|
|
319
|
+
if (forBlock.childComponents) {
|
|
320
|
+
for (const cc of forBlock.childComponents) allChildTags.add(cc.tag);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
if (allChildTags.size > 0) {
|
|
299
325
|
const sourceDir = dirname(filePath);
|
|
300
326
|
|
|
301
|
-
for (const tag of
|
|
327
|
+
for (const tag of allChildTags) {
|
|
302
328
|
const resolved = resolveChildComponent(tag, sourceDir, config);
|
|
303
329
|
if (resolved) {
|
|
304
330
|
childImports.push({ tag, importPath: resolved });
|
|
@@ -319,6 +345,13 @@ async function compileSFC(filePath, config) {
|
|
|
319
345
|
parseResult.slots = slots;
|
|
320
346
|
parseResult.refBindings = refBindings;
|
|
321
347
|
parseResult.childComponents = childComponents;
|
|
348
|
+
|
|
349
|
+
// Add manual .wcc imports from script block
|
|
350
|
+
for (const imp of manualImports) {
|
|
351
|
+
if (!childImports.find(ci => ci.importPath === imp)) {
|
|
352
|
+
childImports.push({ tag: '', importPath: imp });
|
|
353
|
+
}
|
|
354
|
+
}
|
|
322
355
|
parseResult.childImports = childImports;
|
|
323
356
|
parseResult.processedTemplate = rootEl.innerHTML;
|
|
324
357
|
|
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