@sprlab/wccompiler 0.6.3 → 0.6.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 +43 -39
- package/package.json +1 -1
package/lib/codegen.js
CHANGED
|
@@ -904,10 +904,51 @@ export function generateComponent(parseResult, options = {}) {
|
|
|
904
904
|
lines.push('');
|
|
905
905
|
}
|
|
906
906
|
|
|
907
|
-
// Constructor
|
|
907
|
+
// Constructor — reactive state only (no DOM manipulation per Custom Elements spec)
|
|
908
908
|
lines.push(' constructor() {');
|
|
909
909
|
lines.push(' super();');
|
|
910
910
|
|
|
911
|
+
// Prop signal initialization (BEFORE user signals)
|
|
912
|
+
for (const p of propDefs) {
|
|
913
|
+
lines.push(` this._s_${p.name} = __signal(${p.default});`);
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
// Signal initialization
|
|
917
|
+
for (const s of signals) {
|
|
918
|
+
lines.push(` this._${s.name} = __signal(${s.value});`);
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
// Constant initialization
|
|
922
|
+
for (const c of constantVars) {
|
|
923
|
+
lines.push(` this._const_${c.name} = ${c.value};`);
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
// Computed initialization
|
|
927
|
+
for (const c of computeds) {
|
|
928
|
+
const body = transformExpr(c.body, signalNames, computedNames, propsObjectName, propNames, emitsObjectName, constantNames, methodNames);
|
|
929
|
+
lines.push(` this._c_${c.name} = __computed(() => ${body});`);
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
// Watcher prev-value initialization
|
|
933
|
+
for (let idx = 0; idx < watchers.length; idx++) {
|
|
934
|
+
const w = watchers[idx];
|
|
935
|
+
if (w.kind === 'signal') {
|
|
936
|
+
lines.push(` this.__prev_${w.target} = undefined;`);
|
|
937
|
+
} else {
|
|
938
|
+
lines.push(` this.__prev_watch${idx} = undefined;`);
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
lines.push(' }');
|
|
943
|
+
lines.push('');
|
|
944
|
+
|
|
945
|
+
// connectedCallback (idempotent — safe for re-mount)
|
|
946
|
+
lines.push(' connectedCallback() {');
|
|
947
|
+
lines.push(' if (this.__connected) return;');
|
|
948
|
+
lines.push(' this.__connected = true;');
|
|
949
|
+
|
|
950
|
+
// ── DOM SETUP (moved from constructor for Custom Elements spec compliance) ──
|
|
951
|
+
|
|
911
952
|
// Slot resolution: read childNodes BEFORE clearing innerHTML (when slots are present)
|
|
912
953
|
if (slots.length > 0) {
|
|
913
954
|
lines.push(' const __slotMap = {};');
|
|
@@ -973,37 +1014,6 @@ export function generateComponent(parseResult, options = {}) {
|
|
|
973
1014
|
}
|
|
974
1015
|
}
|
|
975
1016
|
|
|
976
|
-
// Prop signal initialization (BEFORE user signals)
|
|
977
|
-
for (const p of propDefs) {
|
|
978
|
-
lines.push(` this._s_${p.name} = __signal(${p.default});`);
|
|
979
|
-
}
|
|
980
|
-
|
|
981
|
-
// Signal initialization
|
|
982
|
-
for (const s of signals) {
|
|
983
|
-
lines.push(` this._${s.name} = __signal(${s.value});`);
|
|
984
|
-
}
|
|
985
|
-
|
|
986
|
-
// Constant initialization
|
|
987
|
-
for (const c of constantVars) {
|
|
988
|
-
lines.push(` this._const_${c.name} = ${c.value};`);
|
|
989
|
-
}
|
|
990
|
-
|
|
991
|
-
// Computed initialization
|
|
992
|
-
for (const c of computeds) {
|
|
993
|
-
const body = transformExpr(c.body, signalNames, computedNames, propsObjectName, propNames, emitsObjectName, constantNames, methodNames);
|
|
994
|
-
lines.push(` this._c_${c.name} = __computed(() => ${body});`);
|
|
995
|
-
}
|
|
996
|
-
|
|
997
|
-
// Watcher prev-value initialization
|
|
998
|
-
for (let idx = 0; idx < watchers.length; idx++) {
|
|
999
|
-
const w = watchers[idx];
|
|
1000
|
-
if (w.kind === 'signal') {
|
|
1001
|
-
lines.push(` this.__prev_${w.target} = undefined;`);
|
|
1002
|
-
} else {
|
|
1003
|
-
lines.push(` this.__prev_watch${idx} = undefined;`);
|
|
1004
|
-
}
|
|
1005
|
-
}
|
|
1006
|
-
|
|
1007
1017
|
// ── if: template creation, anchor reference, state init ──
|
|
1008
1018
|
for (const ifBlock of ifBlocks) {
|
|
1009
1019
|
const vn = ifBlock.varName;
|
|
@@ -1055,13 +1065,7 @@ export function generateComponent(parseResult, options = {}) {
|
|
|
1055
1065
|
}
|
|
1056
1066
|
}
|
|
1057
1067
|
|
|
1058
|
-
|
|
1059
|
-
lines.push('');
|
|
1060
|
-
|
|
1061
|
-
// connectedCallback (idempotent — safe for re-mount)
|
|
1062
|
-
lines.push(' connectedCallback() {');
|
|
1063
|
-
lines.push(' if (this.__connected) return;');
|
|
1064
|
-
lines.push(' this.__connected = true;');
|
|
1068
|
+
// ── EFFECTS AND LISTENERS ──
|
|
1065
1069
|
lines.push(' this.__ac = new AbortController();');
|
|
1066
1070
|
lines.push(' this.__disposers = [];');
|
|
1067
1071
|
lines.push('');
|
package/package.json
CHANGED