@esportsplus/typescript 0.28.0 → 0.28.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.
|
@@ -117,14 +117,14 @@ const transform = (plugins, code, file, program, shared) => {
|
|
|
117
117
|
if (plugins.length === 0) {
|
|
118
118
|
return { changed: false, code, sourceFile: file };
|
|
119
119
|
}
|
|
120
|
-
let currentCode = code, currentFile = file;
|
|
120
|
+
let checker = program.getTypeChecker(), currentCode = code, currentFile = file, fileName = file.fileName;
|
|
121
121
|
for (let i = 0, n = plugins.length; i < n; i++) {
|
|
122
122
|
let plugin = plugins[i];
|
|
123
123
|
if (plugin.patterns && !hasPattern(currentCode, plugin.patterns)) {
|
|
124
124
|
continue;
|
|
125
125
|
}
|
|
126
126
|
let { imports, prepend, replacements } = plugin.transform({
|
|
127
|
-
checker
|
|
127
|
+
checker,
|
|
128
128
|
code: currentCode,
|
|
129
129
|
program,
|
|
130
130
|
shared,
|
|
@@ -132,15 +132,15 @@ const transform = (plugins, code, file, program, shared) => {
|
|
|
132
132
|
});
|
|
133
133
|
if (replacements?.length) {
|
|
134
134
|
currentCode = applyIntents(currentCode, currentFile, replacements);
|
|
135
|
-
currentFile = ts.createSourceFile(
|
|
135
|
+
currentFile = ts.createSourceFile(fileName, currentCode, currentFile.languageVersion, true);
|
|
136
136
|
}
|
|
137
137
|
if (prepend?.length) {
|
|
138
138
|
currentCode = applyPrepend(currentCode, currentFile, prepend);
|
|
139
|
-
currentFile = ts.createSourceFile(
|
|
139
|
+
currentFile = ts.createSourceFile(fileName, currentCode, currentFile.languageVersion, true);
|
|
140
140
|
}
|
|
141
141
|
if (imports?.length) {
|
|
142
142
|
currentCode = applyImports(currentCode, currentFile, imports);
|
|
143
|
-
currentFile = ts.createSourceFile(
|
|
143
|
+
currentFile = ts.createSourceFile(fileName, currentCode, currentFile.languageVersion, true);
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
return {
|
|
@@ -46,7 +46,7 @@ const includes = (checker, node, pkg, symbolName) => {
|
|
|
46
46
|
imports.set(pkg, names);
|
|
47
47
|
}
|
|
48
48
|
if (names.has(node.text)) {
|
|
49
|
-
let symbol = checker
|
|
49
|
+
let symbol = checker.getSymbolAtLocation(node);
|
|
50
50
|
if (symbol) {
|
|
51
51
|
let declarations = symbol.getDeclarations();
|
|
52
52
|
if (declarations && declarations.length > 0) {
|
|
@@ -68,7 +68,7 @@ const includes = (checker, node, pkg, symbolName) => {
|
|
|
68
68
|
}
|
|
69
69
|
return true;
|
|
70
70
|
}
|
|
71
|
-
let symbol = checker
|
|
71
|
+
let symbol = checker.getSymbolAtLocation(node);
|
|
72
72
|
if (!symbol) {
|
|
73
73
|
return false;
|
|
74
74
|
}
|
package/package.json
CHANGED
|
@@ -111,7 +111,6 @@ function modify(code: string, file: ts.SourceFile, pkg: string, options: ModifyO
|
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
let remove = options.remove ? new Set(options.remove) : null,
|
|
114
|
-
// Collect all non-removed specifiers from existing imports
|
|
115
114
|
specifiers = new Set<string>();
|
|
116
115
|
|
|
117
116
|
for (let i = 0, n = found.length; i < n; i++) {
|
|
@@ -128,7 +127,6 @@ function modify(code: string, file: ts.SourceFile, pkg: string, options: ModifyO
|
|
|
128
127
|
}
|
|
129
128
|
}
|
|
130
129
|
|
|
131
|
-
// Build replacement text - namespace import first, then named imports
|
|
132
130
|
let statements: string[] = [];
|
|
133
131
|
|
|
134
132
|
if (namespace) {
|
|
@@ -139,7 +137,6 @@ function modify(code: string, file: ts.SourceFile, pkg: string, options: ModifyO
|
|
|
139
137
|
statements.push(`import { ${[...specifiers].sort().join(', ')} } from '${pkg}';`);
|
|
140
138
|
}
|
|
141
139
|
|
|
142
|
-
// Build replacements - replace first import, remove others
|
|
143
140
|
let replacements: Replacement[] = [];
|
|
144
141
|
|
|
145
142
|
for (let i = 0, n = found.length; i < n; i++) {
|
|
@@ -175,6 +172,7 @@ function replaceReverse(code: string, replacements: Replacement[]): string {
|
|
|
175
172
|
/**
|
|
176
173
|
* Transform source through all plugins sequentially.
|
|
177
174
|
* Each plugin receives fresh AST with accurate positions.
|
|
175
|
+
* All plugins share the original program type checker for import resolution.
|
|
178
176
|
*/
|
|
179
177
|
const transform = (
|
|
180
178
|
plugins: Plugin[],
|
|
@@ -187,8 +185,10 @@ const transform = (
|
|
|
187
185
|
return { changed: false, code, sourceFile: file };
|
|
188
186
|
}
|
|
189
187
|
|
|
190
|
-
let
|
|
191
|
-
|
|
188
|
+
let checker = program.getTypeChecker(),
|
|
189
|
+
currentCode = code,
|
|
190
|
+
currentFile = file,
|
|
191
|
+
fileName = file.fileName;
|
|
192
192
|
|
|
193
193
|
for (let i = 0, n = plugins.length; i < n; i++) {
|
|
194
194
|
let plugin = plugins[i];
|
|
@@ -198,7 +198,7 @@ const transform = (
|
|
|
198
198
|
}
|
|
199
199
|
|
|
200
200
|
let { imports, prepend, replacements } = plugin.transform({
|
|
201
|
-
checker
|
|
201
|
+
checker,
|
|
202
202
|
code: currentCode,
|
|
203
203
|
program,
|
|
204
204
|
shared,
|
|
@@ -208,7 +208,7 @@ const transform = (
|
|
|
208
208
|
if (replacements?.length) {
|
|
209
209
|
currentCode = applyIntents(currentCode, currentFile, replacements);
|
|
210
210
|
currentFile = ts.createSourceFile(
|
|
211
|
-
|
|
211
|
+
fileName,
|
|
212
212
|
currentCode,
|
|
213
213
|
currentFile.languageVersion,
|
|
214
214
|
true
|
|
@@ -218,7 +218,7 @@ const transform = (
|
|
|
218
218
|
if (prepend?.length) {
|
|
219
219
|
currentCode = applyPrepend(currentCode, currentFile, prepend);
|
|
220
220
|
currentFile = ts.createSourceFile(
|
|
221
|
-
|
|
221
|
+
fileName,
|
|
222
222
|
currentCode,
|
|
223
223
|
currentFile.languageVersion,
|
|
224
224
|
true
|
|
@@ -228,7 +228,7 @@ const transform = (
|
|
|
228
228
|
if (imports?.length) {
|
|
229
229
|
currentCode = applyImports(currentCode, currentFile, imports);
|
|
230
230
|
currentFile = ts.createSourceFile(
|
|
231
|
-
|
|
231
|
+
fileName,
|
|
232
232
|
currentCode,
|
|
233
233
|
currentFile.languageVersion,
|
|
234
234
|
true
|
|
@@ -245,4 +245,4 @@ const transform = (
|
|
|
245
245
|
|
|
246
246
|
|
|
247
247
|
export default { transform };
|
|
248
|
-
export type { CoordinatorResult };
|
|
248
|
+
export type { CoordinatorResult };
|
package/src/compiler/imports.ts
CHANGED
|
@@ -89,7 +89,7 @@ const includes = (checker: ts.TypeChecker, node: ts.Node, pkg: string, symbolNam
|
|
|
89
89
|
|
|
90
90
|
// Fast path: direct import from package
|
|
91
91
|
if (names.has(node.text)) {
|
|
92
|
-
let symbol = checker
|
|
92
|
+
let symbol = checker.getSymbolAtLocation(node);
|
|
93
93
|
|
|
94
94
|
if (symbol) {
|
|
95
95
|
let declarations = symbol.getDeclarations();
|
|
@@ -120,7 +120,7 @@ const includes = (checker: ts.TypeChecker, node: ts.Node, pkg: string, symbolNam
|
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
// Slow path: check for re-exports via aliased symbol
|
|
123
|
-
let symbol = checker
|
|
123
|
+
let symbol = checker.getSymbolAtLocation(node);
|
|
124
124
|
|
|
125
125
|
if (!symbol) {
|
|
126
126
|
return false;
|