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

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 +21 -7
  2. package/package.json +1 -1
package/core/encode.js CHANGED
@@ -244,13 +244,27 @@ function getSrcMethodNames(entry, srcAst) {
244
244
  function getMethods(entry, ast) {
245
245
  const methods = [];
246
246
  (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
- }
247
+ Program(path) {
248
+ path.node.body.forEach((statement) => {
249
+ if (core_1.types.isVariableDeclaration(statement)) {
250
+ const variableDeclaration = statement;
251
+ variableDeclaration.declarations.filter((declaration) => {
252
+ if (core_1.types.isIdentifier(declaration.id)) {
253
+ const id = declaration.id;
254
+ if (id.name === entry) {
255
+ return true;
256
+ }
257
+ }
258
+ return false;
259
+ }).forEach((declaration) => {
260
+ if (core_1.types.isObjectExpression(declaration.init)) {
261
+ const init = declaration.init;
262
+ const objectMethods = init.properties.filter(property => core_1.types.isObjectMethod(property));
263
+ methods.push(...objectMethods);
264
+ }
265
+ });
266
+ }
267
+ });
254
268
  }
255
269
  });
256
270
  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.19",
4
4
  "description": "自定义代码转换器",
5
5
  "main": "index.js",
6
6
  "bin": {