@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?:
|
|
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
|
|
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
package/src/transformer/index.ts
CHANGED
|
@@ -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
|
|
185
|
-
return
|
|
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 => {
|