babel-plugin-essor 0.0.15-beta.1 → 0.0.15-beta.6
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/dist/index.cjs +327 -302
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +327 -302
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -19,7 +19,7 @@ var __spreadValues = (a2, b) => {
|
|
|
19
19
|
var __spreadProps = (a2, b) => __defProps(a2, __getOwnPropDescs(b));
|
|
20
20
|
|
|
21
21
|
// src/program.ts
|
|
22
|
-
import { types as
|
|
22
|
+
import { types as t4 } from "@babel/core";
|
|
23
23
|
|
|
24
24
|
// src/import.ts
|
|
25
25
|
import { types as t } from "@babel/core";
|
|
@@ -205,75 +205,31 @@ function createImport(path, imports, from) {
|
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
207
|
|
|
208
|
-
// src/
|
|
209
|
-
|
|
210
|
-
enter: (path, state) => {
|
|
211
|
-
const opts = __spreadValues(__spreadValues({}, DEFAULT_OPTIONS), state.opts);
|
|
212
|
-
const imports = createImportIdentifiers(path);
|
|
213
|
-
clearImport();
|
|
214
|
-
path.state = __spreadProps(__spreadValues({}, state), {
|
|
215
|
-
opts,
|
|
216
|
-
imports,
|
|
217
|
-
declarations: [],
|
|
218
|
-
// Collect template declarations during transformation
|
|
219
|
-
filename: state.filename,
|
|
220
|
-
events: /* @__PURE__ */ new Set()
|
|
221
|
-
// Track delegated events for optimization
|
|
222
|
-
});
|
|
223
|
-
},
|
|
224
|
-
// eslint-disable-next-line unused-imports/no-unused-vars
|
|
225
|
-
exit: (path, state) => {
|
|
226
|
-
const pluginState = path.state;
|
|
227
|
-
const { imports, declarations, events } = pluginState;
|
|
228
|
-
const insertIndex = path.node.body.findIndex(
|
|
229
|
-
(node) => !t2.isImportDeclaration(node) && !t2.isExportDeclaration(node)
|
|
230
|
-
);
|
|
231
|
-
if (declarations == null ? void 0 : declarations.length) {
|
|
232
|
-
const templateDeclaration = t2.variableDeclaration("const", declarations);
|
|
233
|
-
if (insertIndex !== -1) {
|
|
234
|
-
path.node.body.splice(insertIndex, 0, templateDeclaration);
|
|
235
|
-
} else {
|
|
236
|
-
path.node.body.push(templateDeclaration);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
if (events && events.size > 0) {
|
|
240
|
-
const eventsDeclaration = t2.expressionStatement(
|
|
241
|
-
t2.callExpression(imports.delegateEvents, [
|
|
242
|
-
t2.arrayExpression(Array.from(events).map((event) => t2.stringLiteral(event)))
|
|
243
|
-
])
|
|
244
|
-
);
|
|
245
|
-
addImport(importMap.delegateEvents);
|
|
246
|
-
path.node.body.push(eventsDeclaration);
|
|
247
|
-
}
|
|
248
|
-
createImport(path, imports, "essor");
|
|
249
|
-
}
|
|
250
|
-
};
|
|
251
|
-
|
|
252
|
-
// src/signals/props.ts
|
|
253
|
-
import { types as t4 } from "@babel/core";
|
|
208
|
+
// src/signals/symbol.ts
|
|
209
|
+
import { types as t3 } from "@babel/core";
|
|
254
210
|
|
|
255
211
|
// src/signals/utils.ts
|
|
256
|
-
import { types as
|
|
212
|
+
import { types as t2 } from "@babel/core";
|
|
257
213
|
function isValidPath(path) {
|
|
258
214
|
return !!(path && path.node);
|
|
259
215
|
}
|
|
260
216
|
function isJSXNode(node) {
|
|
261
|
-
return !!(node && (
|
|
217
|
+
return !!(node && (t2.isJSXElement(node) || t2.isJSXFragment(node)));
|
|
262
218
|
}
|
|
263
219
|
function mightReturnJSX(expr) {
|
|
264
220
|
if (isJSXNode(expr)) {
|
|
265
221
|
return true;
|
|
266
222
|
}
|
|
267
|
-
if (
|
|
223
|
+
if (t2.isConditionalExpression(expr)) {
|
|
268
224
|
return mightReturnJSX(expr.consequent) || mightReturnJSX(expr.alternate);
|
|
269
225
|
}
|
|
270
|
-
if (
|
|
226
|
+
if (t2.isLogicalExpression(expr)) {
|
|
271
227
|
return mightReturnJSX(expr.left) || mightReturnJSX(expr.right);
|
|
272
228
|
}
|
|
273
|
-
if (
|
|
229
|
+
if (t2.isSequenceExpression(expr)) {
|
|
274
230
|
return expr.expressions.some(mightReturnJSX);
|
|
275
231
|
}
|
|
276
|
-
if (
|
|
232
|
+
if (t2.isParenthesizedExpression(expr)) {
|
|
277
233
|
return mightReturnJSX(expr.expression);
|
|
278
234
|
}
|
|
279
235
|
return false;
|
|
@@ -283,7 +239,7 @@ function checkHasJSXReturn(path) {
|
|
|
283
239
|
try {
|
|
284
240
|
const body = path.get("body");
|
|
285
241
|
if (!isValidPath(body)) return false;
|
|
286
|
-
if (!
|
|
242
|
+
if (!t2.isBlockStatement(body.node)) {
|
|
287
243
|
return mightReturnJSX(body.node);
|
|
288
244
|
}
|
|
289
245
|
let hasJSX = false;
|
|
@@ -304,202 +260,22 @@ function checkHasJSXReturn(path) {
|
|
|
304
260
|
}
|
|
305
261
|
}
|
|
306
262
|
function isMemberAccessingProperty(node, propertyName) {
|
|
307
|
-
if (!node.computed &&
|
|
263
|
+
if (!node.computed && t2.isIdentifier(node.property) && node.property.name === propertyName) {
|
|
308
264
|
return true;
|
|
309
265
|
}
|
|
310
|
-
if (node.computed &&
|
|
266
|
+
if (node.computed && t2.isStringLiteral(node.property) && node.property.value === propertyName) {
|
|
311
267
|
return true;
|
|
312
268
|
}
|
|
313
269
|
return false;
|
|
314
270
|
}
|
|
315
271
|
|
|
316
|
-
// src/signals/props.ts
|
|
317
|
-
function transformProperty(path, properties, parentPath, defaultValues = {}) {
|
|
318
|
-
properties.forEach((property, index) => {
|
|
319
|
-
try {
|
|
320
|
-
if (!t4.isObjectProperty(property)) {
|
|
321
|
-
return;
|
|
322
|
-
}
|
|
323
|
-
if (!t4.isIdentifier(property.key)) {
|
|
324
|
-
if (true) {
|
|
325
|
-
ne("transformObjectProperties: Skipping computed property", { index });
|
|
326
|
-
}
|
|
327
|
-
return;
|
|
328
|
-
}
|
|
329
|
-
const keyName = property.key.name;
|
|
330
|
-
if (t4.isIdentifier(property.value)) {
|
|
331
|
-
path.scope.rename(property.value.name, `${parentPath}.${keyName}`);
|
|
332
|
-
} else if (t4.isAssignmentPattern(property.value)) {
|
|
333
|
-
if (t4.isIdentifier(property.value.left)) {
|
|
334
|
-
defaultValues[keyName] = property.value.right;
|
|
335
|
-
path.scope.rename(property.value.left.name, `${parentPath}.${keyName}`);
|
|
336
|
-
} else if (t4.isObjectPattern(property.value.left)) {
|
|
337
|
-
transformProperty(
|
|
338
|
-
path,
|
|
339
|
-
property.value.left.properties,
|
|
340
|
-
`${parentPath}.${keyName}`,
|
|
341
|
-
defaultValues
|
|
342
|
-
);
|
|
343
|
-
defaultValues[keyName] = property.value.right;
|
|
344
|
-
}
|
|
345
|
-
} else if (t4.isObjectPattern(property.value)) {
|
|
346
|
-
transformProperty(
|
|
347
|
-
path,
|
|
348
|
-
property.value.properties,
|
|
349
|
-
`${parentPath}.${keyName}`,
|
|
350
|
-
defaultValues
|
|
351
|
-
);
|
|
352
|
-
}
|
|
353
|
-
} catch (error) {
|
|
354
|
-
ne("transformProperty", `Failed to process property at index ${index}`, {
|
|
355
|
-
error: error instanceof Error ? error.message : String(error)
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
});
|
|
359
|
-
return defaultValues;
|
|
360
|
-
}
|
|
361
|
-
function buildRestVariableDeclaration(state, restName, parentPath, excludeProps) {
|
|
362
|
-
const validExcludeProps = excludeProps.filter(Boolean);
|
|
363
|
-
let init;
|
|
364
|
-
const pathParts = parentPath.split(".").filter((part) => part.length > 0);
|
|
365
|
-
let sourceObject = t4.identifier(pathParts[0] || "__props");
|
|
366
|
-
for (let i = 1; i < pathParts.length; i++) {
|
|
367
|
-
sourceObject = t4.memberExpression(sourceObject, t4.identifier(pathParts[i]));
|
|
368
|
-
}
|
|
369
|
-
if (validExcludeProps.length === 0) {
|
|
370
|
-
init = sourceObject;
|
|
371
|
-
} else {
|
|
372
|
-
init = t4.callExpression(state.imports.omitProps, [
|
|
373
|
-
sourceObject,
|
|
374
|
-
t4.arrayExpression(validExcludeProps.map((name) => t4.stringLiteral(name)))
|
|
375
|
-
]);
|
|
376
|
-
}
|
|
377
|
-
return t4.variableDeclaration("const", [t4.variableDeclarator(t4.identifier(restName), init)]);
|
|
378
|
-
}
|
|
379
|
-
function transformRestProperties(path, restProperties, notRestNames = [], nestedRestParams = []) {
|
|
380
|
-
if (!t4.isIdentifier(restProperties.argument)) {
|
|
381
|
-
return;
|
|
382
|
-
}
|
|
383
|
-
const restName = restProperties.argument.name;
|
|
384
|
-
if (notRestNames.length === 0 && nestedRestParams.length === 0) {
|
|
385
|
-
path.node.params[0] = t4.identifier(restName);
|
|
386
|
-
} else {
|
|
387
|
-
const restDeclarations = [];
|
|
388
|
-
if (nestedRestParams.length > 0) {
|
|
389
|
-
for (const nestedRest of nestedRestParams) {
|
|
390
|
-
const nestedRestDeclaration = buildRestVariableDeclaration(
|
|
391
|
-
path.state,
|
|
392
|
-
nestedRest.name,
|
|
393
|
-
nestedRest.parentPath,
|
|
394
|
-
nestedRest.excludeProps
|
|
395
|
-
);
|
|
396
|
-
restDeclarations.push(nestedRestDeclaration);
|
|
397
|
-
if (nestedRest.excludeProps.length > 0) {
|
|
398
|
-
addImport(importMap.omitProps);
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
if (restProperties) {
|
|
403
|
-
const restDeclaration = buildRestVariableDeclaration(
|
|
404
|
-
path.state,
|
|
405
|
-
restName,
|
|
406
|
-
TRANSFORM_PROPERTY_NAME,
|
|
407
|
-
notRestNames
|
|
408
|
-
);
|
|
409
|
-
restDeclarations.push(restDeclaration);
|
|
410
|
-
if (notRestNames.length) {
|
|
411
|
-
addImport(importMap.omitProps);
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
for (const declaration of restDeclarations) {
|
|
415
|
-
const body = path.node.body;
|
|
416
|
-
body.body.unshift(declaration);
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
function buildDefaultValueObject(defaultValues) {
|
|
421
|
-
if (!P(defaultValues)) {
|
|
422
|
-
return t4.objectExpression([]);
|
|
423
|
-
}
|
|
424
|
-
const properties = [];
|
|
425
|
-
for (const [key, value] of Object.entries(defaultValues)) {
|
|
426
|
-
if (!key) {
|
|
427
|
-
continue;
|
|
428
|
-
}
|
|
429
|
-
let propertyValue;
|
|
430
|
-
if (P(value) && !t4.isNode(value)) {
|
|
431
|
-
propertyValue = buildDefaultValueObject(value);
|
|
432
|
-
} else if (t4.isExpression(value)) {
|
|
433
|
-
propertyValue = value;
|
|
434
|
-
} else {
|
|
435
|
-
continue;
|
|
436
|
-
}
|
|
437
|
-
properties.push(t4.objectProperty(t4.identifier(key), propertyValue));
|
|
438
|
-
}
|
|
439
|
-
return t4.objectExpression(properties);
|
|
440
|
-
}
|
|
441
|
-
function buildDefaultValue(path, defaultValues) {
|
|
442
|
-
const propsParam = Object.keys(defaultValues).length > 0 ? t4.assignmentPattern(
|
|
443
|
-
t4.identifier(TRANSFORM_PROPERTY_NAME),
|
|
444
|
-
buildDefaultValueObject(defaultValues)
|
|
445
|
-
) : t4.identifier(TRANSFORM_PROPERTY_NAME);
|
|
446
|
-
path.node.params[0] = propsParam;
|
|
447
|
-
}
|
|
448
|
-
function transformProps(path) {
|
|
449
|
-
const firstParam = path.node.params[0];
|
|
450
|
-
if (!firstParam || !t4.isObjectPattern(firstParam) || !checkHasJSXReturn(path)) {
|
|
451
|
-
return;
|
|
452
|
-
}
|
|
453
|
-
const state = path.state;
|
|
454
|
-
const properties = firstParam.properties;
|
|
455
|
-
const signalPrefix = state.opts.symbol || "$";
|
|
456
|
-
const notRestProperties = properties.filter((prop) => !t4.isRestElement(prop));
|
|
457
|
-
const restProperties = properties.find((prop) => t4.isRestElement(prop));
|
|
458
|
-
const notRestNames = notRestProperties.map((prop) => t4.isIdentifier(prop.key) ? prop.key.name : null).filter((name) => name !== null);
|
|
459
|
-
if (true) {
|
|
460
|
-
if (notRestNames.some((name) => q(name, signalPrefix))) {
|
|
461
|
-
ne(
|
|
462
|
-
"transformProps",
|
|
463
|
-
"Property names cannot start with signal prefix",
|
|
464
|
-
notRestNames.filter((name) => q(name, signalPrefix))
|
|
465
|
-
);
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
if (notRestProperties.length) {
|
|
469
|
-
const defaultValues = transformProperty(path, notRestProperties, TRANSFORM_PROPERTY_NAME);
|
|
470
|
-
buildDefaultValue(path, defaultValues);
|
|
471
|
-
}
|
|
472
|
-
if (restProperties) {
|
|
473
|
-
transformRestProperties(path, restProperties, notRestNames);
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
// src/jsx/context.ts
|
|
478
|
-
var contextStack = [];
|
|
479
|
-
function getContext() {
|
|
480
|
-
if (!contextStack.length) {
|
|
481
|
-
throw new Error("No active context found. Ensure setContext has been called.");
|
|
482
|
-
}
|
|
483
|
-
return contextStack[contextStack.length - 1];
|
|
484
|
-
}
|
|
485
|
-
function setContext(context) {
|
|
486
|
-
contextStack.push(context);
|
|
487
|
-
}
|
|
488
|
-
function resetContext() {
|
|
489
|
-
contextStack.pop();
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
// src/jsx/client.ts
|
|
493
|
-
import { types as t8 } from "@babel/core";
|
|
494
|
-
|
|
495
272
|
// src/signals/symbol.ts
|
|
496
|
-
import { types as t5 } from "@babel/core";
|
|
497
273
|
function isSignal(name) {
|
|
498
274
|
return !!name && name.startsWith("$");
|
|
499
275
|
}
|
|
500
276
|
function replaceSymbol(path) {
|
|
501
277
|
const { init, id } = path.node;
|
|
502
|
-
if (!
|
|
278
|
+
if (!t3.isIdentifier(id)) {
|
|
503
279
|
return;
|
|
504
280
|
}
|
|
505
281
|
const variableName = id.name;
|
|
@@ -509,16 +285,16 @@ function replaceSymbol(path) {
|
|
|
509
285
|
if (isAlreadySignalCall(init)) {
|
|
510
286
|
return;
|
|
511
287
|
}
|
|
512
|
-
const isComputed = init && (
|
|
288
|
+
const isComputed = init && (t3.isFunctionExpression(init) || t3.isArrowFunctionExpression(init)) && path.parent.kind === "const";
|
|
513
289
|
const importName = isComputed ? "computed" : "signal";
|
|
514
290
|
const state = path.state;
|
|
515
291
|
const args = init ? [init] : [];
|
|
516
|
-
const newInit =
|
|
292
|
+
const newInit = t3.callExpression(t3.identifier(state.imports[importName].name), args);
|
|
517
293
|
addImport(importName);
|
|
518
294
|
path.node.init = newInit;
|
|
519
295
|
}
|
|
520
296
|
function isAlreadySignalCall(init) {
|
|
521
|
-
if (!init || !
|
|
297
|
+
if (!init || !t3.isCallExpression(init) || !t3.isIdentifier(init.callee)) {
|
|
522
298
|
return false;
|
|
523
299
|
}
|
|
524
300
|
const calleeName = init.callee.name;
|
|
@@ -538,7 +314,11 @@ function symbolIdentifier(path) {
|
|
|
538
314
|
if (isAlreadyValueAccess(path)) {
|
|
539
315
|
return;
|
|
540
316
|
}
|
|
541
|
-
path.
|
|
317
|
+
const parent = path.parent;
|
|
318
|
+
if (t3.isMemberExpression(parent) && parent.property === path.node) {
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
path.replaceWith(t3.memberExpression(t3.identifier(name), t3.identifier("value")));
|
|
542
322
|
}
|
|
543
323
|
function shouldProcessIdentifier(path, parentPath) {
|
|
544
324
|
if (!parentPath) {
|
|
@@ -546,38 +326,38 @@ function shouldProcessIdentifier(path, parentPath) {
|
|
|
546
326
|
}
|
|
547
327
|
const parent = parentPath.node;
|
|
548
328
|
const currentNode = path.node;
|
|
549
|
-
if (
|
|
329
|
+
if (t3.isVariableDeclarator(parent) || t3.isArrayPattern(parent) || t3.isObjectPattern(parent)) {
|
|
550
330
|
return false;
|
|
551
331
|
}
|
|
552
|
-
if (
|
|
332
|
+
if (t3.isImportSpecifier(parent) || t3.isImportDefaultSpecifier(parent) || t3.isImportNamespaceSpecifier(parent)) {
|
|
553
333
|
return false;
|
|
554
334
|
}
|
|
555
|
-
if (
|
|
335
|
+
if (t3.isFunctionDeclaration(parent) || t3.isFunctionExpression(parent) || t3.isArrowFunctionExpression(parent)) {
|
|
556
336
|
return false;
|
|
557
337
|
}
|
|
558
|
-
if (
|
|
338
|
+
if (t3.isClassDeclaration(parent) && parent.id === currentNode) {
|
|
559
339
|
return false;
|
|
560
340
|
}
|
|
561
|
-
if (
|
|
341
|
+
if (t3.isObjectMethod(parent) || t3.isClassMethod(parent)) {
|
|
562
342
|
return false;
|
|
563
343
|
}
|
|
564
|
-
if (
|
|
344
|
+
if (t3.isObjectProperty(parent) && parent.key === currentNode) {
|
|
565
345
|
return false;
|
|
566
346
|
}
|
|
567
|
-
if (
|
|
347
|
+
if (t3.isLabeledStatement(parent) && parent.label === currentNode) {
|
|
568
348
|
return false;
|
|
569
349
|
}
|
|
570
|
-
if ((
|
|
350
|
+
if ((t3.isBreakStatement(parent) || t3.isContinueStatement(parent)) && parent.label === currentNode) {
|
|
571
351
|
return false;
|
|
572
352
|
}
|
|
573
353
|
return true;
|
|
574
354
|
}
|
|
575
355
|
function isAlreadyValueAccess(path) {
|
|
576
356
|
const parent = path.parent;
|
|
577
|
-
if (
|
|
357
|
+
if (t3.isMemberExpression(parent) && parent.object === path.node) {
|
|
578
358
|
return isMemberAccessingProperty(parent, "value");
|
|
579
359
|
}
|
|
580
|
-
if (!
|
|
360
|
+
if (!t3.isParenthesizedExpression(parent) && !t3.isTSAsExpression(parent) && !t3.isTSNonNullExpression(parent)) {
|
|
581
361
|
return false;
|
|
582
362
|
}
|
|
583
363
|
const ancestorCheck = path.findParent((p) => {
|
|
@@ -594,7 +374,7 @@ function symbolAssignment(path) {
|
|
|
594
374
|
return;
|
|
595
375
|
}
|
|
596
376
|
const { left } = path.node;
|
|
597
|
-
if (!
|
|
377
|
+
if (!t3.isIdentifier(left)) {
|
|
598
378
|
return;
|
|
599
379
|
}
|
|
600
380
|
const name = left.name;
|
|
@@ -604,17 +384,17 @@ function symbolAssignment(path) {
|
|
|
604
384
|
if (isAlreadyValueAssignment(left)) {
|
|
605
385
|
return;
|
|
606
386
|
}
|
|
607
|
-
path.node.left =
|
|
387
|
+
path.node.left = t3.memberExpression(t3.identifier(name), t3.identifier("value"));
|
|
608
388
|
}
|
|
609
389
|
function isAlreadyValueAssignment(left) {
|
|
610
|
-
return
|
|
390
|
+
return t3.isMemberExpression(left) && isMemberAccessingProperty(left, "value");
|
|
611
391
|
}
|
|
612
392
|
function symbolUpdate(path) {
|
|
613
393
|
if (!isValidPath(path)) {
|
|
614
394
|
return;
|
|
615
395
|
}
|
|
616
396
|
const { argument } = path.node;
|
|
617
|
-
if (!
|
|
397
|
+
if (!t3.isIdentifier(argument)) {
|
|
618
398
|
return;
|
|
619
399
|
}
|
|
620
400
|
const name = argument.name;
|
|
@@ -624,10 +404,10 @@ function symbolUpdate(path) {
|
|
|
624
404
|
if (isAlreadyValueUpdate(argument)) {
|
|
625
405
|
return;
|
|
626
406
|
}
|
|
627
|
-
path.node.argument =
|
|
407
|
+
path.node.argument = t3.memberExpression(t3.identifier(name), t3.identifier("value"));
|
|
628
408
|
}
|
|
629
409
|
function isAlreadyValueUpdate(argument) {
|
|
630
|
-
return
|
|
410
|
+
return t3.isMemberExpression(argument) && isMemberAccessingProperty(argument, "value");
|
|
631
411
|
}
|
|
632
412
|
function symbolObjectPattern(path) {
|
|
633
413
|
if (!isValidPath(path)) {
|
|
@@ -639,9 +419,9 @@ function symbolObjectPattern(path) {
|
|
|
639
419
|
}
|
|
640
420
|
for (const property of properties) {
|
|
641
421
|
if (!property) continue;
|
|
642
|
-
if (
|
|
422
|
+
if (t3.isObjectProperty(property)) {
|
|
643
423
|
handleObjectProperty(property, path);
|
|
644
|
-
} else if (
|
|
424
|
+
} else if (t3.isRestElement(property)) {
|
|
645
425
|
handleRestElement(property, path);
|
|
646
426
|
}
|
|
647
427
|
}
|
|
@@ -651,34 +431,34 @@ function handleObjectProperty(property, parentPath) {
|
|
|
651
431
|
return;
|
|
652
432
|
}
|
|
653
433
|
const value = property.value;
|
|
654
|
-
if (
|
|
434
|
+
if (t3.isObjectPattern(value)) {
|
|
655
435
|
const mockPath = {
|
|
656
436
|
node: value,
|
|
657
437
|
state: parentPath.state,
|
|
658
438
|
parentPath
|
|
659
439
|
};
|
|
660
440
|
symbolObjectPattern(mockPath);
|
|
661
|
-
} else if (
|
|
441
|
+
} else if (t3.isArrayPattern(value)) {
|
|
662
442
|
const mockPath = {
|
|
663
443
|
node: value,
|
|
664
444
|
state: parentPath.state,
|
|
665
445
|
parentPath
|
|
666
446
|
};
|
|
667
447
|
symbolArrayPattern(mockPath);
|
|
668
|
-
} else if (
|
|
448
|
+
} else if (t3.isAssignmentPattern(value)) {
|
|
669
449
|
handleAssignmentPattern(value, parentPath);
|
|
670
450
|
}
|
|
671
451
|
}
|
|
672
452
|
function handleAssignmentPattern(pattern, parentPath) {
|
|
673
453
|
const left = pattern.left;
|
|
674
|
-
if (
|
|
454
|
+
if (t3.isObjectPattern(left)) {
|
|
675
455
|
const mockPath = {
|
|
676
456
|
node: left,
|
|
677
457
|
state: parentPath.state,
|
|
678
458
|
parentPath
|
|
679
459
|
};
|
|
680
460
|
symbolObjectPattern(mockPath);
|
|
681
|
-
} else if (
|
|
461
|
+
} else if (t3.isArrayPattern(left)) {
|
|
682
462
|
const mockPath = {
|
|
683
463
|
node: left,
|
|
684
464
|
state: parentPath.state,
|
|
@@ -692,14 +472,14 @@ function handleRestElement(restElement, parentPath) {
|
|
|
692
472
|
return;
|
|
693
473
|
}
|
|
694
474
|
const argument = restElement.argument;
|
|
695
|
-
if (
|
|
475
|
+
if (t3.isObjectPattern(argument)) {
|
|
696
476
|
const mockPath = {
|
|
697
477
|
node: argument,
|
|
698
478
|
state: parentPath.state,
|
|
699
479
|
parentPath
|
|
700
480
|
};
|
|
701
481
|
symbolObjectPattern(mockPath);
|
|
702
|
-
} else if (
|
|
482
|
+
} else if (t3.isArrayPattern(argument)) {
|
|
703
483
|
const mockPath = {
|
|
704
484
|
node: argument,
|
|
705
485
|
state: parentPath.state,
|
|
@@ -718,18 +498,18 @@ function symbolArrayPattern(path) {
|
|
|
718
498
|
}
|
|
719
499
|
for (const element of elements) {
|
|
720
500
|
if (!element) continue;
|
|
721
|
-
if (
|
|
501
|
+
if (t3.isAssignmentPattern(element)) {
|
|
722
502
|
handleAssignmentPattern(element, path);
|
|
723
|
-
} else if (
|
|
503
|
+
} else if (t3.isRestElement(element)) {
|
|
724
504
|
handleArrayRestElement(element, path);
|
|
725
|
-
} else if (
|
|
505
|
+
} else if (t3.isObjectPattern(element)) {
|
|
726
506
|
const mockPath = {
|
|
727
507
|
node: element,
|
|
728
508
|
state: path.state,
|
|
729
509
|
parentPath: path
|
|
730
510
|
};
|
|
731
511
|
symbolObjectPattern(mockPath);
|
|
732
|
-
} else if (
|
|
512
|
+
} else if (t3.isArrayPattern(element)) {
|
|
733
513
|
const mockPath = {
|
|
734
514
|
node: element,
|
|
735
515
|
state: path.state,
|
|
@@ -744,14 +524,14 @@ function handleArrayRestElement(restElement, parentPath) {
|
|
|
744
524
|
return;
|
|
745
525
|
}
|
|
746
526
|
const argument = restElement.argument;
|
|
747
|
-
if (
|
|
527
|
+
if (t3.isArrayPattern(argument)) {
|
|
748
528
|
const mockPath = {
|
|
749
529
|
node: argument,
|
|
750
530
|
state: parentPath.state,
|
|
751
531
|
parentPath
|
|
752
532
|
};
|
|
753
533
|
symbolArrayPattern(mockPath);
|
|
754
|
-
} else if (
|
|
534
|
+
} else if (t3.isObjectPattern(argument)) {
|
|
755
535
|
const mockPath = {
|
|
756
536
|
node: argument,
|
|
757
537
|
state: parentPath.state,
|
|
@@ -761,6 +541,249 @@ function handleArrayRestElement(restElement, parentPath) {
|
|
|
761
541
|
}
|
|
762
542
|
}
|
|
763
543
|
|
|
544
|
+
// src/program.ts
|
|
545
|
+
function withState(visitor, parentState) {
|
|
546
|
+
return (path) => {
|
|
547
|
+
path.state = parentState;
|
|
548
|
+
visitor(path);
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
var transformProgram = {
|
|
552
|
+
enter: (path, state) => {
|
|
553
|
+
const opts = __spreadValues(__spreadValues({}, DEFAULT_OPTIONS), state.opts);
|
|
554
|
+
const imports = createImportIdentifiers(path);
|
|
555
|
+
clearImport();
|
|
556
|
+
path.state = __spreadProps(__spreadValues({}, state), {
|
|
557
|
+
opts,
|
|
558
|
+
imports,
|
|
559
|
+
declarations: [],
|
|
560
|
+
// Collect template declarations during transformation
|
|
561
|
+
filename: state.filename,
|
|
562
|
+
events: /* @__PURE__ */ new Set()
|
|
563
|
+
// Track delegated events for optimization
|
|
564
|
+
});
|
|
565
|
+
const parentState = path.state;
|
|
566
|
+
path.traverse({
|
|
567
|
+
VariableDeclarator: withState(replaceSymbol, parentState),
|
|
568
|
+
// let $x = 0 → let $x = signal(0)
|
|
569
|
+
Identifier: withState(symbolIdentifier, parentState),
|
|
570
|
+
// $x → $x.value
|
|
571
|
+
AssignmentExpression: withState(symbolAssignment, parentState),
|
|
572
|
+
// $x = 1 → $x.value = 1
|
|
573
|
+
UpdateExpression: withState(symbolUpdate, parentState),
|
|
574
|
+
// $x++ → $x.value++
|
|
575
|
+
ObjectPattern: withState(symbolObjectPattern, parentState),
|
|
576
|
+
// { $x } → handle nested patterns
|
|
577
|
+
ArrayPattern: withState(symbolArrayPattern, parentState)
|
|
578
|
+
// [$x] → handle nested patterns
|
|
579
|
+
});
|
|
580
|
+
},
|
|
581
|
+
// eslint-disable-next-line unused-imports/no-unused-vars
|
|
582
|
+
exit: (path, state) => {
|
|
583
|
+
const pluginState = path.state;
|
|
584
|
+
const { imports, declarations, events } = pluginState;
|
|
585
|
+
const insertIndex = path.node.body.findIndex((node) => !t4.isImportDeclaration(node));
|
|
586
|
+
if (declarations == null ? void 0 : declarations.length) {
|
|
587
|
+
const templateDeclaration = t4.variableDeclaration("const", declarations);
|
|
588
|
+
if (insertIndex !== -1) {
|
|
589
|
+
path.node.body.splice(insertIndex, 0, templateDeclaration);
|
|
590
|
+
} else {
|
|
591
|
+
path.node.body.push(templateDeclaration);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
if (events && events.size > 0) {
|
|
595
|
+
const eventsDeclaration = t4.expressionStatement(
|
|
596
|
+
t4.callExpression(imports.delegateEvents, [
|
|
597
|
+
t4.arrayExpression(Array.from(events).map((event) => t4.stringLiteral(event)))
|
|
598
|
+
])
|
|
599
|
+
);
|
|
600
|
+
addImport(importMap.delegateEvents);
|
|
601
|
+
path.node.body.push(eventsDeclaration);
|
|
602
|
+
}
|
|
603
|
+
createImport(path, imports, "essor");
|
|
604
|
+
}
|
|
605
|
+
};
|
|
606
|
+
|
|
607
|
+
// src/signals/props.ts
|
|
608
|
+
import { types as t5 } from "@babel/core";
|
|
609
|
+
function transformProperty(path, properties, parentPath, defaultValues = {}) {
|
|
610
|
+
properties.forEach((property, index) => {
|
|
611
|
+
try {
|
|
612
|
+
if (!t5.isObjectProperty(property)) {
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
if (!t5.isIdentifier(property.key)) {
|
|
616
|
+
if (true) {
|
|
617
|
+
ne("transformObjectProperties: Skipping computed property", { index });
|
|
618
|
+
}
|
|
619
|
+
return;
|
|
620
|
+
}
|
|
621
|
+
const keyName = property.key.name;
|
|
622
|
+
if (t5.isIdentifier(property.value)) {
|
|
623
|
+
path.scope.rename(property.value.name, `${parentPath}.${keyName}`);
|
|
624
|
+
} else if (t5.isAssignmentPattern(property.value)) {
|
|
625
|
+
if (t5.isIdentifier(property.value.left)) {
|
|
626
|
+
defaultValues[keyName] = property.value.right;
|
|
627
|
+
path.scope.rename(property.value.left.name, `${parentPath}.${keyName}`);
|
|
628
|
+
} else if (t5.isObjectPattern(property.value.left)) {
|
|
629
|
+
transformProperty(
|
|
630
|
+
path,
|
|
631
|
+
property.value.left.properties,
|
|
632
|
+
`${parentPath}.${keyName}`,
|
|
633
|
+
defaultValues
|
|
634
|
+
);
|
|
635
|
+
defaultValues[keyName] = property.value.right;
|
|
636
|
+
}
|
|
637
|
+
} else if (t5.isObjectPattern(property.value)) {
|
|
638
|
+
transformProperty(
|
|
639
|
+
path,
|
|
640
|
+
property.value.properties,
|
|
641
|
+
`${parentPath}.${keyName}`,
|
|
642
|
+
defaultValues
|
|
643
|
+
);
|
|
644
|
+
}
|
|
645
|
+
} catch (error) {
|
|
646
|
+
ne("transformProperty", `Failed to process property at index ${index}`, {
|
|
647
|
+
error: error instanceof Error ? error.message : String(error)
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
});
|
|
651
|
+
return defaultValues;
|
|
652
|
+
}
|
|
653
|
+
function buildRestVariableDeclaration(state, restName, parentPath, excludeProps) {
|
|
654
|
+
const validExcludeProps = excludeProps.filter(Boolean);
|
|
655
|
+
let init;
|
|
656
|
+
const pathParts = parentPath.split(".").filter((part) => part.length > 0);
|
|
657
|
+
let sourceObject = t5.identifier(pathParts[0] || "__props");
|
|
658
|
+
for (let i = 1; i < pathParts.length; i++) {
|
|
659
|
+
sourceObject = t5.memberExpression(sourceObject, t5.identifier(pathParts[i]));
|
|
660
|
+
}
|
|
661
|
+
if (validExcludeProps.length === 0) {
|
|
662
|
+
init = sourceObject;
|
|
663
|
+
} else {
|
|
664
|
+
init = t5.callExpression(state.imports.omitProps, [
|
|
665
|
+
sourceObject,
|
|
666
|
+
t5.arrayExpression(validExcludeProps.map((name) => t5.stringLiteral(name)))
|
|
667
|
+
]);
|
|
668
|
+
}
|
|
669
|
+
return t5.variableDeclaration("const", [t5.variableDeclarator(t5.identifier(restName), init)]);
|
|
670
|
+
}
|
|
671
|
+
function transformRestProperties(path, restProperties, notRestNames = [], nestedRestParams = []) {
|
|
672
|
+
if (!t5.isIdentifier(restProperties.argument)) {
|
|
673
|
+
return;
|
|
674
|
+
}
|
|
675
|
+
const restName = restProperties.argument.name;
|
|
676
|
+
if (notRestNames.length === 0 && nestedRestParams.length === 0) {
|
|
677
|
+
path.node.params[0] = t5.identifier(restName);
|
|
678
|
+
} else {
|
|
679
|
+
const restDeclarations = [];
|
|
680
|
+
if (nestedRestParams.length > 0) {
|
|
681
|
+
for (const nestedRest of nestedRestParams) {
|
|
682
|
+
const nestedRestDeclaration = buildRestVariableDeclaration(
|
|
683
|
+
path.state,
|
|
684
|
+
nestedRest.name,
|
|
685
|
+
nestedRest.parentPath,
|
|
686
|
+
nestedRest.excludeProps
|
|
687
|
+
);
|
|
688
|
+
restDeclarations.push(nestedRestDeclaration);
|
|
689
|
+
if (nestedRest.excludeProps.length > 0) {
|
|
690
|
+
addImport(importMap.omitProps);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
if (restProperties) {
|
|
695
|
+
const restDeclaration = buildRestVariableDeclaration(
|
|
696
|
+
path.state,
|
|
697
|
+
restName,
|
|
698
|
+
TRANSFORM_PROPERTY_NAME,
|
|
699
|
+
notRestNames
|
|
700
|
+
);
|
|
701
|
+
restDeclarations.push(restDeclaration);
|
|
702
|
+
if (notRestNames.length) {
|
|
703
|
+
addImport(importMap.omitProps);
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
for (const declaration of restDeclarations) {
|
|
707
|
+
const body = path.node.body;
|
|
708
|
+
body.body.unshift(declaration);
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
function buildDefaultValueObject(defaultValues) {
|
|
713
|
+
if (!P(defaultValues)) {
|
|
714
|
+
return t5.objectExpression([]);
|
|
715
|
+
}
|
|
716
|
+
const properties = [];
|
|
717
|
+
for (const [key, value] of Object.entries(defaultValues)) {
|
|
718
|
+
if (!key) {
|
|
719
|
+
continue;
|
|
720
|
+
}
|
|
721
|
+
let propertyValue;
|
|
722
|
+
if (P(value) && !t5.isNode(value)) {
|
|
723
|
+
propertyValue = buildDefaultValueObject(value);
|
|
724
|
+
} else if (t5.isExpression(value)) {
|
|
725
|
+
propertyValue = value;
|
|
726
|
+
} else {
|
|
727
|
+
continue;
|
|
728
|
+
}
|
|
729
|
+
properties.push(t5.objectProperty(t5.identifier(key), propertyValue));
|
|
730
|
+
}
|
|
731
|
+
return t5.objectExpression(properties);
|
|
732
|
+
}
|
|
733
|
+
function buildDefaultValue(path, defaultValues) {
|
|
734
|
+
const propsParam = Object.keys(defaultValues).length > 0 ? t5.assignmentPattern(
|
|
735
|
+
t5.identifier(TRANSFORM_PROPERTY_NAME),
|
|
736
|
+
buildDefaultValueObject(defaultValues)
|
|
737
|
+
) : t5.identifier(TRANSFORM_PROPERTY_NAME);
|
|
738
|
+
path.node.params[0] = propsParam;
|
|
739
|
+
}
|
|
740
|
+
function transformProps(path) {
|
|
741
|
+
const firstParam = path.node.params[0];
|
|
742
|
+
if (!firstParam || !t5.isObjectPattern(firstParam) || !checkHasJSXReturn(path)) {
|
|
743
|
+
return;
|
|
744
|
+
}
|
|
745
|
+
const state = path.state;
|
|
746
|
+
const properties = firstParam.properties;
|
|
747
|
+
const signalPrefix = state.opts.symbol || "$";
|
|
748
|
+
const notRestProperties = properties.filter((prop) => !t5.isRestElement(prop));
|
|
749
|
+
const restProperties = properties.find((prop) => t5.isRestElement(prop));
|
|
750
|
+
const notRestNames = notRestProperties.map((prop) => t5.isIdentifier(prop.key) ? prop.key.name : null).filter((name) => name !== null);
|
|
751
|
+
if (true) {
|
|
752
|
+
if (notRestNames.some((name) => q(name, signalPrefix))) {
|
|
753
|
+
ne(
|
|
754
|
+
"transformProps",
|
|
755
|
+
"Property names cannot start with signal prefix",
|
|
756
|
+
notRestNames.filter((name) => q(name, signalPrefix))
|
|
757
|
+
);
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
if (notRestProperties.length) {
|
|
761
|
+
const defaultValues = transformProperty(path, notRestProperties, TRANSFORM_PROPERTY_NAME);
|
|
762
|
+
buildDefaultValue(path, defaultValues);
|
|
763
|
+
}
|
|
764
|
+
if (restProperties) {
|
|
765
|
+
transformRestProperties(path, restProperties, notRestNames);
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
// src/jsx/context.ts
|
|
770
|
+
var contextStack = [];
|
|
771
|
+
function getContext() {
|
|
772
|
+
if (!contextStack.length) {
|
|
773
|
+
throw new Error("No active context found. Ensure setContext has been called.");
|
|
774
|
+
}
|
|
775
|
+
return contextStack[contextStack.length - 1];
|
|
776
|
+
}
|
|
777
|
+
function setContext(context) {
|
|
778
|
+
contextStack.push(context);
|
|
779
|
+
}
|
|
780
|
+
function resetContext() {
|
|
781
|
+
contextStack.pop();
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
// src/jsx/client.ts
|
|
785
|
+
import { types as t8 } from "@babel/core";
|
|
786
|
+
|
|
764
787
|
// src/jsx/constants.ts
|
|
765
788
|
var CLASS_NAME = "class";
|
|
766
789
|
var STYLE_NAME = "style";
|
|
@@ -768,6 +791,7 @@ var EVENT_ATTR_NAME = "on";
|
|
|
768
791
|
var UPDATE_PREFIX = "update";
|
|
769
792
|
var FRAGMENT_NAME = "Fragment";
|
|
770
793
|
var CHILDREN_NAME = "children";
|
|
794
|
+
var REF_KEY = "ref";
|
|
771
795
|
var SPREAD_NAME = "_$spread$";
|
|
772
796
|
var CREATE_COMPONENT_NAME = "createComponent";
|
|
773
797
|
var BIND_REG = /^bind:.+/;
|
|
@@ -798,15 +822,17 @@ function isTreeNode(node) {
|
|
|
798
822
|
var treeIndex = 1;
|
|
799
823
|
function createTree(path, parentNode) {
|
|
800
824
|
const treeNode = createDefaultTree();
|
|
825
|
+
const tagName = getTagName(path.node);
|
|
826
|
+
treeNode.tag = tagName;
|
|
827
|
+
treeNode.type = determineNodeType(tagName);
|
|
828
|
+
treeNode.selfClosing = Ne(tagName);
|
|
801
829
|
if (parentNode) {
|
|
802
|
-
const
|
|
803
|
-
|
|
804
|
-
const isComponentOrFragment = isComponentName(getTagName(nodeInfo));
|
|
805
|
-
if (!isComponentOrFragment && !isBuiltInComponent) {
|
|
806
|
-
treeNode.index = ++treeIndex;
|
|
807
|
-
}
|
|
808
|
-
if (isBuiltInComponent) {
|
|
830
|
+
const parentIsComponent = parentNode.type === 1 /* COMPONENT */;
|
|
831
|
+
if (parentIsComponent) {
|
|
809
832
|
treeIndex = 1;
|
|
833
|
+
treeNode.index = treeIndex;
|
|
834
|
+
} else if (treeNode.type !== 1 /* COMPONENT */) {
|
|
835
|
+
treeNode.index = ++treeIndex;
|
|
810
836
|
}
|
|
811
837
|
treeNode.parentIndex = treeIndex;
|
|
812
838
|
} else {
|
|
@@ -822,10 +848,6 @@ function createTree(path, parentNode) {
|
|
|
822
848
|
return treeNode;
|
|
823
849
|
}
|
|
824
850
|
function processJSXElement(path, treeNode) {
|
|
825
|
-
const tagName = getTagName(path.node);
|
|
826
|
-
treeNode.tag = tagName;
|
|
827
|
-
treeNode.type = determineNodeType(tagName);
|
|
828
|
-
treeNode.selfClosing = Ne(tagName);
|
|
829
851
|
if (!path.isJSXFragment()) {
|
|
830
852
|
treeNode.props = processProps(path);
|
|
831
853
|
}
|
|
@@ -1465,7 +1487,7 @@ function transformJSXToClient(path, node) {
|
|
|
1465
1487
|
])
|
|
1466
1488
|
);
|
|
1467
1489
|
}
|
|
1468
|
-
if (dynamicCollection.children.length || dynamicCollection.props.length) {
|
|
1490
|
+
if (dynamicCollection.children.length || dynamicCollection.props.length || dynamicCollection.operations.length) {
|
|
1469
1491
|
addImport(importMap.mapNodes);
|
|
1470
1492
|
statements.push(
|
|
1471
1493
|
t8.variableDeclaration("const", [
|
|
@@ -1561,6 +1583,22 @@ function generateIndexMap({
|
|
|
1561
1583
|
}
|
|
1562
1584
|
return indexMap;
|
|
1563
1585
|
}
|
|
1586
|
+
function createRefStatement(nodesId, nodeIndex, value) {
|
|
1587
|
+
const elementRef = t8.memberExpression(nodesId, t8.numericLiteral(nodeIndex), true);
|
|
1588
|
+
const typeofCheck = t8.binaryExpression(
|
|
1589
|
+
"===",
|
|
1590
|
+
t8.unaryExpression("typeof", value),
|
|
1591
|
+
t8.stringLiteral("function")
|
|
1592
|
+
);
|
|
1593
|
+
const functionCall = t8.callExpression(value, [elementRef]);
|
|
1594
|
+
const assignmentExpr = t8.assignmentExpression(
|
|
1595
|
+
"=",
|
|
1596
|
+
t8.memberExpression(value, t8.identifier("value")),
|
|
1597
|
+
elementRef
|
|
1598
|
+
);
|
|
1599
|
+
const conditionalExpr = t8.conditionalExpression(typeofCheck, functionCall, assignmentExpr);
|
|
1600
|
+
return t8.expressionStatement(conditionalExpr);
|
|
1601
|
+
}
|
|
1564
1602
|
function createAttributeStatement(functionIdentifier, nodesId, nodeIndex, value, key) {
|
|
1565
1603
|
const args = [t8.memberExpression(nodesId, t8.numericLiteral(nodeIndex), true)];
|
|
1566
1604
|
if (key) {
|
|
@@ -1618,6 +1656,9 @@ function generateSpecificAttributeCode(attributeName, attributeValue, nodesId, n
|
|
|
1618
1656
|
createAttributeStatement(state.imports.setSpread, nodesId, nodeIndex, attributeValue)
|
|
1619
1657
|
);
|
|
1620
1658
|
break;
|
|
1659
|
+
case REF_KEY:
|
|
1660
|
+
statements.push(createRefStatement(nodesId, nodeIndex, attributeValue));
|
|
1661
|
+
break;
|
|
1621
1662
|
case STYLE_NAME:
|
|
1622
1663
|
addImport(importMap.patchStyle);
|
|
1623
1664
|
statements.push(
|
|
@@ -1768,10 +1809,7 @@ function generateDynamicPropsCode(dynamicProps, statements, state, nodesId, inde
|
|
|
1768
1809
|
function generateUnifiedMemoizedEffect(reactiveOperations, statements, state, nodesId, indexMap) {
|
|
1769
1810
|
addImport(importMap.memoEffect);
|
|
1770
1811
|
const variableDeclarations = reactiveOperations.map((op, index) => {
|
|
1771
|
-
|
|
1772
|
-
if (t8.isIdentifier(op.attrValue) && isSignal(op.attrValue.name)) {
|
|
1773
|
-
attrValue = t8.memberExpression(attrValue, t8.identifier("value"));
|
|
1774
|
-
}
|
|
1812
|
+
const attrValue = op.attrValue;
|
|
1775
1813
|
return t8.variableDeclarator(t8.identifier(`_v$${index}`), attrValue);
|
|
1776
1814
|
});
|
|
1777
1815
|
const updateStatements = reactiveOperations.map((op, index) => {
|
|
@@ -1941,7 +1979,7 @@ function processNodeDynamic(dynamicCollection, node, parentNode) {
|
|
|
1941
1979
|
if (node.props && Object.keys(node.props).length > 0) {
|
|
1942
1980
|
const currentProps = {};
|
|
1943
1981
|
for (const [attrName, attrValue] of Object.entries(node.props)) {
|
|
1944
|
-
const isReactive = t8.isNode(attrValue) && isDynamicExpression(attrValue) && !q(attrName, `${UPDATE_PREFIX}:`) && !q(attrName, EVENT_ATTR_NAME);
|
|
1982
|
+
const isReactive = t8.isNode(attrValue) && isDynamicExpression(attrValue) && !q(attrName, `${UPDATE_PREFIX}:`) && !q(attrName, EVENT_ATTR_NAME) && attrName !== REF_KEY;
|
|
1945
1983
|
if (q(attrName, `${UPDATE_PREFIX}:`)) {
|
|
1946
1984
|
const name = attrName.split(":")[1];
|
|
1947
1985
|
const setFunction = getSetFunctionForAttribute();
|
|
@@ -2263,19 +2301,6 @@ function index_default() {
|
|
|
2263
2301
|
// props
|
|
2264
2302
|
FunctionDeclaration: transformProps,
|
|
2265
2303
|
ArrowFunctionExpression: transformProps,
|
|
2266
|
-
// Symbol
|
|
2267
|
-
VariableDeclarator: replaceSymbol,
|
|
2268
|
-
// let $x = 0 → let $x = signal(0)
|
|
2269
|
-
Identifier: symbolIdentifier,
|
|
2270
|
-
// $x → $x.value
|
|
2271
|
-
AssignmentExpression: symbolAssignment,
|
|
2272
|
-
// $x = 1 → $x.value = 1
|
|
2273
|
-
UpdateExpression: symbolUpdate,
|
|
2274
|
-
// $x++ → $x.value++
|
|
2275
|
-
ObjectPattern: symbolObjectPattern,
|
|
2276
|
-
// { $x } → handle nested patterns
|
|
2277
|
-
ArrayPattern: symbolArrayPattern,
|
|
2278
|
-
// [$x] → handle nested patterns
|
|
2279
2304
|
// JSX
|
|
2280
2305
|
JSXElement: transformJSX,
|
|
2281
2306
|
JSXFragment: transformJSX
|