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