@sprlab/wccompiler 0.11.1 → 0.11.3
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/tree-walker.js +22 -9
- package/package.json +1 -1
package/lib/tree-walker.js
CHANGED
|
@@ -88,7 +88,9 @@ export function walkTree(rootEl, signalNames, computedNames, propNames = new Set
|
|
|
88
88
|
// Detect <slot> elements — replace with <span data-slot="..."> placeholder
|
|
89
89
|
if (el.tagName === 'SLOT') {
|
|
90
90
|
const slotName = el.getAttribute('name') || '';
|
|
91
|
-
const
|
|
91
|
+
const safeName = slotName ? slotName.replace(/[^a-zA-Z0-9_]/g, '_') : 'default';
|
|
92
|
+
const varName = `__slot_${safeName}_${slotIdx}`;
|
|
93
|
+
slotIdx++;
|
|
92
94
|
const defaultContent = el.innerHTML.trim();
|
|
93
95
|
|
|
94
96
|
// Collect :prop="expr" attributes (slot props for scoped slots)
|
|
@@ -155,10 +157,13 @@ export function walkTree(rootEl, signalNames, computedNames, propNames = new Set
|
|
|
155
157
|
const attrsToRemove = [];
|
|
156
158
|
for (const attr of Array.from(el.attributes)) {
|
|
157
159
|
if (attr.name.startsWith('@')) {
|
|
158
|
-
const
|
|
160
|
+
const eventName = attr.name.slice(1);
|
|
161
|
+
const handlerName = attr.value.replace(/[^a-zA-Z0-9_]/g, '_').slice(0, 20);
|
|
162
|
+
const varName = `__evt_${eventName.replace(/-/g, '_')}_${handlerName}`;
|
|
163
|
+
eventIdx++;
|
|
159
164
|
events.push({
|
|
160
165
|
varName,
|
|
161
|
-
event:
|
|
166
|
+
event: eventName,
|
|
162
167
|
handler: attr.value,
|
|
163
168
|
path: [...pathParts],
|
|
164
169
|
});
|
|
@@ -180,7 +185,8 @@ export function walkTree(rootEl, signalNames, computedNames, propNames = new Set
|
|
|
180
185
|
kind = 'attr';
|
|
181
186
|
}
|
|
182
187
|
|
|
183
|
-
const varName = `
|
|
188
|
+
const varName = `__attr_${attrName.replace(/-/g, '_')}_${attrIdx}`;
|
|
189
|
+
attrIdx++;
|
|
184
190
|
attrBindings.push({
|
|
185
191
|
varName,
|
|
186
192
|
attr: attrName,
|
|
@@ -195,7 +201,8 @@ export function walkTree(rootEl, signalNames, computedNames, propNames = new Set
|
|
|
195
201
|
|
|
196
202
|
// Detect show attribute
|
|
197
203
|
if (el.hasAttribute('show')) {
|
|
198
|
-
const varName = `
|
|
204
|
+
const varName = `__show_${showIdx}`;
|
|
205
|
+
showIdx++;
|
|
199
206
|
showBindings.push({
|
|
200
207
|
varName,
|
|
201
208
|
expression: el.getAttribute('show'),
|
|
@@ -244,7 +251,8 @@ export function walkTree(rootEl, signalNames, computedNames, propNames = new Set
|
|
|
244
251
|
prop = 'value'; event = 'input';
|
|
245
252
|
}
|
|
246
253
|
|
|
247
|
-
const varName = `
|
|
254
|
+
const varName = `__model_${signalName}_${modelIdx}`;
|
|
255
|
+
modelIdx++;
|
|
248
256
|
modelBindings.push({ varName, signal: signalName, prop, event, coerce, radioValue, path: [...pathParts] });
|
|
249
257
|
el.removeAttribute('model');
|
|
250
258
|
}
|
|
@@ -265,7 +273,8 @@ export function walkTree(rootEl, signalNames, computedNames, propNames = new Set
|
|
|
265
273
|
throw error;
|
|
266
274
|
}
|
|
267
275
|
|
|
268
|
-
const varName = `
|
|
276
|
+
const varName = `__modelProp_${propName}`;
|
|
277
|
+
modelPropIdx++;
|
|
269
278
|
modelPropBindings.push({ varName, propName, signal, path: [...pathParts] });
|
|
270
279
|
modelPropAttrsToRemove.push(attr.name);
|
|
271
280
|
}
|
|
@@ -287,8 +296,10 @@ export function walkTree(rootEl, signalNames, computedNames, propNames = new Set
|
|
|
287
296
|
|
|
288
297
|
// Case 1: {{var}} is the sole content of the parent element and parent has only one child text node
|
|
289
298
|
if (soleMatch && parent.childNodes.length === 1) {
|
|
290
|
-
const varName = `__b${bindIdx++}`;
|
|
291
299
|
const name = baseName(soleMatch[1]);
|
|
300
|
+
const safeName = name.replace(/[^a-zA-Z0-9_]/g, '_').slice(0, 30);
|
|
301
|
+
const varName = `__text_${safeName}`;
|
|
302
|
+
bindIdx++;
|
|
292
303
|
bindings.push({
|
|
293
304
|
varName,
|
|
294
305
|
name,
|
|
@@ -317,8 +328,10 @@ export function walkTree(rootEl, signalNames, computedNames, propNames = new Set
|
|
|
317
328
|
const bm = part.match(/^\{\{((?:[^}]|\}(?!\}))+)\}\}$/);
|
|
318
329
|
if (bm) {
|
|
319
330
|
fragment.appendChild(doc.createElement('span'));
|
|
320
|
-
const varName = `__b${bindIdx++}`;
|
|
321
331
|
const name = baseName(bm[1]);
|
|
332
|
+
const safeName = name.replace(/[^a-zA-Z0-9_]/g, '_').slice(0, 30);
|
|
333
|
+
const varName = `__text_${safeName}_${bindIdx}`;
|
|
334
|
+
bindIdx++;
|
|
322
335
|
bindings.push({
|
|
323
336
|
varName,
|
|
324
337
|
name,
|
package/package.json
CHANGED