@dune2/babel 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/createStore.cjs +15 -10
- package/dist/createStore.cjs.map +1 -1
- package/dist/createStore.mjs +13 -9
- package/dist/createStore.mjs.map +1 -1
- package/package.json +18 -17
package/dist/createStore.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -80,24 +81,26 @@ function handleIdentifierSnapshot(path) {
|
|
|
80
81
|
if (!arr.length || arr.length !== (binding === null || binding === void 0 ? void 0 : binding.referencePaths.length)) return;
|
|
81
82
|
arr.forEach((item) => {
|
|
82
83
|
const { memberExprStart, nodePath, accessKey } = item;
|
|
83
|
-
let
|
|
84
|
-
if (!
|
|
85
|
-
|
|
86
|
-
accessorMap.set(accessKey,
|
|
84
|
+
let key = accessorMap.get(accessKey);
|
|
85
|
+
if (!key) {
|
|
86
|
+
key = accessKey.slice(1);
|
|
87
|
+
accessorMap.set(accessKey, key);
|
|
87
88
|
memberAccessors.push({
|
|
88
89
|
node: _babel_types.default.cloneDeepWithoutLoc(memberExprStart),
|
|
89
|
-
|
|
90
|
+
key
|
|
90
91
|
});
|
|
91
92
|
}
|
|
92
|
-
|
|
93
|
+
const isComputed = key.includes(".");
|
|
94
|
+
nodePath.replaceWith(_babel_types.default.memberExpression(_babel_types.default.cloneWithoutLoc(id), isComputed ? _babel_types.default.stringLiteral(key) : _babel_types.default.identifier(key), isComputed));
|
|
93
95
|
});
|
|
94
96
|
if (!memberAccessors.length) return;
|
|
95
97
|
}
|
|
96
98
|
const selectorName = path.scope.generateUidIdentifier("selector_");
|
|
97
99
|
const selector = _babel_types.default.functionDeclaration(selectorName, [_babel_types.default.identifier(id.name)], _babel_types.default.blockStatement([_babel_types.default.returnStatement(_babel_types.default.objectExpression(memberAccessors.map((accessor) => {
|
|
98
|
-
|
|
100
|
+
const propKey = accessor.key.includes(".") ? _babel_types.default.stringLiteral(accessor.key) : _babel_types.default.identifier(accessor.key);
|
|
101
|
+
return _babel_types.default.objectProperty(propKey, accessor.node);
|
|
99
102
|
})))]));
|
|
100
|
-
path.parentPath.insertBefore(selector);
|
|
103
|
+
(path.findParent((p) => p.isFunctionDeclaration() || p.isFunctionExpression() || p.isArrowFunctionExpression()) ?? path.parentPath).insertBefore(selector);
|
|
101
104
|
callee.property.name = "useShallowSnapshot";
|
|
102
105
|
init.arguments = [selectorName];
|
|
103
106
|
}
|
|
@@ -120,6 +123,8 @@ function findMemberExpression(path) {
|
|
|
120
123
|
const parent = current.parentPath;
|
|
121
124
|
const node = parent.node;
|
|
122
125
|
if ((_babel_types.default.isMemberExpression(node) || _babel_types.default.isOptionalMemberExpression(node)) && _babel_types.default.isIdentifier(node.property)) {
|
|
126
|
+
const grandParent = parent.parentPath;
|
|
127
|
+
if (grandParent && _babel_types.default.isCallExpression(grandParent.node) && grandParent.node.callee === node) break;
|
|
123
128
|
memberExprStart = node;
|
|
124
129
|
current = parent;
|
|
125
130
|
accessKey += "." + node.property.name;
|
|
@@ -159,7 +164,7 @@ function handleObjectPattern(path) {
|
|
|
159
164
|
}
|
|
160
165
|
return _babel_types.default.cloneDeepWithoutLoc(v);
|
|
161
166
|
})))]));
|
|
162
|
-
path.parentPath.insertBefore(selector);
|
|
167
|
+
(path.findParent((p) => p.isFunctionDeclaration() || p.isFunctionExpression() || p.isArrowFunctionExpression()) ?? path.parentPath).insertBefore(selector);
|
|
163
168
|
callee.property.name = "useShallowSnapshot";
|
|
164
169
|
init.arguments = [selectorName];
|
|
165
170
|
}
|
package/dist/createStore.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createStore.cjs","names":["t","t","t"],"sources":["../src/createStore/shared.ts","../src/createStore/handleIdentifierSnapshot.ts","../src/createStore/handleObjectPattern.ts","../src/createStore/index.ts"],"sourcesContent":["import type { CallExpression } from \"@babel/types\";\nimport t from \"@babel/types\";\n\n/**\n * 检查 selector 参数的返回值类型\n * 如果返回值是对象类型,则将 useSnapshot 转换为 useShallowSnapshot\n */\nexport function handleSelectorArgument(init: CallExpression) {\n const selector = init.arguments[0];\n if (\n t.isFunctionExpression(selector) ||\n t.isArrowFunctionExpression(selector)\n ) {\n const body = selector.body;\n if (t.isBlockStatement(body)) {\n const returnStmt = body.body.find((stmt) => t.isReturnStatement(stmt));\n if (\n returnStmt &&\n t.isReturnStatement(returnStmt) &&\n t.isObjectExpression(returnStmt.argument)\n ) {\n return true;\n }\n } else if (t.isObjectExpression(body)) {\n return true;\n }\n }\n return false;\n}\n","import type { NodePath } from \"@babel/traverse\";\nimport type {\n Identifier,\n MemberExpression,\n OptionalMemberExpression,\n VariableDeclarator,\n} from \"@babel/types\";\nimport t from \"@babel/types\";\nimport { handleSelectorArgument } from \"./shared\";\n/**\n * 处理 store.useSnapshot() 的变量声明\n * 示例: const state = store.useSnapshot()\n * 将会转换为:\n * function selector(state) { return { _prop: state.a.b } }\n * const state = store.useShallowSnapshot(selector)\n */\nexport function handleIdentifierSnapshot(path: NodePath<VariableDeclarator>) {\n const { id, init } = path.node;\n\n // 预检查:确保是 CallExpression 且变量是标识符\n if (!t.isCallExpression(init) || !t.isIdentifier(id)) {\n return;\n }\n if (!t.isMemberExpression(init.callee)) {\n return;\n }\n\n // 检查是否为 store.useSnapshot 调用\n const callee = init.callee;\n if (\n !t.isIdentifier(callee.property) ||\n callee.property.name !== \"useSnapshot\"\n ) {\n return;\n }\n\n // 如果已经有 selector 参数,则需要检查返回值类型\n // 如果返回值是对象类型,则转换为 useShallowSnapshot\n if (init.arguments.length > 0) {\n if (handleSelectorArgument(init)) {\n callee.property.name = \"useShallowSnapshot\";\n }\n return;\n }\n\n // 初始化成员访问器数组和访问器映射\n // memberAccessors 用于存储所有的成员访问表达式\n // accessorMap 用于缓存已处理过的访问路径,避免重复创建\n const memberAccessors: MemberAccessor[] = [];\n const accessorMap = new Map<string, Identifier>();\n {\n // 获取变量的绑定信息,用于查找所有引用\n const binding = path.scope.getOwnBinding(id.name);\n\n // 存储所有有效的成员表达式访问\n const arr: ReturnType<typeof findMemberExpression>[] = [];\n\n // 第一次遍历:收集所有有效的成员表达式\n binding?.referencePaths.forEach((refPath) => {\n const { memberExprStart, nodePath, accessKey } =\n findMemberExpression(refPath);\n if (memberExprStart && nodePath && accessKey) {\n arr.push({ memberExprStart, nodePath, accessKey });\n }\n });\n\n // 如果存在无效的成员表达式访问,则不进行转换\n if (!arr.length || arr.length !== binding?.referencePaths.length) {\n return;\n }\n\n // 第二次遍历:处理每个成员表达式\n // 1. 为每个唯一的访问路径生成标识符\n // 2. 收集成员访问器信息\n // 3. 替换原始表达式为新的访问方式\n arr.forEach((item) => {\n const { memberExprStart, nodePath, accessKey } = item;\n let propIdentifier = accessorMap.get(accessKey);\n if (!propIdentifier) {\n // 生成唯一的属性标识符\n propIdentifier = path.scope.generateUidIdentifier(\"prop_\");\n accessorMap.set(accessKey, propIdentifier);\n memberAccessors.push({\n node: t.cloneDeepWithoutLoc(memberExprStart!),\n identifier: propIdentifier,\n });\n }\n\n // 替换原始的成员表达式为新的访问方式\n nodePath!.replaceWith(\n t.memberExpression(\n t.cloneWithoutLoc(id),\n t.cloneDeepWithoutLoc(propIdentifier),\n ),\n );\n });\n\n if (!memberAccessors.length) {\n return;\n }\n }\n\n // 生成选择器函数\n // 创建一个新的函数,返回包含所有访问路径的对象\n const selectorName = path.scope.generateUidIdentifier(\"selector_\");\n const selector = t.functionDeclaration(\n selectorName,\n [t.identifier(id.name)],\n t.blockStatement([\n t.returnStatement(\n t.objectExpression(\n memberAccessors.map((accessor) => {\n return t.objectProperty(accessor.identifier, accessor.node);\n }),\n ),\n ),\n ]),\n );\n path.parentPath.insertBefore(selector);\n\n // 修改原始调用为 useShallowSnapshot\n callee.property.name = \"useShallowSnapshot\";\n init.arguments = [selectorName];\n}\n\ntype MemberAccessor = {\n node: MemberExpression | OptionalMemberExpression;\n identifier: Identifier;\n};\n\n/**\n * 查找成员表达式链\n * 例如: a.b.c 会找到最后一个成员表达式 a.b.c\n *\n * @param path - 当前节点路径\n * @returns {\n * memberExprStart - 成员表达式的起始节点\n * nodePath - 当前节点路径\n * accessKey - 完整的访问路径字符串\n * }\n */\nfunction findMemberExpression(path: NodePath) {\n let current: NodePath | null = path;\n let memberExprStart: MemberAccessor[\"node\"] | undefined;\n let accessKey = \"\";\n\n while (current?.parentPath) {\n const parent = current.parentPath;\n const node = parent.node;\n\n if (\n (t.isMemberExpression(node) || t.isOptionalMemberExpression(node)) &&\n t.isIdentifier(node.property)\n ) {\n memberExprStart = node;\n current = parent;\n accessKey += \".\" + node.property.name;\n } else {\n break; // 如果不是成员表达式,立即停止向上查找\n }\n }\n\n return { memberExprStart, nodePath: current, accessKey };\n}\n","import type { NodePath } from \"@babel/traverse\";\nimport type { VariableDeclarator } from \"@babel/types\";\nimport t from \"@babel/types\";\nimport { handleSelectorArgument } from \"./shared\";\n\n/**\n * 处理 store.useSnapshot() 的变量声明\n * 示例: const { a, c: { name } } = store.useSnapshot()\n * 将会转换为:\n * function selector({ a, c: { name } } ) { return { a, c: { name } } }\n * const { a, c: { name } } = store.useShallowSnapshot(selector)\n */\nexport function handleObjectPattern(path: NodePath<VariableDeclarator>) {\n const { id, init } = path.node;\n\n // 预检查:确保是 CallExpression 且变量是 ObjectPattern\n if (!t.isCallExpression(init) || !t.isObjectPattern(id)) {\n return;\n }\n if (!t.isMemberExpression(init.callee)) {\n return;\n }\n\n // 检查是否为 store.useSnapshot 调用\n const callee = init.callee;\n if (\n !t.isIdentifier(callee.property) ||\n callee.property.name !== \"useSnapshot\"\n ) {\n return;\n }\n // 如果已经有 selector 参数,则不需要转换\n if (init.arguments.length > 0) {\n if (handleSelectorArgument(init)) {\n callee.property.name = \"useShallowSnapshot\";\n }\n return;\n }\n\n // 进入主流程\n // 进入主流程\n const selectorName = path.scope.generateUidIdentifier(\"selector_\");\n\n // 创建 selector 函数,使用相同的解构模式\n const selector = t.functionDeclaration(\n selectorName,\n [t.cloneDeepWithoutLoc(id)],\n t.blockStatement([\n t.returnStatement(\n t.objectExpression(\n id.properties.map((v) => {\n if (t.isRestElement(v)) {\n if (!t.isIdentifier(v.argument)) {\n throw path.buildCodeFrameError(\n \"Rest element in object pattern must be a simple identifier\",\n );\n }\n return t.spreadElement(t.cloneDeepWithoutLoc(v.argument));\n }\n return t.cloneDeepWithoutLoc(v);\n }),\n ),\n ),\n ]),\n );\n\n // 插入 selector 函数声明\n path.parentPath.insertBefore(selector);\n\n // 修改为使用 useShallowSnapshot 并传入选择器\n callee.property.name = \"useShallowSnapshot\";\n init.arguments = [selectorName];\n}\n","import type babel from \"@babel/core\";\nimport type { PluginObj } from \"@babel/core\";\nimport { handleIdentifierSnapshot } from \"./handleIdentifierSnapshot\";\nimport { handleObjectPattern } from \"./handleObjectPattern\";\n\nexport const createStorePlugin = (api: typeof babel): PluginObj => {\n return {\n name: \"create-store\",\n visitor: {\n VariableDeclarator(path) {\n handleIdentifierSnapshot(path);\n handleObjectPattern(path);\n },\n },\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,SAAgB,uBAAuB,MAAsB;CAC3D,MAAM,WAAW,KAAK,UAAU;AAChC,KACEA,qBAAE,qBAAqB,SAAS,IAChCA,qBAAE,0BAA0B,SAAS,EACrC;EACA,MAAM,OAAO,SAAS;AACtB,MAAIA,qBAAE,iBAAiB,KAAK,EAAE;GAC5B,MAAM,aAAa,KAAK,KAAK,MAAM,SAASA,qBAAE,kBAAkB,KAAK,CAAC;AACtE,OACE,cACAA,qBAAE,kBAAkB,WAAW,IAC/BA,qBAAE,mBAAmB,WAAW,SAAS,CAEz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;CAGlE,MAAM,WAAWA,qBAAE,oBACjB,cACA,CAACA,qBAAE,oBAAoB,GAAG,CAAC,EAC3BA,qBAAE,eAAe,CACfA,qBAAE,gBACAA,qBAAE,iBACA,GAAG,WAAW,KAAK,MAAM;AACvB,MAAIA,qBAAE,cAAc,EAAE,EAAE;AACtB,OAAI,CAACA,qBAAE,aAAa,EAAE,SAAS,CAC7B,OAAM,KAAK,oBACT,6DACD;AAEH,UAAOA,qBAAE,cAAcA,qBAAE,oBAAoB,EAAE,SAAS,CAAC;;AAE3D,SAAOA,qBAAE,oBAAoB,EAAE;GAC/B,CACH,CACF,CACF,CAAC,CACH;AAGD,MAAK,WAAW,aAAa,SAAS;AAGtC,QAAO,SAAS,OAAO;AACvB,MAAK,YAAY,CAAC,aAAa;;;;;AClEjC,MAAa,qBAAqB,QAAiC;AACjE,QAAO;EACL,MAAM;EACN,SAAS,EACP,mBAAmB,MAAM;AACvB,4BAAyB,KAAK;AAC9B,uBAAoB,KAAK;KAE5B;EACF"}
|
|
1
|
+
{"version":3,"file":"createStore.cjs","names":["t","t","t"],"sources":["../src/createStore/shared.ts","../src/createStore/handleIdentifierSnapshot.ts","../src/createStore/handleObjectPattern.ts","../src/createStore/index.ts"],"sourcesContent":["import type { CallExpression } from '@babel/types';\nimport t from '@babel/types';\n\n/**\n * 检查 selector 参数的返回值类型\n * 如果返回值是对象类型,则将 useSnapshot 转换为 useShallowSnapshot\n */\nexport function handleSelectorArgument(init: CallExpression) {\n const selector = init.arguments[0];\n if (\n t.isFunctionExpression(selector) ||\n t.isArrowFunctionExpression(selector)\n ) {\n const body = selector.body;\n if (t.isBlockStatement(body)) {\n const returnStmt = body.body.find((stmt) => t.isReturnStatement(stmt));\n if (\n returnStmt &&\n t.isReturnStatement(returnStmt) &&\n t.isObjectExpression(returnStmt.argument)\n ) {\n return true;\n }\n } else if (t.isObjectExpression(body)) {\n return true;\n }\n }\n return false;\n}\n","import type { NodePath } from '@babel/traverse';\nimport type {\n MemberExpression,\n OptionalMemberExpression,\n VariableDeclarator,\n} from '@babel/types';\nimport t from '@babel/types';\nimport { handleSelectorArgument } from './shared';\n/**\n * 处理 store.useSnapshot() 的变量声明\n * 示例: const state = store.useSnapshot()\n * 将会转换为:\n * function selector(state) { return { _prop: state.a.b } }\n * const state = store.useShallowSnapshot(selector)\n */\nexport function handleIdentifierSnapshot(path: NodePath<VariableDeclarator>) {\n const { id, init } = path.node;\n\n // 预检查:确保是 CallExpression 且变量是标识符\n if (!t.isCallExpression(init) || !t.isIdentifier(id)) {\n return;\n }\n if (!t.isMemberExpression(init.callee)) {\n return;\n }\n\n // 检查是否为 store.useSnapshot 调用\n const callee = init.callee;\n if (\n !t.isIdentifier(callee.property) ||\n callee.property.name !== 'useSnapshot'\n ) {\n return;\n }\n\n // 如果已经有 selector 参数,则需要检查返回值类型\n // 如果返回值是对象类型,则转换为 useShallowSnapshot\n if (init.arguments.length > 0) {\n if (handleSelectorArgument(init)) {\n callee.property.name = 'useShallowSnapshot';\n }\n return;\n }\n\n // 初始化成员访问器数组和访问器映射\n // memberAccessors 用于存储所有的成员访问表达式\n // accessorMap 用于缓存已处理过的访问路径,避免重复创建\n const memberAccessors: MemberAccessor[] = [];\n const accessorMap = new Map<string, string>();\n {\n // 获取变量的绑定信息,用于查找所有引用\n const binding = path.scope.getOwnBinding(id.name);\n\n // 存储所有有效的成员表达式访问\n const arr: ReturnType<typeof findMemberExpression>[] = [];\n\n // 第一次遍历:收集所有有效的成员表达式\n binding?.referencePaths.forEach((refPath) => {\n const { memberExprStart, nodePath, accessKey } =\n findMemberExpression(refPath);\n if (memberExprStart && nodePath && accessKey) {\n arr.push({ memberExprStart, nodePath, accessKey });\n }\n });\n\n // 如果存在无效的成员表达式访问,则不进行转换\n if (!arr.length || arr.length !== binding?.referencePaths.length) {\n return;\n }\n\n // 第二次遍历:处理每个成员表达式\n // 1. 为每个唯一的访问路径生成标识符\n // 2. 收集成员访问器信息\n // 3. 替换原始表达式为新的访问方式\n arr.forEach((item) => {\n const { memberExprStart, nodePath, accessKey } = item;\n let key = accessorMap.get(accessKey);\n if (!key) {\n // 使用访问路径作为属性名,如 'a', 'c.name'\n key = accessKey.slice(1);\n accessorMap.set(accessKey, key);\n memberAccessors.push({\n node: t.cloneDeepWithoutLoc(memberExprStart!),\n key,\n });\n }\n\n // 替换原始的成员表达式为新的访问方式\n const isComputed = key.includes('.');\n nodePath!.replaceWith(\n t.memberExpression(\n t.cloneWithoutLoc(id),\n isComputed ? t.stringLiteral(key) : t.identifier(key),\n isComputed,\n ),\n );\n });\n\n if (!memberAccessors.length) {\n return;\n }\n }\n\n // 生成选择器函数\n // 创建一个新的函数,返回包含所有访问路径的对象\n const selectorName = path.scope.generateUidIdentifier('selector_');\n const selector = t.functionDeclaration(\n selectorName,\n [t.identifier(id.name)],\n t.blockStatement([\n t.returnStatement(\n t.objectExpression(\n memberAccessors.map((accessor) => {\n const isComputed = accessor.key.includes('.');\n const propKey = isComputed\n ? t.stringLiteral(accessor.key)\n : t.identifier(accessor.key);\n return t.objectProperty(propKey, accessor.node);\n }),\n ),\n ),\n ]),\n );\n // 将 selector 函数提升到组件外部,使其更持久化\n const funcParent =\n path.findParent(\n (p) =>\n p.isFunctionDeclaration() ||\n p.isFunctionExpression() ||\n p.isArrowFunctionExpression(),\n ) ?? path.parentPath;\n funcParent.insertBefore(selector);\n\n // 修改原始调用为 useShallowSnapshot\n callee.property.name = 'useShallowSnapshot';\n init.arguments = [selectorName];\n}\n\ntype MemberAccessor = {\n node: MemberExpression | OptionalMemberExpression;\n key: string;\n};\n\n/**\n * 查找成员表达式链\n * 例如: a.b.c 会找到最后一个成员表达式 a.b.c\n *\n * @param path - 当前节点路径\n * @returns {\n * memberExprStart - 成员表达式的起始节点\n * nodePath - 当前节点路径\n * accessKey - 完整的访问路径字符串\n * }\n */\nfunction findMemberExpression(path: NodePath) {\n let current: NodePath | null = path;\n let memberExprStart: MemberAccessor['node'] | undefined;\n let accessKey = '';\n\n while (current?.parentPath) {\n const parent = current.parentPath;\n const node = parent.node;\n\n if (\n (t.isMemberExpression(node) || t.isOptionalMemberExpression(node)) &&\n t.isIdentifier(node.property)\n ) {\n // 如果该成员表达式是 CallExpression 的 callee,说明是方法调用,停止收集\n const grandParent = parent.parentPath;\n if (\n grandParent &&\n t.isCallExpression(grandParent.node) &&\n grandParent.node.callee === node\n ) {\n break;\n }\n memberExprStart = node;\n current = parent;\n accessKey += '.' + node.property.name;\n } else {\n break; // 如果不是成员表达式,立即停止向上查找\n }\n }\n\n return { memberExprStart, nodePath: current, accessKey };\n}\n","import type { NodePath } from '@babel/traverse';\nimport type { VariableDeclarator } from '@babel/types';\nimport t from '@babel/types';\nimport { handleSelectorArgument } from './shared';\n\n/**\n * 处理 store.useSnapshot() 的变量声明\n * 示例: const { a, c: { name } } = store.useSnapshot()\n * 将会转换为:\n * function selector({ a, c: { name } } ) { return { a, c: { name } } }\n * const { a, c: { name } } = store.useShallowSnapshot(selector)\n */\nexport function handleObjectPattern(path: NodePath<VariableDeclarator>) {\n const { id, init } = path.node;\n\n // 预检查:确保是 CallExpression 且变量是 ObjectPattern\n if (!t.isCallExpression(init) || !t.isObjectPattern(id)) {\n return;\n }\n if (!t.isMemberExpression(init.callee)) {\n return;\n }\n\n // 检查是否为 store.useSnapshot 调用\n const callee = init.callee;\n if (\n !t.isIdentifier(callee.property) ||\n callee.property.name !== 'useSnapshot'\n ) {\n return;\n }\n // 如果已经有 selector 参数,则不需要转换\n if (init.arguments.length > 0) {\n if (handleSelectorArgument(init)) {\n callee.property.name = 'useShallowSnapshot';\n }\n return;\n }\n\n // 进入主流程\n // 进入主流程\n const selectorName = path.scope.generateUidIdentifier('selector_');\n\n // 创建 selector 函数,使用相同的解构模式\n const selector = t.functionDeclaration(\n selectorName,\n [t.cloneDeepWithoutLoc(id)],\n t.blockStatement([\n t.returnStatement(\n t.objectExpression(\n id.properties.map((v) => {\n if (t.isRestElement(v)) {\n if (!t.isIdentifier(v.argument)) {\n throw path.buildCodeFrameError(\n 'Rest element in object pattern must be a simple identifier',\n );\n }\n return t.spreadElement(t.cloneDeepWithoutLoc(v.argument));\n }\n return t.cloneDeepWithoutLoc(v);\n }),\n ),\n ),\n ]),\n );\n\n // 将 selector 函数提升到组件外部,使其更持久化\n const funcParent =\n path.findParent(\n (p) =>\n p.isFunctionDeclaration() ||\n p.isFunctionExpression() ||\n p.isArrowFunctionExpression(),\n ) ?? path.parentPath;\n funcParent.insertBefore(selector);\n\n // 修改为使用 useShallowSnapshot 并传入选择器\n callee.property.name = 'useShallowSnapshot';\n init.arguments = [selectorName];\n}\n","import type babel from '@babel/core';\nimport type { PluginObj } from '@babel/core';\nimport { handleIdentifierSnapshot } from './handleIdentifierSnapshot';\nimport { handleObjectPattern } from './handleObjectPattern';\n\nexport const createStorePlugin = (api: typeof babel): PluginObj => {\n return {\n name: 'create-store',\n visitor: {\n VariableDeclarator(path) {\n handleIdentifierSnapshot(path);\n handleObjectPattern(path);\n },\n },\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,SAAgB,uBAAuB,MAAsB;CAC3D,MAAM,WAAW,KAAK,UAAU;AAChC,KACEA,qBAAE,qBAAqB,SAAS,IAChCA,qBAAE,0BAA0B,SAAS,EACrC;EACA,MAAM,OAAO,SAAS;AACtB,MAAIA,qBAAE,iBAAiB,KAAK,EAAE;GAC5B,MAAM,aAAa,KAAK,KAAK,MAAM,SAASA,qBAAE,kBAAkB,KAAK,CAAC;AACtE,OACE,cACAA,qBAAE,kBAAkB,WAAW,IAC/BA,qBAAE,mBAAmB,WAAW,SAAS,CAEzC,QAAO;aAEAA,qBAAE,mBAAmB,KAAK,CACnC,QAAO;;AAGX,QAAO;;;;;;;;;;;;ACZT,SAAgB,yBAAyB,MAAoC;CAC3E,MAAM,EAAE,IAAI,SAAS,KAAK;AAG1B,KAAI,CAACC,qBAAE,iBAAiB,KAAK,IAAI,CAACA,qBAAE,aAAa,GAAG,CAClD;AAEF,KA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AG;AAC7B,MAAI,uBAAuB,KAAK,CAC9B,QAAO,SAAS,OAAO;AAEzB;;CAKF,MAAM,eAAe,KAAK,MAAM,sBAAsB,YAAY;CAGlE,MAAM,WAAWA,qBAAE,oBACjB,cACA,CAACA,qBAAE,oBAAoB,GAAG,CAAC,EAC3BA,qBAAE,eAAe,CACfA,qBAAE,gBACAA,qBAAE,iBACA,GAAG,WAAW,KAAK,MAAM;AACvB,MAAIA,qBAAE,cAAc,EAAE,EAAE;AACtB,OAAI,CAACA,qBAAE,aAAa,EAAE,SAAS,CAC7B,OAAM,KAAK,oBACT,6DACD;AAEH,UAAOA,qBAAE,cAAcA,qBAAE,oBAAoB,EAAE,SAAS,CAAC;;AAE3D,SAAOA,qBAAE,oBAAoB,EAAE;GAC/B,CACH,CACF,CACF,CAAC,CACH;AAUD,EANE,KAAK,YACF,MACC,EAAE,uBAAuB,IACzB,EAAE,sBAAsB,IACxB,EAAE,2BAA2B,CAChC,IAAI,KAAK,YACD,aAAa,SAAS;AAGjC,QAAO,SAAS,OAAO;AACvB,MAAK,YAAY,CAAC,aAAa;;;;;ACzEjC,MAAa,qBAAqB,QAAiC;AACjE,QAAO;EACL,MAAM;EACN,SAAS,EACP,mBAAmB,MAAM;AACvB,4BAAyB,KAAK;AAC9B,uBAAoB,KAAK;KAE5B;EACF"}
|
package/dist/createStore.mjs
CHANGED
|
@@ -52,24 +52,26 @@ function handleIdentifierSnapshot(path) {
|
|
|
52
52
|
if (!arr.length || arr.length !== (binding === null || binding === void 0 ? void 0 : binding.referencePaths.length)) return;
|
|
53
53
|
arr.forEach((item) => {
|
|
54
54
|
const { memberExprStart, nodePath, accessKey } = item;
|
|
55
|
-
let
|
|
56
|
-
if (!
|
|
57
|
-
|
|
58
|
-
accessorMap.set(accessKey,
|
|
55
|
+
let key = accessorMap.get(accessKey);
|
|
56
|
+
if (!key) {
|
|
57
|
+
key = accessKey.slice(1);
|
|
58
|
+
accessorMap.set(accessKey, key);
|
|
59
59
|
memberAccessors.push({
|
|
60
60
|
node: t.cloneDeepWithoutLoc(memberExprStart),
|
|
61
|
-
|
|
61
|
+
key
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
|
-
|
|
64
|
+
const isComputed = key.includes(".");
|
|
65
|
+
nodePath.replaceWith(t.memberExpression(t.cloneWithoutLoc(id), isComputed ? t.stringLiteral(key) : t.identifier(key), isComputed));
|
|
65
66
|
});
|
|
66
67
|
if (!memberAccessors.length) return;
|
|
67
68
|
}
|
|
68
69
|
const selectorName = path.scope.generateUidIdentifier("selector_");
|
|
69
70
|
const selector = t.functionDeclaration(selectorName, [t.identifier(id.name)], t.blockStatement([t.returnStatement(t.objectExpression(memberAccessors.map((accessor) => {
|
|
70
|
-
|
|
71
|
+
const propKey = accessor.key.includes(".") ? t.stringLiteral(accessor.key) : t.identifier(accessor.key);
|
|
72
|
+
return t.objectProperty(propKey, accessor.node);
|
|
71
73
|
})))]));
|
|
72
|
-
path.parentPath.insertBefore(selector);
|
|
74
|
+
(path.findParent((p) => p.isFunctionDeclaration() || p.isFunctionExpression() || p.isArrowFunctionExpression()) ?? path.parentPath).insertBefore(selector);
|
|
73
75
|
callee.property.name = "useShallowSnapshot";
|
|
74
76
|
init.arguments = [selectorName];
|
|
75
77
|
}
|
|
@@ -92,6 +94,8 @@ function findMemberExpression(path) {
|
|
|
92
94
|
const parent = current.parentPath;
|
|
93
95
|
const node = parent.node;
|
|
94
96
|
if ((t.isMemberExpression(node) || t.isOptionalMemberExpression(node)) && t.isIdentifier(node.property)) {
|
|
97
|
+
const grandParent = parent.parentPath;
|
|
98
|
+
if (grandParent && t.isCallExpression(grandParent.node) && grandParent.node.callee === node) break;
|
|
95
99
|
memberExprStart = node;
|
|
96
100
|
current = parent;
|
|
97
101
|
accessKey += "." + node.property.name;
|
|
@@ -131,7 +135,7 @@ function handleObjectPattern(path) {
|
|
|
131
135
|
}
|
|
132
136
|
return t.cloneDeepWithoutLoc(v);
|
|
133
137
|
})))]));
|
|
134
|
-
path.parentPath.insertBefore(selector);
|
|
138
|
+
(path.findParent((p) => p.isFunctionDeclaration() || p.isFunctionExpression() || p.isArrowFunctionExpression()) ?? path.parentPath).insertBefore(selector);
|
|
135
139
|
callee.property.name = "useShallowSnapshot";
|
|
136
140
|
init.arguments = [selectorName];
|
|
137
141
|
}
|
package/dist/createStore.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createStore.mjs","names":[],"sources":["../src/createStore/shared.ts","../src/createStore/handleIdentifierSnapshot.ts","../src/createStore/handleObjectPattern.ts","../src/createStore/index.ts"],"sourcesContent":["import type { CallExpression } from \"@babel/types\";\nimport t from \"@babel/types\";\n\n/**\n * 检查 selector 参数的返回值类型\n * 如果返回值是对象类型,则将 useSnapshot 转换为 useShallowSnapshot\n */\nexport function handleSelectorArgument(init: CallExpression) {\n const selector = init.arguments[0];\n if (\n t.isFunctionExpression(selector) ||\n t.isArrowFunctionExpression(selector)\n ) {\n const body = selector.body;\n if (t.isBlockStatement(body)) {\n const returnStmt = body.body.find((stmt) => t.isReturnStatement(stmt));\n if (\n returnStmt &&\n t.isReturnStatement(returnStmt) &&\n t.isObjectExpression(returnStmt.argument)\n ) {\n return true;\n }\n } else if (t.isObjectExpression(body)) {\n return true;\n }\n }\n return false;\n}\n","import type { NodePath } from \"@babel/traverse\";\nimport type {\n Identifier,\n MemberExpression,\n OptionalMemberExpression,\n VariableDeclarator,\n} from \"@babel/types\";\nimport t from \"@babel/types\";\nimport { handleSelectorArgument } from \"./shared\";\n/**\n * 处理 store.useSnapshot() 的变量声明\n * 示例: const state = store.useSnapshot()\n * 将会转换为:\n * function selector(state) { return { _prop: state.a.b } }\n * const state = store.useShallowSnapshot(selector)\n */\nexport function handleIdentifierSnapshot(path: NodePath<VariableDeclarator>) {\n const { id, init } = path.node;\n\n // 预检查:确保是 CallExpression 且变量是标识符\n if (!t.isCallExpression(init) || !t.isIdentifier(id)) {\n return;\n }\n if (!t.isMemberExpression(init.callee)) {\n return;\n }\n\n // 检查是否为 store.useSnapshot 调用\n const callee = init.callee;\n if (\n !t.isIdentifier(callee.property) ||\n callee.property.name !== \"useSnapshot\"\n ) {\n return;\n }\n\n // 如果已经有 selector 参数,则需要检查返回值类型\n // 如果返回值是对象类型,则转换为 useShallowSnapshot\n if (init.arguments.length > 0) {\n if (handleSelectorArgument(init)) {\n callee.property.name = \"useShallowSnapshot\";\n }\n return;\n }\n\n // 初始化成员访问器数组和访问器映射\n // memberAccessors 用于存储所有的成员访问表达式\n // accessorMap 用于缓存已处理过的访问路径,避免重复创建\n const memberAccessors: MemberAccessor[] = [];\n const accessorMap = new Map<string, Identifier>();\n {\n // 获取变量的绑定信息,用于查找所有引用\n const binding = path.scope.getOwnBinding(id.name);\n\n // 存储所有有效的成员表达式访问\n const arr: ReturnType<typeof findMemberExpression>[] = [];\n\n // 第一次遍历:收集所有有效的成员表达式\n binding?.referencePaths.forEach((refPath) => {\n const { memberExprStart, nodePath, accessKey } =\n findMemberExpression(refPath);\n if (memberExprStart && nodePath && accessKey) {\n arr.push({ memberExprStart, nodePath, accessKey });\n }\n });\n\n // 如果存在无效的成员表达式访问,则不进行转换\n if (!arr.length || arr.length !== binding?.referencePaths.length) {\n return;\n }\n\n // 第二次遍历:处理每个成员表达式\n // 1. 为每个唯一的访问路径生成标识符\n // 2. 收集成员访问器信息\n // 3. 替换原始表达式为新的访问方式\n arr.forEach((item) => {\n const { memberExprStart, nodePath, accessKey } = item;\n let propIdentifier = accessorMap.get(accessKey);\n if (!propIdentifier) {\n // 生成唯一的属性标识符\n propIdentifier = path.scope.generateUidIdentifier(\"prop_\");\n accessorMap.set(accessKey, propIdentifier);\n memberAccessors.push({\n node: t.cloneDeepWithoutLoc(memberExprStart!),\n identifier: propIdentifier,\n });\n }\n\n // 替换原始的成员表达式为新的访问方式\n nodePath!.replaceWith(\n t.memberExpression(\n t.cloneWithoutLoc(id),\n t.cloneDeepWithoutLoc(propIdentifier),\n ),\n );\n });\n\n if (!memberAccessors.length) {\n return;\n }\n }\n\n // 生成选择器函数\n // 创建一个新的函数,返回包含所有访问路径的对象\n const selectorName = path.scope.generateUidIdentifier(\"selector_\");\n const selector = t.functionDeclaration(\n selectorName,\n [t.identifier(id.name)],\n t.blockStatement([\n t.returnStatement(\n t.objectExpression(\n memberAccessors.map((accessor) => {\n return t.objectProperty(accessor.identifier, accessor.node);\n }),\n ),\n ),\n ]),\n );\n path.parentPath.insertBefore(selector);\n\n // 修改原始调用为 useShallowSnapshot\n callee.property.name = \"useShallowSnapshot\";\n init.arguments = [selectorName];\n}\n\ntype MemberAccessor = {\n node: MemberExpression | OptionalMemberExpression;\n identifier: Identifier;\n};\n\n/**\n * 查找成员表达式链\n * 例如: a.b.c 会找到最后一个成员表达式 a.b.c\n *\n * @param path - 当前节点路径\n * @returns {\n * memberExprStart - 成员表达式的起始节点\n * nodePath - 当前节点路径\n * accessKey - 完整的访问路径字符串\n * }\n */\nfunction findMemberExpression(path: NodePath) {\n let current: NodePath | null = path;\n let memberExprStart: MemberAccessor[\"node\"] | undefined;\n let accessKey = \"\";\n\n while (current?.parentPath) {\n const parent = current.parentPath;\n const node = parent.node;\n\n if (\n (t.isMemberExpression(node) || t.isOptionalMemberExpression(node)) &&\n t.isIdentifier(node.property)\n ) {\n memberExprStart = node;\n current = parent;\n accessKey += \".\" + node.property.name;\n } else {\n break; // 如果不是成员表达式,立即停止向上查找\n }\n }\n\n return { memberExprStart, nodePath: current, accessKey };\n}\n","import type { NodePath } from \"@babel/traverse\";\nimport type { VariableDeclarator } from \"@babel/types\";\nimport t from \"@babel/types\";\nimport { handleSelectorArgument } from \"./shared\";\n\n/**\n * 处理 store.useSnapshot() 的变量声明\n * 示例: const { a, c: { name } } = store.useSnapshot()\n * 将会转换为:\n * function selector({ a, c: { name } } ) { return { a, c: { name } } }\n * const { a, c: { name } } = store.useShallowSnapshot(selector)\n */\nexport function handleObjectPattern(path: NodePath<VariableDeclarator>) {\n const { id, init } = path.node;\n\n // 预检查:确保是 CallExpression 且变量是 ObjectPattern\n if (!t.isCallExpression(init) || !t.isObjectPattern(id)) {\n return;\n }\n if (!t.isMemberExpression(init.callee)) {\n return;\n }\n\n // 检查是否为 store.useSnapshot 调用\n const callee = init.callee;\n if (\n !t.isIdentifier(callee.property) ||\n callee.property.name !== \"useSnapshot\"\n ) {\n return;\n }\n // 如果已经有 selector 参数,则不需要转换\n if (init.arguments.length > 0) {\n if (handleSelectorArgument(init)) {\n callee.property.name = \"useShallowSnapshot\";\n }\n return;\n }\n\n // 进入主流程\n // 进入主流程\n const selectorName = path.scope.generateUidIdentifier(\"selector_\");\n\n // 创建 selector 函数,使用相同的解构模式\n const selector = t.functionDeclaration(\n selectorName,\n [t.cloneDeepWithoutLoc(id)],\n t.blockStatement([\n t.returnStatement(\n t.objectExpression(\n id.properties.map((v) => {\n if (t.isRestElement(v)) {\n if (!t.isIdentifier(v.argument)) {\n throw path.buildCodeFrameError(\n \"Rest element in object pattern must be a simple identifier\",\n );\n }\n return t.spreadElement(t.cloneDeepWithoutLoc(v.argument));\n }\n return t.cloneDeepWithoutLoc(v);\n }),\n ),\n ),\n ]),\n );\n\n // 插入 selector 函数声明\n path.parentPath.insertBefore(selector);\n\n // 修改为使用 useShallowSnapshot 并传入选择器\n callee.property.name = \"useShallowSnapshot\";\n init.arguments = [selectorName];\n}\n","import type babel from \"@babel/core\";\nimport type { PluginObj } from \"@babel/core\";\nimport { handleIdentifierSnapshot } from \"./handleIdentifierSnapshot\";\nimport { handleObjectPattern } from \"./handleObjectPattern\";\n\nexport const createStorePlugin = (api: typeof babel): PluginObj => {\n return {\n name: \"create-store\",\n visitor: {\n VariableDeclarator(path) {\n handleIdentifierSnapshot(path);\n handleObjectPattern(path);\n },\n },\n };\n};\n"],"mappings":";;;;;;;AAOA,SAAgB,uBAAuB,MAAsB;CAC3D,MAAM,WAAW,KAAK,UAAU;AAChC,KACE,EAAE,qBAAqB,SAAS,IAChC,EAAE,0BAA0B,SAAS,EACrC;EACA,MAAM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SAAS,cAEzB;AAGF,KAAI,KAAK,UAAU,SAAS,GAAG;AAC7B,MAAI,uBAAuB,KAAK,CAC9B,QAAO,SAAS,OAAO;AAEzB;;CAKF,MAAM,eAAe,KAAK,MAAM,sBAAsB,YAAY;CAGlE,MAAM,WAAW,EAAE,oBACjB,cACA,CAAC,EAAE,oBAAoB,GAAG,CAAC,EAC3B,EAAE,eAAe,CACf,EAAE,gBACA,EAAE,iBACA,GAAG,WAAW,KAAK,MAAM;AACvB,MAAI,EAAE,cAAc,EAAE,EAAE;AACtB,OAAI,CAAC,EAAE,aAAa,EAAE,SAAS,CAC7B,OAAM,KAAK,oBACT,6DACD;AAEH,UAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,SAAS,CAAC;;AAE3D,SAAO,EAAE,oBAAoB,EAAE;GAC/B,CACH,CACF,CACF,CAAC,CACH;AAGD,MAAK,WAAW,aAAa,SAAS;AAGtC,QAAO,SAAS,OAAO;AACvB,MAAK,YAAY,CAAC,aAAa;;;;;AClEjC,MAAa,qBAAqB,QAAiC;AACjE,QAAO;EACL,MAAM;EACN,SAAS,EACP,mBAAmB,MAAM;AACvB,4BAAyB,KAAK;AAC9B,uBAAoB,KAAK;KAE5B;EACF"}
|
|
1
|
+
{"version":3,"file":"createStore.mjs","names":[],"sources":["../src/createStore/shared.ts","../src/createStore/handleIdentifierSnapshot.ts","../src/createStore/handleObjectPattern.ts","../src/createStore/index.ts"],"sourcesContent":["import type { CallExpression } from '@babel/types';\nimport t from '@babel/types';\n\n/**\n * 检查 selector 参数的返回值类型\n * 如果返回值是对象类型,则将 useSnapshot 转换为 useShallowSnapshot\n */\nexport function handleSelectorArgument(init: CallExpression) {\n const selector = init.arguments[0];\n if (\n t.isFunctionExpression(selector) ||\n t.isArrowFunctionExpression(selector)\n ) {\n const body = selector.body;\n if (t.isBlockStatement(body)) {\n const returnStmt = body.body.find((stmt) => t.isReturnStatement(stmt));\n if (\n returnStmt &&\n t.isReturnStatement(returnStmt) &&\n t.isObjectExpression(returnStmt.argument)\n ) {\n return true;\n }\n } else if (t.isObjectExpression(body)) {\n return true;\n }\n }\n return false;\n}\n","import type { NodePath } from '@babel/traverse';\nimport type {\n MemberExpression,\n OptionalMemberExpression,\n VariableDeclarator,\n} from '@babel/types';\nimport t from '@babel/types';\nimport { handleSelectorArgument } from './shared';\n/**\n * 处理 store.useSnapshot() 的变量声明\n * 示例: const state = store.useSnapshot()\n * 将会转换为:\n * function selector(state) { return { _prop: state.a.b } }\n * const state = store.useShallowSnapshot(selector)\n */\nexport function handleIdentifierSnapshot(path: NodePath<VariableDeclarator>) {\n const { id, init } = path.node;\n\n // 预检查:确保是 CallExpression 且变量是标识符\n if (!t.isCallExpression(init) || !t.isIdentifier(id)) {\n return;\n }\n if (!t.isMemberExpression(init.callee)) {\n return;\n }\n\n // 检查是否为 store.useSnapshot 调用\n const callee = init.callee;\n if (\n !t.isIdentifier(callee.property) ||\n callee.property.name !== 'useSnapshot'\n ) {\n return;\n }\n\n // 如果已经有 selector 参数,则需要检查返回值类型\n // 如果返回值是对象类型,则转换为 useShallowSnapshot\n if (init.arguments.length > 0) {\n if (handleSelectorArgument(init)) {\n callee.property.name = 'useShallowSnapshot';\n }\n return;\n }\n\n // 初始化成员访问器数组和访问器映射\n // memberAccessors 用于存储所有的成员访问表达式\n // accessorMap 用于缓存已处理过的访问路径,避免重复创建\n const memberAccessors: MemberAccessor[] = [];\n const accessorMap = new Map<string, string>();\n {\n // 获取变量的绑定信息,用于查找所有引用\n const binding = path.scope.getOwnBinding(id.name);\n\n // 存储所有有效的成员表达式访问\n const arr: ReturnType<typeof findMemberExpression>[] = [];\n\n // 第一次遍历:收集所有有效的成员表达式\n binding?.referencePaths.forEach((refPath) => {\n const { memberExprStart, nodePath, accessKey } =\n findMemberExpression(refPath);\n if (memberExprStart && nodePath && accessKey) {\n arr.push({ memberExprStart, nodePath, accessKey });\n }\n });\n\n // 如果存在无效的成员表达式访问,则不进行转换\n if (!arr.length || arr.length !== binding?.referencePaths.length) {\n return;\n }\n\n // 第二次遍历:处理每个成员表达式\n // 1. 为每个唯一的访问路径生成标识符\n // 2. 收集成员访问器信息\n // 3. 替换原始表达式为新的访问方式\n arr.forEach((item) => {\n const { memberExprStart, nodePath, accessKey } = item;\n let key = accessorMap.get(accessKey);\n if (!key) {\n // 使用访问路径作为属性名,如 'a', 'c.name'\n key = accessKey.slice(1);\n accessorMap.set(accessKey, key);\n memberAccessors.push({\n node: t.cloneDeepWithoutLoc(memberExprStart!),\n key,\n });\n }\n\n // 替换原始的成员表达式为新的访问方式\n const isComputed = key.includes('.');\n nodePath!.replaceWith(\n t.memberExpression(\n t.cloneWithoutLoc(id),\n isComputed ? t.stringLiteral(key) : t.identifier(key),\n isComputed,\n ),\n );\n });\n\n if (!memberAccessors.length) {\n return;\n }\n }\n\n // 生成选择器函数\n // 创建一个新的函数,返回包含所有访问路径的对象\n const selectorName = path.scope.generateUidIdentifier('selector_');\n const selector = t.functionDeclaration(\n selectorName,\n [t.identifier(id.name)],\n t.blockStatement([\n t.returnStatement(\n t.objectExpression(\n memberAccessors.map((accessor) => {\n const isComputed = accessor.key.includes('.');\n const propKey = isComputed\n ? t.stringLiteral(accessor.key)\n : t.identifier(accessor.key);\n return t.objectProperty(propKey, accessor.node);\n }),\n ),\n ),\n ]),\n );\n // 将 selector 函数提升到组件外部,使其更持久化\n const funcParent =\n path.findParent(\n (p) =>\n p.isFunctionDeclaration() ||\n p.isFunctionExpression() ||\n p.isArrowFunctionExpression(),\n ) ?? path.parentPath;\n funcParent.insertBefore(selector);\n\n // 修改原始调用为 useShallowSnapshot\n callee.property.name = 'useShallowSnapshot';\n init.arguments = [selectorName];\n}\n\ntype MemberAccessor = {\n node: MemberExpression | OptionalMemberExpression;\n key: string;\n};\n\n/**\n * 查找成员表达式链\n * 例如: a.b.c 会找到最后一个成员表达式 a.b.c\n *\n * @param path - 当前节点路径\n * @returns {\n * memberExprStart - 成员表达式的起始节点\n * nodePath - 当前节点路径\n * accessKey - 完整的访问路径字符串\n * }\n */\nfunction findMemberExpression(path: NodePath) {\n let current: NodePath | null = path;\n let memberExprStart: MemberAccessor['node'] | undefined;\n let accessKey = '';\n\n while (current?.parentPath) {\n const parent = current.parentPath;\n const node = parent.node;\n\n if (\n (t.isMemberExpression(node) || t.isOptionalMemberExpression(node)) &&\n t.isIdentifier(node.property)\n ) {\n // 如果该成员表达式是 CallExpression 的 callee,说明是方法调用,停止收集\n const grandParent = parent.parentPath;\n if (\n grandParent &&\n t.isCallExpression(grandParent.node) &&\n grandParent.node.callee === node\n ) {\n break;\n }\n memberExprStart = node;\n current = parent;\n accessKey += '.' + node.property.name;\n } else {\n break; // 如果不是成员表达式,立即停止向上查找\n }\n }\n\n return { memberExprStart, nodePath: current, accessKey };\n}\n","import type { NodePath } from '@babel/traverse';\nimport type { VariableDeclarator } from '@babel/types';\nimport t from '@babel/types';\nimport { handleSelectorArgument } from './shared';\n\n/**\n * 处理 store.useSnapshot() 的变量声明\n * 示例: const { a, c: { name } } = store.useSnapshot()\n * 将会转换为:\n * function selector({ a, c: { name } } ) { return { a, c: { name } } }\n * const { a, c: { name } } = store.useShallowSnapshot(selector)\n */\nexport function handleObjectPattern(path: NodePath<VariableDeclarator>) {\n const { id, init } = path.node;\n\n // 预检查:确保是 CallExpression 且变量是 ObjectPattern\n if (!t.isCallExpression(init) || !t.isObjectPattern(id)) {\n return;\n }\n if (!t.isMemberExpression(init.callee)) {\n return;\n }\n\n // 检查是否为 store.useSnapshot 调用\n const callee = init.callee;\n if (\n !t.isIdentifier(callee.property) ||\n callee.property.name !== 'useSnapshot'\n ) {\n return;\n }\n // 如果已经有 selector 参数,则不需要转换\n if (init.arguments.length > 0) {\n if (handleSelectorArgument(init)) {\n callee.property.name = 'useShallowSnapshot';\n }\n return;\n }\n\n // 进入主流程\n // 进入主流程\n const selectorName = path.scope.generateUidIdentifier('selector_');\n\n // 创建 selector 函数,使用相同的解构模式\n const selector = t.functionDeclaration(\n selectorName,\n [t.cloneDeepWithoutLoc(id)],\n t.blockStatement([\n t.returnStatement(\n t.objectExpression(\n id.properties.map((v) => {\n if (t.isRestElement(v)) {\n if (!t.isIdentifier(v.argument)) {\n throw path.buildCodeFrameError(\n 'Rest element in object pattern must be a simple identifier',\n );\n }\n return t.spreadElement(t.cloneDeepWithoutLoc(v.argument));\n }\n return t.cloneDeepWithoutLoc(v);\n }),\n ),\n ),\n ]),\n );\n\n // 将 selector 函数提升到组件外部,使其更持久化\n const funcParent =\n path.findParent(\n (p) =>\n p.isFunctionDeclaration() ||\n p.isFunctionExpression() ||\n p.isArrowFunctionExpression(),\n ) ?? path.parentPath;\n funcParent.insertBefore(selector);\n\n // 修改为使用 useShallowSnapshot 并传入选择器\n callee.property.name = 'useShallowSnapshot';\n init.arguments = [selectorName];\n}\n","import type babel from '@babel/core';\nimport type { PluginObj } from '@babel/core';\nimport { handleIdentifierSnapshot } from './handleIdentifierSnapshot';\nimport { handleObjectPattern } from './handleObjectPattern';\n\nexport const createStorePlugin = (api: typeof babel): PluginObj => {\n return {\n name: 'create-store',\n visitor: {\n VariableDeclarator(path) {\n handleIdentifierSnapshot(path);\n handleObjectPattern(path);\n },\n },\n };\n};\n"],"mappings":";;;;;;;AAOA,SAAgB,uBAAuB,MAAsB;CAC3D,MAAM,WAAW,KAAK,UAAU;AAChC,KACE,EAAE,qBAAqB,SAAS,IAChC,EAAE,0BAA0B,SAAS,EACrC;EACA,MAAM,OAAO,SAAS;AACtB,MAAI,EAAE,iBAAiB,KAAK,EAAE;GAC5B,MAAM,aAAa,KAAK,KAAK,MAAM,SAAS,EAAE,kBAAkB,KAAK,CAAC;AACtE,OACE,cACA,EAAE,kBAAkB,WAAW,IAC/B,EAAE,mBAAmB,WAAW,SAAS,CAEzC,QAAO;aAEA,EAAE,mBAAmB,KAAK,CACnC,QAAO;;AAGX,QAAO;;;;;;;;;;;;ACZT,SAAgB,yBAAyB,MAAoC;CAC3E,MAAM,EAAE,IAAI,SAAS,KAAK;AAG1B,KAAI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AAI,KAAK,UAAU,SAAS,GAAG;AAC7B,MAAI,uBAAuB,KAAK,CAC9B,QAAO,SAAS,OAAO;AAEzB;;CAKF,MAAM,eAAe,KAAK,MAAM,sBAAsB,YAAY;CAGlE,MAAM,WAAW,EAAE,oBACjB,cACA,CAAC,EAAE,oBAAoB,GAAG,CAAC,EAC3B,EAAE,eAAe,CACf,EAAE,gBACA,EAAE,iBACA,GAAG,WAAW,KAAK,MAAM;AACvB,MAAI,EAAE,cAAc,EAAE,EAAE;AACtB,OAAI,CAAC,EAAE,aAAa,EAAE,SAAS,CAC7B,OAAM,KAAK,oBACT,6DACD;AAEH,UAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,SAAS,CAAC;;AAE3D,SAAO,EAAE,oBAAoB,EAAE;GAC/B,CACH,CACF,CACF,CAAC,CACH;AAUD,EANE,KAAK,YACF,MACC,EAAE,uBAAuB,IACzB,EAAE,sBAAsB,IACxB,EAAE,2BAA2B,CAChC,IAAI,KAAK,YACD,aAAa,SAAS;AAGjC,QAAO,SAAS,OAAO;AACvB,MAAK,YAAY,CAAC,aAAa;;;;;ACzEjC,MAAa,qBAAqB,QAAiC;AACjE,QAAO;EACL,MAAM;EACN,SAAS,EACP,mBAAmB,MAAM;AACvB,4BAAyB,KAAK;AAC9B,uBAAoB,KAAK;KAE5B;EACF"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dune2/babel",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/liaoyinglong/next-tools.git",
|
|
7
7
|
"directory": "packages/babel"
|
|
8
8
|
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
9
12
|
"type": "module",
|
|
10
13
|
"exports": {
|
|
11
14
|
".": {
|
|
@@ -15,26 +18,24 @@
|
|
|
15
18
|
},
|
|
16
19
|
"./package.json": "./package.json"
|
|
17
20
|
},
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
21
24
|
"dependencies": {
|
|
22
|
-
"@babel/types": "^7"
|
|
25
|
+
"@babel/types": "^7.29.0"
|
|
23
26
|
},
|
|
24
27
|
"devDependencies": {
|
|
25
|
-
"@babel/core": "7.25.2",
|
|
26
|
-
"@babel/generator": "7.25.0",
|
|
27
|
-
"@babel/parser": "7.26.5",
|
|
28
|
-
"@babel/plugin-syntax-typescript": "^7.
|
|
29
|
-
"@babel/traverse": "7.25.3",
|
|
30
|
-
"@types/babel__core": "7.20.1",
|
|
31
|
-
"@types/babel__generator": "7.6.8",
|
|
32
|
-
"@types/babel__traverse": "7.20.6",
|
|
28
|
+
"@babel/core": "^7.25.2",
|
|
29
|
+
"@babel/generator": "^7.25.0",
|
|
30
|
+
"@babel/parser": "^7.26.5",
|
|
31
|
+
"@babel/plugin-syntax-typescript": "^7.28.6",
|
|
32
|
+
"@babel/traverse": "^7.25.3",
|
|
33
|
+
"@types/babel__core": "^7.20.1",
|
|
34
|
+
"@types/babel__generator": "^7.6.8",
|
|
35
|
+
"@types/babel__traverse": "^7.20.6",
|
|
33
36
|
"@types/debug": "4.1.7",
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
"publishConfig": {
|
|
37
|
-
"access": "public"
|
|
37
|
+
"prettier": "^3.8.1",
|
|
38
|
+
"tsdown": "^0.20.0"
|
|
38
39
|
},
|
|
39
40
|
"scripts": {
|
|
40
41
|
"prebuild": "tsc --diagnostics",
|