@sprlab/wccompiler 0.5.6 → 0.5.8

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/bin/wcc.js CHANGED
@@ -19,7 +19,7 @@ async function build(config, cwd) {
19
19
  const __filename = fileURLToPath(import.meta.url);
20
20
  const __dirname = dirname(__filename);
21
21
  const { reactiveRuntime } = await import('../lib/reactive-runtime.js');
22
- const signalsContent = reactiveRuntime.trim().replace(/^/gm, '') + '\nexport { __signal, __computed, __effect, __batch };\n';
22
+ const signalsContent = reactiveRuntime.trim().replace(/^/gm, '') + '\nexport { __signal, __computed, __effect, __batch, __untrack };\n';
23
23
  const signalsDest = join(outputDir, '__wcc-signals.js');
24
24
  writeFileSync(signalsDest, signalsContent);
25
25
 
package/lib/codegen.js CHANGED
@@ -541,6 +541,7 @@ export function generateComponent(parseResult, options = {}) {
541
541
  const usedRuntime = new Set(['__signal']); // always need __signal
542
542
  if (computeds.length > 0) usedRuntime.add('__computed');
543
543
  if (effects.length > 0 || bindings.length > 0 || showBindings.length > 0 || modelBindings.length > 0 || attrBindings.length > 0 || ifBlocks.length > 0 || forBlocks.length > 0 || watchers.length > 0 || childComponents.length > 0 || slots.some(s => s.slotProps.length > 0)) usedRuntime.add('__effect');
544
+ if (watchers.length > 0) usedRuntime.add('__untrack');
544
545
  const imports = [...usedRuntime].join(', ');
545
546
  lines.push(`import { ${imports} } from '${options.runtimeImportPath}';`);
546
547
  } else {
@@ -848,10 +849,12 @@ export function generateComponent(parseResult, options = {}) {
848
849
  lines.push(` const ${w.newParam} = ${watchRef};`);
849
850
  lines.push(` if (this.__prev_${w.target} !== undefined) {`);
850
851
  lines.push(` const ${w.oldParam} = this.__prev_${w.target};`);
852
+ lines.push(' __untrack(() => {');
851
853
  const bodyLines = body.split('\n');
852
854
  for (const line of bodyLines) {
853
- lines.push(` ${line}`);
855
+ lines.push(` ${line}`);
854
856
  }
857
+ lines.push(' });');
855
858
  lines.push(' }');
856
859
  lines.push(` this.__prev_${w.target} = ${w.newParam};`);
857
860
  lines.push(' }));');
@@ -863,10 +866,12 @@ export function generateComponent(parseResult, options = {}) {
863
866
  lines.push(` const ${w.newParam} = ${getterExpr};`);
864
867
  lines.push(` if (this.${prevName} !== undefined) {`);
865
868
  lines.push(` const ${w.oldParam} = this.${prevName};`);
866
- const bodyLines = body.split('\n');
867
- for (const line of bodyLines) {
868
- lines.push(` ${line}`);
869
+ lines.push(' __untrack(() => {');
870
+ const bodyLines2 = body.split('\n');
871
+ for (const line of bodyLines2) {
872
+ lines.push(` ${line}`);
869
873
  }
874
+ lines.push(' });');
870
875
  lines.push(' }');
871
876
  lines.push(` this.${prevName} = ${w.newParam};`);
872
877
  lines.push(' }));');
@@ -1088,7 +1093,7 @@ export function generateComponent(parseResult, options = {}) {
1088
1093
  for (const hook of onMountHooks) {
1089
1094
  const body = transformMethodBody(hook.body, signalNames, computedNames, propsObjectName, propNames, emitsObjectName, refVarNames, constantNames);
1090
1095
  if (hook.async) {
1091
- lines.push(' (async () => {');
1096
+ lines.push(' ;(async () => {');
1092
1097
  const bodyLines = body.split('\n');
1093
1098
  for (const line of bodyLines) {
1094
1099
  lines.push(` ${line}`);
@@ -1097,7 +1102,9 @@ export function generateComponent(parseResult, options = {}) {
1097
1102
  } else {
1098
1103
  const bodyLines = body.split('\n');
1099
1104
  for (const line of bodyLines) {
1100
- lines.push(` ${line}`);
1105
+ const trimmed = line.trimEnd();
1106
+ const needsSemi = trimmed && !trimmed.endsWith(';') && !trimmed.endsWith('{') && !trimmed.endsWith('}');
1107
+ lines.push(` ${trimmed}${needsSemi ? ';' : ''}`);
1101
1108
  }
1102
1109
  }
1103
1110
  }
@@ -1114,7 +1121,7 @@ export function generateComponent(parseResult, options = {}) {
1114
1121
  for (const hook of onDestroyHooks) {
1115
1122
  const body = transformMethodBody(hook.body, signalNames, computedNames, propsObjectName, propNames, emitsObjectName, refVarNames, constantNames);
1116
1123
  if (hook.async) {
1117
- lines.push(' (async () => {');
1124
+ lines.push(' ;(async () => {');
1118
1125
  const bodyLines = body.split('\n');
1119
1126
  for (const line of bodyLines) {
1120
1127
  lines.push(` ${line}`);
@@ -1123,7 +1130,9 @@ export function generateComponent(parseResult, options = {}) {
1123
1130
  } else {
1124
1131
  const bodyLines = body.split('\n');
1125
1132
  for (const line of bodyLines) {
1126
- lines.push(` ${line}`);
1133
+ const trimmed = line.trimEnd();
1134
+ const needsSemi = trimmed && !trimmed.endsWith(';') && !trimmed.endsWith('{') && !trimmed.endsWith('}');
1135
+ lines.push(` ${trimmed}${needsSemi ? ';' : ''}`);
1127
1136
  }
1128
1137
  }
1129
1138
  }
@@ -90,4 +90,11 @@ function __batch(fn) {
90
90
  }
91
91
  }
92
92
  }
93
+
94
+ function __untrack(fn) {
95
+ const prev = __currentEffect;
96
+ __currentEffect = null;
97
+ try { return fn(); }
98
+ finally { __currentEffect = prev; }
99
+ }
93
100
  `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sprlab/wccompiler",
3
- "version": "0.5.6",
3
+ "version": "0.5.8",
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": {