@sprlab/wccompiler 0.5.7 → 0.5.9
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 +20 -6
- package/package.json +1 -1
package/lib/codegen.js
CHANGED
|
@@ -1000,6 +1000,7 @@ export function generateComponent(parseResult, options = {}) {
|
|
|
1000
1000
|
lines.push(' const clone = tpl.content.cloneNode(true);');
|
|
1001
1001
|
lines.push(' const node = clone.firstChild;');
|
|
1002
1002
|
lines.push(` this.${vn}_anchor.parentNode.insertBefore(node, this.${vn}_anchor);`);
|
|
1003
|
+
lines.push(' customElements.upgrade(node);');
|
|
1003
1004
|
lines.push(` this.${vn}_current = node;`);
|
|
1004
1005
|
// Setup bindings/events for active branch (only if any branch has bindings/events)
|
|
1005
1006
|
const hasSetup = ifBlock.branches.some(b =>
|
|
@@ -1066,7 +1067,7 @@ export function generateComponent(parseResult, options = {}) {
|
|
|
1066
1067
|
lines.push(' for (const n of __oldMap.values()) n.remove();');
|
|
1067
1068
|
lines.push('');
|
|
1068
1069
|
lines.push(' // Reorder: insert all nodes in correct order before anchor');
|
|
1069
|
-
lines.push(` for (const n of __newNodes) this.${vn}_anchor.parentNode.insertBefore(n, this.${vn}_anchor)
|
|
1070
|
+
lines.push(` for (const n of __newNodes) { this.${vn}_anchor.parentNode.insertBefore(n, this.${vn}_anchor); customElements.upgrade(n); }`);
|
|
1070
1071
|
lines.push('');
|
|
1071
1072
|
lines.push(` this.${vn}_nodes = __newNodes;`);
|
|
1072
1073
|
lines.push(` this.${vn}_keyMap = __newMap;`);
|
|
@@ -1083,6 +1084,7 @@ export function generateComponent(parseResult, options = {}) {
|
|
|
1083
1084
|
generateItemSetup(lines, forBlock, itemVar, indexVar, propNames, signalNamesSet, computedNamesSet);
|
|
1084
1085
|
|
|
1085
1086
|
lines.push(` this.${vn}_anchor.parentNode.insertBefore(node, this.${vn}_anchor);`);
|
|
1087
|
+
lines.push(' customElements.upgrade(node);');
|
|
1086
1088
|
lines.push(` this.${vn}_nodes.push(node);`);
|
|
1087
1089
|
lines.push(' });');
|
|
1088
1090
|
lines.push(' }));');
|
|
@@ -1093,7 +1095,7 @@ export function generateComponent(parseResult, options = {}) {
|
|
|
1093
1095
|
for (const hook of onMountHooks) {
|
|
1094
1096
|
const body = transformMethodBody(hook.body, signalNames, computedNames, propsObjectName, propNames, emitsObjectName, refVarNames, constantNames);
|
|
1095
1097
|
if (hook.async) {
|
|
1096
|
-
lines.push(' (async () => {');
|
|
1098
|
+
lines.push(' ;(async () => {');
|
|
1097
1099
|
const bodyLines = body.split('\n');
|
|
1098
1100
|
for (const line of bodyLines) {
|
|
1099
1101
|
lines.push(` ${line}`);
|
|
@@ -1102,7 +1104,9 @@ export function generateComponent(parseResult, options = {}) {
|
|
|
1102
1104
|
} else {
|
|
1103
1105
|
const bodyLines = body.split('\n');
|
|
1104
1106
|
for (const line of bodyLines) {
|
|
1105
|
-
|
|
1107
|
+
const trimmed = line.trimEnd();
|
|
1108
|
+
const needsSemi = trimmed && !trimmed.endsWith(';') && !trimmed.endsWith('{') && !trimmed.endsWith('}');
|
|
1109
|
+
lines.push(` ${trimmed}${needsSemi ? ';' : ''}`);
|
|
1106
1110
|
}
|
|
1107
1111
|
}
|
|
1108
1112
|
}
|
|
@@ -1119,7 +1123,7 @@ export function generateComponent(parseResult, options = {}) {
|
|
|
1119
1123
|
for (const hook of onDestroyHooks) {
|
|
1120
1124
|
const body = transformMethodBody(hook.body, signalNames, computedNames, propsObjectName, propNames, emitsObjectName, refVarNames, constantNames);
|
|
1121
1125
|
if (hook.async) {
|
|
1122
|
-
lines.push(' (async () => {');
|
|
1126
|
+
lines.push(' ;(async () => {');
|
|
1123
1127
|
const bodyLines = body.split('\n');
|
|
1124
1128
|
for (const line of bodyLines) {
|
|
1125
1129
|
lines.push(` ${line}`);
|
|
@@ -1128,7 +1132,9 @@ export function generateComponent(parseResult, options = {}) {
|
|
|
1128
1132
|
} else {
|
|
1129
1133
|
const bodyLines = body.split('\n');
|
|
1130
1134
|
for (const line of bodyLines) {
|
|
1131
|
-
|
|
1135
|
+
const trimmed = line.trimEnd();
|
|
1136
|
+
const needsSemi = trimmed && !trimmed.endsWith(';') && !trimmed.endsWith('{') && !trimmed.endsWith('}');
|
|
1137
|
+
lines.push(` ${trimmed}${needsSemi ? ';' : ''}`);
|
|
1132
1138
|
}
|
|
1133
1139
|
}
|
|
1134
1140
|
}
|
|
@@ -1250,7 +1256,15 @@ export function generateComponent(parseResult, options = {}) {
|
|
|
1250
1256
|
} else if (b.type === 'computed') {
|
|
1251
1257
|
lines.push(` __effect(() => { ${b.varName}.textContent = this._c_${b.name}() ?? ''; });`);
|
|
1252
1258
|
} else {
|
|
1253
|
-
|
|
1259
|
+
// method/expression type — check for props.x pattern
|
|
1260
|
+
let ref;
|
|
1261
|
+
if (propsObjectName && b.name.startsWith(propsObjectName + '.')) {
|
|
1262
|
+
const propName = b.name.slice(propsObjectName.length + 1);
|
|
1263
|
+
ref = `this._s_${propName}()`;
|
|
1264
|
+
} else {
|
|
1265
|
+
ref = transformExpr(b.name, signalNames, computedNames, propsObjectName, propNames, emitsObjectName, constantNames, methodNames);
|
|
1266
|
+
}
|
|
1267
|
+
lines.push(` __effect(() => { ${b.varName}.textContent = ${ref} ?? ''; });`);
|
|
1254
1268
|
}
|
|
1255
1269
|
}
|
|
1256
1270
|
|
package/package.json
CHANGED