@sprlab/wccompiler 0.16.9 → 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 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
@@ -90,6 +90,7 @@ function findBlocks(source, blockName) {
90
90
  }
91
91
 
92
92
  if (closeIdx === -1) continue;
93
+
93
94
  matches.push({
94
95
  content: source.slice(openEnd, closeIdx),
95
96
  attrs,
@@ -286,14 +287,21 @@ export function parseSFC(source, fileName = '<unknown>') {
286
287
  }
287
288
 
288
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">
289
292
  /** @type {Array<{start: number, end: number}>} */
290
293
  const allRanges = [
291
294
  ...scriptBlocks,
292
- ...templateBlocks,
295
+ ...templateBlocks, // Only main SFC blocks (filtered to exclude slot templates)
293
296
  ...styleBlocks,
294
297
  ].sort((a, b) => a.start - b.start);
295
298
 
296
- validateNoUnexpectedContent(source, allRanges, fileName);
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
+ }
297
305
 
298
306
  // Extract block contents
299
307
  const scriptContent = scriptBlocks[0].content;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sprlab/wccompiler",
3
- "version": "0.16.9",
3
+ "version": "0.16.11",
4
4
  "description": "Zero-runtime compiler that transforms .wcc single-file components into native web components with signals-based reactivity",
5
5
  "type": "module",
6
6
  "exports": {