@tslite/services 1.16.0 → 1.17.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/NOTICE +3 -1
- package/dist/_namespaces/edit.d.ts +1 -1
- package/dist/_namespaces/edit.js +10759 -11
- package/dist/_namespaces/ts.codefix.d.ts +0 -1
- package/dist/_namespaces/ts.js +10196 -19
- package/dist/classifier.d.ts +3 -1
- package/dist/codeFixProvider.d.ts +2 -1
- package/dist/codefixes/helpers.d.ts +3 -1
- package/dist/codefixes/importFixes.d.ts +3 -1
- package/dist/completions.d.ts +5 -2
- package/dist/documentHighlights.d.ts +3 -1
- package/dist/documentRegistry.d.ts +2 -1
- package/dist/findAllReferences.d.ts +3 -1
- package/dist/formatting/formatting.d.ts +3 -2
- package/dist/formatting/formattingContext.d.ts +2 -1
- package/dist/formatting/formattingScanner.d.ts +2 -2
- package/dist/formatting/rule.d.ts +1 -1
- package/dist/formatting/rulesMap.d.ts +1 -1
- package/dist/formatting/smartIndenter.d.ts +2 -1
- package/dist/getEditsForFileRename.d.ts +4 -1
- package/dist/goToDefinition.d.ts +3 -1
- package/dist/importTracker.d.ts +2 -1
- package/dist/navigationBar.d.ts +3 -1
- package/dist/organizeImports.d.ts +4 -2
- package/dist/outliningElementsCollector.d.ts +3 -1
- package/dist/refactorProvider.d.ts +1 -1
- package/dist/refactors/extractSymbol.d.ts +2 -1
- package/dist/rename.d.ts +3 -1
- package/dist/services.d.ts +5 -2
- package/dist/signatureHelp.d.ts +3 -1
- package/dist/smartSelection.d.ts +2 -1
- package/dist/stringCompletions.d.ts +3 -1
- package/dist/suggestionDiagnostics.d.ts +4 -3
- package/dist/symbolDisplay.d.ts +3 -1
- package/dist/textChanges.d.ts +4 -2
- package/dist/types.d.ts +3 -3
- package/dist/utilities.d.ts +7 -2
- package/package.json +7 -5
- package/dist/_namespaces/ts.Completions.StringCompletions.js +0 -2
- package/dist/_namespaces/ts.Completions.js +0 -3
- package/dist/_namespaces/ts.FindAllReferences.js +0 -3
- package/dist/_namespaces/ts.GoToDefinition.js +0 -2
- package/dist/_namespaces/ts.NavigationBar.js +0 -2
- package/dist/_namespaces/ts.OrganizeImports.js +0 -2
- package/dist/_namespaces/ts.OutliningElementsCollector.js +0 -2
- package/dist/_namespaces/ts.Rename.js +0 -2
- package/dist/_namespaces/ts.SignatureHelp.js +0 -2
- package/dist/_namespaces/ts.SmartSelectionRange.js +0 -2
- package/dist/_namespaces/ts.SymbolDisplay.js +0 -2
- package/dist/_namespaces/ts.codefix.js +0 -27
- package/dist/_namespaces/ts.formatting.js +0 -8
- package/dist/_namespaces/ts.refactor.addOrRemoveBracesToArrowFunction.js +0 -2
- package/dist/_namespaces/ts.refactor.convertParamsToDestructuredObject.js +0 -2
- package/dist/_namespaces/ts.refactor.convertStringOrTemplateLiteral.js +0 -2
- package/dist/_namespaces/ts.refactor.extractSymbol.js +0 -2
- package/dist/_namespaces/ts.refactor.js +0 -10
- package/dist/_namespaces/ts.textChanges.js +0 -2
- package/dist/classifier.js +0 -715
- package/dist/codeFixProvider.js +0 -84
- package/dist/codefixes/addConvertToUnknownForNonOverlappingTypes.d.ts +0 -1
- package/dist/codefixes/addConvertToUnknownForNonOverlappingTypes.js +0 -21
- package/dist/codefixes/addEmptyExportDeclaration.js +0 -17
- package/dist/codefixes/addMissingAsync.js +0 -75
- package/dist/codefixes/addMissingAwait.js +0 -236
- package/dist/codefixes/addMissingConst.js +0 -91
- package/dist/codefixes/addNameToNamelessParameter.js +0 -29
- package/dist/codefixes/convertConstToLet.js +0 -30
- package/dist/codefixes/convertToAsyncFunction.js +0 -495
- package/dist/codefixes/convertToMappedObjectType.js +0 -48
- package/dist/codefixes/correctQualifiedNameToIndexedAccessType.js +0 -33
- package/dist/codefixes/fixAddModuleReferTypeMissingTypeof.js +0 -27
- package/dist/codefixes/fixAwaitInSyncFunction.js +0 -69
- package/dist/codefixes/fixExpectedComma.js +0 -35
- package/dist/codefixes/fixInvalidJsxCharacters.js +0 -41
- package/dist/codefixes/fixMissingCallParentheses.js +0 -42
- package/dist/codefixes/fixSpelling.js +0 -94
- package/dist/codefixes/fixUnreachableCode.js +0 -65
- package/dist/codefixes/fixUnusedIdentifier.js +0 -224
- package/dist/codefixes/helpers.js +0 -53
- package/dist/codefixes/importFixes.js +0 -441
- package/dist/codefixes/inferFromUsage.js +0 -742
- package/dist/codefixes/removeUnnecessaryAwait.js +0 -41
- package/dist/codefixes/returnValueCorrect.js +0 -132
- package/dist/codefixes/splitTypeOnlyImport.js +0 -32
- package/dist/codefixes/useBigintLiteral.js +0 -29
- package/dist/completions.js +0 -1720
- package/dist/documentHighlights.js +0 -367
- package/dist/documentRegistry.js +0 -63
- package/dist/editingServices.js +0 -4
- package/dist/findAllReferences.js +0 -1366
- package/dist/formatting/formatting.js +0 -1021
- package/dist/formatting/formattingContext.js +0 -78
- package/dist/formatting/formattingScanner.js +0 -228
- package/dist/formatting/rule.js +0 -22
- package/dist/formatting/rules.js +0 -610
- package/dist/formatting/rulesMap.js +0 -127
- package/dist/formatting/smartIndenter.js +0 -518
- package/dist/getEditsForFileRename.js +0 -86
- package/dist/goToDefinition.js +0 -246
- package/dist/importTracker.js +0 -422
- package/dist/index.js +0 -3
- package/dist/navigationBar.js +0 -549
- package/dist/organizeImports.js +0 -290
- package/dist/outliningElementsCollector.js +0 -261
- package/dist/refactorProvider.js +0 -16
- package/dist/refactors/addOrRemoveBracesToArrowFunction.js +0 -86
- package/dist/refactors/convertExport.js +0 -126
- package/dist/refactors/convertImport.js +0 -116
- package/dist/refactors/convertParamsToDestructuredObject.js +0 -282
- package/dist/refactors/convertStringOrTemplateLiteral.js +0 -148
- package/dist/refactors/extractSymbol.js +0 -1281
- package/dist/refactors/extractType.js +0 -102
- package/dist/refactors/moveToNewFile.js +0 -477
- package/dist/rename.js +0 -100
- package/dist/services.js +0 -1480
- package/dist/signatureHelp.js +0 -414
- package/dist/smartSelection.js +0 -243
- package/dist/stringCompletions.js +0 -220
- package/dist/suggestionDiagnostics.js +0 -92
- package/dist/symbolDisplay.js +0 -400
- package/dist/textChanges.js +0 -1163
- package/dist/types.js +0 -263
- package/dist/utilities.js +0 -1981
package/dist/symbolDisplay.js
DELETED
|
@@ -1,400 +0,0 @@
|
|
|
1
|
-
// Modificado de microsoft/TypeScript v3.9.10, src/services/symbolDisplay.ts: o namespace virou módulo ES, com os imports explícitos.
|
|
2
|
-
import { CheckFlags, Debug, EmitHint, ListFormat, NodeBuilderFlags, ObjectFlags, SymbolDisplayPartKind, SymbolFlags, SymbolFormatFlags, SyntaxKind, TypeFormatFlags, addRange, contains, createPrinter, displayPart, forEach, getCombinedLocalAndExportSymbolFlags, getDeclarationOfKind, getMeaningFromLocation, getNameOfDeclaration, getNodeModifiers, getObjectFlags, getParseTreeNode, getRootDeclaration, getSourceFileOfNode, isArrowFunction, isCallExpression, isCallExpressionTarget, isCatchClause, isFirstDeclarationOfSymbolParameter, isFunctionBlock, isFunctionLike, isFunctionLikeKind, isJsxOpeningLikeElement, isLet, isParameter, isVarConst, isVariableDeclaration, keywordPart, lineBreakPart, mapToDisplayParts, operatorPart, punctuationPart, signatureToDisplayParts, some, spacePart, symbolToDisplayParts, textOrKeywordPart, textPart, typeToDisplayParts, } from "./_namespaces/ts.js";
|
|
3
|
-
const symbolDisplayNodeBuilderFlags = NodeBuilderFlags.OmitParameterModifiers | NodeBuilderFlags.IgnoreErrors | NodeBuilderFlags.UseAliasDefinedOutsideCurrentScope;
|
|
4
|
-
export function getSymbolKind(typeChecker, symbol, location) {
|
|
5
|
-
const result = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(typeChecker, symbol, location);
|
|
6
|
-
if (result !== "" /* ScriptElementKind.unknown */) {
|
|
7
|
-
return result;
|
|
8
|
-
}
|
|
9
|
-
const flags = getCombinedLocalAndExportSymbolFlags(symbol);
|
|
10
|
-
if (flags & SymbolFlags.TypeAlias)
|
|
11
|
-
return "type" /* ScriptElementKind.typeElement */;
|
|
12
|
-
// A interface é a dos embutidos que nascem no checker (CK-48): um programa da Linguagem não a declara.
|
|
13
|
-
if (flags & SymbolFlags.Interface)
|
|
14
|
-
return "interface" /* ScriptElementKind.interfaceElement */;
|
|
15
|
-
if (flags & SymbolFlags.TypeParameter)
|
|
16
|
-
return "type parameter" /* ScriptElementKind.typeParameterElement */;
|
|
17
|
-
if (flags & SymbolFlags.Alias)
|
|
18
|
-
return "alias" /* ScriptElementKind.alias */;
|
|
19
|
-
if (flags & SymbolFlags.Module)
|
|
20
|
-
return "module" /* ScriptElementKind.moduleElement */;
|
|
21
|
-
return result;
|
|
22
|
-
}
|
|
23
|
-
function getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(typeChecker, symbol, location) {
|
|
24
|
-
// O `undefined` global é uma constante. Na tag, `var` (CK-68).
|
|
25
|
-
if (typeChecker.isUndefinedSymbol(symbol)) {
|
|
26
|
-
return "const" /* ScriptElementKind.constElement */;
|
|
27
|
-
}
|
|
28
|
-
const flags = getCombinedLocalAndExportSymbolFlags(symbol);
|
|
29
|
-
if (flags & SymbolFlags.Variable) {
|
|
30
|
-
// O nome desestruturado num parâmetro e a variável do `catch` também são parâmetros. Na tag, `var`, o rótulo do que
|
|
31
|
-
// não é `const` nem `let` (CK-68).
|
|
32
|
-
const rootDeclaration = symbol.valueDeclaration && getRootDeclaration(symbol.valueDeclaration);
|
|
33
|
-
if (isFirstDeclarationOfSymbolParameter(symbol) ||
|
|
34
|
-
rootDeclaration && (isParameter(rootDeclaration) || isVariableDeclaration(rootDeclaration) && isCatchClause(rootDeclaration.parent))) {
|
|
35
|
-
return "parameter" /* ScriptElementKind.parameterElement */;
|
|
36
|
-
}
|
|
37
|
-
else if (symbol.valueDeclaration && isVarConst(symbol.valueDeclaration)) {
|
|
38
|
-
return "const" /* ScriptElementKind.constElement */;
|
|
39
|
-
}
|
|
40
|
-
else if (forEach(symbol.declarations, isLet)) {
|
|
41
|
-
return "let" /* ScriptElementKind.letElement */;
|
|
42
|
-
}
|
|
43
|
-
return isLocalVariableOrFunction(symbol) ? "local var" /* ScriptElementKind.localVariableElement */ : "var" /* ScriptElementKind.variableElement */;
|
|
44
|
-
}
|
|
45
|
-
if (flags & SymbolFlags.Function)
|
|
46
|
-
return isLocalVariableOrFunction(symbol) ? "local function" /* ScriptElementKind.localFunctionElement */ : "function" /* ScriptElementKind.functionElement */;
|
|
47
|
-
if (flags & SymbolFlags.Property) {
|
|
48
|
-
if (flags & SymbolFlags.Transient && symbol.checkFlags & CheckFlags.Synthetic) {
|
|
49
|
-
// A propriedade de uma união que só junta o que não é método (propriedade, variável) é propriedade.
|
|
50
|
-
const unionPropertyKind = forEach(typeChecker.getRootSymbols(symbol), rootSymbol => {
|
|
51
|
-
const rootSymbolFlags = rootSymbol.getFlags();
|
|
52
|
-
// Na tag, também o acessor (CK-02).
|
|
53
|
-
if (rootSymbolFlags & (SymbolFlags.Property | SymbolFlags.Variable)) {
|
|
54
|
-
return "property" /* ScriptElementKind.memberVariableElement */;
|
|
55
|
-
}
|
|
56
|
-
// Pode ser uma função, num `typeof N` de um namespace que a declara.
|
|
57
|
-
Debug.assert(!!(rootSymbolFlags & (SymbolFlags.Method | SymbolFlags.Function)));
|
|
58
|
-
});
|
|
59
|
-
if (!unionPropertyKind) {
|
|
60
|
-
// A união só de funções é método, se o tipo dela tem assinatura de chamada.
|
|
61
|
-
const typeOfUnionProperty = typeChecker.getTypeOfSymbolAtLocation(symbol, location);
|
|
62
|
-
if (typeOfUnionProperty.getCallSignatures().length) {
|
|
63
|
-
return "method" /* ScriptElementKind.memberFunctionElement */;
|
|
64
|
-
}
|
|
65
|
-
return "property" /* ScriptElementKind.memberVariableElement */;
|
|
66
|
-
}
|
|
67
|
-
return unionPropertyKind;
|
|
68
|
-
}
|
|
69
|
-
// O completion depois de `x.` no topo pode estar no arquivo.
|
|
70
|
-
switch (location.parent && location.parent.kind) {
|
|
71
|
-
// Com um caractere do nome do atributo escrito, é o `JsxAttribute`; senão, o `JsxOpeningElement`.
|
|
72
|
-
case SyntaxKind.JsxOpeningElement:
|
|
73
|
-
case SyntaxKind.JsxElement:
|
|
74
|
-
case SyntaxKind.JsxSelfClosingElement:
|
|
75
|
-
return location.kind === SyntaxKind.Identifier ? "property" /* ScriptElementKind.memberVariableElement */ : "JSX attribute" /* ScriptElementKind.jsxAttribute */;
|
|
76
|
-
case SyntaxKind.JsxAttribute:
|
|
77
|
-
return "JSX attribute" /* ScriptElementKind.jsxAttribute */;
|
|
78
|
-
default:
|
|
79
|
-
return "property" /* ScriptElementKind.memberVariableElement */;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return "" /* ScriptElementKind.unknown */;
|
|
83
|
-
}
|
|
84
|
-
export function getSymbolModifiers(symbol) {
|
|
85
|
-
const nodeModifiers = symbol && symbol.declarations && symbol.declarations.length > 0
|
|
86
|
-
? getNodeModifiers(symbol.declarations[0])
|
|
87
|
-
: "" /* ScriptElementKindModifier.none */;
|
|
88
|
-
const symbolModifiers = symbol && symbol.flags & SymbolFlags.Optional ?
|
|
89
|
-
"optional" /* ScriptElementKindModifier.optionalModifier */
|
|
90
|
-
: "" /* ScriptElementKindModifier.none */;
|
|
91
|
-
return nodeModifiers && symbolModifiers ? nodeModifiers + "," + symbolModifiers : nodeModifiers || symbolModifiers;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* O texto do símbolo no ponto (`displayParts`), o tipo de símbolo e a documentação. A documentação e as tags vinham do
|
|
95
|
-
* JSDoc, que a cópia não tem (CK-03): saem vazias.
|
|
96
|
-
*/
|
|
97
|
-
export function getSymbolDisplayPartsDocumentationAndSymbolKind(typeChecker, symbol, sourceFile, enclosingDeclaration, location, semanticMeaning = getMeaningFromLocation(location), alias) {
|
|
98
|
-
const displayParts = [];
|
|
99
|
-
const symbolFlags = getCombinedLocalAndExportSymbolFlags(symbol);
|
|
100
|
-
let symbolKind = semanticMeaning & 1 /* SemanticMeaning.Value */ ? getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(typeChecker, symbol, location) : "" /* ScriptElementKind.unknown */;
|
|
101
|
-
let hasAddedSymbolInfo = false;
|
|
102
|
-
let type;
|
|
103
|
-
let printer;
|
|
104
|
-
if (symbolKind !== "" /* ScriptElementKind.unknown */ || symbolFlags & SymbolFlags.Alias) {
|
|
105
|
-
let signature;
|
|
106
|
-
type = typeChecker.getTypeOfSymbolAtLocation(symbol.exportSymbol || symbol, location);
|
|
107
|
-
if (location.parent && location.parent.kind === SyntaxKind.PropertyAccessExpression) {
|
|
108
|
-
const right = location.parent.name;
|
|
109
|
-
// O ponto está à direita de um acesso, ou à esquerda com a direita faltando.
|
|
110
|
-
if (right === location || (right && right.getFullWidth() === 0)) {
|
|
111
|
-
location = location.parent;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
// a assinatura da chamada, quando o ponto é uma
|
|
115
|
-
let callExpressionLike;
|
|
116
|
-
if (isCallExpression(location)) {
|
|
117
|
-
callExpressionLike = location;
|
|
118
|
-
}
|
|
119
|
-
else if (isCallExpressionTarget(location)) {
|
|
120
|
-
callExpressionLike = location.parent;
|
|
121
|
-
}
|
|
122
|
-
else if (location.parent && isJsxOpeningLikeElement(location.parent) && isFunctionLike(symbol.valueDeclaration)) {
|
|
123
|
-
callExpressionLike = location.parent;
|
|
124
|
-
}
|
|
125
|
-
if (callExpressionLike) {
|
|
126
|
-
signature = typeChecker.getResolvedSignature(callExpressionLike);
|
|
127
|
-
const allSignatures = type.getCallSignatures();
|
|
128
|
-
if (!contains(allSignatures, signature.target) && !contains(allSignatures, signature)) {
|
|
129
|
-
// A primeira assinatura, se há: a lista pode ter a original ou o alvo dela.
|
|
130
|
-
signature = allSignatures.length ? allSignatures[0] : undefined;
|
|
131
|
-
}
|
|
132
|
-
if (signature) {
|
|
133
|
-
if (symbolFlags & SymbolFlags.Alias) {
|
|
134
|
-
symbolKind = "alias" /* ScriptElementKind.alias */;
|
|
135
|
-
pushSymbolKind(symbolKind);
|
|
136
|
-
displayParts.push(spacePart());
|
|
137
|
-
addFullSymbolName(symbol);
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
addPrefixForAnyFunctionOrVar(symbol, symbolKind);
|
|
141
|
-
}
|
|
142
|
-
switch (symbolKind) {
|
|
143
|
-
case "JSX attribute" /* ScriptElementKind.jsxAttribute */:
|
|
144
|
-
case "property" /* ScriptElementKind.memberVariableElement */:
|
|
145
|
-
case "var" /* ScriptElementKind.variableElement */:
|
|
146
|
-
case "const" /* ScriptElementKind.constElement */:
|
|
147
|
-
case "let" /* ScriptElementKind.letElement */:
|
|
148
|
-
case "parameter" /* ScriptElementKind.parameterElement */:
|
|
149
|
-
case "local var" /* ScriptElementKind.localVariableElement */:
|
|
150
|
-
// A assinatura de uma arrow escreve o nome do tipo.
|
|
151
|
-
displayParts.push(punctuationPart(SyntaxKind.ColonToken));
|
|
152
|
-
displayParts.push(spacePart());
|
|
153
|
-
if (!(getObjectFlags(type) & ObjectFlags.Anonymous) && type.symbol) {
|
|
154
|
-
addRange(displayParts, symbolToDisplayParts(typeChecker, type.symbol, enclosingDeclaration, /*meaning*/ undefined, SymbolFormatFlags.AllowAnyNodeKind | SymbolFormatFlags.WriteTypeParametersOrArguments));
|
|
155
|
-
displayParts.push(lineBreakPart());
|
|
156
|
-
}
|
|
157
|
-
addSignatureDisplayParts(signature, allSignatures, TypeFormatFlags.WriteArrowStyleSignature);
|
|
158
|
-
break;
|
|
159
|
-
default:
|
|
160
|
-
// só a assinatura
|
|
161
|
-
addSignatureDisplayParts(signature, allSignatures);
|
|
162
|
-
}
|
|
163
|
-
hasAddedSymbolInfo = true;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
if ((symbolFlags & SymbolFlags.Interface) && (semanticMeaning & 2 /* SemanticMeaning.Type */)) {
|
|
168
|
-
prefixNextMeaning();
|
|
169
|
-
// A interface que fica é a do embutido, que nasce no checker (CK-48), e a Linguagem descreve um tipo com o `type`.
|
|
170
|
-
// Na tag, a palavra `interface`, que saiu do scanner (CK-56) (CK-68).
|
|
171
|
-
displayParts.push(keywordPart(SyntaxKind.TypeKeyword));
|
|
172
|
-
displayParts.push(spacePart());
|
|
173
|
-
addFullSymbolName(symbol);
|
|
174
|
-
writeTypeParametersOfSymbol(symbol, sourceFile);
|
|
175
|
-
}
|
|
176
|
-
if ((symbolFlags & SymbolFlags.TypeAlias) && (semanticMeaning & 2 /* SemanticMeaning.Type */)) {
|
|
177
|
-
prefixNextMeaning();
|
|
178
|
-
displayParts.push(keywordPart(SyntaxKind.TypeKeyword));
|
|
179
|
-
displayParts.push(spacePart());
|
|
180
|
-
addFullSymbolName(symbol);
|
|
181
|
-
writeTypeParametersOfSymbol(symbol, sourceFile);
|
|
182
|
-
displayParts.push(spacePart());
|
|
183
|
-
displayParts.push(operatorPart(SyntaxKind.EqualsToken));
|
|
184
|
-
displayParts.push(spacePart());
|
|
185
|
-
addRange(displayParts, typeToDisplayParts(typeChecker, typeChecker.getDeclaredTypeOfSymbol(symbol), enclosingDeclaration, TypeFormatFlags.InTypeAlias));
|
|
186
|
-
}
|
|
187
|
-
if (symbolFlags & SymbolFlags.Module) {
|
|
188
|
-
prefixNextMeaning();
|
|
189
|
-
const declaration = getDeclarationOfKind(symbol, SyntaxKind.ModuleDeclaration);
|
|
190
|
-
const isNamespace = declaration && declaration.name && declaration.name.kind === SyntaxKind.Identifier;
|
|
191
|
-
// O módulo ES é da Linguagem (CK-46), mas a palavra `module` saiu do scanner (CK-56): ela se escreve como texto, com
|
|
192
|
-
// o tipo de palavra-chave que a tag dava (CK-68).
|
|
193
|
-
displayParts.push(isNamespace ? keywordPart(SyntaxKind.NamespaceKeyword) : displayPart("module", SymbolDisplayPartKind.keyword));
|
|
194
|
-
displayParts.push(spacePart());
|
|
195
|
-
addFullSymbolName(symbol);
|
|
196
|
-
}
|
|
197
|
-
if ((symbolFlags & SymbolFlags.TypeParameter) && (semanticMeaning & 2 /* SemanticMeaning.Type */)) {
|
|
198
|
-
prefixNextMeaning();
|
|
199
|
-
displayParts.push(punctuationPart(SyntaxKind.OpenParenToken));
|
|
200
|
-
displayParts.push(textPart("type parameter"));
|
|
201
|
-
displayParts.push(punctuationPart(SyntaxKind.CloseParenToken));
|
|
202
|
-
displayParts.push(spacePart());
|
|
203
|
-
addFullSymbolName(symbol);
|
|
204
|
-
if (symbol.parent) {
|
|
205
|
-
// o parâmetro de tipo de uma interface
|
|
206
|
-
addInPrefix();
|
|
207
|
-
addFullSymbolName(symbol.parent, enclosingDeclaration);
|
|
208
|
-
writeTypeParametersOfSymbol(symbol.parent, enclosingDeclaration);
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
// o parâmetro de tipo de uma função ou de um alias
|
|
212
|
-
const decl = getDeclarationOfKind(symbol, SyntaxKind.TypeParameter);
|
|
213
|
-
if (decl === undefined)
|
|
214
|
-
return Debug.fail();
|
|
215
|
-
const declaration = decl.parent;
|
|
216
|
-
if (declaration) {
|
|
217
|
-
if (isFunctionLikeKind(declaration.kind)) {
|
|
218
|
-
addInPrefix();
|
|
219
|
-
const signature = typeChecker.getSignatureFromDeclaration(declaration);
|
|
220
|
-
if (declaration.kind !== SyntaxKind.CallSignature && declaration.name) {
|
|
221
|
-
addFullSymbolName(declaration.symbol);
|
|
222
|
-
}
|
|
223
|
-
addRange(displayParts, signatureToDisplayParts(typeChecker, signature, sourceFile, TypeFormatFlags.WriteTypeArgumentsOfSignature));
|
|
224
|
-
}
|
|
225
|
-
else if (declaration.kind === SyntaxKind.TypeAliasDeclaration) {
|
|
226
|
-
// O parâmetro de tipo de um alias: em `type list<T> = T[]`, os dois `T` passam por aqui.
|
|
227
|
-
addInPrefix();
|
|
228
|
-
displayParts.push(keywordPart(SyntaxKind.TypeKeyword));
|
|
229
|
-
displayParts.push(spacePart());
|
|
230
|
-
addFullSymbolName(declaration.symbol);
|
|
231
|
-
writeTypeParametersOfSymbol(declaration.symbol, sourceFile);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
if (symbolFlags & SymbolFlags.Alias) {
|
|
237
|
-
prefixNextMeaning();
|
|
238
|
-
if (!hasAddedSymbolInfo) {
|
|
239
|
-
const resolvedSymbol = typeChecker.getAliasedSymbol(symbol);
|
|
240
|
-
if (resolvedSymbol !== symbol && resolvedSymbol.declarations && resolvedSymbol.declarations.length > 0) {
|
|
241
|
-
const resolvedNode = resolvedSymbol.declarations[0];
|
|
242
|
-
const declarationName = getNameOfDeclaration(resolvedNode);
|
|
243
|
-
if (declarationName) {
|
|
244
|
-
// Na tag, o alias de um `declare module "x"` mostrava o nome do módulo; ele saiu (CK-02).
|
|
245
|
-
const shouldUseAliasName = symbol.name !== "default";
|
|
246
|
-
const resolvedInfo = getSymbolDisplayPartsDocumentationAndSymbolKind(typeChecker, resolvedSymbol, getSourceFileOfNode(resolvedNode), resolvedNode, declarationName, semanticMeaning, shouldUseAliasName ? symbol : resolvedSymbol);
|
|
247
|
-
displayParts.push(...resolvedInfo.displayParts);
|
|
248
|
-
displayParts.push(lineBreakPart());
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
switch (symbol.declarations[0].kind) {
|
|
253
|
-
case SyntaxKind.ExportAssignment:
|
|
254
|
-
// Na tag, o `export =` dava o `=` no lugar do `default` (CK-03).
|
|
255
|
-
displayParts.push(keywordPart(SyntaxKind.ExportKeyword));
|
|
256
|
-
displayParts.push(spacePart());
|
|
257
|
-
displayParts.push(keywordPart(SyntaxKind.DefaultKeyword));
|
|
258
|
-
break;
|
|
259
|
-
case SyntaxKind.ExportSpecifier:
|
|
260
|
-
displayParts.push(keywordPart(SyntaxKind.ExportKeyword));
|
|
261
|
-
break;
|
|
262
|
-
default:
|
|
263
|
-
displayParts.push(keywordPart(SyntaxKind.ImportKeyword));
|
|
264
|
-
}
|
|
265
|
-
displayParts.push(spacePart());
|
|
266
|
-
addFullSymbolName(symbol);
|
|
267
|
-
}
|
|
268
|
-
if (!hasAddedSymbolInfo) {
|
|
269
|
-
if (symbolKind !== "" /* ScriptElementKind.unknown */) {
|
|
270
|
-
if (type) {
|
|
271
|
-
addPrefixForAnyFunctionOrVar(symbol, symbolKind);
|
|
272
|
-
// a propriedade, a variável e o local mostram o tipo
|
|
273
|
-
if (symbolKind === "property" /* ScriptElementKind.memberVariableElement */ ||
|
|
274
|
-
symbolKind === "JSX attribute" /* ScriptElementKind.jsxAttribute */ ||
|
|
275
|
-
symbolFlags & SymbolFlags.Variable ||
|
|
276
|
-
symbolKind === "local var" /* ScriptElementKind.localVariableElement */) {
|
|
277
|
-
displayParts.push(punctuationPart(SyntaxKind.ColonToken));
|
|
278
|
-
displayParts.push(spacePart());
|
|
279
|
-
// o parâmetro de tipo se escreve como a declaração dele
|
|
280
|
-
if (type.symbol && type.symbol.flags & SymbolFlags.TypeParameter) {
|
|
281
|
-
const typeParameterParts = mapToDisplayParts(writer => {
|
|
282
|
-
const param = typeChecker.typeParameterToDeclaration(type, enclosingDeclaration, symbolDisplayNodeBuilderFlags);
|
|
283
|
-
getPrinter().writeNode(EmitHint.Unspecified, param, getSourceFileOfNode(getParseTreeNode(enclosingDeclaration)), writer);
|
|
284
|
-
});
|
|
285
|
-
addRange(displayParts, typeParameterParts);
|
|
286
|
-
}
|
|
287
|
-
else {
|
|
288
|
-
addRange(displayParts, typeToDisplayParts(typeChecker, type, enclosingDeclaration));
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
else if (symbolFlags & SymbolFlags.Function ||
|
|
292
|
-
symbolFlags & SymbolFlags.Signature ||
|
|
293
|
-
symbolKind === "method" /* ScriptElementKind.memberFunctionElement */) {
|
|
294
|
-
const allSignatures = type.getNonNullableType().getCallSignatures();
|
|
295
|
-
if (allSignatures.length) {
|
|
296
|
-
addSignatureDisplayParts(allSignatures[0], allSignatures);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
else {
|
|
302
|
-
symbolKind = getSymbolKind(typeChecker, symbol, location);
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
return { displayParts, documentation: [], symbolKind, tags: undefined };
|
|
306
|
-
function getPrinter() {
|
|
307
|
-
if (!printer) {
|
|
308
|
-
printer = createPrinter({ removeComments: true });
|
|
309
|
-
}
|
|
310
|
-
return printer;
|
|
311
|
-
}
|
|
312
|
-
function prefixNextMeaning() {
|
|
313
|
-
if (displayParts.length) {
|
|
314
|
-
displayParts.push(lineBreakPart());
|
|
315
|
-
}
|
|
316
|
-
addAliasPrefixIfNecessary();
|
|
317
|
-
}
|
|
318
|
-
function addAliasPrefixIfNecessary() {
|
|
319
|
-
if (alias) {
|
|
320
|
-
pushSymbolKind("alias" /* ScriptElementKind.alias */);
|
|
321
|
-
displayParts.push(spacePart());
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
function addInPrefix() {
|
|
325
|
-
displayParts.push(spacePart());
|
|
326
|
-
displayParts.push(keywordPart(SyntaxKind.InKeyword));
|
|
327
|
-
displayParts.push(spacePart());
|
|
328
|
-
}
|
|
329
|
-
function addFullSymbolName(symbolToDisplay, enclosingDeclaration) {
|
|
330
|
-
if (alias && symbolToDisplay === symbol) {
|
|
331
|
-
symbolToDisplay = alias;
|
|
332
|
-
}
|
|
333
|
-
const fullSymbolDisplayParts = symbolToDisplayParts(typeChecker, symbolToDisplay, enclosingDeclaration || sourceFile, /*meaning*/ undefined, SymbolFormatFlags.WriteTypeParametersOrArguments | SymbolFormatFlags.UseOnlyExternalAliasing | SymbolFormatFlags.AllowAnyNodeKind);
|
|
334
|
-
addRange(displayParts, fullSymbolDisplayParts);
|
|
335
|
-
if (symbol.flags & SymbolFlags.Optional) {
|
|
336
|
-
displayParts.push(punctuationPart(SyntaxKind.QuestionToken));
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
function addPrefixForAnyFunctionOrVar(symbol, symbolKind) {
|
|
340
|
-
prefixNextMeaning();
|
|
341
|
-
if (symbolKind) {
|
|
342
|
-
pushSymbolKind(symbolKind);
|
|
343
|
-
if (symbol && !some(symbol.declarations, d => isArrowFunction(d))) {
|
|
344
|
-
displayParts.push(spacePart());
|
|
345
|
-
addFullSymbolName(symbol);
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
function pushSymbolKind(symbolKind) {
|
|
350
|
-
switch (symbolKind) {
|
|
351
|
-
case "var" /* ScriptElementKind.variableElement */:
|
|
352
|
-
case "function" /* ScriptElementKind.functionElement */:
|
|
353
|
-
case "let" /* ScriptElementKind.letElement */:
|
|
354
|
-
case "const" /* ScriptElementKind.constElement */:
|
|
355
|
-
displayParts.push(textOrKeywordPart(symbolKind));
|
|
356
|
-
return;
|
|
357
|
-
default:
|
|
358
|
-
displayParts.push(punctuationPart(SyntaxKind.OpenParenToken));
|
|
359
|
-
displayParts.push(textOrKeywordPart(symbolKind));
|
|
360
|
-
displayParts.push(punctuationPart(SyntaxKind.CloseParenToken));
|
|
361
|
-
return;
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
function addSignatureDisplayParts(signature, allSignatures, flags = TypeFormatFlags.None) {
|
|
365
|
-
addRange(displayParts, signatureToDisplayParts(typeChecker, signature, enclosingDeclaration, flags | TypeFormatFlags.WriteTypeArgumentsOfSignature));
|
|
366
|
-
if (allSignatures.length > 1) {
|
|
367
|
-
displayParts.push(spacePart());
|
|
368
|
-
displayParts.push(punctuationPart(SyntaxKind.OpenParenToken));
|
|
369
|
-
displayParts.push(operatorPart(SyntaxKind.PlusToken));
|
|
370
|
-
displayParts.push(displayPart((allSignatures.length - 1).toString(), SymbolDisplayPartKind.numericLiteral));
|
|
371
|
-
displayParts.push(spacePart());
|
|
372
|
-
displayParts.push(textPart(allSignatures.length === 2 ? "overload" : "overloads"));
|
|
373
|
-
displayParts.push(punctuationPart(SyntaxKind.CloseParenToken));
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
function writeTypeParametersOfSymbol(symbol, enclosingDeclaration) {
|
|
377
|
-
const typeParameterParts = mapToDisplayParts(writer => {
|
|
378
|
-
const params = typeChecker.symbolToTypeParameterDeclarations(symbol, enclosingDeclaration, symbolDisplayNodeBuilderFlags);
|
|
379
|
-
getPrinter().writeList(ListFormat.TypeParameters, params, getSourceFileOfNode(getParseTreeNode(enclosingDeclaration)), writer);
|
|
380
|
-
});
|
|
381
|
-
addRange(displayParts, typeParameterParts);
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
function isLocalVariableOrFunction(symbol) {
|
|
385
|
-
if (symbol.parent) {
|
|
386
|
-
return false; // o símbolo exportado
|
|
387
|
-
}
|
|
388
|
-
return forEach(symbol.declarations, declaration => {
|
|
389
|
-
if (declaration.kind !== SyntaxKind.VariableDeclaration) {
|
|
390
|
-
return false;
|
|
391
|
-
}
|
|
392
|
-
// A variável é local se o caminho até o arquivo ou o bloco de módulo passa pelo bloco de uma função.
|
|
393
|
-
for (let parent = declaration.parent; !isFunctionBlock(parent); parent = parent.parent) {
|
|
394
|
-
if (parent.kind === SyntaxKind.SourceFile || parent.kind === SyntaxKind.ModuleBlock) {
|
|
395
|
-
return false;
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
return true;
|
|
399
|
-
});
|
|
400
|
-
}
|