@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.
- package/core/util/ast.js +19 -16
- 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 =
|
|
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 (
|
|
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
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
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
|
-
|
|
316
|
-
});
|
|
319
|
+
}
|
|
317
320
|
}
|
|
318
321
|
});
|
|
319
322
|
}
|