@sigil-dev/compiler 0.7.1 → 0.7.3
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/package.json +1 -1
- package/src/babel/index.ts +57 -54
package/package.json
CHANGED
package/src/babel/index.ts
CHANGED
|
@@ -125,13 +125,17 @@ export default function sigilPlugin(): PluginObject {
|
|
|
125
125
|
t.identifier("insert"),
|
|
126
126
|
t.identifier("insert"),
|
|
127
127
|
),
|
|
128
|
+
|
|
129
|
+
t.importSpecifier(
|
|
130
|
+
t.identifier("getHydrationNodes"),
|
|
131
|
+
t.identifier("getHydrationNodes"),
|
|
132
|
+
),
|
|
128
133
|
],
|
|
129
134
|
t.stringLiteral("@sigil-dev/runtime"),
|
|
130
135
|
),
|
|
131
136
|
);
|
|
132
137
|
},
|
|
133
138
|
exit(path, state) {
|
|
134
|
-
console.log("signals at exit:", [...signals]);
|
|
135
139
|
warnDeadReactivity(path, signals, storeSignals, state.filename)
|
|
136
140
|
}
|
|
137
141
|
},
|
|
@@ -175,78 +179,77 @@ export default function sigilPlugin(): PluginObject {
|
|
|
175
179
|
JSXElement(path) {
|
|
176
180
|
if (path.parentPath?.isJSXElement() || path.parentPath?.isJSXFragment())
|
|
177
181
|
return;
|
|
178
|
-
if (isSSR) {
|
|
179
|
-
|
|
180
|
-
path.replaceWith(
|
|
181
|
-
t.callExpression(t.identifier("__h"), [
|
|
182
|
-
processElementSSR(path.node, signals),
|
|
183
|
-
]),
|
|
184
|
-
);
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
182
|
+
if (isSSR) { /* ... existing ... */ return; }
|
|
183
|
+
|
|
187
184
|
const statements: t.Statement[] = [];
|
|
188
|
-
const genId = (() => {
|
|
189
|
-
|
|
190
|
-
return () => `_el${i++}`;
|
|
191
|
-
})();
|
|
185
|
+
const genId = (() => { let i = 0; return () => `_el${i++}`; })();
|
|
186
|
+
|
|
192
187
|
const root = processElement(
|
|
193
|
-
path.node,
|
|
194
|
-
statements,
|
|
195
|
-
genId,
|
|
196
|
-
signals,
|
|
197
|
-
scopedHash,
|
|
188
|
+
path.node, statements, genId, signals, scopedHash,
|
|
198
189
|
isHydrate,
|
|
199
190
|
isHydrate ? "__nodes" : undefined,
|
|
200
191
|
);
|
|
192
|
+
|
|
193
|
+
const body: t.Statement[] = [];
|
|
194
|
+
|
|
195
|
+
if (isHydrate) {
|
|
196
|
+
// DECLARE __nodes locally — every IIFE owns its own context
|
|
197
|
+
body.push(
|
|
198
|
+
t.variableDeclaration("const", [
|
|
199
|
+
t.variableDeclarator(
|
|
200
|
+
t.identifier("__nodes"),
|
|
201
|
+
t.callExpression(t.identifier("getHydrationNodes"), [])
|
|
202
|
+
)
|
|
203
|
+
])
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
body.push(...statements);
|
|
208
|
+
body.push(t.returnStatement(t.identifier(root)));
|
|
209
|
+
|
|
201
210
|
path.replaceWith(
|
|
202
211
|
t.callExpression(
|
|
203
|
-
t.arrowFunctionExpression(
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
...statements,
|
|
207
|
-
t.returnStatement(t.identifier(root)),
|
|
208
|
-
]),
|
|
209
|
-
),
|
|
210
|
-
[],
|
|
211
|
-
),
|
|
212
|
+
t.arrowFunctionExpression([], t.blockStatement(body)),
|
|
213
|
+
[]
|
|
214
|
+
)
|
|
212
215
|
);
|
|
213
216
|
},
|
|
214
217
|
JSXFragment(path) {
|
|
215
218
|
if (path.parentPath?.isJSXElement() || path.parentPath?.isJSXFragment())
|
|
216
219
|
return;
|
|
217
|
-
if (isSSR) {
|
|
218
|
-
|
|
219
|
-
t.callExpression(t.identifier("__h"), [
|
|
220
|
-
processFragmentSSR(path.node, signals),
|
|
221
|
-
]),
|
|
222
|
-
);
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
220
|
+
if (isSSR) { /* ... existing ... */ return; }
|
|
221
|
+
|
|
225
222
|
const statements: t.Statement[] = [];
|
|
226
|
-
const genId = (() => {
|
|
227
|
-
|
|
228
|
-
return () => `_el${i++}`;
|
|
229
|
-
})();
|
|
223
|
+
const genId = (() => { let i = 0; return () => `_el${i++}`; })();
|
|
224
|
+
|
|
230
225
|
const root = processFragment(
|
|
231
|
-
path.node,
|
|
232
|
-
statements,
|
|
233
|
-
genId,
|
|
234
|
-
signals,
|
|
235
|
-
scopedHash,
|
|
226
|
+
path.node, statements, genId, signals, scopedHash,
|
|
236
227
|
isHydrate,
|
|
237
228
|
isHydrate ? "__nodes" : undefined,
|
|
238
229
|
);
|
|
230
|
+
|
|
231
|
+
const body: t.Statement[] = [];
|
|
232
|
+
|
|
233
|
+
if (isHydrate) {
|
|
234
|
+
// DECLARE __nodes locally — every IIFE owns its own context
|
|
235
|
+
body.push(
|
|
236
|
+
t.variableDeclaration("const", [
|
|
237
|
+
t.variableDeclarator(
|
|
238
|
+
t.identifier("__nodes"),
|
|
239
|
+
t.callExpression(t.identifier("getHydrationNodes"), [])
|
|
240
|
+
)
|
|
241
|
+
])
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
body.push(...statements);
|
|
246
|
+
body.push(t.returnStatement(t.identifier(root)));
|
|
247
|
+
|
|
239
248
|
path.replaceWith(
|
|
240
249
|
t.callExpression(
|
|
241
|
-
t.arrowFunctionExpression(
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
...statements,
|
|
245
|
-
t.returnStatement(t.identifier(root)),
|
|
246
|
-
]),
|
|
247
|
-
),
|
|
248
|
-
[],
|
|
249
|
-
),
|
|
250
|
+
t.arrowFunctionExpression([], t.blockStatement(body)),
|
|
251
|
+
[]
|
|
252
|
+
)
|
|
250
253
|
);
|
|
251
254
|
},
|
|
252
255
|
},
|