babel-plugin-essor 0.0.16-beta.7 → 0.0.16-beta.8
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 +49 -16
- package/dist/index.js +49 -16
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -22443,17 +22443,18 @@ function buildForIR(expression, ctx) {
|
|
|
22443
22443
|
if (indexParam && !core.types.isIdentifier(indexParam) && !core.types.isPattern(indexParam)) {
|
|
22444
22444
|
return null;
|
|
22445
22445
|
}
|
|
22446
|
-
const
|
|
22446
|
+
const callbackBody = getForCallbackBody(
|
|
22447
22447
|
callback
|
|
22448
22448
|
);
|
|
22449
|
-
if (!
|
|
22450
|
-
const key = extractKeyExpression(
|
|
22449
|
+
if (!callbackBody) return null;
|
|
22450
|
+
const key = extractKeyExpression(callbackBody.path);
|
|
22451
22451
|
return {
|
|
22452
22452
|
type: 4 /* FOR */,
|
|
22453
22453
|
each: callee.node.object,
|
|
22454
22454
|
itemParam,
|
|
22455
22455
|
indexParam: indexParam != null ? indexParam : null,
|
|
22456
|
-
|
|
22456
|
+
bodyPrelude: callbackBody.prelude,
|
|
22457
|
+
body: buildIR(callbackBody.path, ctx),
|
|
22457
22458
|
key,
|
|
22458
22459
|
loc: expression.node.loc
|
|
22459
22460
|
};
|
|
@@ -22464,32 +22465,53 @@ function extractKeyExpression(path2) {
|
|
|
22464
22465
|
if (!attrPath.isJSXAttribute()) continue;
|
|
22465
22466
|
if (!core.types.isJSXIdentifier(attrPath.node.name, { name: "key" })) continue;
|
|
22466
22467
|
const value = attrPath.node.value;
|
|
22467
|
-
|
|
22468
|
-
|
|
22469
|
-
|
|
22470
|
-
|
|
22471
|
-
|
|
22468
|
+
if (!value) {
|
|
22469
|
+
attrPath.remove();
|
|
22470
|
+
return core.types.booleanLiteral(true);
|
|
22471
|
+
}
|
|
22472
|
+
if (core.types.isStringLiteral(value)) {
|
|
22473
|
+
attrPath.remove();
|
|
22474
|
+
return core.types.stringLiteral(value.value);
|
|
22475
|
+
}
|
|
22476
|
+
const valuePath = attrPath.get("value");
|
|
22477
|
+
if (!Array.isArray(valuePath) && valuePath.isJSXExpressionContainer()) {
|
|
22478
|
+
const expressionPath = valuePath.get("expression");
|
|
22479
|
+
attrPath.remove();
|
|
22480
|
+
if (expressionPath.isJSXEmptyExpression()) return null;
|
|
22481
|
+
return expressionPath.node;
|
|
22472
22482
|
}
|
|
22483
|
+
attrPath.remove();
|
|
22473
22484
|
return null;
|
|
22474
22485
|
}
|
|
22475
22486
|
return null;
|
|
22476
22487
|
}
|
|
22477
|
-
function
|
|
22488
|
+
function getForCallbackBody(callback) {
|
|
22478
22489
|
const bodyPath = callback.get("body");
|
|
22479
22490
|
if (Array.isArray(bodyPath)) return null;
|
|
22480
22491
|
if (bodyPath.isJSXElement() || bodyPath.isJSXFragment()) {
|
|
22481
|
-
return
|
|
22492
|
+
return {
|
|
22493
|
+
path: bodyPath,
|
|
22494
|
+
prelude: []
|
|
22495
|
+
};
|
|
22482
22496
|
}
|
|
22483
22497
|
if (!bodyPath.isBlockStatement()) {
|
|
22484
22498
|
return null;
|
|
22485
22499
|
}
|
|
22500
|
+
const prelude = [];
|
|
22486
22501
|
for (const statement of bodyPath.get("body")) {
|
|
22487
|
-
if (!statement.isReturnStatement())
|
|
22502
|
+
if (!statement.isReturnStatement()) {
|
|
22503
|
+
prelude.push(core.types.cloneNode(statement.node, true));
|
|
22504
|
+
continue;
|
|
22505
|
+
}
|
|
22488
22506
|
const argument = statement.get("argument");
|
|
22489
|
-
if (Array.isArray(argument) || !argument.node)
|
|
22507
|
+
if (Array.isArray(argument) || !argument.node) {
|
|
22508
|
+
prelude.push(core.types.cloneNode(statement.node, true));
|
|
22509
|
+
continue;
|
|
22510
|
+
}
|
|
22490
22511
|
if (argument.isJSXElement() || argument.isJSXFragment()) {
|
|
22491
|
-
return argument;
|
|
22512
|
+
return { path: argument, prelude };
|
|
22492
22513
|
}
|
|
22514
|
+
prelude.push(core.types.cloneNode(statement.node, true));
|
|
22493
22515
|
}
|
|
22494
22516
|
return null;
|
|
22495
22517
|
}
|
|
@@ -22628,6 +22650,7 @@ function buildComponentPropsExpression(node, options) {
|
|
|
22628
22650
|
function buildForProps(node, bodyExpr) {
|
|
22629
22651
|
const childrenParams = [core.types.cloneNode(node.itemParam, true)];
|
|
22630
22652
|
if (node.indexParam) childrenParams.push(core.types.cloneNode(node.indexParam, true));
|
|
22653
|
+
const childrenBody = buildForCallbackBody(node, bodyExpr);
|
|
22631
22654
|
const props = [
|
|
22632
22655
|
core.types.objectMethod(
|
|
22633
22656
|
"get",
|
|
@@ -22637,20 +22660,30 @@ function buildForProps(node, bodyExpr) {
|
|
|
22637
22660
|
false,
|
|
22638
22661
|
false
|
|
22639
22662
|
),
|
|
22640
|
-
core.types.objectProperty(
|
|
22663
|
+
core.types.objectProperty(
|
|
22664
|
+
core.types.identifier("children"),
|
|
22665
|
+
core.types.arrowFunctionExpression(childrenParams, childrenBody)
|
|
22666
|
+
)
|
|
22641
22667
|
];
|
|
22642
22668
|
if (node.key) {
|
|
22643
22669
|
const keyParams = [core.types.cloneNode(node.itemParam, true)];
|
|
22644
22670
|
if (node.indexParam) keyParams.push(core.types.cloneNode(node.indexParam, true));
|
|
22671
|
+
const keyBody = buildForCallbackBody(node, core.types.cloneNode(node.key, true));
|
|
22645
22672
|
props.push(
|
|
22646
22673
|
core.types.objectProperty(
|
|
22647
22674
|
core.types.identifier("key"),
|
|
22648
|
-
core.types.arrowFunctionExpression(keyParams,
|
|
22675
|
+
core.types.arrowFunctionExpression(keyParams, keyBody)
|
|
22649
22676
|
)
|
|
22650
22677
|
);
|
|
22651
22678
|
}
|
|
22652
22679
|
return core.types.objectExpression(props);
|
|
22653
22680
|
}
|
|
22681
|
+
function buildForCallbackBody(node, returnValue) {
|
|
22682
|
+
return node.bodyPrelude.length ? core.types.blockStatement([
|
|
22683
|
+
...node.bodyPrelude.map((statement) => core.types.cloneNode(statement, true)),
|
|
22684
|
+
core.types.returnStatement(returnValue)
|
|
22685
|
+
]) : returnValue;
|
|
22686
|
+
}
|
|
22654
22687
|
function buildForCall(node, bodyExpr) {
|
|
22655
22688
|
return core.types.callExpression(useImport("createComponent"), [
|
|
22656
22689
|
useImport("For"),
|
package/dist/index.js
CHANGED
|
@@ -22436,17 +22436,18 @@ function buildForIR(expression, ctx) {
|
|
|
22436
22436
|
if (indexParam && !types.isIdentifier(indexParam) && !types.isPattern(indexParam)) {
|
|
22437
22437
|
return null;
|
|
22438
22438
|
}
|
|
22439
|
-
const
|
|
22439
|
+
const callbackBody = getForCallbackBody(
|
|
22440
22440
|
callback
|
|
22441
22441
|
);
|
|
22442
|
-
if (!
|
|
22443
|
-
const key = extractKeyExpression(
|
|
22442
|
+
if (!callbackBody) return null;
|
|
22443
|
+
const key = extractKeyExpression(callbackBody.path);
|
|
22444
22444
|
return {
|
|
22445
22445
|
type: 4 /* FOR */,
|
|
22446
22446
|
each: callee.node.object,
|
|
22447
22447
|
itemParam,
|
|
22448
22448
|
indexParam: indexParam != null ? indexParam : null,
|
|
22449
|
-
|
|
22449
|
+
bodyPrelude: callbackBody.prelude,
|
|
22450
|
+
body: buildIR(callbackBody.path, ctx),
|
|
22450
22451
|
key,
|
|
22451
22452
|
loc: expression.node.loc
|
|
22452
22453
|
};
|
|
@@ -22457,32 +22458,53 @@ function extractKeyExpression(path3) {
|
|
|
22457
22458
|
if (!attrPath.isJSXAttribute()) continue;
|
|
22458
22459
|
if (!types.isJSXIdentifier(attrPath.node.name, { name: "key" })) continue;
|
|
22459
22460
|
const value = attrPath.node.value;
|
|
22460
|
-
|
|
22461
|
-
|
|
22462
|
-
|
|
22463
|
-
|
|
22464
|
-
|
|
22461
|
+
if (!value) {
|
|
22462
|
+
attrPath.remove();
|
|
22463
|
+
return types.booleanLiteral(true);
|
|
22464
|
+
}
|
|
22465
|
+
if (types.isStringLiteral(value)) {
|
|
22466
|
+
attrPath.remove();
|
|
22467
|
+
return types.stringLiteral(value.value);
|
|
22468
|
+
}
|
|
22469
|
+
const valuePath = attrPath.get("value");
|
|
22470
|
+
if (!Array.isArray(valuePath) && valuePath.isJSXExpressionContainer()) {
|
|
22471
|
+
const expressionPath = valuePath.get("expression");
|
|
22472
|
+
attrPath.remove();
|
|
22473
|
+
if (expressionPath.isJSXEmptyExpression()) return null;
|
|
22474
|
+
return expressionPath.node;
|
|
22465
22475
|
}
|
|
22476
|
+
attrPath.remove();
|
|
22466
22477
|
return null;
|
|
22467
22478
|
}
|
|
22468
22479
|
return null;
|
|
22469
22480
|
}
|
|
22470
|
-
function
|
|
22481
|
+
function getForCallbackBody(callback) {
|
|
22471
22482
|
const bodyPath = callback.get("body");
|
|
22472
22483
|
if (Array.isArray(bodyPath)) return null;
|
|
22473
22484
|
if (bodyPath.isJSXElement() || bodyPath.isJSXFragment()) {
|
|
22474
|
-
return
|
|
22485
|
+
return {
|
|
22486
|
+
path: bodyPath,
|
|
22487
|
+
prelude: []
|
|
22488
|
+
};
|
|
22475
22489
|
}
|
|
22476
22490
|
if (!bodyPath.isBlockStatement()) {
|
|
22477
22491
|
return null;
|
|
22478
22492
|
}
|
|
22493
|
+
const prelude = [];
|
|
22479
22494
|
for (const statement of bodyPath.get("body")) {
|
|
22480
|
-
if (!statement.isReturnStatement())
|
|
22495
|
+
if (!statement.isReturnStatement()) {
|
|
22496
|
+
prelude.push(types.cloneNode(statement.node, true));
|
|
22497
|
+
continue;
|
|
22498
|
+
}
|
|
22481
22499
|
const argument = statement.get("argument");
|
|
22482
|
-
if (Array.isArray(argument) || !argument.node)
|
|
22500
|
+
if (Array.isArray(argument) || !argument.node) {
|
|
22501
|
+
prelude.push(types.cloneNode(statement.node, true));
|
|
22502
|
+
continue;
|
|
22503
|
+
}
|
|
22483
22504
|
if (argument.isJSXElement() || argument.isJSXFragment()) {
|
|
22484
|
-
return argument;
|
|
22505
|
+
return { path: argument, prelude };
|
|
22485
22506
|
}
|
|
22507
|
+
prelude.push(types.cloneNode(statement.node, true));
|
|
22486
22508
|
}
|
|
22487
22509
|
return null;
|
|
22488
22510
|
}
|
|
@@ -22621,6 +22643,7 @@ function buildComponentPropsExpression(node, options) {
|
|
|
22621
22643
|
function buildForProps(node, bodyExpr) {
|
|
22622
22644
|
const childrenParams = [types.cloneNode(node.itemParam, true)];
|
|
22623
22645
|
if (node.indexParam) childrenParams.push(types.cloneNode(node.indexParam, true));
|
|
22646
|
+
const childrenBody = buildForCallbackBody(node, bodyExpr);
|
|
22624
22647
|
const props = [
|
|
22625
22648
|
types.objectMethod(
|
|
22626
22649
|
"get",
|
|
@@ -22630,20 +22653,30 @@ function buildForProps(node, bodyExpr) {
|
|
|
22630
22653
|
false,
|
|
22631
22654
|
false
|
|
22632
22655
|
),
|
|
22633
|
-
types.objectProperty(
|
|
22656
|
+
types.objectProperty(
|
|
22657
|
+
types.identifier("children"),
|
|
22658
|
+
types.arrowFunctionExpression(childrenParams, childrenBody)
|
|
22659
|
+
)
|
|
22634
22660
|
];
|
|
22635
22661
|
if (node.key) {
|
|
22636
22662
|
const keyParams = [types.cloneNode(node.itemParam, true)];
|
|
22637
22663
|
if (node.indexParam) keyParams.push(types.cloneNode(node.indexParam, true));
|
|
22664
|
+
const keyBody = buildForCallbackBody(node, types.cloneNode(node.key, true));
|
|
22638
22665
|
props.push(
|
|
22639
22666
|
types.objectProperty(
|
|
22640
22667
|
types.identifier("key"),
|
|
22641
|
-
types.arrowFunctionExpression(keyParams,
|
|
22668
|
+
types.arrowFunctionExpression(keyParams, keyBody)
|
|
22642
22669
|
)
|
|
22643
22670
|
);
|
|
22644
22671
|
}
|
|
22645
22672
|
return types.objectExpression(props);
|
|
22646
22673
|
}
|
|
22674
|
+
function buildForCallbackBody(node, returnValue) {
|
|
22675
|
+
return node.bodyPrelude.length ? types.blockStatement([
|
|
22676
|
+
...node.bodyPrelude.map((statement) => types.cloneNode(statement, true)),
|
|
22677
|
+
types.returnStatement(returnValue)
|
|
22678
|
+
]) : returnValue;
|
|
22679
|
+
}
|
|
22647
22680
|
function buildForCall(node, bodyExpr) {
|
|
22648
22681
|
return types.callExpression(useImport("createComponent"), [
|
|
22649
22682
|
useImport("For"),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "babel-plugin-essor",
|
|
3
|
-
"version": "0.0.16-beta.
|
|
3
|
+
"version": "0.0.16-beta.8",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [],
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"sideEffects": false,
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@babel/core": "^7.29.0",
|
|
36
|
-
"@estjs/shared": "0.0.16-beta.
|
|
36
|
+
"@estjs/shared": "0.0.16-beta.8"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@babel/types": "^7.29.0",
|