@esportsplus/typescript 0.12.1 → 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.
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
declare const BRACES_CONTENT_REGEX: RegExp;
|
|
2
2
|
declare const REGEX_ESCAPE_PATTERN: RegExp;
|
|
3
3
|
declare const TRAILING_SEMICOLON: RegExp;
|
|
4
|
+
declare const TRANSFORM_PATTERN: RegExp;
|
|
4
5
|
declare const UUID_DASH_REGEX: RegExp;
|
|
5
|
-
export { BRACES_CONTENT_REGEX, REGEX_ESCAPE_PATTERN, TRAILING_SEMICOLON, UUID_DASH_REGEX };
|
|
6
|
+
export { BRACES_CONTENT_REGEX, REGEX_ESCAPE_PATTERN, TRAILING_SEMICOLON, TRANSFORM_PATTERN, UUID_DASH_REGEX, };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const BRACES_CONTENT_REGEX = /\{([^}]*)\}/;
|
|
2
2
|
const REGEX_ESCAPE_PATTERN = /[.*+?^${}()|[\]\\]/g;
|
|
3
3
|
const TRAILING_SEMICOLON = /;$/;
|
|
4
|
+
const TRANSFORM_PATTERN = /\.[tj]sx?$/;
|
|
4
5
|
const UUID_DASH_REGEX = /-/g;
|
|
5
|
-
export { BRACES_CONTENT_REGEX, REGEX_ESCAPE_PATTERN, TRAILING_SEMICOLON, UUID_DASH_REGEX };
|
|
6
|
+
export { BRACES_CONTENT_REGEX, REGEX_ESCAPE_PATTERN, TRAILING_SEMICOLON, TRANSFORM_PATTERN, UUID_DASH_REGEX, };
|
|
@@ -6,10 +6,10 @@ 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;
|
|
13
13
|
export { addImport, applyReplacements, applyReplacementsReverse, collectNodes, mightNeedTransform, program, uid, updateImports, visitAst, visitAstWithDepth };
|
|
14
14
|
export type * from './types.js';
|
|
15
|
-
export
|
|
15
|
+
export * from './constants.js';
|
|
@@ -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;
|
|
@@ -156,4 +157,4 @@ const visitAstWithDepth = (sourceFile, callback, state, depthTrigger) => {
|
|
|
156
157
|
return state;
|
|
157
158
|
};
|
|
158
159
|
export { addImport, applyReplacements, applyReplacementsReverse, collectNodes, mightNeedTransform, program, uid, updateImports, visitAst, visitAstWithDepth };
|
|
159
|
-
export
|
|
160
|
+
export * from './constants.js';
|
package/package.json
CHANGED
|
@@ -4,7 +4,14 @@ const REGEX_ESCAPE_PATTERN = /[.*+?^${}()|[\]\\]/g;
|
|
|
4
4
|
|
|
5
5
|
const TRAILING_SEMICOLON = /;$/;
|
|
6
6
|
|
|
7
|
+
const TRANSFORM_PATTERN = /\.[tj]sx?$/;
|
|
8
|
+
|
|
7
9
|
const UUID_DASH_REGEX = /-/g;
|
|
8
10
|
|
|
9
11
|
|
|
10
|
-
export {
|
|
12
|
+
export {
|
|
13
|
+
BRACES_CONTENT_REGEX,
|
|
14
|
+
REGEX_ESCAPE_PATTERN,
|
|
15
|
+
TRAILING_SEMICOLON, TRANSFORM_PATTERN,
|
|
16
|
+
UUID_DASH_REGEX,
|
|
17
|
+
};
|
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 => {
|
|
@@ -250,4 +254,4 @@ export {
|
|
|
250
254
|
visitAst, visitAstWithDepth
|
|
251
255
|
};
|
|
252
256
|
export type * from './types';
|
|
253
|
-
export
|
|
257
|
+
export * from './constants';
|