@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.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
- * Returns an object with methods to generate unique names based on a prefix.
44
- * The `setPrefix` method sets a prefix for the generated names.
45
- * The `getName` method generates a unique name based on the prefix and an input string.
46
- * The `getPrefix` method returns the prefix associated with a key.
47
- * If a prefix is set multiple times, an error will be thrown.
48
- */
49
- function uniqueName() {
50
- var storedPrefix = new Map();
51
- var obj = {
52
- setPrefix: function (_a) {
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("".concat(key, " already exist"));
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
- var length = names.length;
66
- var _name = _fix
67
- ? "".concat(_fix).concat(input, "_").concat(length + 1)
68
- : "$nyein".concat(input, "_").concat(length + 1);
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: getName };
34
+ return { getName };
73
35
  },
74
- getPrefix: function (key) {
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
- var dupName = uniqueName().setPrefix({
44
+ const dupName = __uniqueName().setPrefix({
83
45
  key: "DuplicatesNames",
84
- value: "d_",
46
+ value: "__duplicatesNames__",
85
47
  });
86
- var normalizePathKey = function (filePath) {
87
- var parsed = path.parse(filePath);
88
- var noExt = path.join(parsed.dir, parsed.name);
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
- var getFileKey = function (filePath) { return normalizePathKey(filePath); };
95
- var getModuleKeyFromSpecifier = function (moduleSpecifier, sourceFile, containingFile) {
96
- var spec = "";
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
- var baseDir = path.dirname(containingFile);
66
+ const baseDir = path.dirname(containingFile);
105
67
  return normalizePathKey(path.resolve(baseDir, spec));
106
68
  }
107
69
  return spec;
108
70
  };
109
- /**
110
- * A bundle handler that transforms call expression in a given source file.
111
- * @param callNameMap - A mapping of base names to new names for call expressions.
112
- * @param importNameMap - A mapping of base names to new names for import expressions.
113
- * @param compilerOptions - The compiler options for the TypeScript compiler.
114
- * @return A new source file with transformed call expressions.
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
- var base_1 = node.expression.text;
126
- var new_name = null;
127
- var mapping = callNameMap.find(function (m) { return m.base === base_1 && m.file === file; });
128
- var importMapping = importNameMap.find(function (m) { return m.base === base_1 && m.file === file; });
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
- var base_2 = node.expression.text;
144
- var new_name = null;
145
- var mapping = callNameMap.find(function (m) { return m.base === base_2 && m.file === file; });
146
- var importMapping = importNameMap.find(function (m) { return m.base === base_2 && m.file === file; });
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
- var base_3 = node.expression.text;
161
- var new_name = null;
162
- var mapping = callNameMap.find(function (m) { return m.base === base_3 && m.file === file; });
163
- var importMapping = importNameMap.find(function (m) { return m.base === base_3 && m.file === file; });
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 function (rootNode) { return ts.visitNode(rootNode, visitor); };
133
+ return (rootNode) => ts.visitNode(rootNode, visitor);
180
134
  }; // transformer;
181
135
  /* --------------------Returns for main handler function--------------------------------- */
182
- var _content = transformFunction(transformer, sourceFile, compilerOptions);
183
- return { file: file, content: _content };
136
+ const _content = transformFunction(transformer, sourceFile, compilerOptions);
137
+ return { file, content: _content, ...rest };
184
138
  }; // returns
185
139
  };
186
- /**
187
- * A bundle handler that renames the exported expression according to the given maps.
188
- * It will traverse the given source file and rename the exported expression if a mapping is found.
189
- *
190
- * @param callNameMap - A map of base names to new names for function calls.
191
- * @param importNameMap - A map of base names to new names for import expressions.
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
- var base_4 = node.name.text;
206
- var new_name = null;
207
- var mapping = callNameMap.find(function (m) { return m.base === base_4 && m.file === file; });
208
- var importMapping = importNameMap.find(function (m) { return m.base === base_4 && m.file === file; });
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: base_4,
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
- var expr = node.expression;
169
+ const expr = node.expression;
227
170
  if (ts.isIdentifier(expr)) {
228
- var base_5 = expr.text;
229
- var new_name = null;
230
- var mapping = callNameMap.find(function (m) { return m.base === base_5 && m.file === file; });
231
- var importMapping = importNameMap.find(function (m) { return m.base === base_5 && m.file === file; });
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: base_5,
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 function (rootNode) { return ts.visitNode(rootNode, visitor); };
195
+ return (rootNode) => ts.visitNode(rootNode, visitor);
253
196
  }; // transformer;
254
197
  /* --------------------Returns for main handler function--------------------------------- */
255
- var _content = transformFunction(transformer, sourceFile, compilerOptions);
256
- return { file: file, content: _content };
198
+ const _content = transformFunction(transformer, sourceFile, compilerOptions);
199
+ return { file, content: _content, ...rest };
257
200
  }; // returns
258
201
  };
259
- /**
260
- * A bundle handler that transforms import expressions in a given source file.
261
- * @param exportNameMap - A mapping of base names to new names for export expressions.
262
- * @param importNameMap - A mapping of base names to new names for import expressions.
263
- * @param compilerOptions - The compiler options for the TypeScript compiler.
264
- * @return A new source file with transformed import expressions.
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
- var moduleKey_1 = getModuleKeyFromSpecifier(node.moduleSpecifier, sourceFile, file);
276
- var baseNames = [];
277
- if (((_a = node.importClause) === null || _a === void 0 ? void 0 : _a.namedBindings) &&
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(function (el) {
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 (((_b = node.importClause) === null || _b === void 0 ? void 0 : _b.name) &&
216
+ if (node.importClause?.name &&
285
217
  ts.isIdentifier(node.importClause.name)) {
286
- var base_6 = node.importClause.name.text.trim();
287
- var mapping = exportNameMap.find(function (m) { return m.base === base_6 && m.file === moduleKey_1; });
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: file,
223
+ file,
292
224
  newName: mapping.newName,
293
225
  });
294
- var newImportClause = factory.updateImportClause(node.importClause, node.importClause.phaseModifier, factory.createIdentifier(mapping.newName), node.importClause.namedBindings);
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
- var updatedElements = node.importClause.namedBindings.elements.map(function (el) {
304
- var mapping = exportNameMap.find(function (m) { return m.base === el.name.text.trim() && m.file === moduleKey_1; });
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: 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
- var newNamedImports = factory.updateNamedImports(node.importClause.namedBindings, updatedElements);
316
- var newImportClause = factory.updateImportClause(node.importClause, node.importClause.phaseModifier, node.importClause.name, newNamedImports);
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 function (rootNode) { return ts.visitNode(rootNode, visitor); };
256
+ return (rootNode) => ts.visitNode(rootNode, visitor);
325
257
  }; // transformer;
326
258
  /* --------------------Returns for main handler function--------------------------------- */
327
- var _content = transformFunction(transformer, sourceFile, compilerOptions);
328
- return { file: file, content: _content };
259
+ const _content = transformFunction(transformer, sourceFile, compilerOptions);
260
+ return { file, content: _content, ...rest };
329
261
  }; // returns
330
262
  };
331
- /**
332
- * A bundle handler that collects information about the usage of given names in a given source file.
333
- * It will traverse the given source file and collect information about the usage of given names.
334
- * The information will be stored in a namesMap.
335
- * @param namesMap - A map of base names to new names for function calls, import expressions, and export expressions.
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(function (decl) {
272
+ node.declarationList.declarations.forEach((decl) => {
352
273
  if (ts.isIdentifier(decl.name)) {
353
- var $name = decl.name.text;
274
+ const $name = decl.name.text;
354
275
  if (!namesMap.has($name)) {
355
- namesMap.set($name, new Set([{ file: 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: 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
- var $name = (_a = node.name) === null || _a === void 0 ? void 0 : _a.text;
291
+ const $name = node.name?.text;
371
292
  if ($name) {
372
293
  if (!namesMap.has($name)) {
373
- namesMap.set($name, new Set([{ file: 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: 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, function (child) { return visitNode(child, false); });
312
+ ts.visitNodes(node.statements, (child) => visitNode(child, false));
392
313
  }
393
314
  else {
394
- ts.forEachChild(node, function (child) {
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, function (child) { return visitNode(child, isGlobalScope); }, context);
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 function (rootNode) { return visitNode(rootNode, true); };
328
+ return (rootNode) => visitNode(rootNode, true);
408
329
  }; // transformer;
409
330
  /* --------------------Returns for main handler function--------------------------------- */
410
- var _content = transformFunction(transformer, sourceFile, compilerOptions);
411
- return { file: file, content: _content };
331
+ const _content = transformFunction(transformer, sourceFile, compilerOptions);
332
+ return { file, content: _content, ...rest };
412
333
  }; // returns
413
334
  };
414
- /**
415
- * A bundle handler that updates the given source file based on the given namesMap and callNameMap.
416
- * It will traverse the given source file and update the names of the exported expressions, call expressions, and import expressions if a mapping is found in the callNameMap.
417
- * The updated source file will be returned.
418
- * @param namesMap - A map of base names to new names for function calls, import expressions, and export expressions.
419
- * @param callNameMap - A map of base names to new names for call expressions.
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
- var newDeclarations = node.declarationList.declarations.map(function (decl) {
342
+ const newDeclarations = node.declarationList.declarations.map((decl) => {
432
343
  if (ts.isIdentifier(decl.name)) {
433
- var base = decl.name.text;
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
- var newName = dupName.getName(base);
437
- callNameMap.push({ base: base, file: file, newName: newName });
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
- var newDeclList = factory.updateVariableDeclarationList(node.declarationList, newDeclarations);
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
- var base = node.name.text;
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
- var newName = dupName.getName(base);
452
- callNameMap.push({ base: base, file: file, newName: newName });
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
- var base = node.name.text;
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
- var newName = dupName.getName(base);
463
- callNameMap.push({ base: base, file: file, newName: newName });
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 function (rootNode) { return ts.visitNode(rootNode, visitor); };
383
+ return (rootNode) => ts.visitNode(rootNode, visitor);
473
384
  }; // transformer;
474
385
  /* --------------------Returns for main handler function--------------------------------- */
475
- var _content = transformFunction(transformer, sourceFile, compilerOptions);
476
- return { file: file, content: _content };
386
+ const _content = transformFunction(transformer, sourceFile, compilerOptions);
387
+ return { file, content: _content, ...rest };
477
388
  }; // returns
478
389
  };
479
- var wait = function (time) {
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: function (deps, namesMap, callNameMap, importNameMap, exportNameMap, compilerOptions) { return __awaiter(void 0, void 0, Promise, function () {
496
- var duplicates, duplicate, _i, duplicate_1, func;
497
- return __generator(this, function (_a) {
498
- switch (_a.label) {
499
- case 0:
500
- duplicates = resolves([
501
- [collector, namesMap, compilerOptions],
502
- [updater, namesMap, callNameMap, compilerOptions],
503
- [callExpression, callNameMap, importNameMap, compilerOptions],
504
- [
505
- exportExpression,
506
- callNameMap,
507
- importNameMap,
508
- exportNameMap,
509
- compilerOptions,
510
- ],
511
- [importExpression, exportNameMap, importNameMap, compilerOptions],
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: function (deps, namesMap, compilerOptions) { return __awaiter(void 0, void 0, Promise, function () {
541
- var _err, duplicates, duplicate;
542
- return __generator(this, function (_a) {
543
- switch (_a.label) {
544
- case 0:
545
- _err = false;
546
- duplicates = resolves([[collector, namesMap, compilerOptions]]);
547
- return [4 /*yield*/, duplicates.concurrent()];
548
- case 1:
549
- duplicate = _a.sent();
550
- deps.map(duplicate[0]);
551
- return [4 /*yield*/, wait(1000)];
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.js.map
450
+ //# sourceMappingURL=index.mjs.map