@sprlab/wccompiler 0.7.0 → 0.7.1

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.
Files changed (2) hide show
  1. package/lib/codegen.js +19 -4
  2. package/package.json +1 -1
package/lib/codegen.js CHANGED
@@ -933,9 +933,24 @@ export function generateComponent(parseResult, options = {}) {
933
933
  for (let idx = 0; idx < watchers.length; idx++) {
934
934
  const w = watchers[idx];
935
935
  if (w.kind === 'signal') {
936
- lines.push(` this.__prev_${w.target} = undefined;`);
936
+ // For signal watchers watching a prop, initialize with the prop's default value
937
+ // so that attributeChangedCallback changes before connectedCallback are detected
938
+ if (propNames.has(w.target)) {
939
+ const propDef = propDefs.find(p => p.name === w.target);
940
+ lines.push(` this.__prev_${w.target} = ${propDef ? propDef.default : 'undefined'};`);
941
+ } else {
942
+ lines.push(` this.__prev_${w.target} = undefined;`);
943
+ }
937
944
  } else {
938
- lines.push(` this.__prev_watch${idx} = undefined;`);
945
+ // For getter watchers, check if the getter references a prop (e.g., props.value)
946
+ // Initialize with the prop's default so pre-connection attribute changes are detected
947
+ const propMatch = propsObjectName ? w.target.match(new RegExp(`^${propsObjectName}\\.(\\w+)$`)) : null;
948
+ if (propMatch && propNames.has(propMatch[1])) {
949
+ const propDef = propDefs.find(p => p.name === propMatch[1]);
950
+ lines.push(` this.__prev_watch${idx} = ${propDef ? propDef.default : 'undefined'};`);
951
+ } else {
952
+ lines.push(` this.__prev_watch${idx} = undefined;`);
953
+ }
939
954
  }
940
955
  }
941
956
 
@@ -1170,7 +1185,7 @@ export function generateComponent(parseResult, options = {}) {
1170
1185
  }
1171
1186
  lines.push(' this.__disposers.push(__effect(() => {');
1172
1187
  lines.push(` const ${w.newParam} = ${watchRef};`);
1173
- lines.push(` if (this.__prev_${w.target} !== undefined) {`);
1188
+ lines.push(` if (this.__prev_${w.target} !== undefined && this.__prev_${w.target} !== ${w.newParam}) {`);
1174
1189
  lines.push(` const ${w.oldParam} = this.__prev_${w.target};`);
1175
1190
  lines.push(' __untrack(() => {');
1176
1191
  const bodyLines = body.split('\n');
@@ -1187,7 +1202,7 @@ export function generateComponent(parseResult, options = {}) {
1187
1202
  const prevName = `__prev_watch${idx}`;
1188
1203
  lines.push(' this.__disposers.push(__effect(() => {');
1189
1204
  lines.push(` const ${w.newParam} = ${getterExpr};`);
1190
- lines.push(` if (this.${prevName} !== undefined) {`);
1205
+ lines.push(` if (this.${prevName} !== undefined && this.${prevName} !== ${w.newParam}) {`);
1191
1206
  lines.push(` const ${w.oldParam} = this.${prevName};`);
1192
1207
  lines.push(' __untrack(() => {');
1193
1208
  const bodyLines2 = body.split('\n');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sprlab/wccompiler",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
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": {