@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,400 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { ScriptKind, SyntaxKind, formatting } from "./_namespaces/edit.js";
|
|
2
|
+
import type { DeclarationStatement, Expression, FileTextChanges, LanguageServiceHost, Modifier, Node, NodeArray, ObjectLiteralElementLike, ObjectLiteralExpression, ParameterDeclaration, PropertyAssignment, PropertySignature, SignatureDeclaration, SourceFile, Statement, TextChange, TextRange, TypeNode, TypeParameterDeclaration, UserPreferences, VariableDeclaration, VariableStatement } from "./_namespaces/edit.js";
|
|
3
|
+
export interface ConfigurableStart {
|
|
4
|
+
leadingTriviaOption?: LeadingTriviaOption;
|
|
5
|
+
}
|
|
6
|
+
export interface ConfigurableEnd {
|
|
7
|
+
trailingTriviaOption?: TrailingTriviaOption;
|
|
8
|
+
}
|
|
9
|
+
export declare enum LeadingTriviaOption {
|
|
10
|
+
/** Exclude all leading trivia (use getStart()) */
|
|
11
|
+
Exclude = 0,
|
|
12
|
+
/** Include leading trivia and,
|
|
13
|
+
* if there are no line breaks between the node and the previous token,
|
|
14
|
+
* include all trivia between the node and the previous token
|
|
15
|
+
*/
|
|
16
|
+
IncludeAll = 1,
|
|
17
|
+
/**
|
|
18
|
+
* Only delete trivia on the same line as getStart().
|
|
19
|
+
* Used to avoid deleting leading comments
|
|
20
|
+
*/
|
|
21
|
+
StartLine = 2
|
|
22
|
+
}
|
|
23
|
+
export declare enum TrailingTriviaOption {
|
|
24
|
+
/** Exclude all trailing trivia (use getEnd()) */
|
|
25
|
+
Exclude = 0,
|
|
26
|
+
/** Include trailing trivia */
|
|
27
|
+
Include = 1
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Usually node.pos points to a position immediately after the previous token.
|
|
31
|
+
* If this position is used as a beginning of the span to remove - it might lead to removing the trailing trivia of the previous node, i.e:
|
|
32
|
+
* const x; // this is x
|
|
33
|
+
* ^ - pos for the next variable declaration will point here
|
|
34
|
+
* const y; // this is y
|
|
35
|
+
* ^ - end for previous variable declaration
|
|
36
|
+
* Usually leading trivia of the variable declaration 'y' should not include trailing trivia (whitespace, comment 'this is x' and newline) from the preceding
|
|
37
|
+
* variable declaration and trailing trivia for 'y' should include (whitespace, comment 'this is y', newline).
|
|
38
|
+
* By default when removing nodes we adjust start and end positions to respect specification of the trivia above.
|
|
39
|
+
* If pos\end should be interpreted literally (that is, withouth including leading and trailing trivia), `leadingTriviaOption` should be set to `LeadingTriviaOption.Exclude`
|
|
40
|
+
* and `trailingTriviaOption` to `TrailingTriviaOption.Exclude`.
|
|
41
|
+
*/
|
|
42
|
+
export interface ConfigurableStartEnd extends ConfigurableStart, ConfigurableEnd {
|
|
43
|
+
}
|
|
44
|
+
export interface InsertNodeOptions {
|
|
45
|
+
/**
|
|
46
|
+
* Text to be inserted before the new node
|
|
47
|
+
*/
|
|
48
|
+
prefix?: string;
|
|
49
|
+
/**
|
|
50
|
+
* Text to be inserted after the new node
|
|
51
|
+
*/
|
|
52
|
+
suffix?: string;
|
|
53
|
+
/**
|
|
54
|
+
* Text of inserted node will be formatted with this indentation, otherwise indentation will be inferred from the old node
|
|
55
|
+
*/
|
|
56
|
+
indentation?: number;
|
|
57
|
+
/**
|
|
58
|
+
* Text of inserted node will be formatted with this delta, otherwise delta will be inferred from the new node kind
|
|
59
|
+
*/
|
|
60
|
+
delta?: number;
|
|
61
|
+
/**
|
|
62
|
+
* Do not trim leading white spaces in the edit range
|
|
63
|
+
*/
|
|
64
|
+
preserveLeadingWhitespace?: boolean;
|
|
65
|
+
}
|
|
66
|
+
export interface ReplaceWithMultipleNodesOptions extends InsertNodeOptions {
|
|
67
|
+
readonly joiner?: string;
|
|
68
|
+
}
|
|
69
|
+
export interface ChangeNodeOptions extends ConfigurableStartEnd, InsertNodeOptions {
|
|
70
|
+
}
|
|
71
|
+
export interface TextChangesContext {
|
|
72
|
+
host: LanguageServiceHost;
|
|
73
|
+
formatContext: formatting.FormatContext;
|
|
74
|
+
preferences: UserPreferences;
|
|
75
|
+
}
|
|
76
|
+
export type TypeAnnotatable = SignatureDeclaration | VariableDeclaration | ParameterDeclaration | PropertySignature;
|
|
77
|
+
export declare class ChangeTracker {
|
|
78
|
+
private readonly newLineCharacter;
|
|
79
|
+
private readonly formatContext;
|
|
80
|
+
private readonly changes;
|
|
81
|
+
private readonly newFiles;
|
|
82
|
+
private readonly classesWithNodesInsertedAtStart;
|
|
83
|
+
private readonly deletedNodes;
|
|
84
|
+
static fromContext(context: TextChangesContext): ChangeTracker;
|
|
85
|
+
static with(context: TextChangesContext, cb: (tracker: ChangeTracker) => void): FileTextChanges[];
|
|
86
|
+
/** Public for tests only. Other callers should use `ChangeTracker.with`. */
|
|
87
|
+
constructor(newLineCharacter: string, formatContext: formatting.FormatContext);
|
|
88
|
+
pushRaw(sourceFile: SourceFile, change: FileTextChanges): void;
|
|
89
|
+
deleteRange(sourceFile: SourceFile, range: TextRange): void;
|
|
90
|
+
delete(sourceFile: SourceFile, node: Node | NodeArray<TypeParameterDeclaration>): void;
|
|
91
|
+
deleteNode(sourceFile: SourceFile, node: Node, options?: ConfigurableStartEnd): void;
|
|
92
|
+
deleteModifier(sourceFile: SourceFile, modifier: Modifier): void;
|
|
93
|
+
deleteNodeRange(sourceFile: SourceFile, startNode: Node, endNode: Node, options?: ConfigurableStartEnd): void;
|
|
94
|
+
deleteNodeRangeExcludingEnd(sourceFile: SourceFile, startNode: Node, afterEndNode: Node | undefined, options?: ConfigurableStartEnd): void;
|
|
95
|
+
replaceRange(sourceFile: SourceFile, range: TextRange, newNode: Node, options?: InsertNodeOptions): void;
|
|
96
|
+
replaceNode(sourceFile: SourceFile, oldNode: Node, newNode: Node, options?: ChangeNodeOptions): void;
|
|
97
|
+
replaceNodeRange(sourceFile: SourceFile, startNode: Node, endNode: Node, newNode: Node, options?: ChangeNodeOptions): void;
|
|
98
|
+
private replaceRangeWithNodes;
|
|
99
|
+
replaceNodeWithNodes(sourceFile: SourceFile, oldNode: Node, newNodes: readonly Node[], options?: ChangeNodeOptions): void;
|
|
100
|
+
replaceNodeWithText(sourceFile: SourceFile, oldNode: Node, text: string): void;
|
|
101
|
+
replaceNodeRangeWithNodes(sourceFile: SourceFile, startNode: Node, endNode: Node, newNodes: readonly Node[], options?: ReplaceWithMultipleNodesOptions & ConfigurableStartEnd): void;
|
|
102
|
+
private nextCommaToken;
|
|
103
|
+
replacePropertyAssignment(sourceFile: SourceFile, oldNode: PropertyAssignment, newNode: PropertyAssignment): void;
|
|
104
|
+
insertNodeAt(sourceFile: SourceFile, pos: number, newNode: Node, options?: InsertNodeOptions): void;
|
|
105
|
+
private insertNodesAt;
|
|
106
|
+
insertNodeAtTopOfFile(sourceFile: SourceFile, newNode: Statement, blankLineBetween: boolean): void;
|
|
107
|
+
insertNodesAtTopOfFile(sourceFile: SourceFile, newNodes: readonly Statement[], blankLineBetween: boolean): void;
|
|
108
|
+
private insertAtTopOfFile;
|
|
109
|
+
insertFirstParameter(sourceFile: SourceFile, parameters: NodeArray<ParameterDeclaration>, newParam: ParameterDeclaration): void;
|
|
110
|
+
insertNodeBefore(sourceFile: SourceFile, before: Node, newNode: Node, blankLineBetween?: boolean): void;
|
|
111
|
+
insertModifierBefore(sourceFile: SourceFile, modifier: SyntaxKind, before: Node): void;
|
|
112
|
+
insertLastModifierBefore(sourceFile: SourceFile, modifier: SyntaxKind, before: Node): void;
|
|
113
|
+
insertCommentBeforeLine(sourceFile: SourceFile, lineNumber: number, position: number, commentText: string): void;
|
|
114
|
+
replaceRangeWithText(sourceFile: SourceFile, range: TextRange, text: string): void;
|
|
115
|
+
insertText(sourceFile: SourceFile, pos: number, text: string): void;
|
|
116
|
+
/** Prefer this over replacing a node with another that has a type annotation, as it avoids reformatting the other parts of the node. */
|
|
117
|
+
tryInsertTypeAnnotation(sourceFile: SourceFile, node: TypeAnnotatable, type: TypeNode): boolean;
|
|
118
|
+
insertTypeParameters(sourceFile: SourceFile, node: SignatureDeclaration, typeParameters: readonly TypeParameterDeclaration[]): void;
|
|
119
|
+
private getOptionsForInsertNodeBefore;
|
|
120
|
+
insertNodeAtEndOfScope(sourceFile: SourceFile, scope: Node, newNode: Node): void;
|
|
121
|
+
insertNodeAtObjectStart(sourceFile: SourceFile, obj: ObjectLiteralExpression, newElement: ObjectLiteralElementLike): void;
|
|
122
|
+
private insertNodeAtStartWorker;
|
|
123
|
+
/**
|
|
124
|
+
* Tries to guess the indentation from the existing members of a class/interface/object. All members must be on
|
|
125
|
+
* new lines and must share the same indentation.
|
|
126
|
+
*/
|
|
127
|
+
private guessIndentationFromExistingMembers;
|
|
128
|
+
private computeIndentationForNewMember;
|
|
129
|
+
private getInsertNodeAtStartInsertOptions;
|
|
130
|
+
insertNodeAfterComma(sourceFile: SourceFile, after: Node, newNode: Node): void;
|
|
131
|
+
insertNodeAfter(sourceFile: SourceFile, after: Node, newNode: Node): void;
|
|
132
|
+
insertNodeAtEndOfList(sourceFile: SourceFile, list: NodeArray<Node>, newNode: Node): void;
|
|
133
|
+
insertNodesAfter(sourceFile: SourceFile, after: Node, newNodes: readonly Node[]): void;
|
|
134
|
+
private insertNodeAfterWorker;
|
|
135
|
+
private getInsertNodeAfterOptions;
|
|
136
|
+
private getInsertNodeAfterOptionsWorker;
|
|
137
|
+
insertExportModifier(sourceFile: SourceFile, node: DeclarationStatement | VariableStatement): void;
|
|
138
|
+
/**
|
|
139
|
+
* This function should be used to insert nodes in lists when nodes don't carry separators as the part of the node range,
|
|
140
|
+
* i.e. arguments in arguments lists, parameters in parameter lists etc.
|
|
141
|
+
* Note that separators are part of the node in statements and class elements.
|
|
142
|
+
*/
|
|
143
|
+
insertNodeInListAfter(sourceFile: SourceFile, after: Node, newNode: Node, containingList?: NodeArray<Node> | undefined): void;
|
|
144
|
+
parenthesizeExpression(sourceFile: SourceFile, expression: Expression): void;
|
|
145
|
+
private finishClassesWithNodesInsertedAtStart;
|
|
146
|
+
private finishDeleteDeclarations;
|
|
147
|
+
/**
|
|
148
|
+
* Note: after calling this, the TextChanges object must be discarded!
|
|
149
|
+
* @param validate only for tests
|
|
150
|
+
* The reason we must validate as part of this method is that `getNonFormattedText` changes the node's positions,
|
|
151
|
+
* so we can only call this once and can't get the non-formatted text separately.
|
|
152
|
+
*/
|
|
153
|
+
getChanges(validate?: ValidateNonFormattedText): FileTextChanges[];
|
|
154
|
+
createNewFile(oldFile: SourceFile | undefined, fileName: string, statements: readonly Statement[]): void;
|
|
155
|
+
}
|
|
156
|
+
export type ValidateNonFormattedText = (node: Node, text: string) => void;
|
|
157
|
+
export declare function getNewFileText(statements: readonly Statement[], scriptKind: ScriptKind, newLineCharacter: string, formatContext: formatting.FormatContext): string;
|
|
158
|
+
export declare function applyChanges(text: string, changes: readonly TextChange[]): string;
|
|
159
|
+
export declare function isValidLocationToAddComment(sourceFile: SourceFile, position: number): boolean;
|
|
160
|
+
/** Warning: This deletes comments too. See `copyComments` in `convertFunctionToEs6Class`. */
|
|
161
|
+
export declare function deleteNode(changes: ChangeTracker, sourceFile: SourceFile, node: Node, options?: ConfigurableStartEnd): void;
|