@esportsplus/typescript 0.29.6 → 0.31.1
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/README.md +97 -3
- package/bin/tsc-alias +1 -1
- package/bin/tsc-lsp +3 -0
- package/build/cli/diagnostics.d.ts +8 -0
- package/build/cli/diagnostics.js +95 -0
- package/build/cli/tsc.d.ts +12 -2
- package/build/cli/tsc.js +343 -52
- package/build/compiler/ast.d.ts +7 -5
- package/build/compiler/ast.js +6 -6
- package/build/compiler/code.d.ts +5 -4
- package/build/compiler/code.js +12 -1
- package/build/compiler/coordinator.d.ts +16 -7
- package/build/compiler/coordinator.js +75 -41
- package/build/compiler/imports.d.ts +8 -3
- package/build/compiler/imports.js +34 -24
- package/build/compiler/index.d.ts +3 -0
- package/build/compiler/index.js +1 -0
- package/build/compiler/language-service.d.ts +36 -6
- package/build/compiler/language-service.js +252 -58
- package/build/compiler/plugins/index.d.ts +4 -2
- package/build/compiler/plugins/tsc.d.ts +1 -1
- package/build/compiler/plugins/vite.d.ts +6 -3
- package/build/compiler/plugins/vite.js +15 -8
- package/build/compiler/sourcemap.d.ts +52 -0
- package/build/compiler/sourcemap.js +265 -0
- package/build/compiler/types.d.ts +7 -6
- package/build/compiler/uid.d.ts +5 -2
- package/build/compiler/uid.js +33 -4
- package/build/index.d.ts +1 -1
- package/build/index.js +1 -1
- package/build/jsonc.d.ts +2 -0
- package/build/jsonc.js +85 -0
- package/build/lsp/bin.d.ts +1 -0
- package/build/lsp/bin.js +2 -0
- package/build/lsp/diagnostics.d.ts +10 -0
- package/build/lsp/diagnostics.js +69 -0
- package/build/lsp/index.d.ts +2 -0
- package/build/lsp/index.js +2 -0
- package/build/lsp/server.d.ts +4 -0
- package/build/lsp/server.js +130 -0
- package/build/lsp/workspace.d.ts +14 -0
- package/build/lsp/workspace.js +46 -0
- package/build/probe/adapter.d.ts +14 -0
- package/build/probe/adapter.js +42 -0
- package/build/probe/async/channel.d.ts +4 -0
- package/build/probe/async/channel.js +560 -0
- package/build/probe/async/value.d.ts +9 -0
- package/build/probe/async/value.js +16 -0
- package/build/probe/channels.d.ts +4 -0
- package/build/probe/channels.js +16 -0
- package/build/probe/exceptions/channel.d.ts +5 -0
- package/build/probe/exceptions/channel.js +657 -0
- package/build/probe/exceptions/jsdoc.d.ts +8 -0
- package/build/probe/exceptions/jsdoc.js +34 -0
- package/build/probe/exceptions/value.d.ts +39 -0
- package/build/probe/exceptions/value.js +158 -0
- package/build/probe/kernel/analyze.d.ts +8 -0
- package/build/probe/kernel/analyze.js +68 -0
- package/build/probe/kernel/ast.d.ts +11 -0
- package/build/probe/kernel/ast.js +49 -0
- package/build/probe/kernel/config.d.ts +5 -0
- package/build/probe/kernel/config.js +209 -0
- package/build/probe/kernel/fixpoint.d.ts +6 -0
- package/build/probe/kernel/fixpoint.js +206 -0
- package/build/probe/kernel/format.d.ts +4 -0
- package/build/probe/kernel/format.js +32 -0
- package/build/probe/kernel/graph.d.ts +4 -0
- package/build/probe/kernel/graph.js +507 -0
- package/build/probe/kernel/ids.d.ts +8 -0
- package/build/probe/kernel/ids.js +66 -0
- package/build/probe/kernel/program.d.ts +8 -0
- package/build/probe/kernel/program.js +13 -0
- package/build/probe/kernel/types.d.ts +134 -0
- package/build/probe/kernel/types.js +1 -0
- package/build/probe/overlay/base/async.jsonc +13 -0
- package/build/probe/overlay/base/exceptions.jsonc +54 -0
- package/build/probe/overlay/base/resources.jsonc +57 -0
- package/build/probe/overlay/load.d.ts +18 -0
- package/build/probe/overlay/load.js +302 -0
- package/build/probe/overlay/presets/express.jsonc +25 -0
- package/build/probe/overlay/presets/node.jsonc +17 -0
- package/build/probe/resources/channel.d.ts +4 -0
- package/build/probe/resources/channel.js +798 -0
- package/build/probe/resources/value.d.ts +9 -0
- package/build/probe/resources/value.js +36 -0
- package/build/ts.d.ts +3 -0
- package/build/ts.js +3 -0
- package/build/tsconfig.d.ts +2 -0
- package/build/tsconfig.js +150 -0
- package/package.json +29 -9
- package/tsconfig.base.json +19 -0
- package/tsconfig.dev.json +13 -0
- package/tsconfig.package.json +4 -1
- package/.claude/skills/code-audit/registry-typescript.json +0 -326
- package/.editorconfig +0 -9
- package/.gitattributes +0 -2
- package/.github/dependabot.yml +0 -25
- package/.github/workflows/bump.yml +0 -27
- package/.github/workflows/dependabot.yml +0 -58
- package/.github/workflows/publish.yml +0 -42
- package/.github/workflows/templates/bump.yml +0 -9
- package/.github/workflows/templates/dependabot.yml +0 -12
- package/.github/workflows/templates/publish.yml +0 -16
- package/pnpm-workspace.yaml +0 -6
- package/src/cli/tsc.ts +0 -235
- package/src/compiler/ast.ts +0 -60
- package/src/compiler/code.ts +0 -27
- package/src/compiler/coordinator.ts +0 -284
- package/src/compiler/imports.ts +0 -185
- package/src/compiler/index.ts +0 -7
- package/src/compiler/language-service.ts +0 -121
- package/src/compiler/plugins/index.ts +0 -5
- package/src/compiler/plugins/tsc.ts +0 -6
- package/src/compiler/plugins/vite.ts +0 -91
- package/src/compiler/types.ts +0 -83
- package/src/compiler/uid.ts +0 -10
- package/src/constants.ts +0 -4
- package/src/index.ts +0 -1
- package/tests/cli/tsc.test.ts +0 -155
- package/tests/compiler/ast.test.ts +0 -131
- package/tests/compiler/code.test.ts +0 -73
- package/tests/compiler/coordinator.bench.ts +0 -101
- package/tests/compiler/coordinator.test.ts +0 -872
- package/tests/compiler/imports.test.ts +0 -167
- package/tests/compiler/language-service.test.ts +0 -90
- package/tests/compiler/plugins.test.ts +0 -172
- package/tests/compiler/uid.test.ts +0 -70
- package/tsconfig.json +0 -3
- package/vitest.config.ts +0 -14
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isImportDeclaration } from 'typescript/unstable/ast/is';
|
|
2
2
|
import imports from './imports.js';
|
|
3
3
|
import languageService from './language-service.js';
|
|
4
|
+
import sourcemap from './sourcemap.js';
|
|
5
|
+
import uid from './uid.js';
|
|
4
6
|
function applyImports(code, file, intents) {
|
|
5
7
|
let merged = new Map();
|
|
6
8
|
for (let i = 0, n = intents.length; i < n; i++) {
|
|
@@ -24,33 +26,35 @@ function applyImports(code, file, intents) {
|
|
|
24
26
|
});
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
|
-
let keys = [...merged.keys()];
|
|
29
|
+
let edits = [], keys = [...merged.keys()];
|
|
28
30
|
for (let i = 0, n = keys.length; i < n; i++) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
let result = modify(code, file, keys[i], merged.get(keys[i]));
|
|
32
|
+
edits.push(...result.edits);
|
|
33
|
+
}
|
|
34
|
+
if (edits.length === 0) {
|
|
35
|
+
return { batches: [], code };
|
|
33
36
|
}
|
|
34
|
-
return code;
|
|
37
|
+
return { batches: [{ before: code, edits }], code: replaceReverse(code, edits) };
|
|
35
38
|
}
|
|
36
39
|
function applyIntents(code, file, intents) {
|
|
37
40
|
if (intents.length === 0) {
|
|
38
|
-
return code;
|
|
41
|
+
return { code, edits: [] };
|
|
39
42
|
}
|
|
40
|
-
|
|
43
|
+
let edits = intents.map(intent => ({
|
|
41
44
|
end: intent.node.end,
|
|
42
45
|
newText: intent.generate(file),
|
|
43
46
|
start: intent.node.getStart(file)
|
|
44
|
-
}))
|
|
47
|
+
}));
|
|
48
|
+
return { code: replaceReverse(code, edits), edits };
|
|
45
49
|
}
|
|
46
50
|
function applyPrepend(code, file, prepend) {
|
|
47
51
|
if (prepend.length === 0) {
|
|
48
|
-
return code;
|
|
52
|
+
return { code, edits: [] };
|
|
49
53
|
}
|
|
50
54
|
let position = 0;
|
|
51
55
|
for (let i = 0, n = file.statements.length; i < n; i++) {
|
|
52
56
|
let stmt = file.statements[i];
|
|
53
|
-
if (
|
|
57
|
+
if (isImportDeclaration(stmt)) {
|
|
54
58
|
position = stmt.end;
|
|
55
59
|
}
|
|
56
60
|
else {
|
|
@@ -58,9 +62,11 @@ function applyPrepend(code, file, prepend) {
|
|
|
58
62
|
}
|
|
59
63
|
}
|
|
60
64
|
if (position === 0) {
|
|
61
|
-
|
|
65
|
+
let newText = prepend.join('\n') + '\n';
|
|
66
|
+
return { code: newText + code, edits: [{ end: 0, newText, start: 0 }] };
|
|
62
67
|
}
|
|
63
|
-
|
|
68
|
+
let newText = '\n' + prepend.join('\n') + '\n';
|
|
69
|
+
return { code: code.slice(0, position) + newText + code.slice(position), edits: [{ end: position, newText, start: position }] };
|
|
64
70
|
}
|
|
65
71
|
function hasPattern(code, patterns) {
|
|
66
72
|
for (let i = 0, n = patterns.length; i < n; i++) {
|
|
@@ -72,9 +78,12 @@ function hasPattern(code, patterns) {
|
|
|
72
78
|
}
|
|
73
79
|
function modify(code, file, pkg, options) {
|
|
74
80
|
if (!options.add && !options.namespace && !options.remove) {
|
|
75
|
-
return code;
|
|
81
|
+
return { code, edits: [] };
|
|
76
82
|
}
|
|
77
83
|
let { namespace } = options, add = options.add ? new Set(options.add) : null, found = imports.all(file, pkg);
|
|
84
|
+
if (namespace && !add && !options.remove && found.some(info => info.namespace === namespace)) {
|
|
85
|
+
return { code, edits: [] };
|
|
86
|
+
}
|
|
78
87
|
if (found.length === 0) {
|
|
79
88
|
let statements = [];
|
|
80
89
|
if (namespace) {
|
|
@@ -84,11 +93,12 @@ function modify(code, file, pkg, options) {
|
|
|
84
93
|
statements.push(`import { ${[...add].sort().join(', ')} } from '${pkg}';`);
|
|
85
94
|
}
|
|
86
95
|
if (statements.length === 0) {
|
|
87
|
-
return code;
|
|
96
|
+
return { code, edits: [] };
|
|
88
97
|
}
|
|
89
|
-
|
|
98
|
+
let newText = statements.join('\n') + '\n';
|
|
99
|
+
return { code: newText + code, edits: [{ end: 0, newText, start: 0 }] };
|
|
90
100
|
}
|
|
91
|
-
let remove = options.remove ? new Set(options.remove) : null, specifiers = new Set();
|
|
101
|
+
let remove = options.remove ? new Set(options.remove) : null, specifiers = new Set(), nonNamespace = found.filter(info => !info.namespace), existingNamespace = found.some(info => info.namespace === namespace), defaultImport = nonNamespace.find(info => info.defaultName), target = defaultImport ?? nonNamespace[0];
|
|
92
102
|
for (let i = 0, n = found.length; i < n; i++) {
|
|
93
103
|
for (let [name, alias] of found[i].specifiers) {
|
|
94
104
|
if (!remove || (!remove.has(name) && !remove.has(alias))) {
|
|
@@ -103,21 +113,35 @@ function modify(code, file, pkg, options) {
|
|
|
103
113
|
}
|
|
104
114
|
}
|
|
105
115
|
let statements = [];
|
|
106
|
-
if (namespace) {
|
|
116
|
+
if (namespace && !existingNamespace) {
|
|
107
117
|
statements.push(`import * as ${namespace} from '${pkg}';`);
|
|
108
118
|
}
|
|
109
|
-
if (
|
|
119
|
+
if (target) {
|
|
120
|
+
let named = specifiers.size > 0 ? `{ ${[...specifiers].sort().join(', ')} }` : '', defaultName = target.defaultName, clause = defaultName && named ? `${defaultName}, ${named}` : defaultName ?? named;
|
|
121
|
+
if (clause) {
|
|
122
|
+
statements.push(`import ${clause} from '${pkg}';`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
else if (specifiers.size > 0) {
|
|
110
126
|
statements.push(`import { ${[...specifiers].sort().join(', ')} } from '${pkg}';`);
|
|
111
127
|
}
|
|
112
128
|
let replacements = [];
|
|
113
129
|
for (let i = 0, n = found.length; i < n; i++) {
|
|
130
|
+
let info = found[i];
|
|
131
|
+
if (info.namespace) {
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
114
134
|
replacements.push({
|
|
115
|
-
end:
|
|
116
|
-
newText:
|
|
117
|
-
start:
|
|
135
|
+
end: info.end,
|
|
136
|
+
newText: info === target ? statements.join('\n') : info.defaultName ? `import ${info.defaultName} from '${pkg}';` : '',
|
|
137
|
+
start: info.start
|
|
118
138
|
});
|
|
119
139
|
}
|
|
120
|
-
|
|
140
|
+
if (!target && statements.length > 0) {
|
|
141
|
+
let first = found[0];
|
|
142
|
+
replacements.push({ end: first.start, newText: statements.join('\n') + '\n', start: first.start });
|
|
143
|
+
}
|
|
144
|
+
return { code: replaceReverse(code, replacements), edits: replacements };
|
|
121
145
|
}
|
|
122
146
|
function replaceReverse(code, replacements) {
|
|
123
147
|
if (replacements.length === 0) {
|
|
@@ -138,53 +162,63 @@ function replaceReverse(code, replacements) {
|
|
|
138
162
|
}
|
|
139
163
|
return parts.reverse().join('');
|
|
140
164
|
}
|
|
141
|
-
const transform = (plugins, code, file,
|
|
165
|
+
const transform = (plugins, code, file, project, root, shared) => {
|
|
142
166
|
if (plugins.length === 0) {
|
|
143
|
-
return { changed: false, code,
|
|
167
|
+
return { changed: false, code, map: { generations: [] } };
|
|
144
168
|
}
|
|
145
|
-
|
|
169
|
+
uid.scope(root, file.fileName, code);
|
|
170
|
+
let changed = false, currentCode = code, currentFile = file, currentProject = project, fileName = file.fileName, generations = [], last = plugins.length - 1;
|
|
146
171
|
for (let i = 0, n = plugins.length; i < n; i++) {
|
|
147
172
|
let plugin = plugins[i];
|
|
148
173
|
if (plugin.patterns && !hasPattern(currentCode, plugin.patterns)) {
|
|
149
174
|
continue;
|
|
150
175
|
}
|
|
151
176
|
let { imports, prepend, replacements } = plugin.transform({
|
|
152
|
-
checker:
|
|
177
|
+
checker: currentProject.checker,
|
|
153
178
|
code: currentCode,
|
|
154
|
-
program:
|
|
179
|
+
program: currentProject.program,
|
|
155
180
|
shared,
|
|
156
181
|
sourceFile: currentFile
|
|
157
182
|
}), pluginChanged = false;
|
|
158
183
|
if (replacements?.length) {
|
|
159
|
-
currentCode = applyIntents(currentCode, currentFile, replacements);
|
|
184
|
+
let before = currentCode, result = applyIntents(currentCode, currentFile, replacements);
|
|
185
|
+
if (result.edits.length > 0) {
|
|
186
|
+
generations.push(sourcemap.buildGeneration(before, result.edits));
|
|
187
|
+
}
|
|
188
|
+
currentCode = result.code;
|
|
160
189
|
pluginChanged = true;
|
|
161
190
|
}
|
|
162
191
|
if (prepend?.length) {
|
|
163
192
|
if (pluginChanged) {
|
|
164
|
-
currentFile =
|
|
193
|
+
currentFile = languageService.parse(fileName, currentCode);
|
|
165
194
|
}
|
|
166
|
-
currentCode = applyPrepend(currentCode, currentFile, prepend);
|
|
195
|
+
let before = currentCode, result = applyPrepend(currentCode, currentFile, prepend);
|
|
196
|
+
if (result.edits.length > 0) {
|
|
197
|
+
generations.push(sourcemap.buildGeneration(before, result.edits));
|
|
198
|
+
}
|
|
199
|
+
currentCode = result.code;
|
|
167
200
|
pluginChanged = true;
|
|
168
201
|
}
|
|
169
202
|
if (imports?.length) {
|
|
170
203
|
if (pluginChanged) {
|
|
171
|
-
currentFile =
|
|
204
|
+
currentFile = languageService.parse(fileName, currentCode);
|
|
205
|
+
}
|
|
206
|
+
let result = applyImports(currentCode, currentFile, imports);
|
|
207
|
+
for (let j = 0, m = result.batches.length; j < m; j++) {
|
|
208
|
+
generations.push(sourcemap.buildGeneration(result.batches[j].before, result.batches[j].edits));
|
|
172
209
|
}
|
|
173
|
-
currentCode =
|
|
210
|
+
currentCode = result.code;
|
|
174
211
|
pluginChanged = true;
|
|
175
212
|
}
|
|
176
213
|
if (pluginChanged) {
|
|
177
214
|
changed = true;
|
|
178
215
|
if (i < last) {
|
|
179
|
-
|
|
180
|
-
currentFile =
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
currentFile = ts.createSourceFile(fileName, currentCode, file.languageVersion, true);
|
|
216
|
+
currentProject = languageService.update(project.configPath ?? languageService.findConfig(root) ?? root, fileName, currentCode);
|
|
217
|
+
currentFile = currentProject.program.getSourceFile(fileName) ??
|
|
218
|
+
languageService.parse(fileName, currentCode);
|
|
185
219
|
}
|
|
186
220
|
}
|
|
187
221
|
}
|
|
188
|
-
return { changed, code: currentCode,
|
|
222
|
+
return { changed, code: currentCode, map: { generations } };
|
|
189
223
|
};
|
|
190
224
|
export default { transform };
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Node, SourceFile } from 'typescript/unstable/ast';
|
|
2
|
+
import type { Checker } from 'typescript/unstable/sync';
|
|
2
3
|
type ImportInfo = {
|
|
4
|
+
defaultName?: string;
|
|
3
5
|
end: number;
|
|
6
|
+
namespace?: string;
|
|
4
7
|
specifiers: Map<string, string>;
|
|
5
8
|
typeOnly: Set<string>;
|
|
6
9
|
start: number;
|
|
@@ -10,9 +13,11 @@ type ModifyOptions = {
|
|
|
10
13
|
namespace?: string;
|
|
11
14
|
remove?: Iterable<string>;
|
|
12
15
|
};
|
|
16
|
+
declare const all: (file: SourceFile, pkg: string) => ImportInfo[];
|
|
17
|
+
declare const includes: (checker: Checker, node: Node, pkg: string, symbolName?: string) => boolean;
|
|
13
18
|
declare const _default: {
|
|
14
|
-
all:
|
|
15
|
-
includes:
|
|
19
|
+
all: typeof all;
|
|
20
|
+
includes: typeof includes;
|
|
16
21
|
};
|
|
17
22
|
export default _default;
|
|
18
23
|
export type { ImportInfo, ModifyOptions };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SyntaxKind } from 'typescript/unstable/ast';
|
|
2
|
+
import { isIdentifier, isImportDeclaration, isNamedImports, isNamespaceImport, isStringLiteral } from 'typescript/unstable/ast/is';
|
|
3
|
+
import { SymbolFlags } from 'typescript/unstable/sync';
|
|
2
4
|
let cache = new WeakMap();
|
|
3
5
|
function fileNameMatchesPackage(fileName, pkg) {
|
|
4
6
|
let normalized = fileName.replace(/\\/g, '/'), marker = `/node_modules/${pkg}/`;
|
|
@@ -8,15 +10,15 @@ const all = (file, pkg) => {
|
|
|
8
10
|
let imports = [];
|
|
9
11
|
for (let i = 0, n = file.statements.length; i < n; i++) {
|
|
10
12
|
let stmt = file.statements[i];
|
|
11
|
-
if (!
|
|
13
|
+
if (!isImportDeclaration(stmt)) {
|
|
12
14
|
continue;
|
|
13
15
|
}
|
|
14
16
|
let moduleSpecifier = stmt.moduleSpecifier;
|
|
15
|
-
if (!
|
|
17
|
+
if (!isStringLiteral(moduleSpecifier) || moduleSpecifier.text !== pkg) {
|
|
16
18
|
continue;
|
|
17
19
|
}
|
|
18
|
-
let bindings = stmt.importClause?.namedBindings, declTypeOnly = stmt.importClause?.
|
|
19
|
-
if (bindings &&
|
|
20
|
+
let bindings = stmt.importClause?.namedBindings, declTypeOnly = stmt.importClause?.phaseModifier === SyntaxKind.TypeKeyword, specifiers = new Map(), typeOnly = new Set();
|
|
21
|
+
if (bindings && isNamedImports(bindings)) {
|
|
20
22
|
for (let j = 0, m = bindings.elements.length; j < m; j++) {
|
|
21
23
|
let element = bindings.elements[j], name = element.name.text, propertyName = element.propertyName?.text || name;
|
|
22
24
|
specifiers.set(propertyName, name);
|
|
@@ -25,12 +27,19 @@ const all = (file, pkg) => {
|
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
|
-
imports.push({
|
|
30
|
+
imports.push({
|
|
31
|
+
defaultName: stmt.importClause?.name?.text,
|
|
32
|
+
end: stmt.end,
|
|
33
|
+
namespace: bindings && isNamespaceImport(bindings) ? bindings.name.text : undefined,
|
|
34
|
+
specifiers,
|
|
35
|
+
start: stmt.getStart(file),
|
|
36
|
+
typeOnly
|
|
37
|
+
});
|
|
29
38
|
}
|
|
30
39
|
return imports;
|
|
31
40
|
};
|
|
32
41
|
const includes = (checker, node, pkg, symbolName) => {
|
|
33
|
-
if (!
|
|
42
|
+
if (!isIdentifier(node)) {
|
|
34
43
|
return false;
|
|
35
44
|
}
|
|
36
45
|
if (symbolName && node.text !== symbolName) {
|
|
@@ -55,54 +64,55 @@ const includes = (checker, node, pkg, symbolName) => {
|
|
|
55
64
|
if (names.has(node.text)) {
|
|
56
65
|
let symbol = checker.getSymbolAtLocation(node);
|
|
57
66
|
if (symbol) {
|
|
58
|
-
let declarations = symbol.
|
|
67
|
+
let declarations = symbol.declarations;
|
|
59
68
|
if (declarations && declarations.length > 0) {
|
|
60
69
|
for (let i = 0, n = declarations.length; i < n; i++) {
|
|
61
|
-
let
|
|
62
|
-
if (
|
|
63
|
-
let
|
|
64
|
-
if (
|
|
65
|
-
|
|
66
|
-
|
|
70
|
+
let handle = declarations[i];
|
|
71
|
+
if (handle.kind === SyntaxKind.ImportSpecifier) {
|
|
72
|
+
let decl = handle.resolve();
|
|
73
|
+
if (decl) {
|
|
74
|
+
let importDecl = decl.parent?.parent?.parent;
|
|
75
|
+
if (importDecl && isImportDeclaration(importDecl) && isStringLiteral(importDecl.moduleSpecifier)) {
|
|
76
|
+
if (importDecl.moduleSpecifier.text === pkg) {
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
67
79
|
}
|
|
68
80
|
}
|
|
69
81
|
}
|
|
70
|
-
if (fileNameMatchesPackage(
|
|
82
|
+
if (fileNameMatchesPackage(handle.path, pkg)) {
|
|
71
83
|
return true;
|
|
72
84
|
}
|
|
73
85
|
}
|
|
74
86
|
}
|
|
75
87
|
}
|
|
76
|
-
return
|
|
88
|
+
return false;
|
|
77
89
|
}
|
|
78
90
|
let symbol = checker.getSymbolAtLocation(node);
|
|
79
91
|
if (!symbol) {
|
|
80
92
|
return false;
|
|
81
93
|
}
|
|
82
|
-
let declarations = symbol.
|
|
94
|
+
let declarations = symbol.declarations;
|
|
83
95
|
if (declarations && declarations.length > 0) {
|
|
84
96
|
for (let i = 0, n = declarations.length; i < n; i++) {
|
|
85
|
-
let
|
|
86
|
-
if (fileNameMatchesPackage(
|
|
97
|
+
let handle = declarations[i];
|
|
98
|
+
if (fileNameMatchesPackage(handle.path, pkg)) {
|
|
87
99
|
return true;
|
|
88
100
|
}
|
|
89
101
|
}
|
|
90
102
|
}
|
|
91
|
-
|
|
103
|
+
if ((symbol.flags & SymbolFlags.Alias) !== 0) {
|
|
92
104
|
let aliased = checker.getAliasedSymbol(symbol);
|
|
93
105
|
if (aliased && aliased !== symbol) {
|
|
94
|
-
let aliasedDecls = aliased.
|
|
106
|
+
let aliasedDecls = aliased.declarations;
|
|
95
107
|
if (aliasedDecls) {
|
|
96
108
|
for (let i = 0, n = aliasedDecls.length; i < n; i++) {
|
|
97
|
-
if (fileNameMatchesPackage(aliasedDecls[i].
|
|
109
|
+
if (fileNameMatchesPackage(aliasedDecls[i].path, pkg)) {
|
|
98
110
|
return true;
|
|
99
111
|
}
|
|
100
112
|
}
|
|
101
113
|
}
|
|
102
114
|
}
|
|
103
115
|
}
|
|
104
|
-
catch {
|
|
105
|
-
}
|
|
106
116
|
return false;
|
|
107
117
|
};
|
|
108
118
|
export default { all, includes };
|
|
@@ -2,6 +2,9 @@ export { default as ast } from './ast.js';
|
|
|
2
2
|
export { default as code } from './code.js';
|
|
3
3
|
export { default as coordinator } from './coordinator.js';
|
|
4
4
|
export { default as imports } from './imports.js';
|
|
5
|
+
export { default as languageService } from './language-service.js';
|
|
5
6
|
export { default as plugin } from './plugins/index.js';
|
|
6
7
|
export { default as uid } from './uid.js';
|
|
8
|
+
export type { OffsetAnchor, PositionMapping, SourceMapV3 } from './sourcemap.js';
|
|
9
|
+
export type { ScratchResult, UpdateResult } from './language-service.js';
|
|
7
10
|
export type * from './types.js';
|
package/build/compiler/index.js
CHANGED
|
@@ -2,5 +2,6 @@ export { default as ast } from './ast.js';
|
|
|
2
2
|
export { default as code } from './code.js';
|
|
3
3
|
export { default as coordinator } from './coordinator.js';
|
|
4
4
|
export { default as imports } from './imports.js';
|
|
5
|
+
export { default as languageService } from './language-service.js';
|
|
5
6
|
export { default as plugin } from './plugins/index.js';
|
|
6
7
|
export { default as uid } from './uid.js';
|
|
@@ -1,9 +1,39 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { SourceFile } from 'typescript/unstable/ast';
|
|
2
|
+
import type { FileSystem } from 'typescript/unstable/fs';
|
|
3
|
+
import { API, type Checker, type Program, type Project, type Snapshot } from 'typescript/unstable/sync';
|
|
4
|
+
type ScratchResult = {
|
|
5
|
+
checker: Checker;
|
|
6
|
+
program: Program;
|
|
7
|
+
sourceFile: SourceFile;
|
|
8
|
+
};
|
|
9
|
+
type UpdateResult = {
|
|
10
|
+
checker: Checker;
|
|
11
|
+
program: Program;
|
|
12
|
+
};
|
|
13
|
+
type OpenProject = {
|
|
14
|
+
api: API;
|
|
15
|
+
dispose: () => void;
|
|
16
|
+
project: Project;
|
|
17
|
+
snapshot: Snapshot;
|
|
18
|
+
};
|
|
19
|
+
declare function open(configPath: string, overlay?: FileSystem): OpenProject;
|
|
20
|
+
declare const dispose: (root?: string) => void;
|
|
21
|
+
declare const findConfig: (startDir: string) => string | null;
|
|
22
|
+
declare const invalidate: (configFileName: string, fileName: string) => void;
|
|
23
|
+
declare const parse: (fileName: string, content: string) => SourceFile;
|
|
24
|
+
declare const scratch: (fileName: string, content: string) => ScratchResult;
|
|
25
|
+
declare const update: (configFileName: string, fileName: string, content: string) => UpdateResult;
|
|
26
|
+
declare const updateMany: (configFileName: string, updates: Map<string, string>) => UpdateResult;
|
|
4
27
|
declare const _default: {
|
|
5
|
-
|
|
6
|
-
|
|
28
|
+
dispose: typeof dispose;
|
|
29
|
+
findConfig: typeof findConfig;
|
|
30
|
+
invalidate: typeof invalidate;
|
|
31
|
+
open: typeof open;
|
|
32
|
+
parse: typeof parse;
|
|
33
|
+
scratch: typeof scratch;
|
|
34
|
+
update: typeof update;
|
|
35
|
+
updateMany: typeof updateMany;
|
|
7
36
|
};
|
|
8
37
|
export default _default;
|
|
9
|
-
export { invalidate, update };
|
|
38
|
+
export { dispose, findConfig, invalidate, open, parse, scratch, update, updateMany };
|
|
39
|
+
export type { ScratchResult, UpdateResult };
|