@tslite/services 0.0.0-stage → 1.13.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,549 @@
|
|
|
1
|
+
// Modificado de microsoft/TypeScript v3.9.10, src/services/navigationBar.ts: o namespace virou módulo ES, com os imports explícitos.
|
|
2
|
+
import { Debug, InternalSymbolName, SyntaxKind, compareStringsCaseSensitiveUI, compareValues, concatenate, contains, createMap, createTextSpanFromNode, createTextSpanFromRange, declarationNameToString, escapeString, filterMutate, forEachChild, getBaseFileName, getNameOfDeclaration, getNodeKind, getNodeModifiers, getPropertyNameForPropertyNameNode, getTextOfIdentifierOrLiteral, getTextOfNode, hasDynamicName, isAmbientModule, isBinaryExpression, isBindingPattern, isCallExpression, isDeclaration, isElementAccessExpression, isExpression, isExternalModule, isIdentifier, isModuleBlock, isModuleDeclaration, isPropertyAccessExpression, isPropertyAssignment, isPropertyName, isStringLiteralLike, isToken, isVariableDeclaration, map, mapDefined, normalizePath, removeFileExtension, unescapeLeadingUnderscores, } from "./_namespaces/ts.js";
|
|
3
|
+
/**
|
|
4
|
+
* Matches all whitespace characters in a string. Eg:
|
|
5
|
+
*
|
|
6
|
+
* "app.
|
|
7
|
+
*
|
|
8
|
+
* onactivated"
|
|
9
|
+
*
|
|
10
|
+
* matches because of the newline, whereas
|
|
11
|
+
*
|
|
12
|
+
* "app.onactivated"
|
|
13
|
+
*
|
|
14
|
+
* does not match.
|
|
15
|
+
*/
|
|
16
|
+
const whiteSpaceRegex = /\s+/g;
|
|
17
|
+
/**
|
|
18
|
+
* Maximum amount of characters to return
|
|
19
|
+
* The amount was chosen arbitrarily.
|
|
20
|
+
*/
|
|
21
|
+
const maxLength = 150;
|
|
22
|
+
// Keep sourceFile handy so we don't have to search for it every time we need to call `getText`.
|
|
23
|
+
let curCancellationToken;
|
|
24
|
+
let curSourceFile;
|
|
25
|
+
/**
|
|
26
|
+
* For performance, we keep navigation bar parents on a stack rather than passing them through each recursion.
|
|
27
|
+
* `parent` is the current parent and is *not* stored in parentsStack.
|
|
28
|
+
* `startNode` sets a new parent and `endNode` returns to the previous parent.
|
|
29
|
+
*/
|
|
30
|
+
let parentsStack = [];
|
|
31
|
+
let parent;
|
|
32
|
+
// Na tag, também a pilha das classes ES5 que se acompanhavam: a `function` declarada e o `prototype` de JavaScript
|
|
33
|
+
// (CK-02, CK-03).
|
|
34
|
+
// NavigationBarItem requires an array, but will not mutate it, so just give it this for performance.
|
|
35
|
+
let emptyChildItemArray = [];
|
|
36
|
+
export function getNavigationBarItems(sourceFile, cancellationToken) {
|
|
37
|
+
curCancellationToken = cancellationToken;
|
|
38
|
+
curSourceFile = sourceFile;
|
|
39
|
+
try {
|
|
40
|
+
return map(primaryNavBarMenuItems(rootNavigationBarNode(sourceFile)), convertToPrimaryNavBarMenuItem);
|
|
41
|
+
}
|
|
42
|
+
finally {
|
|
43
|
+
reset();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export function getNavigationTree(sourceFile, cancellationToken) {
|
|
47
|
+
curCancellationToken = cancellationToken;
|
|
48
|
+
curSourceFile = sourceFile;
|
|
49
|
+
try {
|
|
50
|
+
return convertToTree(rootNavigationBarNode(sourceFile));
|
|
51
|
+
}
|
|
52
|
+
finally {
|
|
53
|
+
reset();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function reset() {
|
|
57
|
+
curSourceFile = undefined;
|
|
58
|
+
curCancellationToken = undefined;
|
|
59
|
+
parentsStack = [];
|
|
60
|
+
parent = undefined;
|
|
61
|
+
emptyChildItemArray = [];
|
|
62
|
+
}
|
|
63
|
+
function nodeText(node) {
|
|
64
|
+
return cleanText(node.getText(curSourceFile));
|
|
65
|
+
}
|
|
66
|
+
function navigationBarNodeKind(n) {
|
|
67
|
+
return n.node.kind;
|
|
68
|
+
}
|
|
69
|
+
function pushChild(parent, child) {
|
|
70
|
+
if (parent.children) {
|
|
71
|
+
parent.children.push(child);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
parent.children = [child];
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function rootNavigationBarNode(sourceFile) {
|
|
78
|
+
Debug.assert(!parentsStack.length);
|
|
79
|
+
const root = { node: sourceFile, name: undefined, additionalNodes: undefined, parent: undefined, children: undefined, indent: 0 };
|
|
80
|
+
parent = root;
|
|
81
|
+
for (const statement of sourceFile.statements) {
|
|
82
|
+
addChildrenRecursively(statement);
|
|
83
|
+
}
|
|
84
|
+
endNode();
|
|
85
|
+
Debug.assert(!parent && !parentsStack.length);
|
|
86
|
+
return root;
|
|
87
|
+
}
|
|
88
|
+
function addLeafNode(node, name) {
|
|
89
|
+
pushChild(parent, emptyNavigationBarNode(node, name));
|
|
90
|
+
}
|
|
91
|
+
function emptyNavigationBarNode(node, name) {
|
|
92
|
+
return {
|
|
93
|
+
node,
|
|
94
|
+
name: name || (isDeclaration(node) || isExpression(node) ? getNameOfDeclaration(node) : undefined),
|
|
95
|
+
additionalNodes: undefined,
|
|
96
|
+
parent,
|
|
97
|
+
children: undefined,
|
|
98
|
+
indent: parent.indent + 1
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Add a new level of NavigationBarNodes.
|
|
103
|
+
* This pushes to the stack, so you must call `endNode` when you are done adding to this node.
|
|
104
|
+
*/
|
|
105
|
+
function startNode(node, name) {
|
|
106
|
+
const navNode = emptyNavigationBarNode(node, name);
|
|
107
|
+
pushChild(parent, navNode);
|
|
108
|
+
// Save the old parent
|
|
109
|
+
parentsStack.push(parent);
|
|
110
|
+
parent = navNode;
|
|
111
|
+
}
|
|
112
|
+
/** Call after calling `startNode` and adding children to it. */
|
|
113
|
+
function endNode() {
|
|
114
|
+
if (parent.children) {
|
|
115
|
+
mergeChildren(parent.children, parent);
|
|
116
|
+
sortChildren(parent.children);
|
|
117
|
+
}
|
|
118
|
+
parent = parentsStack.pop();
|
|
119
|
+
}
|
|
120
|
+
function addNodeWithRecursiveChild(node, child, name) {
|
|
121
|
+
startNode(node, name);
|
|
122
|
+
addChildrenRecursively(child);
|
|
123
|
+
endNode();
|
|
124
|
+
}
|
|
125
|
+
/** Look for navigation bar items in node's subtree, adding them to the current `parent`. */
|
|
126
|
+
function addChildrenRecursively(node) {
|
|
127
|
+
curCancellationToken.throwIfCancellationRequested();
|
|
128
|
+
if (!node || isToken(node)) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
switch (node.kind) {
|
|
132
|
+
// Na tag, também o construtor, com as parameter properties, o método e o acessor (CK-02), e a method signature
|
|
133
|
+
// (CK-36).
|
|
134
|
+
// Na tag, também a propriedade de classe (CK-02).
|
|
135
|
+
case SyntaxKind.PropertySignature:
|
|
136
|
+
if (!hasDynamicName(node)) {
|
|
137
|
+
addLeafNode(node);
|
|
138
|
+
}
|
|
139
|
+
break;
|
|
140
|
+
case SyntaxKind.ImportClause:
|
|
141
|
+
const importClause = node;
|
|
142
|
+
// Handle default import case e.g.:
|
|
143
|
+
// import d from "mod";
|
|
144
|
+
if (importClause.name) {
|
|
145
|
+
addLeafNode(importClause.name);
|
|
146
|
+
}
|
|
147
|
+
// Handle named bindings in imports e.g.:
|
|
148
|
+
// import * as NS from "mod";
|
|
149
|
+
// import {a, b as B} from "mod";
|
|
150
|
+
const { namedBindings } = importClause;
|
|
151
|
+
if (namedBindings) {
|
|
152
|
+
if (namedBindings.kind === SyntaxKind.NamespaceImport) {
|
|
153
|
+
addLeafNode(namedBindings);
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
for (const element of namedBindings.elements) {
|
|
157
|
+
addLeafNode(element);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
break;
|
|
162
|
+
case SyntaxKind.ShorthandPropertyAssignment:
|
|
163
|
+
addNodeWithRecursiveChild(node, node.name);
|
|
164
|
+
break;
|
|
165
|
+
case SyntaxKind.SpreadAssignment:
|
|
166
|
+
const { expression } = node;
|
|
167
|
+
// Use the expression as the name of the SpreadAssignment, otherwise show as <unknown>.
|
|
168
|
+
isIdentifier(expression) ? addLeafNode(node, expression) : addLeafNode(node);
|
|
169
|
+
break;
|
|
170
|
+
case SyntaxKind.BindingElement:
|
|
171
|
+
case SyntaxKind.PropertyAssignment:
|
|
172
|
+
case SyntaxKind.VariableDeclaration:
|
|
173
|
+
const { name, initializer } = node;
|
|
174
|
+
if (isBindingPattern(name)) {
|
|
175
|
+
addChildrenRecursively(name);
|
|
176
|
+
}
|
|
177
|
+
else if (initializer && isFunctionOrClassExpression(initializer)) {
|
|
178
|
+
// Add a node for the VariableDeclaration, but not for the initializer.
|
|
179
|
+
startNode(node);
|
|
180
|
+
forEachChild(initializer, addChildrenRecursively);
|
|
181
|
+
endNode();
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
addNodeWithRecursiveChild(node, initializer);
|
|
185
|
+
}
|
|
186
|
+
break;
|
|
187
|
+
// Na tag, também a `function` declarada, que se acompanhava como possível classe ES5 (CK-02).
|
|
188
|
+
case SyntaxKind.ArrowFunction:
|
|
189
|
+
// Na tag, também a function expression (CK-02).
|
|
190
|
+
addNodeWithRecursiveChild(node, node.body);
|
|
191
|
+
break;
|
|
192
|
+
// Na tag, também o enum, a classe, a class expression e a interface (CK-02).
|
|
193
|
+
case SyntaxKind.ModuleDeclaration:
|
|
194
|
+
addNodeWithRecursiveChild(node, getInteriorModule(node).body);
|
|
195
|
+
break;
|
|
196
|
+
case SyntaxKind.ExportAssignment:
|
|
197
|
+
case SyntaxKind.ExportSpecifier:
|
|
198
|
+
// Na tag, também o `import =` (CK-03).
|
|
199
|
+
case SyntaxKind.IndexSignature:
|
|
200
|
+
case SyntaxKind.CallSignature:
|
|
201
|
+
// Na tag, também a construct signature (CK-02).
|
|
202
|
+
case SyntaxKind.TypeAliasDeclaration:
|
|
203
|
+
addLeafNode(node);
|
|
204
|
+
break;
|
|
205
|
+
// Na tag, também a atribuição que declara em JavaScript (o `exports.x`, o `module.exports`, o `prototype` e o
|
|
206
|
+
// `Object.defineProperty`) e a que dava um membro a uma classe ES5 acompanhada (CK-03, CK-02).
|
|
207
|
+
default:
|
|
208
|
+
// Na tag, também o typedef e o callback do JSDoc do nó (CK-03).
|
|
209
|
+
forEachChild(node, addChildrenRecursively);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/** Merge declarations of the same kind. */
|
|
213
|
+
function mergeChildren(children, node) {
|
|
214
|
+
const nameToItems = createMap();
|
|
215
|
+
filterMutate(children, (child, index) => {
|
|
216
|
+
const declName = child.name || getNameOfDeclaration(child.node);
|
|
217
|
+
const name = declName && nodeText(declName);
|
|
218
|
+
if (!name) {
|
|
219
|
+
// Anonymous items are never merged.
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
const itemsWithSameName = nameToItems.get(name);
|
|
223
|
+
if (!itemsWithSameName) {
|
|
224
|
+
nameToItems.set(name, child);
|
|
225
|
+
return true;
|
|
226
|
+
}
|
|
227
|
+
if (itemsWithSameName instanceof Array) {
|
|
228
|
+
for (const itemWithSameName of itemsWithSameName) {
|
|
229
|
+
if (tryMerge(itemWithSameName, child, index, node)) {
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
itemsWithSameName.push(child);
|
|
234
|
+
return true;
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
const itemWithSameName = itemsWithSameName;
|
|
238
|
+
if (tryMerge(itemWithSameName, child, index, node)) {
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
nameToItems.set(name, [itemWithSameName, child]);
|
|
242
|
+
return true;
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
function tryMerge(a, b, _bIndex, parent) {
|
|
247
|
+
// Na tag, antes, a fusão de uma classe ES5 com os membros dela, que só a `function` declarada e a atribuição de
|
|
248
|
+
// JavaScript davam (CK-02, CK-03).
|
|
249
|
+
if (shouldReallyMerge(a.node, b.node, parent)) {
|
|
250
|
+
merge(a, b);
|
|
251
|
+
return true;
|
|
252
|
+
}
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
/** a and b have the same name, but they may not be mergeable. */
|
|
256
|
+
function shouldReallyMerge(a, b, parent) {
|
|
257
|
+
if (a.kind !== b.kind || a.parent !== b.parent && !(isOwnChild(a, parent) && isOwnChild(b, parent))) {
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
switch (a.kind) {
|
|
261
|
+
// Na tag, também a propriedade de classe, o método e o acessor, que se fundiam só com o mesmo `static` (CK-02).
|
|
262
|
+
case SyntaxKind.ModuleDeclaration:
|
|
263
|
+
return areSameModule(a, b);
|
|
264
|
+
default:
|
|
265
|
+
return true;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
// We want to merge own children like `I` in in `module A { interface I {} } module A { interface I {} }`
|
|
269
|
+
// We don't want to merge unrelated children like `m` in `const o = { a: { m() {} }, b: { m() {} } };`
|
|
270
|
+
function isOwnChild(n, parent) {
|
|
271
|
+
const par = isModuleBlock(n.parent) ? n.parent.parent : n.parent;
|
|
272
|
+
return par === parent.node || contains(parent.additionalNodes, par);
|
|
273
|
+
}
|
|
274
|
+
// We use 1 NavNode to represent 'A.B.C', but there are multiple source nodes.
|
|
275
|
+
// Only merge module nodes that have the same chain. Don't merge 'A.B.C' with 'A'!
|
|
276
|
+
function areSameModule(a, b) {
|
|
277
|
+
// TODO: GH#18217
|
|
278
|
+
return a.body.kind === b.body.kind && (a.body.kind !== SyntaxKind.ModuleDeclaration || areSameModule(a.body, b.body));
|
|
279
|
+
}
|
|
280
|
+
/** Merge source into target. Source should be thrown away after this is called. */
|
|
281
|
+
function merge(target, source) {
|
|
282
|
+
target.additionalNodes = target.additionalNodes || [];
|
|
283
|
+
target.additionalNodes.push(source.node);
|
|
284
|
+
if (source.additionalNodes) {
|
|
285
|
+
target.additionalNodes.push(...source.additionalNodes);
|
|
286
|
+
}
|
|
287
|
+
target.children = concatenate(target.children, source.children);
|
|
288
|
+
if (target.children) {
|
|
289
|
+
mergeChildren(target.children, target);
|
|
290
|
+
sortChildren(target.children);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
/** Recursively ensure that each NavNode's children are in sorted order. */
|
|
294
|
+
function sortChildren(children) {
|
|
295
|
+
children.sort(compareChildren);
|
|
296
|
+
}
|
|
297
|
+
function compareChildren(child1, child2) {
|
|
298
|
+
return compareStringsCaseSensitiveUI(tryGetName(child1.node), tryGetName(child2.node)) // TODO: GH#18217
|
|
299
|
+
|| compareValues(navigationBarNodeKind(child1), navigationBarNodeKind(child2));
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* This differs from getItemName because this is just used for sorting.
|
|
303
|
+
* We only sort nodes by name that have a more-or-less "direct" name, as opposed to `new()` and the like.
|
|
304
|
+
* So `new()` can still come before an `aardvark` method.
|
|
305
|
+
*/
|
|
306
|
+
function tryGetName(node) {
|
|
307
|
+
if (node.kind === SyntaxKind.ModuleDeclaration) {
|
|
308
|
+
return getModuleName(node);
|
|
309
|
+
}
|
|
310
|
+
const declName = getNameOfDeclaration(node);
|
|
311
|
+
if (declName && isPropertyName(declName)) {
|
|
312
|
+
const propertyName = getPropertyNameForPropertyNameNode(declName);
|
|
313
|
+
return propertyName && unescapeLeadingUnderscores(propertyName);
|
|
314
|
+
}
|
|
315
|
+
switch (node.kind) {
|
|
316
|
+
// Na tag, também a function expression e a class expression (CK-02).
|
|
317
|
+
case SyntaxKind.ArrowFunction:
|
|
318
|
+
return getFunctionOrClassName(node);
|
|
319
|
+
default:
|
|
320
|
+
return undefined;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
function getItemName(node, name) {
|
|
324
|
+
if (node.kind === SyntaxKind.ModuleDeclaration) {
|
|
325
|
+
return cleanText(getModuleName(node));
|
|
326
|
+
}
|
|
327
|
+
if (name) {
|
|
328
|
+
const text = isIdentifier(name) ? name.text
|
|
329
|
+
: isElementAccessExpression(name) ? `[${nodeText(name.argumentExpression)}]`
|
|
330
|
+
: nodeText(name);
|
|
331
|
+
if (text.length > 0) {
|
|
332
|
+
return cleanText(text);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
switch (node.kind) {
|
|
336
|
+
case SyntaxKind.SourceFile:
|
|
337
|
+
const sourceFile = node;
|
|
338
|
+
return isExternalModule(sourceFile)
|
|
339
|
+
? `"${escapeString(getBaseFileName(removeFileExtension(normalizePath(sourceFile.fileName))))}"`
|
|
340
|
+
: "<global>";
|
|
341
|
+
case SyntaxKind.ExportAssignment:
|
|
342
|
+
// Na tag, também o `export =` (CK-03).
|
|
343
|
+
return InternalSymbolName.Default;
|
|
344
|
+
// Na tag, também a `function` declarada, a function expression, a classe e a class expression, e o nome
|
|
345
|
+
// `default` delas com o modificador (CK-02).
|
|
346
|
+
case SyntaxKind.ArrowFunction:
|
|
347
|
+
// We may get a string with newlines or other whitespace in the case of an object dereference
|
|
348
|
+
// (eg: "app\n.onactivated"), so we should remove the whitespace for readabiltiy in the
|
|
349
|
+
// navigation bar.
|
|
350
|
+
return getFunctionOrClassName(node);
|
|
351
|
+
// Na tag, também o construtor e a construct signature (CK-02).
|
|
352
|
+
case SyntaxKind.CallSignature:
|
|
353
|
+
return "()";
|
|
354
|
+
case SyntaxKind.IndexSignature:
|
|
355
|
+
return "[]";
|
|
356
|
+
default:
|
|
357
|
+
return "<unknown>";
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
/** Flattens the NavNode tree to a list of items to appear in the primary navbar menu. */
|
|
361
|
+
function primaryNavBarMenuItems(root) {
|
|
362
|
+
// The primary (middle) navbar menu displays the general code navigation hierarchy, similar to the navtree.
|
|
363
|
+
// The secondary (right) navbar menu displays the child items of whichever primary item is selected.
|
|
364
|
+
// Some less interesting items without their own child navigation items (e.g. a local variable declaration) only show up in the secondary menu.
|
|
365
|
+
const primaryNavBarMenuItems = [];
|
|
366
|
+
function recur(item) {
|
|
367
|
+
if (shouldAppearInPrimaryNavBarMenu(item)) {
|
|
368
|
+
primaryNavBarMenuItems.push(item);
|
|
369
|
+
if (item.children) {
|
|
370
|
+
for (const child of item.children) {
|
|
371
|
+
recur(child);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
recur(root);
|
|
377
|
+
return primaryNavBarMenuItems;
|
|
378
|
+
/** Determines if a node should appear in the primary navbar menu. */
|
|
379
|
+
function shouldAppearInPrimaryNavBarMenu(item) {
|
|
380
|
+
// Items with children should always appear in the primary navbar menu.
|
|
381
|
+
if (item.children) {
|
|
382
|
+
return true;
|
|
383
|
+
}
|
|
384
|
+
// Some nodes are otherwise important enough to always include in the primary navigation menu.
|
|
385
|
+
switch (navigationBarNodeKind(item)) {
|
|
386
|
+
// Na tag, também a classe, a class expression, o enum e a interface (CK-02), e o typedef e o callback do
|
|
387
|
+
// JSDoc (CK-03).
|
|
388
|
+
case SyntaxKind.ModuleDeclaration:
|
|
389
|
+
case SyntaxKind.SourceFile:
|
|
390
|
+
case SyntaxKind.TypeAliasDeclaration:
|
|
391
|
+
return true;
|
|
392
|
+
// Na tag, também a `function` declarada e a function expression (CK-02).
|
|
393
|
+
case SyntaxKind.ArrowFunction:
|
|
394
|
+
return isTopLevelFunctionDeclaration(item);
|
|
395
|
+
default:
|
|
396
|
+
return false;
|
|
397
|
+
}
|
|
398
|
+
function isTopLevelFunctionDeclaration(item) {
|
|
399
|
+
if (!item.node.body) {
|
|
400
|
+
return false;
|
|
401
|
+
}
|
|
402
|
+
switch (navigationBarNodeKind(item.parent)) {
|
|
403
|
+
case SyntaxKind.ModuleBlock:
|
|
404
|
+
case SyntaxKind.SourceFile:
|
|
405
|
+
// Na tag, também o método e o construtor (CK-02).
|
|
406
|
+
return true;
|
|
407
|
+
default:
|
|
408
|
+
return false;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
function convertToTree(n) {
|
|
414
|
+
return {
|
|
415
|
+
text: getItemName(n.node, n.name),
|
|
416
|
+
kind: getNodeKind(n.node),
|
|
417
|
+
kindModifiers: getModifiers(n.node),
|
|
418
|
+
spans: getSpans(n),
|
|
419
|
+
nameSpan: n.name && getNodeSpan(n.name),
|
|
420
|
+
childItems: map(n.children, convertToTree)
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
function convertToPrimaryNavBarMenuItem(n) {
|
|
424
|
+
return {
|
|
425
|
+
text: getItemName(n.node, n.name),
|
|
426
|
+
kind: getNodeKind(n.node),
|
|
427
|
+
kindModifiers: getModifiers(n.node),
|
|
428
|
+
spans: getSpans(n),
|
|
429
|
+
childItems: map(n.children, convertToSecondaryNavBarMenuItem) || emptyChildItemArray,
|
|
430
|
+
indent: n.indent,
|
|
431
|
+
bolded: false,
|
|
432
|
+
grayed: false
|
|
433
|
+
};
|
|
434
|
+
function convertToSecondaryNavBarMenuItem(n) {
|
|
435
|
+
return {
|
|
436
|
+
text: getItemName(n.node, n.name),
|
|
437
|
+
kind: getNodeKind(n.node),
|
|
438
|
+
kindModifiers: getNodeModifiers(n.node),
|
|
439
|
+
spans: getSpans(n),
|
|
440
|
+
childItems: emptyChildItemArray,
|
|
441
|
+
indent: 0,
|
|
442
|
+
bolded: false,
|
|
443
|
+
grayed: false
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
function getSpans(n) {
|
|
448
|
+
const spans = [getNodeSpan(n.node)];
|
|
449
|
+
if (n.additionalNodes) {
|
|
450
|
+
for (const node of n.additionalNodes) {
|
|
451
|
+
spans.push(getNodeSpan(node));
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
return spans;
|
|
455
|
+
}
|
|
456
|
+
function getModuleName(moduleDeclaration) {
|
|
457
|
+
// We want to maintain quotation marks.
|
|
458
|
+
if (isAmbientModule(moduleDeclaration)) {
|
|
459
|
+
return getTextOfNode(moduleDeclaration.name);
|
|
460
|
+
}
|
|
461
|
+
// Otherwise, we need to aggregate each identifier to build up the qualified name.
|
|
462
|
+
const result = [];
|
|
463
|
+
result.push(getTextOfIdentifierOrLiteral(moduleDeclaration.name));
|
|
464
|
+
while (moduleDeclaration.body && moduleDeclaration.body.kind === SyntaxKind.ModuleDeclaration) {
|
|
465
|
+
moduleDeclaration = moduleDeclaration.body;
|
|
466
|
+
result.push(getTextOfIdentifierOrLiteral(moduleDeclaration.name));
|
|
467
|
+
}
|
|
468
|
+
return result.join(".");
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* For 'module A.B.C', we want to get the node for 'C'.
|
|
472
|
+
* We store 'A' as associated with a NavNode, and use getModuleName to traverse down again.
|
|
473
|
+
*/
|
|
474
|
+
function getInteriorModule(decl) {
|
|
475
|
+
return decl.body && isModuleDeclaration(decl.body) ? getInteriorModule(decl.body) : decl;
|
|
476
|
+
}
|
|
477
|
+
function getNodeSpan(node) {
|
|
478
|
+
return node.kind === SyntaxKind.SourceFile ? createTextSpanFromRange(node) : createTextSpanFromNode(node, curSourceFile);
|
|
479
|
+
}
|
|
480
|
+
function getModifiers(node) {
|
|
481
|
+
if (node.parent && node.parent.kind === SyntaxKind.VariableDeclaration) {
|
|
482
|
+
node = node.parent;
|
|
483
|
+
}
|
|
484
|
+
return getNodeModifiers(node);
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* O nome de uma arrow. Na tag, também o da `function` declarada, da function expression e da classe: o nome próprio
|
|
488
|
+
* delas, o `default` do modificador e o `<class>` da classe anônima (CK-02).
|
|
489
|
+
*/
|
|
490
|
+
function getFunctionOrClassName(node) {
|
|
491
|
+
const { parent } = node;
|
|
492
|
+
// See if it is a var initializer. If so, use the var name.
|
|
493
|
+
if (isVariableDeclaration(parent)) {
|
|
494
|
+
return cleanText(declarationNameToString(parent.name));
|
|
495
|
+
}
|
|
496
|
+
// See if it is of the form "<expr> = function(){...}". If so, use the text from the left-hand side.
|
|
497
|
+
else if (isBinaryExpression(parent) && parent.operatorToken.kind === SyntaxKind.EqualsToken) {
|
|
498
|
+
return nodeText(parent.left).replace(whiteSpaceRegex, "");
|
|
499
|
+
}
|
|
500
|
+
// See if it is a property assignment, and if so use the property name
|
|
501
|
+
else if (isPropertyAssignment(parent)) {
|
|
502
|
+
return nodeText(parent.name);
|
|
503
|
+
}
|
|
504
|
+
else if (isCallExpression(parent)) {
|
|
505
|
+
let name = getCalledExpressionName(parent.expression);
|
|
506
|
+
if (name !== undefined) {
|
|
507
|
+
name = cleanText(name);
|
|
508
|
+
if (name.length > maxLength) {
|
|
509
|
+
return `${name} callback`;
|
|
510
|
+
}
|
|
511
|
+
const args = cleanText(mapDefined(parent.arguments, a => isStringLiteralLike(a) ? a.getText(curSourceFile) : undefined).join(", "));
|
|
512
|
+
return `${name}(${args}) callback`;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
return "<function>";
|
|
516
|
+
}
|
|
517
|
+
// See also 'tryGetPropertyAccessOrIdentifierToString'
|
|
518
|
+
function getCalledExpressionName(expr) {
|
|
519
|
+
if (isIdentifier(expr)) {
|
|
520
|
+
return expr.text;
|
|
521
|
+
}
|
|
522
|
+
else if (isPropertyAccessExpression(expr)) {
|
|
523
|
+
const left = getCalledExpressionName(expr.expression);
|
|
524
|
+
const right = expr.name.text;
|
|
525
|
+
return left === undefined ? right : `${left}.${right}`;
|
|
526
|
+
}
|
|
527
|
+
else {
|
|
528
|
+
return undefined;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
/** A arrow. Na tag, também a function expression e a class expression (CK-02). */
|
|
532
|
+
function isFunctionOrClassExpression(node) {
|
|
533
|
+
switch (node.kind) {
|
|
534
|
+
case SyntaxKind.ArrowFunction:
|
|
535
|
+
return true;
|
|
536
|
+
default:
|
|
537
|
+
return false;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
function cleanText(text) {
|
|
541
|
+
// Truncate to maximum amount of characters as we don't want to do a big replace operation.
|
|
542
|
+
text = text.length > maxLength ? text.substring(0, maxLength) + "..." : text;
|
|
543
|
+
// Replaces ECMAScript line terminators and removes the trailing `\` from each line:
|
|
544
|
+
// \n - Line Feed
|
|
545
|
+
// \r - Carriage Return
|
|
546
|
+
// \u2028 - Line separator
|
|
547
|
+
// \u2029 - Paragraph separator
|
|
548
|
+
return text.replace(/\\?(\r?\n|\r|\u2028|\u2029)/g, "");
|
|
549
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { formatting } from "./_namespaces/edit.js";
|
|
2
|
+
import type { CheckResult, ExportDeclaration, Expression, ImportDeclaration, LanguageServiceHost, SourceFile, UserPreferences } from "./_namespaces/edit.js";
|
|
3
|
+
/**
|
|
4
|
+
* Organize imports by:
|
|
5
|
+
* 1) Removing unused imports
|
|
6
|
+
* 2) Coalescing imports from the same module
|
|
7
|
+
* 3) Sorting imports
|
|
8
|
+
*/
|
|
9
|
+
export declare function organizeImports(sourceFile: SourceFile, formatContext: formatting.FormatContext, host: LanguageServiceHost, program: CheckResult, preferences: UserPreferences): import("./types.js").FileTextChanges[];
|
|
10
|
+
/**
|
|
11
|
+
* @param importGroup a list of ImportDeclarations, all with the same module name.
|
|
12
|
+
*/
|
|
13
|
+
export declare function coalesceImports(importGroup: readonly ImportDeclaration[]): readonly ImportDeclaration[];
|
|
14
|
+
/**
|
|
15
|
+
* @param exportGroup a list of ExportDeclarations, all with the same module name.
|
|
16
|
+
*/
|
|
17
|
+
export declare function coalesceExports(exportGroup: readonly ExportDeclaration[]): readonly ExportDeclaration[];
|
|
18
|
+
export declare function compareModuleSpecifiers(m1: Expression, m2: Expression): import("@tslite/parser").Comparison;
|