@esportsplus/typescript 0.29.6 → 0.31.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.
- package/README.md +11 -3
- package/bin/tsc-alias +1 -1
- package/build/cli/diagnostics.d.ts +4 -0
- package/build/cli/diagnostics.js +90 -0
- package/build/cli/tsc.d.ts +10 -2
- package/build/cli/tsc.js +352 -51
- 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 +17 -7
- package/build/compiler/coordinator.js +54 -31
- package/build/compiler/imports.d.ts +6 -3
- package/build/compiler/imports.js +26 -23
- package/build/compiler/index.d.ts +3 -0
- package/build/compiler/index.js +1 -0
- package/build/compiler/language-service.d.ts +24 -5
- package/build/compiler/language-service.js +215 -53
- 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 +12 -7
- package/build/compiler/sourcemap.d.ts +50 -0
- package/build/compiler/sourcemap.js +247 -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/ts.d.ts +3 -0
- package/build/ts.js +3 -0
- package/package.json +22 -8
- 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
package/build/compiler/ast.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isIdentifier, isPropertyAccessExpression } from 'typescript/unstable/ast/is';
|
|
2
2
|
const expression = {
|
|
3
3
|
name: (node) => {
|
|
4
|
-
if (
|
|
4
|
+
if (isIdentifier(node)) {
|
|
5
5
|
return node.text;
|
|
6
6
|
}
|
|
7
|
-
if (
|
|
7
|
+
if (isPropertyAccessExpression(node)) {
|
|
8
8
|
return property.path(node);
|
|
9
9
|
}
|
|
10
10
|
return null;
|
|
@@ -22,11 +22,11 @@ const inRange = (ranges, start, end) => {
|
|
|
22
22
|
const property = {
|
|
23
23
|
path: (node) => {
|
|
24
24
|
let current = node, parts = [];
|
|
25
|
-
while (
|
|
25
|
+
while (isPropertyAccessExpression(current)) {
|
|
26
26
|
parts.push(current.name.text);
|
|
27
27
|
current = current.expression;
|
|
28
28
|
}
|
|
29
|
-
if (
|
|
29
|
+
if (isIdentifier(current)) {
|
|
30
30
|
parts.push(current.text);
|
|
31
31
|
return parts.reverse().join('.');
|
|
32
32
|
}
|
|
@@ -37,6 +37,6 @@ const test = (node, fn) => {
|
|
|
37
37
|
if (fn(node)) {
|
|
38
38
|
return true;
|
|
39
39
|
}
|
|
40
|
-
return !!
|
|
40
|
+
return !!node.forEachChild(child => test(child, fn) || undefined);
|
|
41
41
|
};
|
|
42
42
|
export default { expression, inRange, property, test };
|
package/build/compiler/code.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
declare
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
1
|
+
declare function code(literals: TemplateStringsArray, ...values: unknown[]): string;
|
|
2
|
+
declare namespace code {
|
|
3
|
+
var _a: (str: string) => string;
|
|
4
|
+
export { _a as escape };
|
|
5
|
+
}
|
|
5
6
|
export default code;
|
package/build/compiler/code.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
const BACKSLASH_REGEX = /\\/g;
|
|
2
|
+
const CR_REGEX = /\r/g;
|
|
3
|
+
const LINE_SEPARATOR_REGEX = /\u2028/g;
|
|
4
|
+
const NEWLINE_REGEX = /\n/g;
|
|
5
|
+
const PARAGRAPH_SEPARATOR_REGEX = /\u2029/g;
|
|
1
6
|
const SINGLE_QUOTE_REGEX = /'/g;
|
|
2
7
|
const code = (literals, ...values) => {
|
|
3
8
|
let buffer = '';
|
|
@@ -12,6 +17,12 @@ const code = (literals, ...values) => {
|
|
|
12
17
|
return buffer;
|
|
13
18
|
};
|
|
14
19
|
code.escape = (str) => {
|
|
15
|
-
return str
|
|
20
|
+
return str
|
|
21
|
+
.replace(BACKSLASH_REGEX, '\\\\')
|
|
22
|
+
.replace(SINGLE_QUOTE_REGEX, "\\'")
|
|
23
|
+
.replace(NEWLINE_REGEX, '\\n')
|
|
24
|
+
.replace(CR_REGEX, '\\r')
|
|
25
|
+
.replace(LINE_SEPARATOR_REGEX, '\\u2028')
|
|
26
|
+
.replace(PARAGRAPH_SEPARATOR_REGEX, '\\u2029');
|
|
16
27
|
};
|
|
17
28
|
export default code;
|
|
@@ -1,16 +1,26 @@
|
|
|
1
|
+
import type { SourceFile } from 'typescript/unstable/ast';
|
|
2
|
+
import type { Checker, Program } from 'typescript/unstable/sync';
|
|
1
3
|
import type { Plugin, SharedContext } from './types.js';
|
|
2
|
-
import {
|
|
4
|
+
import type { OffsetAnchor, PositionMapping } from './sourcemap.js';
|
|
3
5
|
type CoordinatorResult = {
|
|
4
6
|
changed: boolean;
|
|
5
7
|
code: string;
|
|
6
|
-
|
|
8
|
+
map: PositionMapping;
|
|
9
|
+
sourceFile: SourceFile;
|
|
7
10
|
};
|
|
8
|
-
declare const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
declare const transform: (plugins: Plugin[], code: string, file: SourceFile, project: {
|
|
12
|
+
checker: Checker;
|
|
13
|
+
program: Program;
|
|
14
|
+
}, root: string, shared: SharedContext) => {
|
|
15
|
+
changed: boolean;
|
|
16
|
+
code: string;
|
|
17
|
+
map: {
|
|
18
|
+
generations: OffsetAnchor[][];
|
|
13
19
|
};
|
|
20
|
+
sourceFile: SourceFile;
|
|
21
|
+
};
|
|
22
|
+
declare const _default: {
|
|
23
|
+
transform: typeof transform;
|
|
14
24
|
};
|
|
15
25
|
export default _default;
|
|
16
26
|
export type { CoordinatorResult };
|
|
@@ -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,38 @@ function applyImports(code, file, intents) {
|
|
|
24
26
|
});
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
|
-
let keys = [...merged.keys()];
|
|
29
|
+
let batches = [], keys = [...merged.keys()];
|
|
28
30
|
for (let i = 0, n = keys.length; i < n; i++) {
|
|
29
|
-
code = modify(code, file, keys[i], merged.get(keys[i]));
|
|
31
|
+
let before = code, result = modify(code, file, keys[i], merged.get(keys[i]));
|
|
32
|
+
code = result.code;
|
|
33
|
+
if (result.edits.length > 0) {
|
|
34
|
+
batches.push({ before, edits: result.edits });
|
|
35
|
+
}
|
|
30
36
|
if (i < n - 1) {
|
|
31
|
-
file =
|
|
37
|
+
file = languageService.parse(file.fileName, code);
|
|
32
38
|
}
|
|
33
39
|
}
|
|
34
|
-
return code;
|
|
40
|
+
return { batches, code };
|
|
35
41
|
}
|
|
36
42
|
function applyIntents(code, file, intents) {
|
|
37
43
|
if (intents.length === 0) {
|
|
38
|
-
return code;
|
|
44
|
+
return { code, edits: [] };
|
|
39
45
|
}
|
|
40
|
-
|
|
46
|
+
let edits = intents.map(intent => ({
|
|
41
47
|
end: intent.node.end,
|
|
42
48
|
newText: intent.generate(file),
|
|
43
49
|
start: intent.node.getStart(file)
|
|
44
|
-
}))
|
|
50
|
+
}));
|
|
51
|
+
return { code: replaceReverse(code, edits), edits };
|
|
45
52
|
}
|
|
46
53
|
function applyPrepend(code, file, prepend) {
|
|
47
54
|
if (prepend.length === 0) {
|
|
48
|
-
return code;
|
|
55
|
+
return { code, edits: [] };
|
|
49
56
|
}
|
|
50
57
|
let position = 0;
|
|
51
58
|
for (let i = 0, n = file.statements.length; i < n; i++) {
|
|
52
59
|
let stmt = file.statements[i];
|
|
53
|
-
if (
|
|
60
|
+
if (isImportDeclaration(stmt)) {
|
|
54
61
|
position = stmt.end;
|
|
55
62
|
}
|
|
56
63
|
else {
|
|
@@ -58,9 +65,11 @@ function applyPrepend(code, file, prepend) {
|
|
|
58
65
|
}
|
|
59
66
|
}
|
|
60
67
|
if (position === 0) {
|
|
61
|
-
|
|
68
|
+
let newText = prepend.join('\n') + '\n';
|
|
69
|
+
return { code: newText + code, edits: [{ end: 0, newText, start: 0 }] };
|
|
62
70
|
}
|
|
63
|
-
|
|
71
|
+
let newText = '\n' + prepend.join('\n') + '\n';
|
|
72
|
+
return { code: code.slice(0, position) + newText + code.slice(position), edits: [{ end: position, newText, start: position }] };
|
|
64
73
|
}
|
|
65
74
|
function hasPattern(code, patterns) {
|
|
66
75
|
for (let i = 0, n = patterns.length; i < n; i++) {
|
|
@@ -72,7 +81,7 @@ function hasPattern(code, patterns) {
|
|
|
72
81
|
}
|
|
73
82
|
function modify(code, file, pkg, options) {
|
|
74
83
|
if (!options.add && !options.namespace && !options.remove) {
|
|
75
|
-
return code;
|
|
84
|
+
return { code, edits: [] };
|
|
76
85
|
}
|
|
77
86
|
let { namespace } = options, add = options.add ? new Set(options.add) : null, found = imports.all(file, pkg);
|
|
78
87
|
if (found.length === 0) {
|
|
@@ -84,9 +93,10 @@ 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
101
|
let remove = options.remove ? new Set(options.remove) : null, specifiers = new Set();
|
|
92
102
|
for (let i = 0, n = found.length; i < n; i++) {
|
|
@@ -117,7 +127,7 @@ function modify(code, file, pkg, options) {
|
|
|
117
127
|
start: found[i].start
|
|
118
128
|
});
|
|
119
129
|
}
|
|
120
|
-
return replaceReverse(code, replacements);
|
|
130
|
+
return { code: replaceReverse(code, replacements), edits: replacements };
|
|
121
131
|
}
|
|
122
132
|
function replaceReverse(code, replacements) {
|
|
123
133
|
if (replacements.length === 0) {
|
|
@@ -138,53 +148,66 @@ function replaceReverse(code, replacements) {
|
|
|
138
148
|
}
|
|
139
149
|
return parts.reverse().join('');
|
|
140
150
|
}
|
|
141
|
-
const transform = (plugins, code, file,
|
|
151
|
+
const transform = (plugins, code, file, project, root, shared) => {
|
|
142
152
|
if (plugins.length === 0) {
|
|
143
|
-
return { changed: false, code, sourceFile: file };
|
|
153
|
+
return { changed: false, code, map: { generations: [] }, sourceFile: file };
|
|
144
154
|
}
|
|
145
|
-
|
|
155
|
+
uid.scope(root, file.fileName, code);
|
|
156
|
+
let changed = false, currentCode = code, currentFile = file, currentProject = project, fileName = file.fileName, generations = [], last = plugins.length - 1;
|
|
146
157
|
for (let i = 0, n = plugins.length; i < n; i++) {
|
|
147
158
|
let plugin = plugins[i];
|
|
148
159
|
if (plugin.patterns && !hasPattern(currentCode, plugin.patterns)) {
|
|
149
160
|
continue;
|
|
150
161
|
}
|
|
151
162
|
let { imports, prepend, replacements } = plugin.transform({
|
|
152
|
-
checker:
|
|
163
|
+
checker: currentProject.checker,
|
|
153
164
|
code: currentCode,
|
|
154
|
-
program:
|
|
165
|
+
program: currentProject.program,
|
|
155
166
|
shared,
|
|
156
167
|
sourceFile: currentFile
|
|
157
168
|
}), pluginChanged = false;
|
|
158
169
|
if (replacements?.length) {
|
|
159
|
-
currentCode = applyIntents(currentCode, currentFile, replacements);
|
|
170
|
+
let before = currentCode, result = applyIntents(currentCode, currentFile, replacements);
|
|
171
|
+
if (result.edits.length > 0) {
|
|
172
|
+
generations.push(sourcemap.buildGeneration(before, result.edits));
|
|
173
|
+
}
|
|
174
|
+
currentCode = result.code;
|
|
160
175
|
pluginChanged = true;
|
|
161
176
|
}
|
|
162
177
|
if (prepend?.length) {
|
|
163
178
|
if (pluginChanged) {
|
|
164
|
-
currentFile =
|
|
179
|
+
currentFile = languageService.parse(fileName, currentCode);
|
|
180
|
+
}
|
|
181
|
+
let before = currentCode, result = applyPrepend(currentCode, currentFile, prepend);
|
|
182
|
+
if (result.edits.length > 0) {
|
|
183
|
+
generations.push(sourcemap.buildGeneration(before, result.edits));
|
|
165
184
|
}
|
|
166
|
-
currentCode =
|
|
185
|
+
currentCode = result.code;
|
|
167
186
|
pluginChanged = true;
|
|
168
187
|
}
|
|
169
188
|
if (imports?.length) {
|
|
170
189
|
if (pluginChanged) {
|
|
171
|
-
currentFile =
|
|
190
|
+
currentFile = languageService.parse(fileName, currentCode);
|
|
191
|
+
}
|
|
192
|
+
let result = applyImports(currentCode, currentFile, imports);
|
|
193
|
+
for (let j = 0, m = result.batches.length; j < m; j++) {
|
|
194
|
+
generations.push(sourcemap.buildGeneration(result.batches[j].before, result.batches[j].edits));
|
|
172
195
|
}
|
|
173
|
-
currentCode =
|
|
196
|
+
currentCode = result.code;
|
|
174
197
|
pluginChanged = true;
|
|
175
198
|
}
|
|
176
199
|
if (pluginChanged) {
|
|
177
200
|
changed = true;
|
|
178
201
|
if (i < last) {
|
|
179
|
-
|
|
180
|
-
currentFile =
|
|
181
|
-
|
|
202
|
+
currentProject = languageService.update(root, fileName, currentCode);
|
|
203
|
+
currentFile = currentProject.program.getSourceFile(fileName) ??
|
|
204
|
+
languageService.parse(fileName, currentCode);
|
|
182
205
|
}
|
|
183
206
|
else {
|
|
184
|
-
currentFile =
|
|
207
|
+
currentFile = languageService.parse(fileName, currentCode);
|
|
185
208
|
}
|
|
186
209
|
}
|
|
187
210
|
}
|
|
188
|
-
return { changed, code: currentCode, sourceFile: currentFile };
|
|
211
|
+
return { changed, code: currentCode, map: { generations }, sourceFile: currentFile };
|
|
189
212
|
};
|
|
190
213
|
export default { transform };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Node, SourceFile } from 'typescript/unstable/ast';
|
|
2
|
+
import type { Checker } from 'typescript/unstable/sync';
|
|
2
3
|
type ImportInfo = {
|
|
3
4
|
end: number;
|
|
4
5
|
specifiers: Map<string, string>;
|
|
@@ -10,9 +11,11 @@ type ModifyOptions = {
|
|
|
10
11
|
namespace?: string;
|
|
11
12
|
remove?: Iterable<string>;
|
|
12
13
|
};
|
|
14
|
+
declare const all: (file: SourceFile, pkg: string) => ImportInfo[];
|
|
15
|
+
declare const includes: (checker: Checker, node: Node, pkg: string, symbolName?: string) => boolean;
|
|
13
16
|
declare const _default: {
|
|
14
|
-
all:
|
|
15
|
-
includes:
|
|
17
|
+
all: typeof all;
|
|
18
|
+
includes: typeof includes;
|
|
16
19
|
};
|
|
17
20
|
export default _default;
|
|
18
21
|
export type { ImportInfo, ModifyOptions };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SyntaxKind } from 'typescript/unstable/ast';
|
|
2
|
+
import { isIdentifier, isImportDeclaration, isNamedImports, 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);
|
|
@@ -30,7 +32,7 @@ const all = (file, pkg) => {
|
|
|
30
32
|
return imports;
|
|
31
33
|
};
|
|
32
34
|
const includes = (checker, node, pkg, symbolName) => {
|
|
33
|
-
if (!
|
|
35
|
+
if (!isIdentifier(node)) {
|
|
34
36
|
return false;
|
|
35
37
|
}
|
|
36
38
|
if (symbolName && node.text !== symbolName) {
|
|
@@ -55,54 +57,55 @@ const includes = (checker, node, pkg, symbolName) => {
|
|
|
55
57
|
if (names.has(node.text)) {
|
|
56
58
|
let symbol = checker.getSymbolAtLocation(node);
|
|
57
59
|
if (symbol) {
|
|
58
|
-
let declarations = symbol.
|
|
60
|
+
let declarations = symbol.declarations;
|
|
59
61
|
if (declarations && declarations.length > 0) {
|
|
60
62
|
for (let i = 0, n = declarations.length; i < n; i++) {
|
|
61
|
-
let
|
|
62
|
-
if (
|
|
63
|
-
let
|
|
64
|
-
if (
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
let handle = declarations[i];
|
|
64
|
+
if (handle.kind === SyntaxKind.ImportSpecifier) {
|
|
65
|
+
let decl = handle.resolve();
|
|
66
|
+
if (decl) {
|
|
67
|
+
let importDecl = decl.parent?.parent?.parent;
|
|
68
|
+
if (importDecl && isImportDeclaration(importDecl) && isStringLiteral(importDecl.moduleSpecifier)) {
|
|
69
|
+
if (importDecl.moduleSpecifier.text === pkg) {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
67
72
|
}
|
|
68
73
|
}
|
|
69
74
|
}
|
|
70
|
-
if (fileNameMatchesPackage(
|
|
75
|
+
if (fileNameMatchesPackage(handle.path, pkg)) {
|
|
71
76
|
return true;
|
|
72
77
|
}
|
|
73
78
|
}
|
|
74
79
|
}
|
|
75
80
|
}
|
|
76
|
-
return
|
|
81
|
+
return false;
|
|
77
82
|
}
|
|
78
83
|
let symbol = checker.getSymbolAtLocation(node);
|
|
79
84
|
if (!symbol) {
|
|
80
85
|
return false;
|
|
81
86
|
}
|
|
82
|
-
let declarations = symbol.
|
|
87
|
+
let declarations = symbol.declarations;
|
|
83
88
|
if (declarations && declarations.length > 0) {
|
|
84
89
|
for (let i = 0, n = declarations.length; i < n; i++) {
|
|
85
|
-
let
|
|
86
|
-
if (fileNameMatchesPackage(
|
|
90
|
+
let handle = declarations[i];
|
|
91
|
+
if (fileNameMatchesPackage(handle.path, pkg)) {
|
|
87
92
|
return true;
|
|
88
93
|
}
|
|
89
94
|
}
|
|
90
95
|
}
|
|
91
|
-
|
|
96
|
+
if ((symbol.flags & SymbolFlags.Alias) !== 0) {
|
|
92
97
|
let aliased = checker.getAliasedSymbol(symbol);
|
|
93
98
|
if (aliased && aliased !== symbol) {
|
|
94
|
-
let aliasedDecls = aliased.
|
|
99
|
+
let aliasedDecls = aliased.declarations;
|
|
95
100
|
if (aliasedDecls) {
|
|
96
101
|
for (let i = 0, n = aliasedDecls.length; i < n; i++) {
|
|
97
|
-
if (fileNameMatchesPackage(aliasedDecls[i].
|
|
102
|
+
if (fileNameMatchesPackage(aliasedDecls[i].path, pkg)) {
|
|
98
103
|
return true;
|
|
99
104
|
}
|
|
100
105
|
}
|
|
101
106
|
}
|
|
102
107
|
}
|
|
103
108
|
}
|
|
104
|
-
catch {
|
|
105
|
-
}
|
|
106
109
|
return false;
|
|
107
110
|
};
|
|
108
111
|
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,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { SourceFile } from 'typescript/unstable/ast';
|
|
2
|
+
import { type Checker, type Program } from 'typescript/unstable/sync';
|
|
3
|
+
type ScratchResult = {
|
|
4
|
+
checker: Checker;
|
|
5
|
+
program: Program;
|
|
6
|
+
sourceFile: SourceFile;
|
|
7
|
+
};
|
|
8
|
+
type UpdateResult = {
|
|
9
|
+
checker: Checker;
|
|
10
|
+
program: Program;
|
|
11
|
+
};
|
|
12
|
+
declare const dispose: (root?: string) => void;
|
|
13
|
+
declare const findConfig: (startDir: string) => string | null;
|
|
2
14
|
declare const invalidate: (root: string, fileName: string) => void;
|
|
3
|
-
declare const
|
|
15
|
+
declare const parse: (fileName: string, content: string) => SourceFile;
|
|
16
|
+
declare const scratch: (fileName: string, content: string) => ScratchResult;
|
|
17
|
+
declare const update: (root: string, fileName: string, content: string) => UpdateResult;
|
|
4
18
|
declare const _default: {
|
|
5
|
-
|
|
6
|
-
|
|
19
|
+
dispose: typeof dispose;
|
|
20
|
+
findConfig: typeof findConfig;
|
|
21
|
+
invalidate: typeof invalidate;
|
|
22
|
+
parse: typeof parse;
|
|
23
|
+
scratch: typeof scratch;
|
|
24
|
+
update: typeof update;
|
|
7
25
|
};
|
|
8
26
|
export default _default;
|
|
9
|
-
export { invalidate, update };
|
|
27
|
+
export { dispose, findConfig, invalidate, parse, scratch, update };
|
|
28
|
+
export type { ScratchResult, UpdateResult };
|