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