@kezh/my-custom-js-converter 0.1.55 → 0.1.58

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.
@@ -36,14 +36,14 @@ function decoding$0(inPath, outPath, config) {
36
36
  let src = fs_1.default.readFileSync(inPath, {
37
37
  encoding: "utf-8"
38
38
  });
39
- src = `const ${config.decode.mount} = {${src}};\r\nmodule.exports = customEvent;`;
39
+ src = `const ${config.decode.mount} = {${src}};\r\nmodule.exports = ${config.decode.mount};`;
40
40
  const srcAst = (0, parser_1.parse)(src);
41
41
  if (!core_1.types.isNode(srcAst)) {
42
42
  return;
43
43
  }
44
44
  (0, ast_1.importMods)(path_1.default.dirname(outPath), srcAst, mapContext);
45
45
  (0, ast_1.deleteModMethods)(srcAst, mapContext);
46
- let { code: dist } = (0, generator_1.default)(srcAst);
46
+ let { code: dist } = (0, generator_1.default)(srcAst, { compact: true });
47
47
  dist = dist.replace(/},\n\n/g, "},\n");
48
48
  dist = prettier_1.default.format(dist, {
49
49
  parser: "babel",
package/core/util/ast.js CHANGED
@@ -302,7 +302,7 @@ function importMods(outDir, srcAst, mapContext) {
302
302
  const depNames = mapContext.getDependencyNameByMod("self");
303
303
  const importMods = depNames.map(name => {
304
304
  const srcPath = mapContext.getSrcPathByMod(name);
305
- const requireFrom = (0, path_1.relative)(outDir, srcPath.replace(/index\.js$/, "")).replace(/[\\]+/g, "/");
305
+ const requireFrom = (0, path_1.relative)(outDir, srcPath.replace(/(index)?\.js$/, "")).replace(/[\\]+/g, "/");
306
306
  const variableDeclarator = core_1.types.variableDeclarator(core_1.types.identifier(name), core_1.types.callExpression(core_1.types.identifier("require"), [
307
307
  core_1.types.stringLiteral(requireFrom)
308
308
  ]));
@@ -343,7 +343,10 @@ function deleteModMethods(srcAst, mapContext) {
343
343
  }
344
344
  const methodName = path.node.property.name;
345
345
  const split = methodName.split("__");
346
- const depName = split.length ? split[split.length - 1] : "";
346
+ if (split.length > 1) {
347
+ return;
348
+ }
349
+ const depName = split[split.length - 1];
347
350
  if (deps.has(depName)) {
348
351
  path.node.property.name = methodName.replace(`__${depName}`, "");
349
352
  if (core_1.types.isThisExpression(path.node.object)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kezh/my-custom-js-converter",
3
- "version": "0.1.55",
3
+ "version": "0.1.58",
4
4
  "description": "自定义代码转换器",
5
5
  "main": "index.js",
6
6
  "bin": {