@kezh/my-custom-js-converter 0.1.42 → 0.1.44

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.
Files changed (2) hide show
  1. package/core/util/ast.js +19 -16
  2. package/package.json +1 -1
package/core/util/ast.js CHANGED
@@ -223,7 +223,7 @@ function getInsideOwnMethodNames(srcAst, entry, methodNames, allMethodNameSet =
223
223
  return insideMethodNames;
224
224
  }
225
225
  function modifyObjectMethods(srcAst, entry, mod, methods, root = false) {
226
- const deps = [entry, ...Object.keys(mod.dependencies)];
226
+ const deps = Object.keys(mod.dependencies);
227
227
  const methodNames = getObjectMethodNames(methods);
228
228
  (0, traverse_1.default)(srcAst, {
229
229
  MemberExpression(path) {
@@ -238,11 +238,11 @@ function modifyObjectMethods(srcAst, entry, mod, methods, root = false) {
238
238
  }
239
239
  if (core_1.types.isIdentifier(path.node.object)) {
240
240
  const depName = path.node.object.name;
241
- if (deps.includes(depName)) {
241
+ if (root && depName === entry) {
242
+ path.node.object = core_1.types.thisExpression();
243
+ }
244
+ else if (deps.includes(depName)) {
242
245
  path.node.object = core_1.types.thisExpression();
243
- if (root) {
244
- return;
245
- }
246
246
  if (core_1.types.isIdentifier(path.node.property)) {
247
247
  path.node.property.name = `${path.node.property.name}__${depName}`;
248
248
  }
@@ -302,18 +302,21 @@ function deleteModMethods(srcAst, mapContext) {
302
302
  }
303
303
  });
304
304
  (0, traverse_1.default)(srcAst, {
305
- Identifier(path) {
306
- const id = path.node.name;
307
- [...deps]
308
- .filter((name) => id.lastIndexOf(`__${name}`) !== -1)
309
- .forEach((name) => {
310
- path.node.name = id.replace(`__${name}`, "");
311
- const expression = path.findParent((path) => path.isMemberExpression());
312
- if (!core_1.types.isThisExpression(expression === null || expression === void 0 ? void 0 : expression.object)) {
313
- return;
305
+ MemberExpression(path) {
306
+ if (!core_1.types.isIdentifier(path.node.property)) {
307
+ return;
308
+ }
309
+ const methodName = path.node.property.name;
310
+ const depNames = [...deps]
311
+ .filter((name) => methodName.lastIndexOf(`__${name}`) !== -1)
312
+ .map((name) => name);
313
+ if (depNames.length) {
314
+ const depName = depNames[0];
315
+ path.node.property.name = methodName.replace(`__${depName}`, "");
316
+ if (core_1.types.isThisExpression(path.node.object)) {
317
+ path.node.object = core_1.types.identifier(depName);
314
318
  }
315
- expression.object = core_1.types.identifier(name);
316
- });
319
+ }
317
320
  }
318
321
  });
319
322
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kezh/my-custom-js-converter",
3
- "version": "0.1.42",
3
+ "version": "0.1.44",
4
4
  "description": "自定义代码转换器",
5
5
  "main": "index.js",
6
6
  "bin": {