babel-plugin-essor 0.0.15-beta.12 → 0.0.15-beta.13
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 +126 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +126 -26
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -21245,7 +21245,8 @@ var DEFAULT_OPTIONS = {
|
|
|
21245
21245
|
symbol: "$",
|
|
21246
21246
|
props: true,
|
|
21247
21247
|
hmr: true,
|
|
21248
|
-
styled: false
|
|
21248
|
+
styled: false,
|
|
21249
|
+
enableFor: false
|
|
21249
21250
|
};
|
|
21250
21251
|
var IMPORTS_MAPS = [
|
|
21251
21252
|
// Reactive API
|
|
@@ -21262,6 +21263,7 @@ var IMPORTS_MAPS = [
|
|
|
21262
21263
|
"Portal",
|
|
21263
21264
|
// Template related
|
|
21264
21265
|
"mapNodes",
|
|
21266
|
+
"mapArray",
|
|
21265
21267
|
"template",
|
|
21266
21268
|
"delegateEvents",
|
|
21267
21269
|
// styled
|
|
@@ -22815,34 +22817,16 @@ function generateIndexMap({
|
|
|
22815
22817
|
}) {
|
|
22816
22818
|
const indexSet = /* @__PURE__ */ new Set();
|
|
22817
22819
|
for (const item of children) {
|
|
22818
|
-
if (!O(item.parentIndex))
|
|
22819
|
-
|
|
22820
|
-
}
|
|
22821
|
-
if (!O(item.before)) {
|
|
22822
|
-
indexSet.add(item.before);
|
|
22823
|
-
}
|
|
22820
|
+
if (!O(item.parentIndex)) indexSet.add(item.parentIndex);
|
|
22821
|
+
if (!O(item.before)) indexSet.add(item.before);
|
|
22824
22822
|
}
|
|
22825
22823
|
for (const item of props) {
|
|
22826
|
-
if (!O(item.parentIndex))
|
|
22827
|
-
indexSet.add(item.parentIndex);
|
|
22828
|
-
}
|
|
22824
|
+
if (!O(item.parentIndex)) indexSet.add(item.parentIndex);
|
|
22829
22825
|
}
|
|
22830
|
-
|
|
22831
|
-
|
|
22832
|
-
if (!O(item.nodeIndex)) {
|
|
22833
|
-
indexSet.add(item.nodeIndex);
|
|
22834
|
-
}
|
|
22835
|
-
}
|
|
22826
|
+
for (const item of operations) {
|
|
22827
|
+
if (!O(item.nodeIndex)) indexSet.add(item.nodeIndex);
|
|
22836
22828
|
}
|
|
22837
|
-
|
|
22838
|
-
{
|
|
22839
|
-
for (const index of indexMap) {
|
|
22840
|
-
if (!Number.isInteger(index) || index < 1) {
|
|
22841
|
-
re(`Invalid index in index map: ${index}. All indices must be positive integers.`);
|
|
22842
|
-
}
|
|
22843
|
-
}
|
|
22844
|
-
}
|
|
22845
|
-
return indexMap;
|
|
22829
|
+
return Array.from(indexSet).sort((a, b) => a - b);
|
|
22846
22830
|
}
|
|
22847
22831
|
function createRefStatement(nodesId, nodeIndex, value) {
|
|
22848
22832
|
const elementRef = core.types.memberExpression(nodesId, core.types.numericLiteral(nodeIndex), true);
|
|
@@ -23002,7 +22986,123 @@ function createInsertArguments(dynamicContent, nodesIdentifier, indexMap) {
|
|
|
23002
22986
|
function generateDynamicChildrenCode(dynamicChildren, statements, state, nodesId, indexMap) {
|
|
23003
22987
|
addImport(importMap.insert);
|
|
23004
22988
|
for (const dynamicContent of dynamicChildren) {
|
|
23005
|
-
|
|
22989
|
+
let node = dynamicContent.node;
|
|
22990
|
+
let mapCall = null;
|
|
22991
|
+
if (core.types.isCallExpression(node) && core.types.isMemberExpression(node.callee) && core.types.isIdentifier(node.callee.property) && node.callee.property.name === "map" && node.arguments.length > 0) {
|
|
22992
|
+
mapCall = node;
|
|
22993
|
+
} else if (core.types.isArrowFunctionExpression(node) && core.types.isCallExpression(node.body) && core.types.isMemberExpression(node.body.callee) && core.types.isIdentifier(node.body.callee.property) && node.body.callee.property.name === "map" && node.body.arguments.length > 0) {
|
|
22994
|
+
mapCall = node.body;
|
|
22995
|
+
}
|
|
22996
|
+
if (mapCall && state.opts.enableFor !== false) {
|
|
22997
|
+
const listExpr = mapCall.callee.object;
|
|
22998
|
+
const mapFn = mapCall.arguments[0];
|
|
22999
|
+
if (core.types.isExpression(listExpr) && (core.types.isArrowFunctionExpression(mapFn) || core.types.isFunctionExpression(mapFn))) {
|
|
23000
|
+
addImport(importMap.createComponent);
|
|
23001
|
+
addImport(importMap.For);
|
|
23002
|
+
let keyFnExpr = null;
|
|
23003
|
+
let transformedMapFn = mapFn;
|
|
23004
|
+
const mapFnBody = core.types.isArrowFunctionExpression(mapFn) ? mapFn.body : null;
|
|
23005
|
+
const mapFnParams = mapFn.params;
|
|
23006
|
+
let itemParamName = null;
|
|
23007
|
+
if (mapFnParams.length > 0 && core.types.isIdentifier(mapFnParams[0])) {
|
|
23008
|
+
itemParamName = mapFnParams[0].name;
|
|
23009
|
+
}
|
|
23010
|
+
if (itemParamName && mapFnBody) {
|
|
23011
|
+
if (core.types.isCallExpression(mapFnBody)) {
|
|
23012
|
+
const callee = mapFnBody.callee;
|
|
23013
|
+
const args = mapFnBody.arguments;
|
|
23014
|
+
const isCreateComponentCall = core.types.isIdentifier(callee) && callee.name.includes("createComponent") || core.types.isMemberExpression(callee) && core.types.isIdentifier(callee.property) && callee.property.name === "createComponent";
|
|
23015
|
+
if (isCreateComponentCall && args.length >= 2) {
|
|
23016
|
+
const componentRef = args[0];
|
|
23017
|
+
const propsArg = args[1];
|
|
23018
|
+
if (core.types.isExpression(componentRef) && core.types.isObjectExpression(propsArg)) {
|
|
23019
|
+
const newProps = [];
|
|
23020
|
+
for (const prop of propsArg.properties) {
|
|
23021
|
+
if (core.types.isObjectProperty(prop) && core.types.isIdentifier(prop.key) && prop.key.name === "key" && core.types.isExpression(prop.value)) {
|
|
23022
|
+
keyFnExpr = core.types.arrowFunctionExpression(
|
|
23023
|
+
[core.types.identifier(itemParamName)],
|
|
23024
|
+
prop.value
|
|
23025
|
+
);
|
|
23026
|
+
} else if (core.types.isObjectProperty(prop) || core.types.isSpreadElement(prop)) {
|
|
23027
|
+
newProps.push(prop);
|
|
23028
|
+
}
|
|
23029
|
+
}
|
|
23030
|
+
const newPropsObj = core.types.objectExpression(newProps);
|
|
23031
|
+
const directCall = core.types.callExpression(componentRef, [newPropsObj]);
|
|
23032
|
+
transformedMapFn = core.types.arrowFunctionExpression(mapFnParams, directCall);
|
|
23033
|
+
}
|
|
23034
|
+
}
|
|
23035
|
+
} else if (core.types.isJSXElement(mapFnBody)) {
|
|
23036
|
+
const opening = mapFnBody.openingElement;
|
|
23037
|
+
const tagName = opening.name;
|
|
23038
|
+
let componentRef = null;
|
|
23039
|
+
if (core.types.isJSXIdentifier(tagName) && /^[A-Z]/.test(tagName.name)) {
|
|
23040
|
+
componentRef = core.types.identifier(tagName.name);
|
|
23041
|
+
} else if (core.types.isJSXMemberExpression(tagName)) {
|
|
23042
|
+
const convertJSXName = (name) => {
|
|
23043
|
+
if (core.types.isJSXIdentifier(name)) return core.types.identifier(name.name);
|
|
23044
|
+
if (core.types.isJSXMemberExpression(name))
|
|
23045
|
+
return core.types.memberExpression(
|
|
23046
|
+
convertJSXName(name.object),
|
|
23047
|
+
convertJSXName(name.property)
|
|
23048
|
+
);
|
|
23049
|
+
throw new Error("Unsupported JSX Member Expression");
|
|
23050
|
+
};
|
|
23051
|
+
componentRef = core.types.memberExpression(
|
|
23052
|
+
convertJSXName(tagName.object),
|
|
23053
|
+
convertJSXName(tagName.property)
|
|
23054
|
+
);
|
|
23055
|
+
}
|
|
23056
|
+
if (componentRef) {
|
|
23057
|
+
const newProps = [];
|
|
23058
|
+
for (const attr of opening.attributes) {
|
|
23059
|
+
if (core.types.isJSXAttribute(attr)) {
|
|
23060
|
+
const nameNode = attr.name;
|
|
23061
|
+
const name = core.types.isJSXIdentifier(nameNode) ? nameNode.name : nameNode.name.name;
|
|
23062
|
+
let valueExpr = core.types.booleanLiteral(true);
|
|
23063
|
+
if (attr.value) {
|
|
23064
|
+
if (core.types.isJSXExpressionContainer(attr.value)) {
|
|
23065
|
+
if (core.types.isExpression(attr.value.expression)) {
|
|
23066
|
+
valueExpr = attr.value.expression;
|
|
23067
|
+
} else {
|
|
23068
|
+
continue;
|
|
23069
|
+
}
|
|
23070
|
+
} else if (core.types.isStringLiteral(attr.value)) {
|
|
23071
|
+
valueExpr = attr.value;
|
|
23072
|
+
}
|
|
23073
|
+
}
|
|
23074
|
+
if (name === "key") {
|
|
23075
|
+
keyFnExpr = core.types.arrowFunctionExpression([core.types.identifier(itemParamName)], valueExpr);
|
|
23076
|
+
} else {
|
|
23077
|
+
newProps.push(core.types.objectProperty(core.types.identifier(name), valueExpr));
|
|
23078
|
+
}
|
|
23079
|
+
} else if (core.types.isJSXSpreadAttribute(attr)) {
|
|
23080
|
+
newProps.push(core.types.spreadElement(attr.argument));
|
|
23081
|
+
}
|
|
23082
|
+
}
|
|
23083
|
+
const newPropsObj = core.types.objectExpression(newProps);
|
|
23084
|
+
const directCall = core.types.callExpression(componentRef, [newPropsObj]);
|
|
23085
|
+
transformedMapFn = core.types.arrowFunctionExpression(mapFnParams, directCall);
|
|
23086
|
+
}
|
|
23087
|
+
}
|
|
23088
|
+
}
|
|
23089
|
+
const propsProperties = [
|
|
23090
|
+
core.types.objectProperty(core.types.identifier("each"), core.types.arrowFunctionExpression([], listExpr)),
|
|
23091
|
+
core.types.objectProperty(core.types.identifier("children"), transformedMapFn)
|
|
23092
|
+
];
|
|
23093
|
+
if (keyFnExpr) {
|
|
23094
|
+
propsProperties.push(core.types.objectProperty(core.types.identifier("keyFn"), keyFnExpr));
|
|
23095
|
+
}
|
|
23096
|
+
const propsObject = core.types.objectExpression(propsProperties);
|
|
23097
|
+
const newExpr = core.types.callExpression(state.imports.createComponent, [
|
|
23098
|
+
state.imports.For,
|
|
23099
|
+
propsObject
|
|
23100
|
+
]);
|
|
23101
|
+
dynamicContent.node = newExpr;
|
|
23102
|
+
node = newExpr;
|
|
23103
|
+
}
|
|
23104
|
+
}
|
|
23105
|
+
const processedNode = processIIFEExpression(node);
|
|
23006
23106
|
const insertArgs = createInsertArguments(
|
|
23007
23107
|
__spreadProps(__spreadValues({}, dynamicContent), { node: processedNode }),
|
|
23008
23108
|
nodesId,
|