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

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 +22 -7
  2. package/package.json +1 -1
package/core/encode.js CHANGED
@@ -108,6 +108,7 @@ function getImportMethods(modPathByName, methodNamesByMod) {
108
108
  ...new Set([...useMethodNames, ...inlineMethodNames])
109
109
  ];
110
110
  modifyModMethods(name, mergeMethodNames, modAst);
111
+ console.log((0, generator_1.default)(modAst).code);
111
112
  mergeMethodNames = mergeMethodNames.map((m) => `${m}__${name}`);
112
113
  const mergeMethods = mergeMethodNames
113
114
  .map((name) => {
@@ -244,13 +245,27 @@ function getSrcMethodNames(entry, srcAst) {
244
245
  function getMethods(entry, ast) {
245
246
  const methods = [];
246
247
  (0, traverse_1.default)(ast, {
247
- Identifier(path) {
248
- if (path.node.name === entry) {
249
- const declarator = path.findParent((path) => path.isVariableDeclarator());
250
- const methodBody = declarator === null || declarator === void 0 ? void 0 : declarator.node.init;
251
- const inlineMethods = methodBody === null || methodBody === void 0 ? void 0 : methodBody.properties;
252
- (inlineMethods === null || inlineMethods === void 0 ? void 0 : inlineMethods.length) && methods.push(...inlineMethods);
253
- }
248
+ Program(path) {
249
+ path.node.body.forEach((statement) => {
250
+ if (core_1.types.isVariableDeclaration(statement)) {
251
+ const variableDeclaration = statement;
252
+ variableDeclaration.declarations.filter((declaration) => {
253
+ if (core_1.types.isIdentifier(declaration.id)) {
254
+ const id = declaration.id;
255
+ if (id.name === entry) {
256
+ return true;
257
+ }
258
+ }
259
+ return false;
260
+ }).forEach((declaration) => {
261
+ if (core_1.types.isObjectExpression(declaration.init)) {
262
+ const init = declaration.init;
263
+ const objectMethods = init.properties.filter(property => core_1.types.isObjectMethod(property));
264
+ methods.push(...objectMethods);
265
+ }
266
+ });
267
+ }
268
+ });
254
269
  }
255
270
  });
256
271
  return methods;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kezh/my-custom-js-converter",
3
- "version": "0.0.18",
3
+ "version": "0.0.20",
4
4
  "description": "自定义代码转换器",
5
5
  "main": "index.js",
6
6
  "bin": {