@sprlab/wccompiler 0.5.2 → 0.5.4

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
@@ -761,9 +761,17 @@ export function generateComponent(parseResult, options = {}) {
761
761
  lines.push(` this.${b.varName}.textContent = this._c_${b.name}() ?? '';`);
762
762
  lines.push(' }));');
763
763
  } else {
764
- // method type — call the method
764
+ // method/expression type — check if it's a props.x access or a complex expression
765
+ let ref;
766
+ if (propsObjectName && b.name.startsWith(propsObjectName + '.')) {
767
+ const propName = b.name.slice(propsObjectName.length + 1);
768
+ ref = `this._s_${propName}()`;
769
+ } else {
770
+ // Use transformExpr for complex expressions (e.g. items().length, ternary)
771
+ ref = transformExpr(b.name, signalNames, computedNames, propsObjectName, propNames, emitsObjectName, constantNames, methodNames);
772
+ }
765
773
  lines.push(' this.__disposers.push(__effect(() => {');
766
- lines.push(` this.${b.varName}.textContent = this._${b.name}() ?? '';`);
774
+ lines.push(` this.${b.varName}.textContent = ${ref} ?? '';`);
767
775
  lines.push(' }));');
768
776
  }
769
777
  }
@@ -240,10 +240,10 @@ export function walkTree(rootEl, signalNames, computedNames, propNames = new Set
240
240
  }
241
241
 
242
242
  // --- Text node with interpolations ---
243
- if (node.nodeType === 3 && /\{\{[\w.()]+\}\}/.test(node.textContent)) {
243
+ if (node.nodeType === 3 && /\{\{(?:[^}]|\}(?!\}))+\}\}/.test(node.textContent)) {
244
244
  const text = node.textContent;
245
245
  const trimmed = text.trim();
246
- const soleMatch = trimmed.match(/^\{\{([\w.()]+)\}\}$/);
246
+ const soleMatch = trimmed.match(/^\{\{((?:[^}]|\}(?!\}))+)\}\}$/);
247
247
  const parent = node.parentNode;
248
248
 
249
249
  // Strip trailing () from expression to get the base name for type lookup
@@ -268,7 +268,7 @@ export function walkTree(rootEl, signalNames, computedNames, propNames = new Set
268
268
  // Case 2: Mixed text and interpolations — split into spans
269
269
  const doc = node.ownerDocument;
270
270
  const fragment = doc.createDocumentFragment();
271
- const parts = text.split(/(\{\{[\w.()]+\}\})/);
271
+ const parts = text.split(/(\{\{(?:[^}]|\}(?!\}))+\}\})/);
272
272
  const parentPath = pathParts.slice(0, -1);
273
273
 
274
274
  // Find the index of this text node among its siblings
@@ -280,7 +280,7 @@ export function walkTree(rootEl, signalNames, computedNames, propNames = new Set
280
280
 
281
281
  let offset = 0;
282
282
  for (const part of parts) {
283
- const bm = part.match(/^\{\{([\w.()]+)\}\}$/);
283
+ const bm = part.match(/^\{\{((?:[^}]|\}(?!\}))+)\}\}$/);
284
284
  if (bm) {
285
285
  fragment.appendChild(doc.createElement('span'));
286
286
  const varName = `__b${bindIdx++}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sprlab/wccompiler",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
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
  "bin": {