@kezh/my-custom-js-converter 0.0.20 → 0.0.22

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/encode.js +17 -26
  2. package/package.json +1 -1
package/core/encode.js CHANGED
@@ -109,7 +109,6 @@ function getImportMethods(modPathByName, methodNamesByMod) {
109
109
  ];
110
110
  modifyModMethods(name, mergeMethodNames, modAst);
111
111
  console.log((0, generator_1.default)(modAst).code);
112
- mergeMethodNames = mergeMethodNames.map((m) => `${m}__${name}`);
113
112
  const mergeMethods = mergeMethodNames
114
113
  .map((name) => {
115
114
  return modMethods.find((m) => core_1.types.isIdentifier(m.key) && m.key.name === name);
@@ -118,6 +117,10 @@ function getImportMethods(modPathByName, methodNamesByMod) {
118
117
  console.log(`inline methods size => ${inlineMethodNames.length}`);
119
118
  console.log(`import methods size => ${mergeMethods.length}`);
120
119
  return mergeMethods.map((m) => {
120
+ if (core_1.types.isIdentifier(m.key)) {
121
+ const key = m.key;
122
+ key.name = `${key.name}__${name}`;
123
+ }
121
124
  m.body = core_1.types.addComment(m.body, "inner", "auto-generated: Please do not modify the.");
122
125
  return m;
123
126
  });
@@ -249,7 +252,8 @@ function getMethods(entry, ast) {
249
252
  path.node.body.forEach((statement) => {
250
253
  if (core_1.types.isVariableDeclaration(statement)) {
251
254
  const variableDeclaration = statement;
252
- variableDeclaration.declarations.filter((declaration) => {
255
+ variableDeclaration.declarations
256
+ .filter((declaration) => {
253
257
  if (core_1.types.isIdentifier(declaration.id)) {
254
258
  const id = declaration.id;
255
259
  if (id.name === entry) {
@@ -257,10 +261,11 @@ function getMethods(entry, ast) {
257
261
  }
258
262
  }
259
263
  return false;
260
- }).forEach((declaration) => {
264
+ })
265
+ .forEach((declaration) => {
261
266
  if (core_1.types.isObjectExpression(declaration.init)) {
262
267
  const init = declaration.init;
263
- const objectMethods = init.properties.filter(property => core_1.types.isObjectMethod(property));
268
+ const objectMethods = init.properties.filter((property) => core_1.types.isObjectMethod(property));
264
269
  methods.push(...objectMethods);
265
270
  }
266
271
  });
@@ -316,29 +321,15 @@ function modifyCallObjectAndMethodNames(methodNames, importMod, srcAst) {
316
321
  function modifyModMethods(mod, methodNames, modAst) {
317
322
  (0, traverse_1.default)(modAst, {
318
323
  MemberExpression(path) {
319
- const objectMethod = path.findParent((path) => path.isObjectMethod());
320
- if (!core_1.types.isIdentifier(objectMethod === null || objectMethod === void 0 ? void 0 : objectMethod.node.key)) {
321
- return;
322
- }
323
- if (!methodNames.includes((objectMethod === null || objectMethod === void 0 ? void 0 : objectMethod.node.key).name)) {
324
- return;
325
- }
326
- const key = objectMethod === null || objectMethod === void 0 ? void 0 : objectMethod.node.key;
327
- key.name =
328
- key.name.lastIndexOf(`__${mod}`) === -1
329
- ? `${key.name}__${mod}`
330
- : key.name;
331
- if (!core_1.types.isThisExpression(path.node.object)) {
332
- return;
333
- }
334
- if (!core_1.types.isIdentifier(path.node.property)) {
335
- return;
336
- }
337
- const property = path.node.property;
338
- if (!methodNames.includes(property.name)) {
339
- return;
324
+ if (core_1.types.isIdentifier(path.node.property)) {
325
+ const property = path.node.property;
326
+ if (methodNames.includes(property.name)) {
327
+ if (core_1.types.isIdentifier(path.node) ||
328
+ core_1.types.isThisExpression(path.node)) {
329
+ property.name = `${property.name}__${mod}`;
330
+ }
331
+ }
340
332
  }
341
- property.name = `${property.name}__${mod}`;
342
333
  }
343
334
  });
344
335
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kezh/my-custom-js-converter",
3
- "version": "0.0.20",
3
+ "version": "0.0.22",
4
4
  "description": "自定义代码转换器",
5
5
  "main": "index.js",
6
6
  "bin": {