@esportsplus/typescript 0.17.1 → 0.17.2
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/build/cli/tsc.js +1 -1
- package/build/transformer/index.d.ts +2 -1
- package/build/transformer/index.js +20 -1
- package/package.json +1 -1
- package/src/cli/tsc.ts +2 -2
- package/src/transformer/index.ts +29 -1
package/build/cli/tsc.js
CHANGED
|
@@ -6,7 +6,7 @@ import path from 'path';
|
|
|
6
6
|
import ts from 'typescript';
|
|
7
7
|
let require = createRequire(import.meta.url), skipFlags = ['--help', '--init', '--noEmit', '--showConfig', '--version', '-h', '-noEmit', '-v'];
|
|
8
8
|
async function build(tsconfig, plugins) {
|
|
9
|
-
let
|
|
9
|
+
let { config, error } = ts.readConfigFile(tsconfig, ts.sys.readFile), root = path.dirname(path.resolve(tsconfig));
|
|
10
10
|
if (error) {
|
|
11
11
|
console.error(ts.flattenDiagnosticMessageText(error.messageText, '\n'));
|
|
12
12
|
process.exit(1);
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { QuickCheckPattern, Replacement } from './types.js';
|
|
2
2
|
import program from './program.js';
|
|
3
3
|
declare const addImport: (code: string, module: string, specifiers: string[]) => string;
|
|
4
|
+
declare const applyReplacements: (code: string, replacements: Replacement[]) => string;
|
|
4
5
|
declare const applyReplacementsReverse: (code: string, replacements: Replacement[]) => string;
|
|
5
6
|
declare const mightNeedTransform: (code: string, check: QuickCheckPattern) => boolean;
|
|
6
7
|
declare const uid: (prefix: string, updateUUID?: boolean) => string;
|
|
7
|
-
export { addImport, applyReplacementsReverse, mightNeedTransform, program, uid };
|
|
8
|
+
export { addImport, applyReplacements, applyReplacementsReverse, mightNeedTransform, program, uid };
|
|
8
9
|
export type * from './types.js';
|
|
9
10
|
export * from './constants.js';
|
|
@@ -61,6 +61,25 @@ const addImport = (code, module, specifiers) => {
|
|
|
61
61
|
}
|
|
62
62
|
return code.substring(0, first) + adding + code.substring(first);
|
|
63
63
|
};
|
|
64
|
+
const applyReplacements = (code, replacements) => {
|
|
65
|
+
if (replacements.length === 0) {
|
|
66
|
+
return code;
|
|
67
|
+
}
|
|
68
|
+
replacements.sort((a, b) => a.start - b.start);
|
|
69
|
+
let parts = [], pos = 0;
|
|
70
|
+
for (let i = 0, n = replacements.length; i < n; i++) {
|
|
71
|
+
let r = replacements[i];
|
|
72
|
+
if (r.start > pos) {
|
|
73
|
+
parts.push(code.substring(pos, r.start));
|
|
74
|
+
}
|
|
75
|
+
parts.push(r.newText);
|
|
76
|
+
pos = r.end;
|
|
77
|
+
}
|
|
78
|
+
if (pos < code.length) {
|
|
79
|
+
parts.push(code.substring(pos));
|
|
80
|
+
}
|
|
81
|
+
return parts.join('');
|
|
82
|
+
};
|
|
64
83
|
const applyReplacementsReverse = (code, replacements) => {
|
|
65
84
|
if (replacements.length === 0) {
|
|
66
85
|
return code;
|
|
@@ -89,5 +108,5 @@ const mightNeedTransform = (code, check) => {
|
|
|
89
108
|
const uid = (prefix, updateUUID = false) => {
|
|
90
109
|
return prefix + '_' + (updateUUID ? uuid().replace(UUID_DASH_REGEX, '') : uidSuffix) + '_' + (i++).toString(36);
|
|
91
110
|
};
|
|
92
|
-
export { addImport, applyReplacementsReverse, mightNeedTransform, program, uid };
|
|
111
|
+
export { addImport, applyReplacements, applyReplacementsReverse, mightNeedTransform, program, uid };
|
|
93
112
|
export * from './constants.js';
|
package/package.json
CHANGED
package/src/cli/tsc.ts
CHANGED
|
@@ -23,8 +23,8 @@ let require = createRequire(import.meta.url),
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
async function build(tsconfig: string, plugins: PluginConfig[]): Promise<void> {
|
|
26
|
-
let
|
|
27
|
-
|
|
26
|
+
let { config, error } = ts.readConfigFile(tsconfig, ts.sys.readFile),
|
|
27
|
+
root = path.dirname(path.resolve(tsconfig));
|
|
28
28
|
|
|
29
29
|
if (error) {
|
|
30
30
|
console.error(ts.flattenDiagnosticMessageText(error.messageText, '\n'));
|
package/src/transformer/index.ts
CHANGED
|
@@ -99,6 +99,34 @@ const addImport = (code: string, module: string, specifiers: string[]): string =
|
|
|
99
99
|
return code.substring(0, first) + adding + code.substring(first);
|
|
100
100
|
};
|
|
101
101
|
|
|
102
|
+
const applyReplacements = (code: string, replacements: Replacement[]): string => {
|
|
103
|
+
if (replacements.length === 0) {
|
|
104
|
+
return code;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
replacements.sort((a, b) => a.start - b.start);
|
|
108
|
+
|
|
109
|
+
let parts: string[] = [],
|
|
110
|
+
pos = 0;
|
|
111
|
+
|
|
112
|
+
for (let i = 0, n = replacements.length; i < n; i++) {
|
|
113
|
+
let r = replacements[i];
|
|
114
|
+
|
|
115
|
+
if (r.start > pos) {
|
|
116
|
+
parts.push(code.substring(pos, r.start));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
parts.push(r.newText);
|
|
120
|
+
pos = r.end;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (pos < code.length) {
|
|
124
|
+
parts.push(code.substring(pos));
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return parts.join('');
|
|
128
|
+
};
|
|
129
|
+
|
|
102
130
|
const applyReplacementsReverse = (code: string, replacements: Replacement[]): string => {
|
|
103
131
|
if (replacements.length === 0) {
|
|
104
132
|
return code;
|
|
@@ -139,7 +167,7 @@ const uid = (prefix: string, updateUUID = false): string => {
|
|
|
139
167
|
|
|
140
168
|
|
|
141
169
|
export {
|
|
142
|
-
addImport, applyReplacementsReverse,
|
|
170
|
+
addImport, applyReplacements, applyReplacementsReverse,
|
|
143
171
|
mightNeedTransform,
|
|
144
172
|
program,
|
|
145
173
|
uid
|