@esportsplus/typescript 0.12.2 → 0.13.0

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.
@@ -6,7 +6,7 @@ declare const applyReplacements: (code: string, replacements: Replacement[]) =>
6
6
  declare const applyReplacementsReverse: (code: string, replacements: Replacement[]) => string;
7
7
  declare const collectNodes: <T>(sourceFile: ts.SourceFile, predicate: (node: ts.Node) => T | null) => NodeMatch<T>[];
8
8
  declare const mightNeedTransform: (code: string, check: QuickCheckPattern) => boolean;
9
- declare const uid: (prefix?: string) => string;
9
+ declare const uid: (prefix: string, updateUUID?: boolean) => string;
10
10
  declare const updateImports: (code: string, modification: ImportModification) => string;
11
11
  declare const visitAst: <T>(sourceFile: ts.SourceFile, callback: VisitorCallback<T>, state: T, predicate?: VisitorPredicate) => T;
12
12
  declare const visitAstWithDepth: <T>(sourceFile: ts.SourceFile, callback: (node: ts.Node, depth: number, state: T) => void, state: T, depthTrigger: (node: ts.Node) => boolean) => T;
@@ -2,6 +2,7 @@ import { uuid } from '@esportsplus/utilities';
2
2
  import ts from 'typescript';
3
3
  import { BRACES_CONTENT_REGEX, REGEX_ESCAPE_PATTERN, UUID_DASH_REGEX } from './constants.js';
4
4
  import program from './program.js';
5
+ let i = 0, uidSuffix = uuid().replace(UUID_DASH_REGEX, '');
5
6
  function buildImportRegex(escapedModule) {
6
7
  return new RegExp(`(import\\s*\\{[^}]*\\}\\s*from\\s*['"]${escapedModule}['"])`);
7
8
  }
@@ -122,8 +123,8 @@ const mightNeedTransform = (code, check) => {
122
123
  }
123
124
  return false;
124
125
  };
125
- const uid = (prefix) => {
126
- return (prefix ? prefix + '_' : '_') + uuid().replace(UUID_DASH_REGEX, '_');
126
+ const uid = (prefix, updateUUID = false) => {
127
+ return prefix + '_' + (updateUUID ? uuid().replace(UUID_DASH_REGEX, '') : uidSuffix) + '_' + (i++).toString(36);
127
128
  };
128
129
  const updateImports = (code, modification) => {
129
130
  let { module, specifiers } = modification;
package/package.json CHANGED
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "type": "module",
36
36
  "types": "build/index.d.ts",
37
- "version": "0.12.2",
37
+ "version": "0.13.0",
38
38
  "scripts": {
39
39
  "build": "tsc && tsc-alias",
40
40
  "-": "-"
@@ -5,6 +5,10 @@ import type { ImportModification, NodeMatch, QuickCheckPattern, Replacement, Vis
5
5
  import program from './program';
6
6
 
7
7
 
8
+ let i = 0,
9
+ uidSuffix = uuid().replace(UUID_DASH_REGEX, '');
10
+
11
+
8
12
  function buildImportRegex(escapedModule: string): RegExp {
9
13
  return new RegExp(`(import\\s*\\{[^}]*\\}\\s*from\\s*['"]${escapedModule}['"])`);
10
14
  }
@@ -181,8 +185,8 @@ const mightNeedTransform = (code: string, check: QuickCheckPattern): boolean =>
181
185
  return false;
182
186
  };
183
187
 
184
- const uid = (prefix?: string): string => {
185
- return (prefix ? prefix + '_' : '_') + uuid().replace(UUID_DASH_REGEX, '_');
188
+ const uid = (prefix: string, updateUUID = false): string => {
189
+ return prefix + '_' + (updateUUID ? uuid().replace(UUID_DASH_REGEX, '') : uidSuffix) + '_' + (i++).toString(36);
186
190
  };
187
191
 
188
192
  const updateImports = (code: string, modification: ImportModification): string => {