@suseejs/duplicates 0.1.2 → 0.1.3
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/dist/index.cjs +213 -340
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -4
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +4 -3
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +167 -291
- package/dist/index.mjs.map +1 -1
- package/package.json +63 -62
package/dist/index.mjs
CHANGED
|
@@ -1,60 +1,22 @@
|
|
|
1
1
|
// cSpell:disable
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
2
|
import path from "node:path";
|
|
39
3
|
import resolves from "@phothinmaung/resolves";
|
|
40
4
|
import transformFunction from "@suseejs/transformer";
|
|
5
|
+
import utilities from "@suseejs/utils";
|
|
41
6
|
import ts from "typescript";
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
var key = _a.key, value = _a.value;
|
|
54
|
-
var names = [];
|
|
55
|
-
var _fix;
|
|
7
|
+
// construct maps
|
|
8
|
+
const namesMap = new Map();
|
|
9
|
+
const callNameMap = [];
|
|
10
|
+
const importNameMap = [];
|
|
11
|
+
const exportNameMap = [];
|
|
12
|
+
function __uniqueName() {
|
|
13
|
+
const storedPrefix = new Map();
|
|
14
|
+
const obj = {
|
|
15
|
+
setPrefix({ key, value }) {
|
|
16
|
+
const names = [];
|
|
17
|
+
let _fix;
|
|
56
18
|
if (storedPrefix.has(key)) {
|
|
57
|
-
console.warn(
|
|
19
|
+
console.warn(`${key} already exist`);
|
|
58
20
|
throw new Error();
|
|
59
21
|
}
|
|
60
22
|
else {
|
|
@@ -62,16 +24,16 @@ function uniqueName() {
|
|
|
62
24
|
storedPrefix.set(key, value);
|
|
63
25
|
}
|
|
64
26
|
function getName(input) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
?
|
|
68
|
-
:
|
|
27
|
+
const length = names.length;
|
|
28
|
+
const _name = _fix
|
|
29
|
+
? `${_fix}${input}_${length + 1}`
|
|
30
|
+
: `$nyein${input}_${length + 1}`;
|
|
69
31
|
names.push(_name);
|
|
70
32
|
return _name;
|
|
71
33
|
}
|
|
72
|
-
return { getName
|
|
34
|
+
return { getName };
|
|
73
35
|
},
|
|
74
|
-
getPrefix
|
|
36
|
+
getPrefix(key) {
|
|
75
37
|
if (storedPrefix.has(key)) {
|
|
76
38
|
return storedPrefix.get(key);
|
|
77
39
|
}
|
|
@@ -79,21 +41,21 @@ function uniqueName() {
|
|
|
79
41
|
};
|
|
80
42
|
return obj;
|
|
81
43
|
}
|
|
82
|
-
|
|
44
|
+
const dupName = __uniqueName().setPrefix({
|
|
83
45
|
key: "DuplicatesNames",
|
|
84
|
-
value: "
|
|
46
|
+
value: "__duplicatesNames__",
|
|
85
47
|
});
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
48
|
+
const normalizePathKey = (filePath) => {
|
|
49
|
+
const parsed = path.parse(filePath);
|
|
50
|
+
let noExt = path.join(parsed.dir, parsed.name);
|
|
89
51
|
if (parsed.name === "index") {
|
|
90
52
|
noExt = parsed.dir;
|
|
91
53
|
}
|
|
92
54
|
return path.normalize(noExt);
|
|
93
55
|
};
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
56
|
+
const getFileKey = (filePath) => normalizePathKey(filePath);
|
|
57
|
+
const getModuleKeyFromSpecifier = (moduleSpecifier, sourceFile, containingFile) => {
|
|
58
|
+
let spec = "";
|
|
97
59
|
if (ts.isStringLiteral(moduleSpecifier)) {
|
|
98
60
|
spec = moduleSpecifier.text;
|
|
99
61
|
}
|
|
@@ -101,31 +63,23 @@ var getModuleKeyFromSpecifier = function (moduleSpecifier, sourceFile, containin
|
|
|
101
63
|
spec = moduleSpecifier.getText(sourceFile).replace(/^['"]|['"]$/g, "");
|
|
102
64
|
}
|
|
103
65
|
if (spec.startsWith(".") || spec.startsWith("/")) {
|
|
104
|
-
|
|
66
|
+
const baseDir = path.dirname(containingFile);
|
|
105
67
|
return normalizePathKey(path.resolve(baseDir, spec));
|
|
106
68
|
}
|
|
107
69
|
return spec;
|
|
108
70
|
};
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
*/
|
|
116
|
-
var callExpression = function (callNameMap, importNameMap, compilerOptions) {
|
|
117
|
-
return function (_a) {
|
|
118
|
-
var file = _a.file, content = _a.content;
|
|
119
|
-
var sourceFile = ts.createSourceFile(file, content, ts.ScriptTarget.Latest, true);
|
|
120
|
-
var transformer = function (context) {
|
|
121
|
-
var factory = context.factory;
|
|
122
|
-
var visitor = function (node) {
|
|
71
|
+
const callExpression = (compilerOptions) => {
|
|
72
|
+
return ({ file, content, ...rest }) => {
|
|
73
|
+
const sourceFile = ts.createSourceFile(file, content, ts.ScriptTarget.Latest, true);
|
|
74
|
+
const transformer = (context) => {
|
|
75
|
+
const { factory } = context;
|
|
76
|
+
const visitor = (node) => {
|
|
123
77
|
if (ts.isCallExpression(node)) {
|
|
124
78
|
if (ts.isIdentifier(node.expression)) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
79
|
+
const base = node.expression.text;
|
|
80
|
+
let new_name = null;
|
|
81
|
+
const mapping = callNameMap.find((m) => m.base === base && m.file === file);
|
|
82
|
+
const importMapping = importNameMap.find((m) => m.base === base && m.file === file);
|
|
129
83
|
if (mapping) {
|
|
130
84
|
new_name = mapping.newName;
|
|
131
85
|
}
|
|
@@ -140,10 +94,10 @@ var callExpression = function (callNameMap, importNameMap, compilerOptions) {
|
|
|
140
94
|
}
|
|
141
95
|
else if (ts.isPropertyAccessExpression(node)) {
|
|
142
96
|
if (ts.isIdentifier(node.expression)) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
97
|
+
const base = node.expression.text;
|
|
98
|
+
let new_name = null;
|
|
99
|
+
const mapping = callNameMap.find((m) => m.base === base && m.file === file);
|
|
100
|
+
const importMapping = importNameMap.find((m) => m.base === base && m.file === file);
|
|
147
101
|
if (mapping) {
|
|
148
102
|
new_name = mapping.newName;
|
|
149
103
|
}
|
|
@@ -157,10 +111,10 @@ var callExpression = function (callNameMap, importNameMap, compilerOptions) {
|
|
|
157
111
|
}
|
|
158
112
|
else if (ts.isNewExpression(node)) {
|
|
159
113
|
if (ts.isIdentifier(node.expression)) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
114
|
+
const base = node.expression.text;
|
|
115
|
+
let new_name = null;
|
|
116
|
+
const mapping = callNameMap.find((m) => m.base === base && m.file === file);
|
|
117
|
+
const importMapping = importNameMap.find((m) => m.base === base && m.file === file);
|
|
164
118
|
if (mapping) {
|
|
165
119
|
new_name = mapping.newName;
|
|
166
120
|
}
|
|
@@ -176,39 +130,28 @@ var callExpression = function (callNameMap, importNameMap, compilerOptions) {
|
|
|
176
130
|
return ts.visitEachChild(node, visitor, context);
|
|
177
131
|
}; // visitor;
|
|
178
132
|
/* --------------------Returns for transformer function--------------------------------- */
|
|
179
|
-
return
|
|
133
|
+
return (rootNode) => ts.visitNode(rootNode, visitor);
|
|
180
134
|
}; // transformer;
|
|
181
135
|
/* --------------------Returns for main handler function--------------------------------- */
|
|
182
|
-
|
|
183
|
-
return { file
|
|
136
|
+
const _content = transformFunction(transformer, sourceFile, compilerOptions);
|
|
137
|
+
return { file, content: _content, ...rest };
|
|
184
138
|
}; // returns
|
|
185
139
|
};
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
* @param exportNameMap - A map of base names to new names for export expressions.
|
|
193
|
-
* @param compilerOptions - The options for the TypeScript compiler.
|
|
194
|
-
* @returns A bundle handler that takes a source file and returns a new source file with the renamed exported expressions.
|
|
195
|
-
*/
|
|
196
|
-
var exportExpression = function (callNameMap, importNameMap, exportNameMap, compilerOptions) {
|
|
197
|
-
return function (_a) {
|
|
198
|
-
var file = _a.file, content = _a.content;
|
|
199
|
-
var sourceFile = ts.createSourceFile(file, content, ts.ScriptTarget.Latest, true);
|
|
200
|
-
var transformer = function (context) {
|
|
201
|
-
var factory = context.factory;
|
|
202
|
-
var visitor = function (node) {
|
|
140
|
+
const exportExpression = (compilerOptions) => {
|
|
141
|
+
return ({ file, content, ...rest }) => {
|
|
142
|
+
const sourceFile = ts.createSourceFile(file, content, ts.ScriptTarget.Latest, true);
|
|
143
|
+
const transformer = (context) => {
|
|
144
|
+
const { factory } = context;
|
|
145
|
+
const visitor = (node) => {
|
|
203
146
|
if (ts.isExportSpecifier(node)) {
|
|
204
147
|
if (ts.isIdentifier(node.name)) {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
148
|
+
const base = node.name.text;
|
|
149
|
+
let new_name = null;
|
|
150
|
+
const mapping = callNameMap.find((m) => m.base === base && m.file === file);
|
|
151
|
+
const importMapping = importNameMap.find((m) => m.base === base && m.file === file);
|
|
209
152
|
if (mapping) {
|
|
210
153
|
exportNameMap.push({
|
|
211
|
-
base
|
|
154
|
+
base,
|
|
212
155
|
file: getFileKey(file),
|
|
213
156
|
newName: mapping.newName,
|
|
214
157
|
});
|
|
@@ -223,15 +166,15 @@ var exportExpression = function (callNameMap, importNameMap, exportNameMap, comp
|
|
|
223
166
|
}
|
|
224
167
|
}
|
|
225
168
|
else if (ts.isExportAssignment(node)) {
|
|
226
|
-
|
|
169
|
+
const expr = node.expression;
|
|
227
170
|
if (ts.isIdentifier(expr)) {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
171
|
+
const base = expr.text;
|
|
172
|
+
let new_name = null;
|
|
173
|
+
const mapping = callNameMap.find((m) => m.base === base && m.file === file);
|
|
174
|
+
const importMapping = importNameMap.find((m) => m.base === base && m.file === file);
|
|
232
175
|
if (mapping) {
|
|
233
176
|
exportNameMap.push({
|
|
234
|
-
base
|
|
177
|
+
base,
|
|
235
178
|
file: getFileKey(file),
|
|
236
179
|
newName: mapping.newName,
|
|
237
180
|
});
|
|
@@ -249,49 +192,38 @@ var exportExpression = function (callNameMap, importNameMap, exportNameMap, comp
|
|
|
249
192
|
return ts.visitEachChild(node, visitor, context);
|
|
250
193
|
}; // visitor;
|
|
251
194
|
/* --------------------Returns for transformer function--------------------------------- */
|
|
252
|
-
return
|
|
195
|
+
return (rootNode) => ts.visitNode(rootNode, visitor);
|
|
253
196
|
}; // transformer;
|
|
254
197
|
/* --------------------Returns for main handler function--------------------------------- */
|
|
255
|
-
|
|
256
|
-
return { file
|
|
198
|
+
const _content = transformFunction(transformer, sourceFile, compilerOptions);
|
|
199
|
+
return { file, content: _content, ...rest };
|
|
257
200
|
}; // returns
|
|
258
201
|
};
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
*/
|
|
266
|
-
var importExpression = function (exportNameMap, importNameMap, compilerOptions) {
|
|
267
|
-
return function (_a) {
|
|
268
|
-
var file = _a.file, content = _a.content;
|
|
269
|
-
var sourceFile = ts.createSourceFile(file, content, ts.ScriptTarget.Latest, true);
|
|
270
|
-
var transformer = function (context) {
|
|
271
|
-
var factory = context.factory;
|
|
272
|
-
var visitor = function (node) {
|
|
273
|
-
var _a, _b;
|
|
202
|
+
const importExpression = (compilerOptions) => {
|
|
203
|
+
return ({ file, content, ...rest }) => {
|
|
204
|
+
const sourceFile = ts.createSourceFile(file, content, ts.ScriptTarget.Latest, true);
|
|
205
|
+
const transformer = (context) => {
|
|
206
|
+
const { factory } = context;
|
|
207
|
+
const visitor = (node) => {
|
|
274
208
|
if (ts.isImportDeclaration(node)) {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
if (
|
|
209
|
+
const moduleKey = getModuleKeyFromSpecifier(node.moduleSpecifier, sourceFile, file);
|
|
210
|
+
let baseNames = [];
|
|
211
|
+
if (node.importClause?.namedBindings &&
|
|
278
212
|
ts.isNamedImports(node.importClause.namedBindings)) {
|
|
279
|
-
baseNames = node.importClause.namedBindings.elements.map(
|
|
280
|
-
return el.name.text.trim();
|
|
281
|
-
});
|
|
213
|
+
baseNames = node.importClause.namedBindings.elements.map((el) => el.name.text.trim());
|
|
282
214
|
}
|
|
283
215
|
// import default expression
|
|
284
|
-
if (
|
|
216
|
+
if (node.importClause?.name &&
|
|
285
217
|
ts.isIdentifier(node.importClause.name)) {
|
|
286
|
-
|
|
287
|
-
|
|
218
|
+
const base = node.importClause.name.text.trim();
|
|
219
|
+
const mapping = exportNameMap.find((m) => m.base === base && m.file === moduleKey);
|
|
288
220
|
if (mapping) {
|
|
289
221
|
importNameMap.push({
|
|
290
222
|
base: mapping.base,
|
|
291
|
-
file
|
|
223
|
+
file,
|
|
292
224
|
newName: mapping.newName,
|
|
293
225
|
});
|
|
294
|
-
|
|
226
|
+
const newImportClause = factory.updateImportClause(node.importClause, node.importClause.phaseModifier, factory.createIdentifier(mapping.newName), node.importClause.namedBindings);
|
|
295
227
|
return factory.updateImportDeclaration(node, node.modifiers, newImportClause, node.moduleSpecifier, node.attributes);
|
|
296
228
|
}
|
|
297
229
|
}
|
|
@@ -300,20 +232,20 @@ var importExpression = function (exportNameMap, importNameMap, compilerOptions)
|
|
|
300
232
|
node.importClause &&
|
|
301
233
|
node.importClause.namedBindings &&
|
|
302
234
|
ts.isNamedImports(node.importClause.namedBindings)) {
|
|
303
|
-
|
|
304
|
-
|
|
235
|
+
const updatedElements = node.importClause.namedBindings.elements.map((el) => {
|
|
236
|
+
const mapping = exportNameMap.find((m) => m.base === el.name.text.trim() && m.file === moduleKey);
|
|
305
237
|
if (mapping) {
|
|
306
238
|
importNameMap.push({
|
|
307
239
|
base: mapping.base,
|
|
308
|
-
file
|
|
240
|
+
file,
|
|
309
241
|
newName: mapping.newName,
|
|
310
242
|
});
|
|
311
243
|
return factory.updateImportSpecifier(el, el.isTypeOnly, el.propertyName, factory.createIdentifier(mapping.newName));
|
|
312
244
|
}
|
|
313
245
|
return el;
|
|
314
246
|
});
|
|
315
|
-
|
|
316
|
-
|
|
247
|
+
const newNamedImports = factory.updateNamedImports(node.importClause.namedBindings, updatedElements);
|
|
248
|
+
const newImportClause = factory.updateImportClause(node.importClause, node.importClause.phaseModifier, node.importClause.name, newNamedImports);
|
|
317
249
|
return factory.updateImportDeclaration(node, node.modifiers, newImportClause, node.moduleSpecifier, node.attributes);
|
|
318
250
|
}
|
|
319
251
|
} //&&
|
|
@@ -321,42 +253,31 @@ var importExpression = function (exportNameMap, importNameMap, compilerOptions)
|
|
|
321
253
|
return ts.visitEachChild(node, visitor, context);
|
|
322
254
|
}; // visitor;
|
|
323
255
|
/* --------------------Returns for transformer function--------------------------------- */
|
|
324
|
-
return
|
|
256
|
+
return (rootNode) => ts.visitNode(rootNode, visitor);
|
|
325
257
|
}; // transformer;
|
|
326
258
|
/* --------------------Returns for main handler function--------------------------------- */
|
|
327
|
-
|
|
328
|
-
return { file
|
|
259
|
+
const _content = transformFunction(transformer, sourceFile, compilerOptions);
|
|
260
|
+
return { file, content: _content, ...rest };
|
|
329
261
|
}; // returns
|
|
330
262
|
};
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
* @param compilerOptions - The options for the TypeScript compiler.
|
|
337
|
-
* @return A new source file with collected information.
|
|
338
|
-
*/
|
|
339
|
-
var collector = function (namesMap, compilerOptions) {
|
|
340
|
-
return function (_a) {
|
|
341
|
-
var file = _a.file, content = _a.content;
|
|
342
|
-
var sourceFile = ts.createSourceFile(file, content, ts.ScriptTarget.Latest, true);
|
|
343
|
-
var transformer = function (context) {
|
|
344
|
-
function visitNode(node, isGlobalScope) {
|
|
345
|
-
var _a;
|
|
346
|
-
if (isGlobalScope === void 0) { isGlobalScope = true; }
|
|
263
|
+
const collector = (compilerOptions) => {
|
|
264
|
+
return ({ file, content, ...rest }) => {
|
|
265
|
+
const sourceFile = ts.createSourceFile(file, content, ts.ScriptTarget.Latest, true);
|
|
266
|
+
const transformer = (context) => {
|
|
267
|
+
function visitNode(node, isGlobalScope = true) {
|
|
347
268
|
// Global declarations များကိုသာ collect လုပ်မယ်
|
|
348
269
|
if (isGlobalScope) {
|
|
349
270
|
// Variable statements (const, let, var)
|
|
350
271
|
if (ts.isVariableStatement(node)) {
|
|
351
|
-
node.declarationList.declarations.forEach(
|
|
272
|
+
node.declarationList.declarations.forEach((decl) => {
|
|
352
273
|
if (ts.isIdentifier(decl.name)) {
|
|
353
|
-
|
|
274
|
+
const $name = decl.name.text;
|
|
354
275
|
if (!namesMap.has($name)) {
|
|
355
|
-
namesMap.set($name, new Set([{ file
|
|
276
|
+
namesMap.set($name, new Set([{ file }]));
|
|
356
277
|
}
|
|
357
278
|
else {
|
|
358
279
|
// biome-ignore lint/style/noNonNullAssertion : !namesMap.has($name) before
|
|
359
|
-
namesMap.get($name).add({ file
|
|
280
|
+
namesMap.get($name).add({ file });
|
|
360
281
|
}
|
|
361
282
|
}
|
|
362
283
|
});
|
|
@@ -367,14 +288,14 @@ var collector = function (namesMap, compilerOptions) {
|
|
|
367
288
|
ts.isEnumDeclaration(node) ||
|
|
368
289
|
ts.isInterfaceDeclaration(node) ||
|
|
369
290
|
ts.isTypeAliasDeclaration(node)) {
|
|
370
|
-
|
|
291
|
+
const $name = node.name?.text;
|
|
371
292
|
if ($name) {
|
|
372
293
|
if (!namesMap.has($name)) {
|
|
373
|
-
namesMap.set($name, new Set([{ file
|
|
294
|
+
namesMap.set($name, new Set([{ file }]));
|
|
374
295
|
}
|
|
375
296
|
else {
|
|
376
297
|
// biome-ignore lint/style/noNonNullAssertion : !namesMap.has($name) before
|
|
377
|
-
namesMap.get($name).add({ file
|
|
298
|
+
namesMap.get($name).add({ file });
|
|
378
299
|
}
|
|
379
300
|
}
|
|
380
301
|
}
|
|
@@ -388,79 +309,69 @@ var collector = function (namesMap, compilerOptions) {
|
|
|
388
309
|
ts.isClassDeclaration(node)) {
|
|
389
310
|
// Local scope ထဲကို ဝင်သွားပြီဆိုတာနဲ့ isGlobalScope = false
|
|
390
311
|
if (ts.isBlock(node)) {
|
|
391
|
-
ts.visitNodes(node.statements,
|
|
312
|
+
ts.visitNodes(node.statements, (child) => visitNode(child, false));
|
|
392
313
|
}
|
|
393
314
|
else {
|
|
394
|
-
ts.forEachChild(node,
|
|
315
|
+
ts.forEachChild(node, (child) => {
|
|
395
316
|
visitNode(child, false);
|
|
396
317
|
});
|
|
397
318
|
}
|
|
398
319
|
}
|
|
399
320
|
else {
|
|
400
321
|
// Global scope ထဲဆက်ရှိနေတဲ့ node တွေအတွက်
|
|
401
|
-
return ts.visitEachChild(node,
|
|
322
|
+
return ts.visitEachChild(node, (child) => visitNode(child, isGlobalScope), context);
|
|
402
323
|
}
|
|
403
324
|
/* ----------------------Returns for visitNode function------------------------------- */
|
|
404
325
|
return node;
|
|
405
326
|
} // visitNode
|
|
406
327
|
/* --------------------Returns for transformer function--------------------------------- */
|
|
407
|
-
return
|
|
328
|
+
return (rootNode) => visitNode(rootNode, true);
|
|
408
329
|
}; // transformer;
|
|
409
330
|
/* --------------------Returns for main handler function--------------------------------- */
|
|
410
|
-
|
|
411
|
-
return { file
|
|
331
|
+
const _content = transformFunction(transformer, sourceFile, compilerOptions);
|
|
332
|
+
return { file, content: _content, ...rest };
|
|
412
333
|
}; // returns
|
|
413
334
|
};
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
* @param compilerOptions - The options for the TypeScript compiler.
|
|
421
|
-
* @returns A new source file with updated names.
|
|
422
|
-
*/
|
|
423
|
-
var updater = function (namesMap, callNameMap, compilerOptions) {
|
|
424
|
-
return function (_a) {
|
|
425
|
-
var file = _a.file, content = _a.content;
|
|
426
|
-
var sourceFile = ts.createSourceFile(file, content, ts.ScriptTarget.Latest, true);
|
|
427
|
-
var transformer = function (context) {
|
|
428
|
-
var factory = context.factory;
|
|
429
|
-
var visitor = function (node) {
|
|
335
|
+
const updater = (compilerOptions) => {
|
|
336
|
+
return ({ file, content, ...rest }) => {
|
|
337
|
+
const sourceFile = ts.createSourceFile(file, content, ts.ScriptTarget.Latest, true);
|
|
338
|
+
const transformer = (context) => {
|
|
339
|
+
const { factory } = context;
|
|
340
|
+
const visitor = (node) => {
|
|
430
341
|
if (ts.isVariableStatement(node)) {
|
|
431
|
-
|
|
342
|
+
const newDeclarations = node.declarationList.declarations.map((decl) => {
|
|
432
343
|
if (ts.isIdentifier(decl.name)) {
|
|
433
|
-
|
|
344
|
+
const base = decl.name.text;
|
|
434
345
|
// biome-ignore lint/style/noNonNullAssertion : namesMap.has(base) before that get just only size
|
|
435
346
|
if (namesMap.has(base) && namesMap.get(base).size > 1) {
|
|
436
|
-
|
|
437
|
-
callNameMap.push({ base
|
|
347
|
+
const newName = dupName.getName(base);
|
|
348
|
+
callNameMap.push({ base, file, newName });
|
|
438
349
|
return factory.updateVariableDeclaration(decl, factory.createIdentifier(newName), decl.exclamationToken, decl.type, decl.initializer);
|
|
439
350
|
}
|
|
440
351
|
}
|
|
441
352
|
return decl;
|
|
442
353
|
});
|
|
443
|
-
|
|
354
|
+
const newDeclList = factory.updateVariableDeclarationList(node.declarationList, newDeclarations);
|
|
444
355
|
return factory.updateVariableStatement(node, node.modifiers, newDeclList);
|
|
445
356
|
}
|
|
446
357
|
else if (ts.isFunctionDeclaration(node)) {
|
|
447
358
|
if (node.name && ts.isIdentifier(node.name)) {
|
|
448
|
-
|
|
359
|
+
const base = node.name.text;
|
|
449
360
|
// biome-ignore lint/style/noNonNullAssertion : namesMap.has(base) before that get just only size
|
|
450
361
|
if (namesMap.has(base) && namesMap.get(base).size > 1) {
|
|
451
|
-
|
|
452
|
-
callNameMap.push({ base
|
|
362
|
+
const newName = dupName.getName(base);
|
|
363
|
+
callNameMap.push({ base, file, newName });
|
|
453
364
|
return factory.updateFunctionDeclaration(node, node.modifiers, node.asteriskToken, factory.createIdentifier(newName), node.typeParameters, node.parameters, node.type, node.body);
|
|
454
365
|
}
|
|
455
366
|
}
|
|
456
367
|
}
|
|
457
368
|
else if (ts.isClassDeclaration(node)) {
|
|
458
369
|
if (node.name && ts.isIdentifier(node.name)) {
|
|
459
|
-
|
|
370
|
+
const base = node.name.text;
|
|
460
371
|
// biome-ignore lint/style/noNonNullAssertion : namesMap.has(base) before that get just only size
|
|
461
372
|
if (namesMap.has(base) && namesMap.get(base).size > 1) {
|
|
462
|
-
|
|
463
|
-
callNameMap.push({ base
|
|
373
|
+
const newName = dupName.getName(base);
|
|
374
|
+
callNameMap.push({ base, file, newName });
|
|
464
375
|
return factory.updateClassDeclaration(node, node.modifiers, factory.createIdentifier(newName), node.typeParameters, node.heritageClauses, node.members);
|
|
465
376
|
}
|
|
466
377
|
}
|
|
@@ -469,17 +380,14 @@ var updater = function (namesMap, callNameMap, compilerOptions) {
|
|
|
469
380
|
return ts.visitEachChild(node, visitor, context);
|
|
470
381
|
}; // visitor;
|
|
471
382
|
/* --------------------Returns for transformer function--------------------------------- */
|
|
472
|
-
return
|
|
383
|
+
return (rootNode) => ts.visitNode(rootNode, visitor);
|
|
473
384
|
}; // transformer;
|
|
474
385
|
/* --------------------Returns for main handler function--------------------------------- */
|
|
475
|
-
|
|
476
|
-
return { file
|
|
386
|
+
const _content = transformFunction(transformer, sourceFile, compilerOptions);
|
|
387
|
+
return { file, content: _content, ...rest };
|
|
477
388
|
}; // returns
|
|
478
389
|
};
|
|
479
|
-
|
|
480
|
-
return new Promise(function (resolve) { return setTimeout(resolve, time); });
|
|
481
|
-
};
|
|
482
|
-
var duplicateHandlers = {
|
|
390
|
+
const duplicateHandlers = {
|
|
483
391
|
/**
|
|
484
392
|
* A bundle handler that takes a list of source files and transforms them into renamed source files.
|
|
485
393
|
* The transformation is done in a series of steps, each step transforms the source files based on the given maps.
|
|
@@ -492,43 +400,23 @@ var duplicateHandlers = {
|
|
|
492
400
|
* @param compilerOptions - The options for the TypeScript compiler.
|
|
493
401
|
* @returns A list of transformed source files.
|
|
494
402
|
*/
|
|
495
|
-
renamed:
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
[callExpression, callNameMap, importNameMap, compilerOptions],
|
|
513
|
-
[
|
|
514
|
-
exportExpression,
|
|
515
|
-
callNameMap,
|
|
516
|
-
importNameMap,
|
|
517
|
-
exportNameMap,
|
|
518
|
-
compilerOptions,
|
|
519
|
-
],
|
|
520
|
-
]);
|
|
521
|
-
return [4 /*yield*/, duplicates.concurrent()];
|
|
522
|
-
case 1:
|
|
523
|
-
duplicate = _a.sent();
|
|
524
|
-
for (_i = 0, duplicate_1 = duplicate; _i < duplicate_1.length; _i++) {
|
|
525
|
-
func = duplicate_1[_i];
|
|
526
|
-
deps = deps.map(func);
|
|
527
|
-
}
|
|
528
|
-
return [2 /*return*/, deps];
|
|
529
|
-
}
|
|
530
|
-
});
|
|
531
|
-
}); },
|
|
403
|
+
renamed: async (deps, compilerOptions) => {
|
|
404
|
+
// order is important here
|
|
405
|
+
const duplicates = resolves([
|
|
406
|
+
[collector, compilerOptions],
|
|
407
|
+
[updater, compilerOptions],
|
|
408
|
+
[callExpression, compilerOptions],
|
|
409
|
+
[exportExpression, compilerOptions],
|
|
410
|
+
[importExpression, compilerOptions],
|
|
411
|
+
[callExpression, compilerOptions],
|
|
412
|
+
[exportExpression, compilerOptions],
|
|
413
|
+
]);
|
|
414
|
+
const duplicate = await duplicates.concurrent();
|
|
415
|
+
for (const func of duplicate) {
|
|
416
|
+
deps = deps.map(func);
|
|
417
|
+
}
|
|
418
|
+
return deps;
|
|
419
|
+
},
|
|
532
420
|
/**
|
|
533
421
|
* A bundle handler that takes a list of source files and checks if they have been renamed correctly.
|
|
534
422
|
* If a source file has not been renamed, an error will be thrown.
|
|
@@ -537,38 +425,26 @@ var duplicateHandlers = {
|
|
|
537
425
|
* @param compilerOptions - The options for the TypeScript compiler.
|
|
538
426
|
* @returns A list of source files that have been renamed correctly.
|
|
539
427
|
*/
|
|
540
|
-
notRenamed:
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
case 2:
|
|
553
|
-
_a.sent();
|
|
554
|
-
namesMap.forEach(function (files, name) {
|
|
555
|
-
if (files.size > 1) {
|
|
556
|
-
_err = true;
|
|
557
|
-
console.warn("Name -> ".concat(name, " declared in multiple files :"));
|
|
558
|
-
// biome-ignore lint/suspicious/useIterableCallbackReturn : just log warn
|
|
559
|
-
files.forEach(function (f) { return console.warn(" - ".concat(f.file)); });
|
|
560
|
-
}
|
|
561
|
-
});
|
|
562
|
-
return [4 /*yield*/, wait(500)];
|
|
563
|
-
case 3:
|
|
564
|
-
_a.sent();
|
|
565
|
-
if (_err) {
|
|
566
|
-
process.exit(1);
|
|
567
|
-
}
|
|
568
|
-
return [2 /*return*/, deps];
|
|
428
|
+
notRenamed: async (deps, compilerOptions) => {
|
|
429
|
+
let _err = false;
|
|
430
|
+
const duplicates = resolves([[collector, namesMap, compilerOptions]]);
|
|
431
|
+
const duplicate = await duplicates.concurrent();
|
|
432
|
+
deps.map(duplicate[0]);
|
|
433
|
+
await utilities.wait(1000);
|
|
434
|
+
namesMap.forEach((files, name) => {
|
|
435
|
+
if (files.size > 1) {
|
|
436
|
+
_err = true;
|
|
437
|
+
console.warn(`Name -> ${name} declared in multiple files :`);
|
|
438
|
+
// biome-ignore lint/suspicious/useIterableCallbackReturn : just log warn
|
|
439
|
+
files.forEach((f) => console.warn(` - ${f.file}`));
|
|
569
440
|
}
|
|
570
441
|
});
|
|
571
|
-
|
|
442
|
+
await utilities.wait(500);
|
|
443
|
+
if (_err) {
|
|
444
|
+
process.exit(1);
|
|
445
|
+
}
|
|
446
|
+
return deps;
|
|
447
|
+
},
|
|
572
448
|
};
|
|
573
449
|
export default duplicateHandlers;
|
|
574
|
-
//# sourceMappingURL=index.
|
|
450
|
+
//# sourceMappingURL=index.mjs.map
|