@tslite/services 0.0.0-stage → 1.12.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/LICENSE +55 -0
- package/NOTICE +13 -0
- package/dist/_namespaces/edit.d.ts +8 -0
- package/dist/_namespaces/edit.js +11 -0
- package/dist/_namespaces/ts.Completions.StringCompletions.d.ts +1 -0
- package/dist/_namespaces/ts.Completions.StringCompletions.js +2 -0
- package/dist/_namespaces/ts.Completions.d.ts +2 -0
- package/dist/_namespaces/ts.Completions.js +3 -0
- package/dist/_namespaces/ts.FindAllReferences.d.ts +2 -0
- package/dist/_namespaces/ts.FindAllReferences.js +3 -0
- package/dist/_namespaces/ts.GoToDefinition.d.ts +1 -0
- package/dist/_namespaces/ts.GoToDefinition.js +2 -0
- package/dist/_namespaces/ts.NavigationBar.d.ts +1 -0
- package/dist/_namespaces/ts.NavigationBar.js +2 -0
- package/dist/_namespaces/ts.OrganizeImports.d.ts +1 -0
- package/dist/_namespaces/ts.OrganizeImports.js +2 -0
- package/dist/_namespaces/ts.OutliningElementsCollector.d.ts +1 -0
- package/dist/_namespaces/ts.OutliningElementsCollector.js +2 -0
- package/dist/_namespaces/ts.Rename.d.ts +1 -0
- package/dist/_namespaces/ts.Rename.js +2 -0
- package/dist/_namespaces/ts.SignatureHelp.d.ts +1 -0
- package/dist/_namespaces/ts.SignatureHelp.js +2 -0
- package/dist/_namespaces/ts.SmartSelectionRange.d.ts +1 -0
- package/dist/_namespaces/ts.SmartSelectionRange.js +2 -0
- package/dist/_namespaces/ts.SymbolDisplay.d.ts +1 -0
- package/dist/_namespaces/ts.SymbolDisplay.js +2 -0
- package/dist/_namespaces/ts.codefix.d.ts +26 -0
- package/dist/_namespaces/ts.codefix.js +27 -0
- package/dist/_namespaces/ts.d.ts +17 -0
- package/dist/_namespaces/ts.formatting.d.ts +7 -0
- package/dist/_namespaces/ts.formatting.js +8 -0
- package/dist/_namespaces/ts.js +20 -0
- package/dist/_namespaces/ts.refactor.addOrRemoveBracesToArrowFunction.d.ts +1 -0
- package/dist/_namespaces/ts.refactor.addOrRemoveBracesToArrowFunction.js +2 -0
- package/dist/_namespaces/ts.refactor.convertParamsToDestructuredObject.d.ts +1 -0
- package/dist/_namespaces/ts.refactor.convertParamsToDestructuredObject.js +2 -0
- package/dist/_namespaces/ts.refactor.convertStringOrTemplateLiteral.d.ts +1 -0
- package/dist/_namespaces/ts.refactor.convertStringOrTemplateLiteral.js +2 -0
- package/dist/_namespaces/ts.refactor.d.ts +9 -0
- package/dist/_namespaces/ts.refactor.extractSymbol.d.ts +1 -0
- package/dist/_namespaces/ts.refactor.extractSymbol.js +2 -0
- package/dist/_namespaces/ts.refactor.js +10 -0
- package/dist/_namespaces/ts.textChanges.d.ts +1 -0
- package/dist/_namespaces/ts.textChanges.js +2 -0
- package/dist/classifier.d.ts +5 -0
- package/dist/classifier.js +439 -0
- package/dist/codeFixProvider.d.ts +13 -0
- package/dist/codeFixProvider.js +84 -0
- package/dist/codefixes/addConvertToUnknownForNonOverlappingTypes.d.ts +1 -0
- package/dist/codefixes/addConvertToUnknownForNonOverlappingTypes.js +21 -0
- package/dist/codefixes/addEmptyExportDeclaration.d.ts +1 -0
- package/dist/codefixes/addEmptyExportDeclaration.js +17 -0
- package/dist/codefixes/addMissingAsync.d.ts +1 -0
- package/dist/codefixes/addMissingAsync.js +75 -0
- package/dist/codefixes/addMissingAwait.d.ts +1 -0
- package/dist/codefixes/addMissingAwait.js +236 -0
- package/dist/codefixes/addMissingConst.d.ts +1 -0
- package/dist/codefixes/addMissingConst.js +91 -0
- package/dist/codefixes/addNameToNamelessParameter.d.ts +1 -0
- package/dist/codefixes/addNameToNamelessParameter.js +29 -0
- package/dist/codefixes/convertConstToLet.d.ts +1 -0
- package/dist/codefixes/convertConstToLet.js +30 -0
- package/dist/codefixes/convertToAsyncFunction.d.ts +1 -0
- package/dist/codefixes/convertToAsyncFunction.js +495 -0
- package/dist/codefixes/convertToMappedObjectType.d.ts +1 -0
- package/dist/codefixes/convertToMappedObjectType.js +48 -0
- package/dist/codefixes/correctQualifiedNameToIndexedAccessType.d.ts +1 -0
- package/dist/codefixes/correctQualifiedNameToIndexedAccessType.js +33 -0
- package/dist/codefixes/fixAddModuleReferTypeMissingTypeof.d.ts +1 -0
- package/dist/codefixes/fixAddModuleReferTypeMissingTypeof.js +27 -0
- package/dist/codefixes/fixAwaitInSyncFunction.d.ts +1 -0
- package/dist/codefixes/fixAwaitInSyncFunction.js +69 -0
- package/dist/codefixes/fixExpectedComma.d.ts +1 -0
- package/dist/codefixes/fixExpectedComma.js +35 -0
- package/dist/codefixes/fixInvalidJsxCharacters.d.ts +1 -0
- package/dist/codefixes/fixInvalidJsxCharacters.js +41 -0
- package/dist/codefixes/fixMissingCallParentheses.d.ts +1 -0
- package/dist/codefixes/fixMissingCallParentheses.js +42 -0
- package/dist/codefixes/fixSpelling.d.ts +1 -0
- package/dist/codefixes/fixSpelling.js +94 -0
- package/dist/codefixes/fixUnreachableCode.d.ts +1 -0
- package/dist/codefixes/fixUnreachableCode.js +65 -0
- package/dist/codefixes/fixUnusedIdentifier.d.ts +1 -0
- package/dist/codefixes/fixUnusedIdentifier.js +224 -0
- package/dist/codefixes/helpers.d.ts +8 -0
- package/dist/codefixes/helpers.js +53 -0
- package/dist/codefixes/importFixes.d.ts +14 -0
- package/dist/codefixes/importFixes.js +441 -0
- package/dist/codefixes/inferFromUsage.d.ts +1 -0
- package/dist/codefixes/inferFromUsage.js +742 -0
- package/dist/codefixes/removeUnnecessaryAwait.d.ts +1 -0
- package/dist/codefixes/removeUnnecessaryAwait.js +41 -0
- package/dist/codefixes/returnValueCorrect.d.ts +1 -0
- package/dist/codefixes/returnValueCorrect.js +132 -0
- package/dist/codefixes/splitTypeOnlyImport.d.ts +1 -0
- package/dist/codefixes/splitTypeOnlyImport.js +32 -0
- package/dist/codefixes/useBigintLiteral.d.ts +1 -0
- package/dist/codefixes/useBigintLiteral.js +29 -0
- package/dist/completions.d.ts +83 -0
- package/dist/completions.js +1720 -0
- package/dist/documentHighlights.d.ts +8 -0
- package/dist/documentHighlights.js +367 -0
- package/dist/documentRegistry.d.ts +36 -0
- package/dist/documentRegistry.js +63 -0
- package/dist/editingServices.d.ts +1 -0
- package/dist/editingServices.js +4 -0
- package/dist/findAllReferences.d.ts +113 -0
- package/dist/findAllReferences.js +1366 -0
- package/dist/formatting/formatting.d.ts +26 -0
- package/dist/formatting/formatting.js +1021 -0
- package/dist/formatting/formattingContext.d.ts +34 -0
- package/dist/formatting/formattingContext.js +78 -0
- package/dist/formatting/formattingScanner.d.ts +14 -0
- package/dist/formatting/formattingScanner.js +228 -0
- package/dist/formatting/rule.d.ts +31 -0
- package/dist/formatting/rule.js +22 -0
- package/dist/formatting/rules.d.ts +7 -0
- package/dist/formatting/rules.js +610 -0
- package/dist/formatting/rulesMap.d.ts +5 -0
- package/dist/formatting/rulesMap.js +127 -0
- package/dist/formatting/smartIndenter.d.ts +44 -0
- package/dist/formatting/smartIndenter.js +518 -0
- package/dist/getEditsForFileRename.d.ts +6 -0
- package/dist/getEditsForFileRename.js +86 -0
- package/dist/goToDefinition.d.ts +8 -0
- package/dist/goToDefinition.js +246 -0
- package/dist/importTracker.d.ts +50 -0
- package/dist/importTracker.js +422 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -0
- package/dist/navigationBar.d.ts +3 -0
- package/dist/navigationBar.js +549 -0
- package/dist/organizeImports.d.ts +18 -0
- package/dist/organizeImports.js +290 -0
- package/dist/outliningElementsCollector.d.ts +2 -0
- package/dist/outliningElementsCollector.js +261 -0
- package/dist/refactorProvider.d.ts +5 -0
- package/dist/refactorProvider.js +16 -0
- package/dist/refactors/addOrRemoveBracesToArrowFunction.d.ts +1 -0
- package/dist/refactors/addOrRemoveBracesToArrowFunction.js +86 -0
- package/dist/refactors/convertExport.d.ts +1 -0
- package/dist/refactors/convertExport.js +126 -0
- package/dist/refactors/convertImport.d.ts +1 -0
- package/dist/refactors/convertImport.js +116 -0
- package/dist/refactors/convertParamsToDestructuredObject.d.ts +1 -0
- package/dist/refactors/convertParamsToDestructuredObject.js +282 -0
- package/dist/refactors/convertStringOrTemplateLiteral.d.ts +1 -0
- package/dist/refactors/convertStringOrTemplateLiteral.js +148 -0
- package/dist/refactors/extractSymbol.d.ts +60 -0
- package/dist/refactors/extractSymbol.js +1281 -0
- package/dist/refactors/extractType.d.ts +1 -0
- package/dist/refactors/extractType.js +102 -0
- package/dist/refactors/moveToNewFile.d.ts +1 -0
- package/dist/refactors/moveToNewFile.js +477 -0
- package/dist/rename.d.ts +2 -0
- package/dist/rename.js +100 -0
- package/dist/services.d.ts +48 -0
- package/dist/services.js +1480 -0
- package/dist/signatureHelp.d.ts +8 -0
- package/dist/signatureHelp.js +414 -0
- package/dist/smartSelection.d.ts +2 -0
- package/dist/smartSelection.js +243 -0
- package/dist/stringCompletions.d.ts +4 -0
- package/dist/stringCompletions.js +220 -0
- package/dist/suggestionDiagnostics.d.ts +6 -0
- package/dist/suggestionDiagnostics.js +92 -0
- package/dist/symbolDisplay.d.ts +16 -0
- package/dist/symbolDisplay.js +400 -0
- package/dist/textChanges.d.ts +161 -0
- package/dist/textChanges.js +1163 -0
- package/dist/types.d.ts +908 -0
- package/dist/types.js +263 -0
- package/dist/utilities.d.ts +283 -0
- package/dist/utilities.js +1981 -0
- package/package.json +45 -3
- package/README.md +0 -3
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
// Modificado de microsoft/TypeScript v3.9.10, src/services/importTracker.ts: o namespace virou módulo ES, com os imports explícitos.
|
|
2
|
+
import { Debug, InternalSymbolName, ModifierFlags, SymbolFlags, SyntaxKind, cast, createMap, forEach, getFirstIdentifier, getSourceFileOfNode, getSymbolId, hasModifier, importFromModuleSpecifier, isBindingElement, isCatchClause, isDefaultImport, isExportAssignment, isExportDeclaration, isExportSpecifier, isExternalModuleSymbol, isImportTypeNode, isNamedExports, isSourceFile, isStringLiteral, isVariableDeclaration, isVariableStatement, nodeSeenTracker, symbolEscapedNameNoDefault, symbolName, walkUpBindingElementsAndPatterns, } from "./_namespaces/ts.js";
|
|
3
|
+
/** Creates the imports map and returns an ImportTracker that uses it. Call this lazily to avoid calling `getDirectImportsMap` unnecessarily. */
|
|
4
|
+
export function createImportTracker(sourceFiles, sourceFilesSet, checker, cancellationToken) {
|
|
5
|
+
const allDirectImports = getDirectImportsMap(sourceFiles, checker, cancellationToken);
|
|
6
|
+
return (exportSymbol, exportInfo, isForRename) => {
|
|
7
|
+
const { directImports, indirectUsers } = getImportersForExport(sourceFiles, sourceFilesSet, allDirectImports, exportInfo, checker, cancellationToken);
|
|
8
|
+
return { indirectUsers, ...getSearchesFromDirectImports(directImports, exportSymbol, exportInfo.exportKind, checker, isForRename) };
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/** Na tag, também o `export =` (CK-03). */
|
|
12
|
+
export var ExportKind;
|
|
13
|
+
(function (ExportKind) {
|
|
14
|
+
ExportKind[ExportKind["Named"] = 0] = "Named";
|
|
15
|
+
ExportKind[ExportKind["Default"] = 1] = "Default";
|
|
16
|
+
})(ExportKind || (ExportKind = {}));
|
|
17
|
+
export var ImportExport;
|
|
18
|
+
(function (ImportExport) {
|
|
19
|
+
ImportExport[ImportExport["Import"] = 0] = "Import";
|
|
20
|
+
ImportExport[ImportExport["Export"] = 1] = "Export";
|
|
21
|
+
})(ImportExport || (ImportExport = {}));
|
|
22
|
+
/**
|
|
23
|
+
* Returns import statements that directly reference the exporting module, and a list of files that may access the module through a namespace.
|
|
24
|
+
* Na tag, o módulo com `export as namespace` (UMD) era acessível de todo arquivo (CK-03).
|
|
25
|
+
*/
|
|
26
|
+
function getImportersForExport(_sourceFiles, _sourceFilesSet, allDirectImports, { exportingModuleSymbol }, checker, cancellationToken) {
|
|
27
|
+
const markSeenDirectImport = nodeSeenTracker();
|
|
28
|
+
const markSeenIndirectUser = nodeSeenTracker();
|
|
29
|
+
const directImports = [];
|
|
30
|
+
const indirectUserDeclarations = [];
|
|
31
|
+
handleDirectImports(exportingModuleSymbol);
|
|
32
|
+
return { directImports, indirectUsers: getIndirectUsers() };
|
|
33
|
+
function getIndirectUsers() {
|
|
34
|
+
// Na tag, o `declare module "x"` que aumentava o módulo usava os exports dele sem importá-lo (CK-02); e o módulo
|
|
35
|
+
// com `export as namespace` era acessível de todo arquivo (CK-03).
|
|
36
|
+
// This may return duplicates (if there are multiple module declarations in a single source file, all importing the same thing as a namespace), but `State.markSearchedSymbol` will handle that.
|
|
37
|
+
return indirectUserDeclarations.map(getSourceFileOfNode);
|
|
38
|
+
}
|
|
39
|
+
function handleDirectImports(exportingModuleSymbol) {
|
|
40
|
+
const theseDirectImports = getDirectImports(exportingModuleSymbol);
|
|
41
|
+
if (theseDirectImports) {
|
|
42
|
+
for (const direct of theseDirectImports) {
|
|
43
|
+
if (!markSeenDirectImport(direct)) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (cancellationToken)
|
|
47
|
+
cancellationToken.throwIfCancellationRequested();
|
|
48
|
+
switch (direct.kind) {
|
|
49
|
+
case SyntaxKind.CallExpression:
|
|
50
|
+
// Na tag, o `const x = require("y")` de um `export =` era um import direto (CK-03).
|
|
51
|
+
// Don't support re-exporting 'require()' calls, so just add a single indirect user.
|
|
52
|
+
addIndirectUser(direct.getSourceFile());
|
|
53
|
+
break;
|
|
54
|
+
case SyntaxKind.Identifier: // o `const x = require("y")`
|
|
55
|
+
break;
|
|
56
|
+
// Na tag, também o `import x = require("y")` (CK-03).
|
|
57
|
+
case SyntaxKind.ImportDeclaration:
|
|
58
|
+
directImports.push(direct);
|
|
59
|
+
const namedBindings = direct.importClause && direct.importClause.namedBindings;
|
|
60
|
+
if (namedBindings && namedBindings.kind === SyntaxKind.NamespaceImport) {
|
|
61
|
+
handleNamespaceImport(direct, namedBindings.name, /*isReExport*/ false);
|
|
62
|
+
}
|
|
63
|
+
else if (isDefaultImport(direct)) {
|
|
64
|
+
addIndirectUser(getSourceFileLikeForImportDeclaration(direct)); // Add a check for indirect uses to handle synthetic default imports
|
|
65
|
+
}
|
|
66
|
+
break;
|
|
67
|
+
case SyntaxKind.ExportDeclaration:
|
|
68
|
+
if (!direct.exportClause) {
|
|
69
|
+
// This is `export * from "foo"`, so imports of this module may import the export too.
|
|
70
|
+
handleDirectImports(getContainingModuleSymbol(direct, checker));
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
// This is `export { foo } from "foo"` and creates an alias symbol, so recursive search will get handle re-exports.
|
|
74
|
+
directImports.push(direct);
|
|
75
|
+
}
|
|
76
|
+
break;
|
|
77
|
+
case SyntaxKind.ImportType:
|
|
78
|
+
directImports.push(direct);
|
|
79
|
+
break;
|
|
80
|
+
default:
|
|
81
|
+
Debug.failBadSyntaxKind(direct, "Unexpected import kind.");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/** Na tag, o import de namespace de um `export =` era um import direto (CK-03). */
|
|
87
|
+
function handleNamespaceImport(importDeclaration, name, isReExport) {
|
|
88
|
+
const sourceFileLike = getSourceFileLikeForImportDeclaration(importDeclaration);
|
|
89
|
+
Debug.assert(sourceFileLike.kind === SyntaxKind.SourceFile);
|
|
90
|
+
if (isReExport || findNamespaceReExports(sourceFileLike, name, checker)) {
|
|
91
|
+
addIndirectUsers(sourceFileLike);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
addIndirectUser(sourceFileLike);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function addIndirectUser(sourceFileLike) {
|
|
98
|
+
const isNew = markSeenIndirectUser(sourceFileLike);
|
|
99
|
+
if (isNew) {
|
|
100
|
+
indirectUserDeclarations.push(sourceFileLike);
|
|
101
|
+
}
|
|
102
|
+
return isNew;
|
|
103
|
+
}
|
|
104
|
+
/** Adds a module and all of its transitive dependencies as possible indirect users. */
|
|
105
|
+
function addIndirectUsers(sourceFileLike) {
|
|
106
|
+
if (!addIndirectUser(sourceFileLike)) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const moduleSymbol = checker.getMergedSymbol(sourceFileLike.symbol);
|
|
110
|
+
Debug.assert(!!(moduleSymbol.flags & SymbolFlags.Module));
|
|
111
|
+
const directImports = getDirectImports(moduleSymbol);
|
|
112
|
+
if (directImports) {
|
|
113
|
+
for (const directImport of directImports) {
|
|
114
|
+
if (!isImportTypeNode(directImport)) {
|
|
115
|
+
addIndirectUsers(getSourceFileLikeForImportDeclaration(directImport));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function getDirectImports(moduleSymbol) {
|
|
121
|
+
return allDirectImports.get(getSymbolId(moduleSymbol).toString());
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Given the set of direct imports of a module, we need to find which ones import the particular exported symbol.
|
|
126
|
+
* The returned `importSearches` will result in the entire source file being searched.
|
|
127
|
+
* But re-exports will be placed in 'singleReferences' since they cannot be locally referenced.
|
|
128
|
+
* Na tag, o import de namespace (e o `import x = require()`) de um `export =` era também uma busca (o
|
|
129
|
+
* `handleNamespaceImportLike`, CK-03).
|
|
130
|
+
*/
|
|
131
|
+
function getSearchesFromDirectImports(directImports, exportSymbol, exportKind, checker, isForRename) {
|
|
132
|
+
const importSearches = [];
|
|
133
|
+
const singleReferences = [];
|
|
134
|
+
function addSearch(location, symbol) {
|
|
135
|
+
importSearches.push([location, symbol]);
|
|
136
|
+
}
|
|
137
|
+
if (directImports) {
|
|
138
|
+
for (const decl of directImports) {
|
|
139
|
+
handleImport(decl);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return { importSearches, singleReferences };
|
|
143
|
+
function handleImport(decl) {
|
|
144
|
+
if (decl.kind === SyntaxKind.Identifier) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (decl.kind === SyntaxKind.ImportType) {
|
|
148
|
+
if (decl.qualifier) {
|
|
149
|
+
const firstIdentifier = getFirstIdentifier(decl.qualifier);
|
|
150
|
+
if (firstIdentifier.escapedText === symbolName(exportSymbol)) {
|
|
151
|
+
singleReferences.push(firstIdentifier);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
// Ignore if there's a grammar error
|
|
157
|
+
if (decl.moduleSpecifier.kind !== SyntaxKind.StringLiteral) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (decl.kind === SyntaxKind.ExportDeclaration) {
|
|
161
|
+
if (decl.exportClause && isNamedExports(decl.exportClause)) {
|
|
162
|
+
searchForNamedImport(decl.exportClause);
|
|
163
|
+
}
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const { name, namedBindings } = decl.importClause || { name: undefined, namedBindings: undefined };
|
|
167
|
+
if (namedBindings) {
|
|
168
|
+
switch (namedBindings.kind) {
|
|
169
|
+
case SyntaxKind.NamespaceImport:
|
|
170
|
+
break;
|
|
171
|
+
case SyntaxKind.NamedImports:
|
|
172
|
+
// 'default' might be accessed as a named import `{ default as foo }`.
|
|
173
|
+
if (exportKind === 0 /* ExportKind.Named */ || exportKind === 1 /* ExportKind.Default */) {
|
|
174
|
+
searchForNamedImport(namedBindings);
|
|
175
|
+
}
|
|
176
|
+
break;
|
|
177
|
+
default:
|
|
178
|
+
Debug.assertNever(namedBindings);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
// If a default import has the same name as the default export, allow to rename it.
|
|
182
|
+
// Given `import f` and `export default function f`, we will rename both, but for `import g` we will rename just that.
|
|
183
|
+
if (name && exportKind === 1 /* ExportKind.Default */ && (!isForRename || name.escapedText === symbolEscapedNameNoDefault(exportSymbol))) {
|
|
184
|
+
const defaultImportAlias = checker.getSymbolAtLocation(name);
|
|
185
|
+
addSearch(name, defaultImportAlias);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
function searchForNamedImport(namedBindings) {
|
|
189
|
+
if (!namedBindings) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
for (const element of namedBindings.elements) {
|
|
193
|
+
const { name, propertyName } = element;
|
|
194
|
+
if (!isNameMatch((propertyName || name).escapedText)) {
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
if (propertyName) {
|
|
198
|
+
// This is `import { foo as bar } from "./a"` or `export { foo as bar } from "./a"`. `foo` isn't a local in the file, so just add it as a single reference.
|
|
199
|
+
singleReferences.push(propertyName);
|
|
200
|
+
// If renaming `{ foo as bar }`, don't touch `bar`, just `foo`.
|
|
201
|
+
// But do rename `foo` in ` { default as foo }` if that's the original export name.
|
|
202
|
+
if (!isForRename || name.escapedText === exportSymbol.escapedName) {
|
|
203
|
+
// Search locally for `bar`.
|
|
204
|
+
addSearch(name, checker.getSymbolAtLocation(name));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
const localSymbol = element.kind === SyntaxKind.ExportSpecifier && element.propertyName
|
|
209
|
+
? checker.getExportSpecifierLocalTargetSymbol(element) // For re-exporting under a different name, we want to get the re-exported symbol.
|
|
210
|
+
: checker.getSymbolAtLocation(name);
|
|
211
|
+
addSearch(name, localSymbol);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
function isNameMatch(name) {
|
|
216
|
+
return name === exportSymbol.escapedName || exportKind !== 0 /* ExportKind.Named */ && name === InternalSymbolName.Default;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
/** Returns 'true' is the namespace 'name' is re-exported from this module, and 'false' if it is only used locally. */
|
|
220
|
+
function findNamespaceReExports(sourceFileLike, name, checker) {
|
|
221
|
+
const namespaceImportSymbol = checker.getSymbolAtLocation(name);
|
|
222
|
+
return !!forEachPossibleImportOrExportStatement(sourceFileLike, statement => {
|
|
223
|
+
if (!isExportDeclaration(statement))
|
|
224
|
+
return;
|
|
225
|
+
const { exportClause, moduleSpecifier } = statement;
|
|
226
|
+
return !moduleSpecifier && exportClause && isNamedExports(exportClause) &&
|
|
227
|
+
exportClause.elements.some(element => checker.getExportSpecifierLocalTargetSymbol(element) === namespaceImportSymbol);
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
export function findModuleReferences(program, sourceFiles, searchModuleSymbol) {
|
|
231
|
+
const refs = [];
|
|
232
|
+
const checker = program.getTypeChecker();
|
|
233
|
+
for (const referencingFile of sourceFiles) {
|
|
234
|
+
forEachImport(referencingFile, (_importDecl, moduleSpecifier) => {
|
|
235
|
+
const moduleSymbol = checker.getSymbolAtLocation(moduleSpecifier);
|
|
236
|
+
if (moduleSymbol === searchModuleSymbol) {
|
|
237
|
+
refs.push({ kind: "import", literal: moduleSpecifier });
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
return refs;
|
|
242
|
+
}
|
|
243
|
+
/** Returns a map from a module symbol Id to all import statements that directly reference the module. */
|
|
244
|
+
function getDirectImportsMap(sourceFiles, checker, cancellationToken) {
|
|
245
|
+
const map = createMap();
|
|
246
|
+
for (const sourceFile of sourceFiles) {
|
|
247
|
+
if (cancellationToken)
|
|
248
|
+
cancellationToken.throwIfCancellationRequested();
|
|
249
|
+
forEachImport(sourceFile, (importDecl, moduleSpecifier) => {
|
|
250
|
+
const moduleSymbol = checker.getSymbolAtLocation(moduleSpecifier);
|
|
251
|
+
if (moduleSymbol) {
|
|
252
|
+
const id = getSymbolId(moduleSymbol).toString();
|
|
253
|
+
let imports = map.get(id);
|
|
254
|
+
if (!imports) {
|
|
255
|
+
map.set(id, imports = []);
|
|
256
|
+
}
|
|
257
|
+
imports.push(importDecl);
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
return map;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Iterates over all statements at the top level. Returns the first truthy result. Na tag, também os de dentro de um
|
|
265
|
+
* `declare module "x"` (CK-02).
|
|
266
|
+
*/
|
|
267
|
+
function forEachPossibleImportOrExportStatement(sourceFileLike, action) {
|
|
268
|
+
return forEach(sourceFileLike.statements, action);
|
|
269
|
+
}
|
|
270
|
+
/** Calls `action` for each import, re-export, or require() in a file. Na tag, também o `import x = require()` (CK-03). */
|
|
271
|
+
function forEachImport(sourceFile, action) {
|
|
272
|
+
if (sourceFile.externalModuleIndicator || sourceFile.imports !== undefined) {
|
|
273
|
+
for (const i of sourceFile.imports) {
|
|
274
|
+
action(importFromModuleSpecifier(i), i);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
forEachPossibleImportOrExportStatement(sourceFile, statement => {
|
|
279
|
+
switch (statement.kind) {
|
|
280
|
+
case SyntaxKind.ExportDeclaration:
|
|
281
|
+
case SyntaxKind.ImportDeclaration: {
|
|
282
|
+
const decl = statement;
|
|
283
|
+
if (decl.moduleSpecifier && isStringLiteral(decl.moduleSpecifier)) {
|
|
284
|
+
action(decl, decl.moduleSpecifier);
|
|
285
|
+
}
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Given a local reference, we might notice that it's an import/export and recursively search for references of that.
|
|
294
|
+
* If at an import, look locally for the symbol it imports.
|
|
295
|
+
* If at an export, look for all imports of it.
|
|
296
|
+
* This doesn't handle export specifiers; that is done in `getReferencesAtExportSpecifier`.
|
|
297
|
+
* @param comingFromExport If we are doing a search for all exports, don't bother looking backwards for the imported symbol, since that's the reason we're here.
|
|
298
|
+
*/
|
|
299
|
+
export function getImportOrExportSymbol(node, symbol, checker, comingFromExport) {
|
|
300
|
+
return comingFromExport ? getExport() : getExport() || getImport();
|
|
301
|
+
function getExport() {
|
|
302
|
+
const { parent } = node;
|
|
303
|
+
const grandParent = parent.parent;
|
|
304
|
+
if (symbol.exportSymbol) {
|
|
305
|
+
if (parent.kind === SyntaxKind.PropertyAccessExpression) {
|
|
306
|
+
// Na tag, o export de um módulo JavaScript, declarado pela atribuição a um acesso (CK-03).
|
|
307
|
+
return undefined;
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
return exportInfo(symbol.exportSymbol, getExportKindForDeclaration(parent));
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
const exportNode = getExportNode(parent, node);
|
|
315
|
+
// Na tag, também o `export import X = Y`, que importava o `Y` (CK-03).
|
|
316
|
+
if (exportNode && hasModifier(exportNode, ModifierFlags.Export)) {
|
|
317
|
+
return exportInfo(symbol, getExportKindForDeclaration(exportNode));
|
|
318
|
+
}
|
|
319
|
+
// If we are in `export default a;`, `parent` is the export assignment.
|
|
320
|
+
else if (isExportAssignment(parent)) {
|
|
321
|
+
return getExportAssignmentExport(parent);
|
|
322
|
+
}
|
|
323
|
+
// Também quando o `parent.parent` é o export assignment. Na tag, também o `module.exports =`, o `exports.A =`
|
|
324
|
+
// e o typedef do JSDoc (CK-03).
|
|
325
|
+
else if (isExportAssignment(grandParent)) {
|
|
326
|
+
return getExportAssignmentExport(grandParent);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
/** Na tag, também o `export =` (CK-03). */
|
|
330
|
+
function getExportAssignmentExport(ex) {
|
|
331
|
+
const exportingModuleSymbol = Debug.checkDefined(ex.symbol.parent, "Expected export symbol to have a parent");
|
|
332
|
+
return { kind: 1 /* ImportExport.Export */, symbol, exportInfo: { exportingModuleSymbol, exportKind: 1 /* ExportKind.Default */ } };
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
function getImport() {
|
|
336
|
+
const isImport = isNodeImport(node);
|
|
337
|
+
if (!isImport)
|
|
338
|
+
return undefined;
|
|
339
|
+
// A symbol being imported is always an alias. So get what that aliases to find the local symbol.
|
|
340
|
+
let importedSymbol = checker.getImmediateAliasedSymbol(symbol);
|
|
341
|
+
if (!importedSymbol)
|
|
342
|
+
return undefined;
|
|
343
|
+
// Search on the local symbol in the exporting module, not the exported symbol. Na tag, também passava do símbolo
|
|
344
|
+
// do `export =` ao valor dele (CK-03).
|
|
345
|
+
importedSymbol = skipExportSpecifierSymbol(importedSymbol, checker);
|
|
346
|
+
// If the import has a different name than the export, do not continue searching.
|
|
347
|
+
// If `importedName` is undefined, do continue searching as the export is anonymous.
|
|
348
|
+
// (All imports returned from this function will be ignored anyway if we are in rename and this is a not a named export.)
|
|
349
|
+
const importedName = symbolEscapedNameNoDefault(importedSymbol);
|
|
350
|
+
if (importedName === undefined || importedName === InternalSymbolName.Default || importedName === symbol.escapedName) {
|
|
351
|
+
return { kind: 0 /* ImportExport.Import */, symbol: importedSymbol };
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
function exportInfo(symbol, kind) {
|
|
355
|
+
const exportInfo = getExportInfo(symbol, kind, checker);
|
|
356
|
+
return exportInfo && { kind: 1 /* ImportExport.Export */, symbol, exportInfo };
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* O tipo de export de uma declaração, fora o export specifier e o export assignment. Na tag, o modificador `default`
|
|
360
|
+
* dava o `Default`; ele só existia diante da `function` e da classe (CK-02).
|
|
361
|
+
*/
|
|
362
|
+
function getExportKindForDeclaration(_node) {
|
|
363
|
+
return 0 /* ExportKind.Named */;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
// If a reference is a variable declaration, the exported node would be the variable statement. Na tag, também a class
|
|
367
|
+
// expression, cujo nó exportado era o pai (CK-02).
|
|
368
|
+
function getExportNode(parent, node) {
|
|
369
|
+
const declaration = isVariableDeclaration(parent) ? parent : isBindingElement(parent) ? walkUpBindingElementsAndPatterns(parent) : undefined;
|
|
370
|
+
if (declaration) {
|
|
371
|
+
return parent.name !== node ? undefined :
|
|
372
|
+
isCatchClause(declaration.parent) ? undefined : isVariableStatement(declaration.parent.parent) ? declaration.parent.parent : undefined;
|
|
373
|
+
}
|
|
374
|
+
else {
|
|
375
|
+
return parent;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
/** Na tag, também o nome do `import x = require()` (CK-03). */
|
|
379
|
+
function isNodeImport(node) {
|
|
380
|
+
const { parent } = node;
|
|
381
|
+
switch (parent.kind) {
|
|
382
|
+
case SyntaxKind.ImportSpecifier:
|
|
383
|
+
// For a rename import `{ foo as bar }`, don't search for the imported symbol. Just find local uses of `bar`.
|
|
384
|
+
return !parent.propertyName;
|
|
385
|
+
case SyntaxKind.ImportClause:
|
|
386
|
+
case SyntaxKind.NamespaceImport:
|
|
387
|
+
Debug.assert(parent.name === node);
|
|
388
|
+
return true;
|
|
389
|
+
default:
|
|
390
|
+
return false;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
export function getExportInfo(exportSymbol, exportKind, checker) {
|
|
394
|
+
const moduleSymbol = exportSymbol.parent;
|
|
395
|
+
if (!moduleSymbol)
|
|
396
|
+
return undefined; // This can happen if an `export` is not at the top-level (which is a compile error).
|
|
397
|
+
const exportingModuleSymbol = checker.getMergedSymbol(moduleSymbol); // Need to get merged symbol in case there's an augmentation.
|
|
398
|
+
// `export` may appear in a namespace. In that case, just rely on global search.
|
|
399
|
+
return isExternalModuleSymbol(exportingModuleSymbol) ? { exportingModuleSymbol, exportKind } : undefined;
|
|
400
|
+
}
|
|
401
|
+
/** If at an export specifier, go to the symbol it refers to. */
|
|
402
|
+
function skipExportSpecifierSymbol(symbol, checker) {
|
|
403
|
+
// For `export { foo } from './bar", there's nothing to skip, because it does not create a new alias. But `export { foo } does.
|
|
404
|
+
if (symbol.declarations) {
|
|
405
|
+
for (const declaration of symbol.declarations) {
|
|
406
|
+
if (isExportSpecifier(declaration) && !declaration.propertyName && !declaration.parent.parent.moduleSpecifier) {
|
|
407
|
+
return checker.getExportSpecifierLocalTargetSymbol(declaration);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
return symbol;
|
|
412
|
+
}
|
|
413
|
+
function getContainingModuleSymbol(importer, checker) {
|
|
414
|
+
return checker.getMergedSymbol(getSourceFileLikeForImportDeclaration(importer).symbol);
|
|
415
|
+
}
|
|
416
|
+
/** O arquivo do import. Na tag, também o `declare module "x"` em que o import estava (CK-02). */
|
|
417
|
+
function getSourceFileLikeForImportDeclaration(node) {
|
|
418
|
+
if (node.kind === SyntaxKind.CallExpression) {
|
|
419
|
+
return node.getSourceFile();
|
|
420
|
+
}
|
|
421
|
+
return cast(node.parent, isSourceFile);
|
|
422
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./_namespaces/ts.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// A entrada dos testes deste pacote: reexporta o barril, que é a entrada do pacote (o `exports` do `package.json`). O
|
|
2
|
+
// barril avalia os arquivos na ordem do outFile da tag, e um import direto de um arquivo avaliaria os outros noutra ordem.
|
|
3
|
+
export * from "./_namespaces/ts.js";
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { CancellationToken, NavigationBarItem, NavigationTree, SourceFile } from "./_namespaces/ts.js";
|
|
2
|
+
export declare function getNavigationBarItems(sourceFile: SourceFile, cancellationToken: CancellationToken): NavigationBarItem[];
|
|
3
|
+
export declare function getNavigationTree(sourceFile: SourceFile, cancellationToken: CancellationToken): NavigationTree;
|