@sprlab/wccompiler 0.16.10 → 0.16.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/codegen.js +15 -0
- package/lib/sfc-parser.js +9 -4
- package/package.json +1 -1
package/lib/codegen.js
CHANGED
|
@@ -1138,14 +1138,25 @@ export function generateComponent(parseResult, options = {}) {
|
|
|
1138
1138
|
if (slots.length > 0) {
|
|
1139
1139
|
lines.push(' const __slotMap = {};');
|
|
1140
1140
|
lines.push(' const __defaultSlotNodes = [];');
|
|
1141
|
+
lines.push(' const __templatesToRemove = [];');
|
|
1141
1142
|
lines.push(' for (const child of Array.from(this.childNodes)) {');
|
|
1142
1143
|
lines.push(" if (child.nodeName === 'TEMPLATE') {");
|
|
1144
|
+
lines.push(' let handled = false;');
|
|
1143
1145
|
lines.push(' for (const attr of child.attributes) {');
|
|
1144
1146
|
lines.push(" if (attr.name.startsWith('#')) {");
|
|
1145
1147
|
lines.push(' const slotName = attr.name.slice(1);');
|
|
1146
1148
|
lines.push(' __slotMap[slotName] = { content: child.innerHTML, propsExpr: attr.value };');
|
|
1149
|
+
lines.push(' handled = true;');
|
|
1150
|
+
lines.push(' } else if (attr.name === "slot") {');
|
|
1151
|
+
// NEW: <template slot="name"> syntax (Vue standard)
|
|
1152
|
+
lines.push(' const slotName = attr.value;');
|
|
1153
|
+
lines.push(" const propsExpr = child.getAttribute('slot-props') || '';");
|
|
1154
|
+
lines.push(" child.removeAttribute('slot-props');");
|
|
1155
|
+
lines.push(' __slotMap[slotName] = { content: child.innerHTML, propsExpr };');
|
|
1156
|
+
lines.push(' handled = true;');
|
|
1147
1157
|
lines.push(' }');
|
|
1148
1158
|
lines.push(' }');
|
|
1159
|
+
lines.push(' if (handled) __templatesToRemove.push(child);');
|
|
1149
1160
|
lines.push(" } else if (child.nodeType === 1 && child.getAttribute('slot')) {");
|
|
1150
1161
|
// NEW: regular element with slot="name" (cross-framework support)
|
|
1151
1162
|
lines.push(" const slotName = child.getAttribute('slot');");
|
|
@@ -1169,6 +1180,10 @@ export function generateComponent(parseResult, options = {}) {
|
|
|
1169
1180
|
lines.push(' __defaultSlotNodes.push(child);');
|
|
1170
1181
|
lines.push(' }');
|
|
1171
1182
|
lines.push(' }');
|
|
1183
|
+
// Remove processed template elements to prevent them from appearing in default slot
|
|
1184
|
+
lines.push(' for (const tpl of __templatesToRemove) {');
|
|
1185
|
+
lines.push(' if (tpl.parentNode) tpl.parentNode.removeChild(tpl);');
|
|
1186
|
+
lines.push(' }');
|
|
1172
1187
|
}
|
|
1173
1188
|
|
|
1174
1189
|
// Clone template
|
package/lib/sfc-parser.js
CHANGED
|
@@ -287,16 +287,21 @@ export function parseSFC(source, fileName = '<unknown>') {
|
|
|
287
287
|
}
|
|
288
288
|
|
|
289
289
|
// Collect all block ranges for unexpected-content check
|
|
290
|
+
// Use filtered templateBlocks (main SFC template only, not nested slot templates)
|
|
291
|
+
// The main template's range already covers all nested content including <template slot="name">
|
|
290
292
|
/** @type {Array<{start: number, end: number}>} */
|
|
291
293
|
const allRanges = [
|
|
292
294
|
...scriptBlocks,
|
|
293
|
-
...templateBlocks,
|
|
295
|
+
...templateBlocks, // Only main SFC blocks (filtered to exclude slot templates)
|
|
294
296
|
...styleBlocks,
|
|
295
297
|
].sort((a, b) => a.start - b.start);
|
|
296
298
|
|
|
297
|
-
//
|
|
298
|
-
//
|
|
299
|
-
|
|
299
|
+
// Validate unexpected content ONLY if there are no nested slot templates
|
|
300
|
+
// Nested <template slot="name"> elements can cause false positives in range validation
|
|
301
|
+
const hasNestedSlotTemplates = allTemplateBlocks.length > templateBlocks.length;
|
|
302
|
+
if (!hasNestedSlotTemplates) {
|
|
303
|
+
validateNoUnexpectedContent(source, allRanges, fileName);
|
|
304
|
+
}
|
|
300
305
|
|
|
301
306
|
// Extract block contents
|
|
302
307
|
const scriptContent = scriptBlocks[0].content;
|
package/package.json
CHANGED