babel-plugin-essor 0.0.15-beta.1 → 0.0.15-beta.5
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 +329 -302
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +329 -302
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -42,7 +42,7 @@ __export(index_exports, {
|
|
|
42
42
|
module.exports = __toCommonJS(index_exports);
|
|
43
43
|
|
|
44
44
|
// src/program.ts
|
|
45
|
-
var
|
|
45
|
+
var import_core4 = require("@babel/core");
|
|
46
46
|
|
|
47
47
|
// src/import.ts
|
|
48
48
|
var import_core = require("@babel/core");
|
|
@@ -228,75 +228,31 @@ function createImport(path, imports, from) {
|
|
|
228
228
|
}
|
|
229
229
|
}
|
|
230
230
|
|
|
231
|
-
// src/
|
|
232
|
-
var
|
|
233
|
-
enter: (path, state) => {
|
|
234
|
-
const opts = __spreadValues(__spreadValues({}, DEFAULT_OPTIONS), state.opts);
|
|
235
|
-
const imports = createImportIdentifiers(path);
|
|
236
|
-
clearImport();
|
|
237
|
-
path.state = __spreadProps(__spreadValues({}, state), {
|
|
238
|
-
opts,
|
|
239
|
-
imports,
|
|
240
|
-
declarations: [],
|
|
241
|
-
// Collect template declarations during transformation
|
|
242
|
-
filename: state.filename,
|
|
243
|
-
events: /* @__PURE__ */ new Set()
|
|
244
|
-
// Track delegated events for optimization
|
|
245
|
-
});
|
|
246
|
-
},
|
|
247
|
-
// eslint-disable-next-line unused-imports/no-unused-vars
|
|
248
|
-
exit: (path, state) => {
|
|
249
|
-
const pluginState = path.state;
|
|
250
|
-
const { imports, declarations, events } = pluginState;
|
|
251
|
-
const insertIndex = path.node.body.findIndex(
|
|
252
|
-
(node) => !import_core2.types.isImportDeclaration(node) && !import_core2.types.isExportDeclaration(node)
|
|
253
|
-
);
|
|
254
|
-
if (declarations == null ? void 0 : declarations.length) {
|
|
255
|
-
const templateDeclaration = import_core2.types.variableDeclaration("const", declarations);
|
|
256
|
-
if (insertIndex !== -1) {
|
|
257
|
-
path.node.body.splice(insertIndex, 0, templateDeclaration);
|
|
258
|
-
} else {
|
|
259
|
-
path.node.body.push(templateDeclaration);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
if (events && events.size > 0) {
|
|
263
|
-
const eventsDeclaration = import_core2.types.expressionStatement(
|
|
264
|
-
import_core2.types.callExpression(imports.delegateEvents, [
|
|
265
|
-
import_core2.types.arrayExpression(Array.from(events).map((event) => import_core2.types.stringLiteral(event)))
|
|
266
|
-
])
|
|
267
|
-
);
|
|
268
|
-
addImport(importMap.delegateEvents);
|
|
269
|
-
path.node.body.push(eventsDeclaration);
|
|
270
|
-
}
|
|
271
|
-
createImport(path, imports, "essor");
|
|
272
|
-
}
|
|
273
|
-
};
|
|
274
|
-
|
|
275
|
-
// src/signals/props.ts
|
|
276
|
-
var import_core4 = require("@babel/core");
|
|
231
|
+
// src/signals/symbol.ts
|
|
232
|
+
var import_core3 = require("@babel/core");
|
|
277
233
|
|
|
278
234
|
// src/signals/utils.ts
|
|
279
|
-
var
|
|
235
|
+
var import_core2 = require("@babel/core");
|
|
280
236
|
function isValidPath(path) {
|
|
281
237
|
return !!(path && path.node);
|
|
282
238
|
}
|
|
283
239
|
function isJSXNode(node) {
|
|
284
|
-
return !!(node && (
|
|
240
|
+
return !!(node && (import_core2.types.isJSXElement(node) || import_core2.types.isJSXFragment(node)));
|
|
285
241
|
}
|
|
286
242
|
function mightReturnJSX(expr) {
|
|
287
243
|
if (isJSXNode(expr)) {
|
|
288
244
|
return true;
|
|
289
245
|
}
|
|
290
|
-
if (
|
|
246
|
+
if (import_core2.types.isConditionalExpression(expr)) {
|
|
291
247
|
return mightReturnJSX(expr.consequent) || mightReturnJSX(expr.alternate);
|
|
292
248
|
}
|
|
293
|
-
if (
|
|
249
|
+
if (import_core2.types.isLogicalExpression(expr)) {
|
|
294
250
|
return mightReturnJSX(expr.left) || mightReturnJSX(expr.right);
|
|
295
251
|
}
|
|
296
|
-
if (
|
|
252
|
+
if (import_core2.types.isSequenceExpression(expr)) {
|
|
297
253
|
return expr.expressions.some(mightReturnJSX);
|
|
298
254
|
}
|
|
299
|
-
if (
|
|
255
|
+
if (import_core2.types.isParenthesizedExpression(expr)) {
|
|
300
256
|
return mightReturnJSX(expr.expression);
|
|
301
257
|
}
|
|
302
258
|
return false;
|
|
@@ -306,7 +262,7 @@ function checkHasJSXReturn(path) {
|
|
|
306
262
|
try {
|
|
307
263
|
const body = path.get("body");
|
|
308
264
|
if (!isValidPath(body)) return false;
|
|
309
|
-
if (!
|
|
265
|
+
if (!import_core2.types.isBlockStatement(body.node)) {
|
|
310
266
|
return mightReturnJSX(body.node);
|
|
311
267
|
}
|
|
312
268
|
let hasJSX = false;
|
|
@@ -327,202 +283,22 @@ function checkHasJSXReturn(path) {
|
|
|
327
283
|
}
|
|
328
284
|
}
|
|
329
285
|
function isMemberAccessingProperty(node, propertyName) {
|
|
330
|
-
if (!node.computed &&
|
|
286
|
+
if (!node.computed && import_core2.types.isIdentifier(node.property) && node.property.name === propertyName) {
|
|
331
287
|
return true;
|
|
332
288
|
}
|
|
333
|
-
if (node.computed &&
|
|
289
|
+
if (node.computed && import_core2.types.isStringLiteral(node.property) && node.property.value === propertyName) {
|
|
334
290
|
return true;
|
|
335
291
|
}
|
|
336
292
|
return false;
|
|
337
293
|
}
|
|
338
294
|
|
|
339
|
-
// src/signals/props.ts
|
|
340
|
-
function transformProperty(path, properties, parentPath, defaultValues = {}) {
|
|
341
|
-
properties.forEach((property, index) => {
|
|
342
|
-
try {
|
|
343
|
-
if (!import_core4.types.isObjectProperty(property)) {
|
|
344
|
-
return;
|
|
345
|
-
}
|
|
346
|
-
if (!import_core4.types.isIdentifier(property.key)) {
|
|
347
|
-
if (true) {
|
|
348
|
-
ne("transformObjectProperties: Skipping computed property", { index });
|
|
349
|
-
}
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
const keyName = property.key.name;
|
|
353
|
-
if (import_core4.types.isIdentifier(property.value)) {
|
|
354
|
-
path.scope.rename(property.value.name, `${parentPath}.${keyName}`);
|
|
355
|
-
} else if (import_core4.types.isAssignmentPattern(property.value)) {
|
|
356
|
-
if (import_core4.types.isIdentifier(property.value.left)) {
|
|
357
|
-
defaultValues[keyName] = property.value.right;
|
|
358
|
-
path.scope.rename(property.value.left.name, `${parentPath}.${keyName}`);
|
|
359
|
-
} else if (import_core4.types.isObjectPattern(property.value.left)) {
|
|
360
|
-
transformProperty(
|
|
361
|
-
path,
|
|
362
|
-
property.value.left.properties,
|
|
363
|
-
`${parentPath}.${keyName}`,
|
|
364
|
-
defaultValues
|
|
365
|
-
);
|
|
366
|
-
defaultValues[keyName] = property.value.right;
|
|
367
|
-
}
|
|
368
|
-
} else if (import_core4.types.isObjectPattern(property.value)) {
|
|
369
|
-
transformProperty(
|
|
370
|
-
path,
|
|
371
|
-
property.value.properties,
|
|
372
|
-
`${parentPath}.${keyName}`,
|
|
373
|
-
defaultValues
|
|
374
|
-
);
|
|
375
|
-
}
|
|
376
|
-
} catch (error) {
|
|
377
|
-
ne("transformProperty", `Failed to process property at index ${index}`, {
|
|
378
|
-
error: error instanceof Error ? error.message : String(error)
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
});
|
|
382
|
-
return defaultValues;
|
|
383
|
-
}
|
|
384
|
-
function buildRestVariableDeclaration(state, restName, parentPath, excludeProps) {
|
|
385
|
-
const validExcludeProps = excludeProps.filter(Boolean);
|
|
386
|
-
let init;
|
|
387
|
-
const pathParts = parentPath.split(".").filter((part) => part.length > 0);
|
|
388
|
-
let sourceObject = import_core4.types.identifier(pathParts[0] || "__props");
|
|
389
|
-
for (let i = 1; i < pathParts.length; i++) {
|
|
390
|
-
sourceObject = import_core4.types.memberExpression(sourceObject, import_core4.types.identifier(pathParts[i]));
|
|
391
|
-
}
|
|
392
|
-
if (validExcludeProps.length === 0) {
|
|
393
|
-
init = sourceObject;
|
|
394
|
-
} else {
|
|
395
|
-
init = import_core4.types.callExpression(state.imports.omitProps, [
|
|
396
|
-
sourceObject,
|
|
397
|
-
import_core4.types.arrayExpression(validExcludeProps.map((name) => import_core4.types.stringLiteral(name)))
|
|
398
|
-
]);
|
|
399
|
-
}
|
|
400
|
-
return import_core4.types.variableDeclaration("const", [import_core4.types.variableDeclarator(import_core4.types.identifier(restName), init)]);
|
|
401
|
-
}
|
|
402
|
-
function transformRestProperties(path, restProperties, notRestNames = [], nestedRestParams = []) {
|
|
403
|
-
if (!import_core4.types.isIdentifier(restProperties.argument)) {
|
|
404
|
-
return;
|
|
405
|
-
}
|
|
406
|
-
const restName = restProperties.argument.name;
|
|
407
|
-
if (notRestNames.length === 0 && nestedRestParams.length === 0) {
|
|
408
|
-
path.node.params[0] = import_core4.types.identifier(restName);
|
|
409
|
-
} else {
|
|
410
|
-
const restDeclarations = [];
|
|
411
|
-
if (nestedRestParams.length > 0) {
|
|
412
|
-
for (const nestedRest of nestedRestParams) {
|
|
413
|
-
const nestedRestDeclaration = buildRestVariableDeclaration(
|
|
414
|
-
path.state,
|
|
415
|
-
nestedRest.name,
|
|
416
|
-
nestedRest.parentPath,
|
|
417
|
-
nestedRest.excludeProps
|
|
418
|
-
);
|
|
419
|
-
restDeclarations.push(nestedRestDeclaration);
|
|
420
|
-
if (nestedRest.excludeProps.length > 0) {
|
|
421
|
-
addImport(importMap.omitProps);
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
if (restProperties) {
|
|
426
|
-
const restDeclaration = buildRestVariableDeclaration(
|
|
427
|
-
path.state,
|
|
428
|
-
restName,
|
|
429
|
-
TRANSFORM_PROPERTY_NAME,
|
|
430
|
-
notRestNames
|
|
431
|
-
);
|
|
432
|
-
restDeclarations.push(restDeclaration);
|
|
433
|
-
if (notRestNames.length) {
|
|
434
|
-
addImport(importMap.omitProps);
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
for (const declaration of restDeclarations) {
|
|
438
|
-
const body = path.node.body;
|
|
439
|
-
body.body.unshift(declaration);
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
function buildDefaultValueObject(defaultValues) {
|
|
444
|
-
if (!P(defaultValues)) {
|
|
445
|
-
return import_core4.types.objectExpression([]);
|
|
446
|
-
}
|
|
447
|
-
const properties = [];
|
|
448
|
-
for (const [key, value] of Object.entries(defaultValues)) {
|
|
449
|
-
if (!key) {
|
|
450
|
-
continue;
|
|
451
|
-
}
|
|
452
|
-
let propertyValue;
|
|
453
|
-
if (P(value) && !import_core4.types.isNode(value)) {
|
|
454
|
-
propertyValue = buildDefaultValueObject(value);
|
|
455
|
-
} else if (import_core4.types.isExpression(value)) {
|
|
456
|
-
propertyValue = value;
|
|
457
|
-
} else {
|
|
458
|
-
continue;
|
|
459
|
-
}
|
|
460
|
-
properties.push(import_core4.types.objectProperty(import_core4.types.identifier(key), propertyValue));
|
|
461
|
-
}
|
|
462
|
-
return import_core4.types.objectExpression(properties);
|
|
463
|
-
}
|
|
464
|
-
function buildDefaultValue(path, defaultValues) {
|
|
465
|
-
const propsParam = Object.keys(defaultValues).length > 0 ? import_core4.types.assignmentPattern(
|
|
466
|
-
import_core4.types.identifier(TRANSFORM_PROPERTY_NAME),
|
|
467
|
-
buildDefaultValueObject(defaultValues)
|
|
468
|
-
) : import_core4.types.identifier(TRANSFORM_PROPERTY_NAME);
|
|
469
|
-
path.node.params[0] = propsParam;
|
|
470
|
-
}
|
|
471
|
-
function transformProps(path) {
|
|
472
|
-
const firstParam = path.node.params[0];
|
|
473
|
-
if (!firstParam || !import_core4.types.isObjectPattern(firstParam) || !checkHasJSXReturn(path)) {
|
|
474
|
-
return;
|
|
475
|
-
}
|
|
476
|
-
const state = path.state;
|
|
477
|
-
const properties = firstParam.properties;
|
|
478
|
-
const signalPrefix = state.opts.symbol || "$";
|
|
479
|
-
const notRestProperties = properties.filter((prop) => !import_core4.types.isRestElement(prop));
|
|
480
|
-
const restProperties = properties.find((prop) => import_core4.types.isRestElement(prop));
|
|
481
|
-
const notRestNames = notRestProperties.map((prop) => import_core4.types.isIdentifier(prop.key) ? prop.key.name : null).filter((name) => name !== null);
|
|
482
|
-
if (true) {
|
|
483
|
-
if (notRestNames.some((name) => q(name, signalPrefix))) {
|
|
484
|
-
ne(
|
|
485
|
-
"transformProps",
|
|
486
|
-
"Property names cannot start with signal prefix",
|
|
487
|
-
notRestNames.filter((name) => q(name, signalPrefix))
|
|
488
|
-
);
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
if (notRestProperties.length) {
|
|
492
|
-
const defaultValues = transformProperty(path, notRestProperties, TRANSFORM_PROPERTY_NAME);
|
|
493
|
-
buildDefaultValue(path, defaultValues);
|
|
494
|
-
}
|
|
495
|
-
if (restProperties) {
|
|
496
|
-
transformRestProperties(path, restProperties, notRestNames);
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
// src/jsx/context.ts
|
|
501
|
-
var contextStack = [];
|
|
502
|
-
function getContext() {
|
|
503
|
-
if (!contextStack.length) {
|
|
504
|
-
throw new Error("No active context found. Ensure setContext has been called.");
|
|
505
|
-
}
|
|
506
|
-
return contextStack[contextStack.length - 1];
|
|
507
|
-
}
|
|
508
|
-
function setContext(context) {
|
|
509
|
-
contextStack.push(context);
|
|
510
|
-
}
|
|
511
|
-
function resetContext() {
|
|
512
|
-
contextStack.pop();
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
// src/jsx/client.ts
|
|
516
|
-
var import_core8 = require("@babel/core");
|
|
517
|
-
|
|
518
295
|
// src/signals/symbol.ts
|
|
519
|
-
var import_core5 = require("@babel/core");
|
|
520
296
|
function isSignal(name) {
|
|
521
297
|
return !!name && name.startsWith("$");
|
|
522
298
|
}
|
|
523
299
|
function replaceSymbol(path) {
|
|
524
300
|
const { init, id } = path.node;
|
|
525
|
-
if (!
|
|
301
|
+
if (!import_core3.types.isIdentifier(id)) {
|
|
526
302
|
return;
|
|
527
303
|
}
|
|
528
304
|
const variableName = id.name;
|
|
@@ -532,16 +308,16 @@ function replaceSymbol(path) {
|
|
|
532
308
|
if (isAlreadySignalCall(init)) {
|
|
533
309
|
return;
|
|
534
310
|
}
|
|
535
|
-
const isComputed = init && (
|
|
311
|
+
const isComputed = init && (import_core3.types.isFunctionExpression(init) || import_core3.types.isArrowFunctionExpression(init)) && path.parent.kind === "const";
|
|
536
312
|
const importName = isComputed ? "computed" : "signal";
|
|
537
313
|
const state = path.state;
|
|
538
314
|
const args = init ? [init] : [];
|
|
539
|
-
const newInit =
|
|
315
|
+
const newInit = import_core3.types.callExpression(import_core3.types.identifier(state.imports[importName].name), args);
|
|
540
316
|
addImport(importName);
|
|
541
317
|
path.node.init = newInit;
|
|
542
318
|
}
|
|
543
319
|
function isAlreadySignalCall(init) {
|
|
544
|
-
if (!init || !
|
|
320
|
+
if (!init || !import_core3.types.isCallExpression(init) || !import_core3.types.isIdentifier(init.callee)) {
|
|
545
321
|
return false;
|
|
546
322
|
}
|
|
547
323
|
const calleeName = init.callee.name;
|
|
@@ -561,7 +337,11 @@ function symbolIdentifier(path) {
|
|
|
561
337
|
if (isAlreadyValueAccess(path)) {
|
|
562
338
|
return;
|
|
563
339
|
}
|
|
564
|
-
path.
|
|
340
|
+
const parent = path.parent;
|
|
341
|
+
if (import_core3.types.isMemberExpression(parent) && parent.property === path.node) {
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
path.replaceWith(import_core3.types.memberExpression(import_core3.types.identifier(name), import_core3.types.identifier("value")));
|
|
565
345
|
}
|
|
566
346
|
function shouldProcessIdentifier(path, parentPath) {
|
|
567
347
|
if (!parentPath) {
|
|
@@ -569,38 +349,38 @@ function shouldProcessIdentifier(path, parentPath) {
|
|
|
569
349
|
}
|
|
570
350
|
const parent = parentPath.node;
|
|
571
351
|
const currentNode = path.node;
|
|
572
|
-
if (
|
|
352
|
+
if (import_core3.types.isVariableDeclarator(parent) || import_core3.types.isArrayPattern(parent) || import_core3.types.isObjectPattern(parent)) {
|
|
573
353
|
return false;
|
|
574
354
|
}
|
|
575
|
-
if (
|
|
355
|
+
if (import_core3.types.isImportSpecifier(parent) || import_core3.types.isImportDefaultSpecifier(parent) || import_core3.types.isImportNamespaceSpecifier(parent)) {
|
|
576
356
|
return false;
|
|
577
357
|
}
|
|
578
|
-
if (
|
|
358
|
+
if (import_core3.types.isFunctionDeclaration(parent) || import_core3.types.isFunctionExpression(parent) || import_core3.types.isArrowFunctionExpression(parent)) {
|
|
579
359
|
return false;
|
|
580
360
|
}
|
|
581
|
-
if (
|
|
361
|
+
if (import_core3.types.isClassDeclaration(parent) && parent.id === currentNode) {
|
|
582
362
|
return false;
|
|
583
363
|
}
|
|
584
|
-
if (
|
|
364
|
+
if (import_core3.types.isObjectMethod(parent) || import_core3.types.isClassMethod(parent)) {
|
|
585
365
|
return false;
|
|
586
366
|
}
|
|
587
|
-
if (
|
|
367
|
+
if (import_core3.types.isObjectProperty(parent) && parent.key === currentNode) {
|
|
588
368
|
return false;
|
|
589
369
|
}
|
|
590
|
-
if (
|
|
370
|
+
if (import_core3.types.isLabeledStatement(parent) && parent.label === currentNode) {
|
|
591
371
|
return false;
|
|
592
372
|
}
|
|
593
|
-
if ((
|
|
373
|
+
if ((import_core3.types.isBreakStatement(parent) || import_core3.types.isContinueStatement(parent)) && parent.label === currentNode) {
|
|
594
374
|
return false;
|
|
595
375
|
}
|
|
596
376
|
return true;
|
|
597
377
|
}
|
|
598
378
|
function isAlreadyValueAccess(path) {
|
|
599
379
|
const parent = path.parent;
|
|
600
|
-
if (
|
|
380
|
+
if (import_core3.types.isMemberExpression(parent) && parent.object === path.node) {
|
|
601
381
|
return isMemberAccessingProperty(parent, "value");
|
|
602
382
|
}
|
|
603
|
-
if (!
|
|
383
|
+
if (!import_core3.types.isParenthesizedExpression(parent) && !import_core3.types.isTSAsExpression(parent) && !import_core3.types.isTSNonNullExpression(parent)) {
|
|
604
384
|
return false;
|
|
605
385
|
}
|
|
606
386
|
const ancestorCheck = path.findParent((p) => {
|
|
@@ -617,7 +397,7 @@ function symbolAssignment(path) {
|
|
|
617
397
|
return;
|
|
618
398
|
}
|
|
619
399
|
const { left } = path.node;
|
|
620
|
-
if (!
|
|
400
|
+
if (!import_core3.types.isIdentifier(left)) {
|
|
621
401
|
return;
|
|
622
402
|
}
|
|
623
403
|
const name = left.name;
|
|
@@ -627,17 +407,17 @@ function symbolAssignment(path) {
|
|
|
627
407
|
if (isAlreadyValueAssignment(left)) {
|
|
628
408
|
return;
|
|
629
409
|
}
|
|
630
|
-
path.node.left =
|
|
410
|
+
path.node.left = import_core3.types.memberExpression(import_core3.types.identifier(name), import_core3.types.identifier("value"));
|
|
631
411
|
}
|
|
632
412
|
function isAlreadyValueAssignment(left) {
|
|
633
|
-
return
|
|
413
|
+
return import_core3.types.isMemberExpression(left) && isMemberAccessingProperty(left, "value");
|
|
634
414
|
}
|
|
635
415
|
function symbolUpdate(path) {
|
|
636
416
|
if (!isValidPath(path)) {
|
|
637
417
|
return;
|
|
638
418
|
}
|
|
639
419
|
const { argument } = path.node;
|
|
640
|
-
if (!
|
|
420
|
+
if (!import_core3.types.isIdentifier(argument)) {
|
|
641
421
|
return;
|
|
642
422
|
}
|
|
643
423
|
const name = argument.name;
|
|
@@ -647,10 +427,10 @@ function symbolUpdate(path) {
|
|
|
647
427
|
if (isAlreadyValueUpdate(argument)) {
|
|
648
428
|
return;
|
|
649
429
|
}
|
|
650
|
-
path.node.argument =
|
|
430
|
+
path.node.argument = import_core3.types.memberExpression(import_core3.types.identifier(name), import_core3.types.identifier("value"));
|
|
651
431
|
}
|
|
652
432
|
function isAlreadyValueUpdate(argument) {
|
|
653
|
-
return
|
|
433
|
+
return import_core3.types.isMemberExpression(argument) && isMemberAccessingProperty(argument, "value");
|
|
654
434
|
}
|
|
655
435
|
function symbolObjectPattern(path) {
|
|
656
436
|
if (!isValidPath(path)) {
|
|
@@ -662,9 +442,9 @@ function symbolObjectPattern(path) {
|
|
|
662
442
|
}
|
|
663
443
|
for (const property of properties) {
|
|
664
444
|
if (!property) continue;
|
|
665
|
-
if (
|
|
445
|
+
if (import_core3.types.isObjectProperty(property)) {
|
|
666
446
|
handleObjectProperty(property, path);
|
|
667
|
-
} else if (
|
|
447
|
+
} else if (import_core3.types.isRestElement(property)) {
|
|
668
448
|
handleRestElement(property, path);
|
|
669
449
|
}
|
|
670
450
|
}
|
|
@@ -674,34 +454,34 @@ function handleObjectProperty(property, parentPath) {
|
|
|
674
454
|
return;
|
|
675
455
|
}
|
|
676
456
|
const value = property.value;
|
|
677
|
-
if (
|
|
457
|
+
if (import_core3.types.isObjectPattern(value)) {
|
|
678
458
|
const mockPath = {
|
|
679
459
|
node: value,
|
|
680
460
|
state: parentPath.state,
|
|
681
461
|
parentPath
|
|
682
462
|
};
|
|
683
463
|
symbolObjectPattern(mockPath);
|
|
684
|
-
} else if (
|
|
464
|
+
} else if (import_core3.types.isArrayPattern(value)) {
|
|
685
465
|
const mockPath = {
|
|
686
466
|
node: value,
|
|
687
467
|
state: parentPath.state,
|
|
688
468
|
parentPath
|
|
689
469
|
};
|
|
690
470
|
symbolArrayPattern(mockPath);
|
|
691
|
-
} else if (
|
|
471
|
+
} else if (import_core3.types.isAssignmentPattern(value)) {
|
|
692
472
|
handleAssignmentPattern(value, parentPath);
|
|
693
473
|
}
|
|
694
474
|
}
|
|
695
475
|
function handleAssignmentPattern(pattern, parentPath) {
|
|
696
476
|
const left = pattern.left;
|
|
697
|
-
if (
|
|
477
|
+
if (import_core3.types.isObjectPattern(left)) {
|
|
698
478
|
const mockPath = {
|
|
699
479
|
node: left,
|
|
700
480
|
state: parentPath.state,
|
|
701
481
|
parentPath
|
|
702
482
|
};
|
|
703
483
|
symbolObjectPattern(mockPath);
|
|
704
|
-
} else if (
|
|
484
|
+
} else if (import_core3.types.isArrayPattern(left)) {
|
|
705
485
|
const mockPath = {
|
|
706
486
|
node: left,
|
|
707
487
|
state: parentPath.state,
|
|
@@ -715,14 +495,14 @@ function handleRestElement(restElement, parentPath) {
|
|
|
715
495
|
return;
|
|
716
496
|
}
|
|
717
497
|
const argument = restElement.argument;
|
|
718
|
-
if (
|
|
498
|
+
if (import_core3.types.isObjectPattern(argument)) {
|
|
719
499
|
const mockPath = {
|
|
720
500
|
node: argument,
|
|
721
501
|
state: parentPath.state,
|
|
722
502
|
parentPath
|
|
723
503
|
};
|
|
724
504
|
symbolObjectPattern(mockPath);
|
|
725
|
-
} else if (
|
|
505
|
+
} else if (import_core3.types.isArrayPattern(argument)) {
|
|
726
506
|
const mockPath = {
|
|
727
507
|
node: argument,
|
|
728
508
|
state: parentPath.state,
|
|
@@ -741,18 +521,18 @@ function symbolArrayPattern(path) {
|
|
|
741
521
|
}
|
|
742
522
|
for (const element of elements) {
|
|
743
523
|
if (!element) continue;
|
|
744
|
-
if (
|
|
524
|
+
if (import_core3.types.isAssignmentPattern(element)) {
|
|
745
525
|
handleAssignmentPattern(element, path);
|
|
746
|
-
} else if (
|
|
526
|
+
} else if (import_core3.types.isRestElement(element)) {
|
|
747
527
|
handleArrayRestElement(element, path);
|
|
748
|
-
} else if (
|
|
528
|
+
} else if (import_core3.types.isObjectPattern(element)) {
|
|
749
529
|
const mockPath = {
|
|
750
530
|
node: element,
|
|
751
531
|
state: path.state,
|
|
752
532
|
parentPath: path
|
|
753
533
|
};
|
|
754
534
|
symbolObjectPattern(mockPath);
|
|
755
|
-
} else if (
|
|
535
|
+
} else if (import_core3.types.isArrayPattern(element)) {
|
|
756
536
|
const mockPath = {
|
|
757
537
|
node: element,
|
|
758
538
|
state: path.state,
|
|
@@ -767,14 +547,14 @@ function handleArrayRestElement(restElement, parentPath) {
|
|
|
767
547
|
return;
|
|
768
548
|
}
|
|
769
549
|
const argument = restElement.argument;
|
|
770
|
-
if (
|
|
550
|
+
if (import_core3.types.isArrayPattern(argument)) {
|
|
771
551
|
const mockPath = {
|
|
772
552
|
node: argument,
|
|
773
553
|
state: parentPath.state,
|
|
774
554
|
parentPath
|
|
775
555
|
};
|
|
776
556
|
symbolArrayPattern(mockPath);
|
|
777
|
-
} else if (
|
|
557
|
+
} else if (import_core3.types.isObjectPattern(argument)) {
|
|
778
558
|
const mockPath = {
|
|
779
559
|
node: argument,
|
|
780
560
|
state: parentPath.state,
|
|
@@ -784,6 +564,251 @@ function handleArrayRestElement(restElement, parentPath) {
|
|
|
784
564
|
}
|
|
785
565
|
}
|
|
786
566
|
|
|
567
|
+
// src/program.ts
|
|
568
|
+
function withState(visitor, parentState) {
|
|
569
|
+
return (path) => {
|
|
570
|
+
path.state = parentState;
|
|
571
|
+
visitor(path);
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
var transformProgram = {
|
|
575
|
+
enter: (path, state) => {
|
|
576
|
+
const opts = __spreadValues(__spreadValues({}, DEFAULT_OPTIONS), state.opts);
|
|
577
|
+
const imports = createImportIdentifiers(path);
|
|
578
|
+
clearImport();
|
|
579
|
+
path.state = __spreadProps(__spreadValues({}, state), {
|
|
580
|
+
opts,
|
|
581
|
+
imports,
|
|
582
|
+
declarations: [],
|
|
583
|
+
// Collect template declarations during transformation
|
|
584
|
+
filename: state.filename,
|
|
585
|
+
events: /* @__PURE__ */ new Set()
|
|
586
|
+
// Track delegated events for optimization
|
|
587
|
+
});
|
|
588
|
+
const parentState = path.state;
|
|
589
|
+
path.traverse({
|
|
590
|
+
VariableDeclarator: withState(replaceSymbol, parentState),
|
|
591
|
+
// let $x = 0 → let $x = signal(0)
|
|
592
|
+
Identifier: withState(symbolIdentifier, parentState),
|
|
593
|
+
// $x → $x.value
|
|
594
|
+
AssignmentExpression: withState(symbolAssignment, parentState),
|
|
595
|
+
// $x = 1 → $x.value = 1
|
|
596
|
+
UpdateExpression: withState(symbolUpdate, parentState),
|
|
597
|
+
// $x++ → $x.value++
|
|
598
|
+
ObjectPattern: withState(symbolObjectPattern, parentState),
|
|
599
|
+
// { $x } → handle nested patterns
|
|
600
|
+
ArrayPattern: withState(symbolArrayPattern, parentState)
|
|
601
|
+
// [$x] → handle nested patterns
|
|
602
|
+
});
|
|
603
|
+
},
|
|
604
|
+
// eslint-disable-next-line unused-imports/no-unused-vars
|
|
605
|
+
exit: (path, state) => {
|
|
606
|
+
const pluginState = path.state;
|
|
607
|
+
const { imports, declarations, events } = pluginState;
|
|
608
|
+
const insertIndex = path.node.body.findIndex(
|
|
609
|
+
(node) => !import_core4.types.isImportDeclaration(node) && !import_core4.types.isExportDeclaration(node)
|
|
610
|
+
);
|
|
611
|
+
if (declarations == null ? void 0 : declarations.length) {
|
|
612
|
+
const templateDeclaration = import_core4.types.variableDeclaration("const", declarations);
|
|
613
|
+
if (insertIndex !== -1) {
|
|
614
|
+
path.node.body.splice(insertIndex, 0, templateDeclaration);
|
|
615
|
+
} else {
|
|
616
|
+
path.node.body.push(templateDeclaration);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
if (events && events.size > 0) {
|
|
620
|
+
const eventsDeclaration = import_core4.types.expressionStatement(
|
|
621
|
+
import_core4.types.callExpression(imports.delegateEvents, [
|
|
622
|
+
import_core4.types.arrayExpression(Array.from(events).map((event) => import_core4.types.stringLiteral(event)))
|
|
623
|
+
])
|
|
624
|
+
);
|
|
625
|
+
addImport(importMap.delegateEvents);
|
|
626
|
+
path.node.body.push(eventsDeclaration);
|
|
627
|
+
}
|
|
628
|
+
createImport(path, imports, "essor");
|
|
629
|
+
}
|
|
630
|
+
};
|
|
631
|
+
|
|
632
|
+
// src/signals/props.ts
|
|
633
|
+
var import_core5 = require("@babel/core");
|
|
634
|
+
function transformProperty(path, properties, parentPath, defaultValues = {}) {
|
|
635
|
+
properties.forEach((property, index) => {
|
|
636
|
+
try {
|
|
637
|
+
if (!import_core5.types.isObjectProperty(property)) {
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
640
|
+
if (!import_core5.types.isIdentifier(property.key)) {
|
|
641
|
+
if (true) {
|
|
642
|
+
ne("transformObjectProperties: Skipping computed property", { index });
|
|
643
|
+
}
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
const keyName = property.key.name;
|
|
647
|
+
if (import_core5.types.isIdentifier(property.value)) {
|
|
648
|
+
path.scope.rename(property.value.name, `${parentPath}.${keyName}`);
|
|
649
|
+
} else if (import_core5.types.isAssignmentPattern(property.value)) {
|
|
650
|
+
if (import_core5.types.isIdentifier(property.value.left)) {
|
|
651
|
+
defaultValues[keyName] = property.value.right;
|
|
652
|
+
path.scope.rename(property.value.left.name, `${parentPath}.${keyName}`);
|
|
653
|
+
} else if (import_core5.types.isObjectPattern(property.value.left)) {
|
|
654
|
+
transformProperty(
|
|
655
|
+
path,
|
|
656
|
+
property.value.left.properties,
|
|
657
|
+
`${parentPath}.${keyName}`,
|
|
658
|
+
defaultValues
|
|
659
|
+
);
|
|
660
|
+
defaultValues[keyName] = property.value.right;
|
|
661
|
+
}
|
|
662
|
+
} else if (import_core5.types.isObjectPattern(property.value)) {
|
|
663
|
+
transformProperty(
|
|
664
|
+
path,
|
|
665
|
+
property.value.properties,
|
|
666
|
+
`${parentPath}.${keyName}`,
|
|
667
|
+
defaultValues
|
|
668
|
+
);
|
|
669
|
+
}
|
|
670
|
+
} catch (error) {
|
|
671
|
+
ne("transformProperty", `Failed to process property at index ${index}`, {
|
|
672
|
+
error: error instanceof Error ? error.message : String(error)
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
});
|
|
676
|
+
return defaultValues;
|
|
677
|
+
}
|
|
678
|
+
function buildRestVariableDeclaration(state, restName, parentPath, excludeProps) {
|
|
679
|
+
const validExcludeProps = excludeProps.filter(Boolean);
|
|
680
|
+
let init;
|
|
681
|
+
const pathParts = parentPath.split(".").filter((part) => part.length > 0);
|
|
682
|
+
let sourceObject = import_core5.types.identifier(pathParts[0] || "__props");
|
|
683
|
+
for (let i = 1; i < pathParts.length; i++) {
|
|
684
|
+
sourceObject = import_core5.types.memberExpression(sourceObject, import_core5.types.identifier(pathParts[i]));
|
|
685
|
+
}
|
|
686
|
+
if (validExcludeProps.length === 0) {
|
|
687
|
+
init = sourceObject;
|
|
688
|
+
} else {
|
|
689
|
+
init = import_core5.types.callExpression(state.imports.omitProps, [
|
|
690
|
+
sourceObject,
|
|
691
|
+
import_core5.types.arrayExpression(validExcludeProps.map((name) => import_core5.types.stringLiteral(name)))
|
|
692
|
+
]);
|
|
693
|
+
}
|
|
694
|
+
return import_core5.types.variableDeclaration("const", [import_core5.types.variableDeclarator(import_core5.types.identifier(restName), init)]);
|
|
695
|
+
}
|
|
696
|
+
function transformRestProperties(path, restProperties, notRestNames = [], nestedRestParams = []) {
|
|
697
|
+
if (!import_core5.types.isIdentifier(restProperties.argument)) {
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
const restName = restProperties.argument.name;
|
|
701
|
+
if (notRestNames.length === 0 && nestedRestParams.length === 0) {
|
|
702
|
+
path.node.params[0] = import_core5.types.identifier(restName);
|
|
703
|
+
} else {
|
|
704
|
+
const restDeclarations = [];
|
|
705
|
+
if (nestedRestParams.length > 0) {
|
|
706
|
+
for (const nestedRest of nestedRestParams) {
|
|
707
|
+
const nestedRestDeclaration = buildRestVariableDeclaration(
|
|
708
|
+
path.state,
|
|
709
|
+
nestedRest.name,
|
|
710
|
+
nestedRest.parentPath,
|
|
711
|
+
nestedRest.excludeProps
|
|
712
|
+
);
|
|
713
|
+
restDeclarations.push(nestedRestDeclaration);
|
|
714
|
+
if (nestedRest.excludeProps.length > 0) {
|
|
715
|
+
addImport(importMap.omitProps);
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
if (restProperties) {
|
|
720
|
+
const restDeclaration = buildRestVariableDeclaration(
|
|
721
|
+
path.state,
|
|
722
|
+
restName,
|
|
723
|
+
TRANSFORM_PROPERTY_NAME,
|
|
724
|
+
notRestNames
|
|
725
|
+
);
|
|
726
|
+
restDeclarations.push(restDeclaration);
|
|
727
|
+
if (notRestNames.length) {
|
|
728
|
+
addImport(importMap.omitProps);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
for (const declaration of restDeclarations) {
|
|
732
|
+
const body = path.node.body;
|
|
733
|
+
body.body.unshift(declaration);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
function buildDefaultValueObject(defaultValues) {
|
|
738
|
+
if (!P(defaultValues)) {
|
|
739
|
+
return import_core5.types.objectExpression([]);
|
|
740
|
+
}
|
|
741
|
+
const properties = [];
|
|
742
|
+
for (const [key, value] of Object.entries(defaultValues)) {
|
|
743
|
+
if (!key) {
|
|
744
|
+
continue;
|
|
745
|
+
}
|
|
746
|
+
let propertyValue;
|
|
747
|
+
if (P(value) && !import_core5.types.isNode(value)) {
|
|
748
|
+
propertyValue = buildDefaultValueObject(value);
|
|
749
|
+
} else if (import_core5.types.isExpression(value)) {
|
|
750
|
+
propertyValue = value;
|
|
751
|
+
} else {
|
|
752
|
+
continue;
|
|
753
|
+
}
|
|
754
|
+
properties.push(import_core5.types.objectProperty(import_core5.types.identifier(key), propertyValue));
|
|
755
|
+
}
|
|
756
|
+
return import_core5.types.objectExpression(properties);
|
|
757
|
+
}
|
|
758
|
+
function buildDefaultValue(path, defaultValues) {
|
|
759
|
+
const propsParam = Object.keys(defaultValues).length > 0 ? import_core5.types.assignmentPattern(
|
|
760
|
+
import_core5.types.identifier(TRANSFORM_PROPERTY_NAME),
|
|
761
|
+
buildDefaultValueObject(defaultValues)
|
|
762
|
+
) : import_core5.types.identifier(TRANSFORM_PROPERTY_NAME);
|
|
763
|
+
path.node.params[0] = propsParam;
|
|
764
|
+
}
|
|
765
|
+
function transformProps(path) {
|
|
766
|
+
const firstParam = path.node.params[0];
|
|
767
|
+
if (!firstParam || !import_core5.types.isObjectPattern(firstParam) || !checkHasJSXReturn(path)) {
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
770
|
+
const state = path.state;
|
|
771
|
+
const properties = firstParam.properties;
|
|
772
|
+
const signalPrefix = state.opts.symbol || "$";
|
|
773
|
+
const notRestProperties = properties.filter((prop) => !import_core5.types.isRestElement(prop));
|
|
774
|
+
const restProperties = properties.find((prop) => import_core5.types.isRestElement(prop));
|
|
775
|
+
const notRestNames = notRestProperties.map((prop) => import_core5.types.isIdentifier(prop.key) ? prop.key.name : null).filter((name) => name !== null);
|
|
776
|
+
if (true) {
|
|
777
|
+
if (notRestNames.some((name) => q(name, signalPrefix))) {
|
|
778
|
+
ne(
|
|
779
|
+
"transformProps",
|
|
780
|
+
"Property names cannot start with signal prefix",
|
|
781
|
+
notRestNames.filter((name) => q(name, signalPrefix))
|
|
782
|
+
);
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
if (notRestProperties.length) {
|
|
786
|
+
const defaultValues = transformProperty(path, notRestProperties, TRANSFORM_PROPERTY_NAME);
|
|
787
|
+
buildDefaultValue(path, defaultValues);
|
|
788
|
+
}
|
|
789
|
+
if (restProperties) {
|
|
790
|
+
transformRestProperties(path, restProperties, notRestNames);
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
// src/jsx/context.ts
|
|
795
|
+
var contextStack = [];
|
|
796
|
+
function getContext() {
|
|
797
|
+
if (!contextStack.length) {
|
|
798
|
+
throw new Error("No active context found. Ensure setContext has been called.");
|
|
799
|
+
}
|
|
800
|
+
return contextStack[contextStack.length - 1];
|
|
801
|
+
}
|
|
802
|
+
function setContext(context) {
|
|
803
|
+
contextStack.push(context);
|
|
804
|
+
}
|
|
805
|
+
function resetContext() {
|
|
806
|
+
contextStack.pop();
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
// src/jsx/client.ts
|
|
810
|
+
var import_core8 = require("@babel/core");
|
|
811
|
+
|
|
787
812
|
// src/jsx/constants.ts
|
|
788
813
|
var CLASS_NAME = "class";
|
|
789
814
|
var STYLE_NAME = "style";
|
|
@@ -791,6 +816,7 @@ var EVENT_ATTR_NAME = "on";
|
|
|
791
816
|
var UPDATE_PREFIX = "update";
|
|
792
817
|
var FRAGMENT_NAME = "Fragment";
|
|
793
818
|
var CHILDREN_NAME = "children";
|
|
819
|
+
var REF_KEY = "ref";
|
|
794
820
|
var SPREAD_NAME = "_$spread$";
|
|
795
821
|
var CREATE_COMPONENT_NAME = "createComponent";
|
|
796
822
|
var BIND_REG = /^bind:.+/;
|
|
@@ -821,15 +847,17 @@ function isTreeNode(node) {
|
|
|
821
847
|
var treeIndex = 1;
|
|
822
848
|
function createTree(path, parentNode) {
|
|
823
849
|
const treeNode = createDefaultTree();
|
|
850
|
+
const tagName = getTagName(path.node);
|
|
851
|
+
treeNode.tag = tagName;
|
|
852
|
+
treeNode.type = determineNodeType(tagName);
|
|
853
|
+
treeNode.selfClosing = Ne(tagName);
|
|
824
854
|
if (parentNode) {
|
|
825
|
-
const
|
|
826
|
-
|
|
827
|
-
const isComponentOrFragment = isComponentName(getTagName(nodeInfo));
|
|
828
|
-
if (!isComponentOrFragment && !isBuiltInComponent) {
|
|
829
|
-
treeNode.index = ++treeIndex;
|
|
830
|
-
}
|
|
831
|
-
if (isBuiltInComponent) {
|
|
855
|
+
const parentIsComponent = parentNode.type === 1 /* COMPONENT */;
|
|
856
|
+
if (parentIsComponent) {
|
|
832
857
|
treeIndex = 1;
|
|
858
|
+
treeNode.index = treeIndex;
|
|
859
|
+
} else if (treeNode.type !== 1 /* COMPONENT */) {
|
|
860
|
+
treeNode.index = ++treeIndex;
|
|
833
861
|
}
|
|
834
862
|
treeNode.parentIndex = treeIndex;
|
|
835
863
|
} else {
|
|
@@ -845,10 +873,6 @@ function createTree(path, parentNode) {
|
|
|
845
873
|
return treeNode;
|
|
846
874
|
}
|
|
847
875
|
function processJSXElement(path, treeNode) {
|
|
848
|
-
const tagName = getTagName(path.node);
|
|
849
|
-
treeNode.tag = tagName;
|
|
850
|
-
treeNode.type = determineNodeType(tagName);
|
|
851
|
-
treeNode.selfClosing = Ne(tagName);
|
|
852
876
|
if (!path.isJSXFragment()) {
|
|
853
877
|
treeNode.props = processProps(path);
|
|
854
878
|
}
|
|
@@ -1488,7 +1512,7 @@ function transformJSXToClient(path, node) {
|
|
|
1488
1512
|
])
|
|
1489
1513
|
);
|
|
1490
1514
|
}
|
|
1491
|
-
if (dynamicCollection.children.length || dynamicCollection.props.length) {
|
|
1515
|
+
if (dynamicCollection.children.length || dynamicCollection.props.length || dynamicCollection.operations.length) {
|
|
1492
1516
|
addImport(importMap.mapNodes);
|
|
1493
1517
|
statements.push(
|
|
1494
1518
|
import_core8.types.variableDeclaration("const", [
|
|
@@ -1584,6 +1608,22 @@ function generateIndexMap({
|
|
|
1584
1608
|
}
|
|
1585
1609
|
return indexMap;
|
|
1586
1610
|
}
|
|
1611
|
+
function createRefStatement(nodesId, nodeIndex, value) {
|
|
1612
|
+
const elementRef = import_core8.types.memberExpression(nodesId, import_core8.types.numericLiteral(nodeIndex), true);
|
|
1613
|
+
const typeofCheck = import_core8.types.binaryExpression(
|
|
1614
|
+
"===",
|
|
1615
|
+
import_core8.types.unaryExpression("typeof", value),
|
|
1616
|
+
import_core8.types.stringLiteral("function")
|
|
1617
|
+
);
|
|
1618
|
+
const functionCall = import_core8.types.callExpression(value, [elementRef]);
|
|
1619
|
+
const assignmentExpr = import_core8.types.assignmentExpression(
|
|
1620
|
+
"=",
|
|
1621
|
+
import_core8.types.memberExpression(value, import_core8.types.identifier("value")),
|
|
1622
|
+
elementRef
|
|
1623
|
+
);
|
|
1624
|
+
const conditionalExpr = import_core8.types.conditionalExpression(typeofCheck, functionCall, assignmentExpr);
|
|
1625
|
+
return import_core8.types.expressionStatement(conditionalExpr);
|
|
1626
|
+
}
|
|
1587
1627
|
function createAttributeStatement(functionIdentifier, nodesId, nodeIndex, value, key) {
|
|
1588
1628
|
const args = [import_core8.types.memberExpression(nodesId, import_core8.types.numericLiteral(nodeIndex), true)];
|
|
1589
1629
|
if (key) {
|
|
@@ -1641,6 +1681,9 @@ function generateSpecificAttributeCode(attributeName, attributeValue, nodesId, n
|
|
|
1641
1681
|
createAttributeStatement(state.imports.setSpread, nodesId, nodeIndex, attributeValue)
|
|
1642
1682
|
);
|
|
1643
1683
|
break;
|
|
1684
|
+
case REF_KEY:
|
|
1685
|
+
statements.push(createRefStatement(nodesId, nodeIndex, attributeValue));
|
|
1686
|
+
break;
|
|
1644
1687
|
case STYLE_NAME:
|
|
1645
1688
|
addImport(importMap.patchStyle);
|
|
1646
1689
|
statements.push(
|
|
@@ -1791,10 +1834,7 @@ function generateDynamicPropsCode(dynamicProps, statements, state, nodesId, inde
|
|
|
1791
1834
|
function generateUnifiedMemoizedEffect(reactiveOperations, statements, state, nodesId, indexMap) {
|
|
1792
1835
|
addImport(importMap.memoEffect);
|
|
1793
1836
|
const variableDeclarations = reactiveOperations.map((op, index) => {
|
|
1794
|
-
|
|
1795
|
-
if (import_core8.types.isIdentifier(op.attrValue) && isSignal(op.attrValue.name)) {
|
|
1796
|
-
attrValue = import_core8.types.memberExpression(attrValue, import_core8.types.identifier("value"));
|
|
1797
|
-
}
|
|
1837
|
+
const attrValue = op.attrValue;
|
|
1798
1838
|
return import_core8.types.variableDeclarator(import_core8.types.identifier(`_v$${index}`), attrValue);
|
|
1799
1839
|
});
|
|
1800
1840
|
const updateStatements = reactiveOperations.map((op, index) => {
|
|
@@ -1964,7 +2004,7 @@ function processNodeDynamic(dynamicCollection, node, parentNode) {
|
|
|
1964
2004
|
if (node.props && Object.keys(node.props).length > 0) {
|
|
1965
2005
|
const currentProps = {};
|
|
1966
2006
|
for (const [attrName, attrValue] of Object.entries(node.props)) {
|
|
1967
|
-
const isReactive = import_core8.types.isNode(attrValue) && isDynamicExpression(attrValue) && !q(attrName, `${UPDATE_PREFIX}:`) && !q(attrName, EVENT_ATTR_NAME);
|
|
2007
|
+
const isReactive = import_core8.types.isNode(attrValue) && isDynamicExpression(attrValue) && !q(attrName, `${UPDATE_PREFIX}:`) && !q(attrName, EVENT_ATTR_NAME) && attrName !== REF_KEY;
|
|
1968
2008
|
if (q(attrName, `${UPDATE_PREFIX}:`)) {
|
|
1969
2009
|
const name = attrName.split(":")[1];
|
|
1970
2010
|
const setFunction = getSetFunctionForAttribute();
|
|
@@ -2286,19 +2326,6 @@ function index_default() {
|
|
|
2286
2326
|
// props
|
|
2287
2327
|
FunctionDeclaration: transformProps,
|
|
2288
2328
|
ArrowFunctionExpression: transformProps,
|
|
2289
|
-
// Symbol
|
|
2290
|
-
VariableDeclarator: replaceSymbol,
|
|
2291
|
-
// let $x = 0 → let $x = signal(0)
|
|
2292
|
-
Identifier: symbolIdentifier,
|
|
2293
|
-
// $x → $x.value
|
|
2294
|
-
AssignmentExpression: symbolAssignment,
|
|
2295
|
-
// $x = 1 → $x.value = 1
|
|
2296
|
-
UpdateExpression: symbolUpdate,
|
|
2297
|
-
// $x++ → $x.value++
|
|
2298
|
-
ObjectPattern: symbolObjectPattern,
|
|
2299
|
-
// { $x } → handle nested patterns
|
|
2300
|
-
ArrayPattern: symbolArrayPattern,
|
|
2301
|
-
// [$x] → handle nested patterns
|
|
2302
2329
|
// JSX
|
|
2303
2330
|
JSXElement: transformJSX,
|
|
2304
2331
|
JSXFragment: transformJSX
|