@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 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Modificado de microsoft/TypeScript v3.9.10, src/services/codefixes/removeUnnecessaryAwait.ts: o namespace virou módulo ES, com os imports explícitos.
|
|
2
|
+
import { Diagnostics, SyntaxKind, findPrecedingToken, getLeftmostExpression, getTokenAtPosition, isAwaitExpression, isIdentifier, isParenthesizedExpression, textChanges, tryCast, } from "../_namespaces/edit.js";
|
|
3
|
+
import { codeFixAll, createCodeFixAction, registerCodeFix, } from "../_namespaces/ts.codefix.js";
|
|
4
|
+
const fixId = "removeUnnecessaryAwait";
|
|
5
|
+
const errorCodes = [
|
|
6
|
+
Diagnostics.await_has_no_effect_on_the_type_of_this_expression.code,
|
|
7
|
+
];
|
|
8
|
+
registerCodeFix({
|
|
9
|
+
errorCodes,
|
|
10
|
+
getCodeActions: (context) => {
|
|
11
|
+
const changes = textChanges.ChangeTracker.with(context, t => makeChange(t, context.sourceFile, context.span));
|
|
12
|
+
if (changes.length > 0) {
|
|
13
|
+
return [createCodeFixAction(fixId, changes, Diagnostics.Remove_unnecessary_await, fixId, Diagnostics.Remove_all_unnecessary_uses_of_await)];
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
fixIds: [fixId],
|
|
17
|
+
getAllCodeActions: context => {
|
|
18
|
+
return codeFixAll(context, errorCodes, (changes, diag) => makeChange(changes, diag.file, diag));
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
function makeChange(changeTracker, sourceFile, span) {
|
|
22
|
+
const awaitKeyword = tryCast(getTokenAtPosition(sourceFile, span.start), (node) => node.kind === SyntaxKind.AwaitKeyword);
|
|
23
|
+
const awaitExpression = awaitKeyword && tryCast(awaitKeyword.parent, isAwaitExpression);
|
|
24
|
+
if (!awaitExpression) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
let expressionToReplace = awaitExpression;
|
|
28
|
+
const hasSurroundingParens = isParenthesizedExpression(awaitExpression.parent);
|
|
29
|
+
if (hasSurroundingParens) {
|
|
30
|
+
// Na tag, com o `stopAtCallExpressions` desligado, que a cópia tirou porque todo chamador o desligava.
|
|
31
|
+
const leftMostExpression = getLeftmostExpression(awaitExpression.expression);
|
|
32
|
+
if (isIdentifier(leftMostExpression)) {
|
|
33
|
+
const precedingToken = findPrecedingToken(awaitExpression.parent.pos, sourceFile);
|
|
34
|
+
// Na tag, o `new (await x)()` ficava com os parênteses; o `new` saiu (CK-02, CK-56).
|
|
35
|
+
if (precedingToken) {
|
|
36
|
+
expressionToReplace = awaitExpression.parent;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
changeTracker.replaceNode(sourceFile, expressionToReplace, awaitExpression.expression);
|
|
41
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// Modificado de microsoft/TypeScript v3.9.10, src/services/codefixes/returnValueCorrect.ts: o namespace virou módulo ES, com os imports explícitos.
|
|
2
|
+
import { Debug, Diagnostics, SyntaxKind, append, copyComments, createBlock, createParen, createReturn, findAncestor, first, getTokenAtPosition, isArrowFunction, isBlock, isCallExpression, isDeclarationName, isExpressionStatement, isFunctionLikeDeclaration, isJsxAttribute, isJsxExpression, isVariableLike, length, needsParentheses, probablyUsesSemicolons, rangeContainsRange, suppressLeadingAndTrailingTrivia, textChanges, updateFunctionLikeBody, } from "../_namespaces/edit.js";
|
|
3
|
+
import { codeFixAll, createCodeFixAction, registerCodeFix, } from "../_namespaces/ts.codefix.js";
|
|
4
|
+
const fixId = "returnValueCorrect";
|
|
5
|
+
const fixIdAddReturnStatement = "fixAddReturnStatement";
|
|
6
|
+
const fixIdRemoveBlockBodyBrace = "fixRemoveBlockBodyBrace";
|
|
7
|
+
// Na tag, também o `fixWrapTheBlockWithParen`, que punha entre parênteses o corpo de uma arrow que o parser lia como um
|
|
8
|
+
// statement com label (`() => { a: 1 }`); o label saiu (CK-02), e com ele o caso que o fix tratava.
|
|
9
|
+
const errorCodes = [
|
|
10
|
+
Diagnostics.A_function_whose_declared_type_is_neither_void_nor_any_must_return_a_value.code,
|
|
11
|
+
Diagnostics.Type_0_is_not_assignable_to_type_1.code,
|
|
12
|
+
Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1.code
|
|
13
|
+
];
|
|
14
|
+
// Na tag, também o problema dos parênteses que faltavam em volta de um object literal lido como label (CK-02).
|
|
15
|
+
var ProblemKind;
|
|
16
|
+
(function (ProblemKind) {
|
|
17
|
+
ProblemKind[ProblemKind["MissingReturnStatement"] = 0] = "MissingReturnStatement";
|
|
18
|
+
})(ProblemKind || (ProblemKind = {}));
|
|
19
|
+
registerCodeFix({
|
|
20
|
+
errorCodes,
|
|
21
|
+
fixIds: [fixIdAddReturnStatement, fixIdRemoveBlockBodyBrace],
|
|
22
|
+
getCodeActions: context => {
|
|
23
|
+
const { program, sourceFile, span: { start }, errorCode } = context;
|
|
24
|
+
const info = getInfo(program.getTypeChecker(), sourceFile, start, errorCode);
|
|
25
|
+
if (!info)
|
|
26
|
+
return undefined;
|
|
27
|
+
return append([getActionForfixAddReturnStatement(context, info.expression, info.statement)], isArrowFunction(info.declaration) ? getActionForfixRemoveBlockBodyBrace(context, info.declaration, info.expression, info.commentSource) : undefined);
|
|
28
|
+
},
|
|
29
|
+
getAllCodeActions: context => codeFixAll(context, errorCodes, (changes, diag) => {
|
|
30
|
+
const info = getInfo(context.program.getTypeChecker(), diag.file, diag.start, diag.code);
|
|
31
|
+
if (!info)
|
|
32
|
+
return undefined;
|
|
33
|
+
switch (context.fixId) {
|
|
34
|
+
case fixIdAddReturnStatement:
|
|
35
|
+
addReturnStatement(changes, diag.file, info.expression, info.statement);
|
|
36
|
+
break;
|
|
37
|
+
case fixIdRemoveBlockBodyBrace:
|
|
38
|
+
if (!isArrowFunction(info.declaration))
|
|
39
|
+
return undefined;
|
|
40
|
+
removeBlockBodyBrace(changes, diag.file, info.declaration, info.expression, info.commentSource, /* withParen */ false);
|
|
41
|
+
break;
|
|
42
|
+
default:
|
|
43
|
+
Debug.fail(JSON.stringify(context.fixId));
|
|
44
|
+
}
|
|
45
|
+
}),
|
|
46
|
+
});
|
|
47
|
+
function getFixInfo(checker, declaration, expectType, isFunctionType) {
|
|
48
|
+
if (!declaration.body || !isBlock(declaration.body) || length(declaration.body.statements) !== 1)
|
|
49
|
+
return undefined;
|
|
50
|
+
const firstStatement = first(declaration.body.statements);
|
|
51
|
+
if (isExpressionStatement(firstStatement) && checkFixedAssignableTo(checker, declaration, firstStatement.expression, expectType, isFunctionType)) {
|
|
52
|
+
return {
|
|
53
|
+
declaration,
|
|
54
|
+
kind: ProblemKind.MissingReturnStatement,
|
|
55
|
+
expression: firstStatement.expression,
|
|
56
|
+
statement: firstStatement,
|
|
57
|
+
commentSource: firstStatement.expression
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
// Na tag, também o statement com label, sozinho ou num bloco, que o parser lia onde se queria um object literal
|
|
61
|
+
// (`{ a: 1 }`), e que o fix trocava pelo objeto (CK-02).
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
function checkFixedAssignableTo(checker, declaration, expr, type, isFunctionType) {
|
|
65
|
+
return checker.isTypeAssignableTo(checker.getTypeAtLocation(isFunctionType ? updateFunctionLikeBody(declaration, createBlock([createReturn(expr)])) : expr), type);
|
|
66
|
+
}
|
|
67
|
+
function getInfo(checker, sourceFile, position, errorCode) {
|
|
68
|
+
const node = getTokenAtPosition(sourceFile, position);
|
|
69
|
+
if (!node.parent)
|
|
70
|
+
return undefined;
|
|
71
|
+
const declaration = findAncestor(node.parent, isFunctionLikeDeclaration);
|
|
72
|
+
switch (errorCode) {
|
|
73
|
+
case Diagnostics.A_function_whose_declared_type_is_neither_void_nor_any_must_return_a_value.code:
|
|
74
|
+
if (!declaration || !declaration.body || !declaration.type || !rangeContainsRange(declaration.type, node))
|
|
75
|
+
return undefined;
|
|
76
|
+
return getFixInfo(checker, declaration, checker.getTypeFromTypeNode(declaration.type), /* isFunctionType */ false);
|
|
77
|
+
case Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1.code:
|
|
78
|
+
if (!declaration || !isCallExpression(declaration.parent) || !declaration.body)
|
|
79
|
+
return undefined;
|
|
80
|
+
const pos = declaration.parent.arguments.indexOf(declaration);
|
|
81
|
+
const type = checker.getContextualTypeForArgumentAtIndex(declaration.parent, pos);
|
|
82
|
+
if (!type)
|
|
83
|
+
return undefined;
|
|
84
|
+
return getFixInfo(checker, declaration, type, /* isFunctionType */ true);
|
|
85
|
+
case Diagnostics.Type_0_is_not_assignable_to_type_1.code:
|
|
86
|
+
if (!isDeclarationName(node) || !isVariableLike(node.parent) && !isJsxAttribute(node.parent))
|
|
87
|
+
return undefined;
|
|
88
|
+
const initializer = getVariableLikeInitializer(node.parent);
|
|
89
|
+
if (!initializer || !isFunctionLikeDeclaration(initializer) || !initializer.body)
|
|
90
|
+
return undefined;
|
|
91
|
+
return getFixInfo(checker, initializer, checker.getTypeAtLocation(node.parent), /* isFunctionType */ true);
|
|
92
|
+
}
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
// Na tag, também a propriedade de classe, o membro de enum (CK-02) e as tags do JSDoc (CK-03).
|
|
96
|
+
function getVariableLikeInitializer(declaration) {
|
|
97
|
+
switch (declaration.kind) {
|
|
98
|
+
case SyntaxKind.VariableDeclaration:
|
|
99
|
+
case SyntaxKind.Parameter:
|
|
100
|
+
case SyntaxKind.BindingElement:
|
|
101
|
+
case SyntaxKind.PropertyAssignment:
|
|
102
|
+
return declaration.initializer;
|
|
103
|
+
case SyntaxKind.JsxAttribute:
|
|
104
|
+
return declaration.initializer && (isJsxExpression(declaration.initializer) ? declaration.initializer.expression : undefined);
|
|
105
|
+
case SyntaxKind.ShorthandPropertyAssignment:
|
|
106
|
+
case SyntaxKind.PropertySignature:
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function addReturnStatement(changes, sourceFile, expression, statement) {
|
|
111
|
+
suppressLeadingAndTrailingTrivia(expression);
|
|
112
|
+
const probablyNeedSemi = probablyUsesSemicolons(sourceFile);
|
|
113
|
+
changes.replaceNode(sourceFile, statement, createReturn(expression), {
|
|
114
|
+
leadingTriviaOption: textChanges.LeadingTriviaOption.Exclude,
|
|
115
|
+
trailingTriviaOption: textChanges.TrailingTriviaOption.Exclude,
|
|
116
|
+
suffix: probablyNeedSemi ? ";" : undefined
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
function removeBlockBodyBrace(changes, sourceFile, declaration, expression, commentSource, withParen) {
|
|
120
|
+
const newBody = (withParen || needsParentheses(expression)) ? createParen(expression) : expression;
|
|
121
|
+
suppressLeadingAndTrailingTrivia(commentSource);
|
|
122
|
+
copyComments(commentSource, newBody);
|
|
123
|
+
changes.replaceNode(sourceFile, declaration.body, newBody);
|
|
124
|
+
}
|
|
125
|
+
function getActionForfixAddReturnStatement(context, expression, statement) {
|
|
126
|
+
const changes = textChanges.ChangeTracker.with(context, t => addReturnStatement(t, context.sourceFile, expression, statement));
|
|
127
|
+
return createCodeFixAction(fixId, changes, Diagnostics.Add_a_return_statement, fixIdAddReturnStatement, Diagnostics.Add_all_missing_return_statement);
|
|
128
|
+
}
|
|
129
|
+
function getActionForfixRemoveBlockBodyBrace(context, declaration, expression, commentSource) {
|
|
130
|
+
const changes = textChanges.ChangeTracker.with(context, t => removeBlockBodyBrace(t, context.sourceFile, declaration, expression, commentSource, /* withParen */ false));
|
|
131
|
+
return createCodeFixAction(fixId, changes, Diagnostics.Remove_block_body_braces, fixIdRemoveBlockBodyBrace, Diagnostics.Remove_all_incorrect_body_block_braces);
|
|
132
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Modificado de microsoft/TypeScript v3.9.10, src/services/codefixes/splitTypeOnlyImport.ts: o namespace virou módulo ES, com os imports explícitos.
|
|
2
|
+
import { Debug, Diagnostics, createImportDeclaration, findAncestor, getTokenAtPosition, isImportDeclaration, textChanges, updateImportClause, updateImportDeclaration, } from "../_namespaces/edit.js";
|
|
3
|
+
import { codeFixAll, createCodeFixAction, registerCodeFix, } from "../_namespaces/ts.codefix.js";
|
|
4
|
+
const errorCodes = [Diagnostics.A_type_only_import_can_specify_a_default_import_or_named_bindings_but_not_both.code];
|
|
5
|
+
const fixId = "splitTypeOnlyImport";
|
|
6
|
+
registerCodeFix({
|
|
7
|
+
errorCodes,
|
|
8
|
+
fixIds: [fixId],
|
|
9
|
+
getCodeActions: context => {
|
|
10
|
+
const changes = textChanges.ChangeTracker.with(context, t => {
|
|
11
|
+
return splitTypeOnlyImport(t, getImportDeclaration(context.sourceFile, context.span), context);
|
|
12
|
+
});
|
|
13
|
+
if (changes.length) {
|
|
14
|
+
return [createCodeFixAction(fixId, changes, Diagnostics.Split_into_two_separate_import_declarations, fixId, Diagnostics.Split_all_invalid_type_only_imports)];
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
getAllCodeActions: context => codeFixAll(context, errorCodes, (changes, error) => {
|
|
18
|
+
splitTypeOnlyImport(changes, getImportDeclaration(context.sourceFile, error), context);
|
|
19
|
+
}),
|
|
20
|
+
});
|
|
21
|
+
function getImportDeclaration(sourceFile, span) {
|
|
22
|
+
return findAncestor(getTokenAtPosition(sourceFile, span.start), isImportDeclaration);
|
|
23
|
+
}
|
|
24
|
+
function splitTypeOnlyImport(changes, importDeclaration, context) {
|
|
25
|
+
if (!importDeclaration) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const importClause = Debug.checkDefined(importDeclaration.importClause);
|
|
29
|
+
changes.replaceNode(context.sourceFile, importDeclaration, updateImportDeclaration(importDeclaration, importDeclaration.modifiers, updateImportClause(importClause, importClause.name, /*namedBindings*/ undefined, importClause.isTypeOnly), importDeclaration.moduleSpecifier));
|
|
30
|
+
changes.insertNodeAfter(context.sourceFile, importDeclaration, createImportDeclaration(
|
|
31
|
+
/*modifiers*/ undefined, updateImportClause(importClause, /*name*/ undefined, importClause.namedBindings, importClause.isTypeOnly), importDeclaration.moduleSpecifier));
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Modificado de microsoft/TypeScript v3.9.10, src/services/codefixes/useBigintLiteral.ts: o namespace virou módulo ES, com os imports explícitos.
|
|
2
|
+
import { Diagnostics, createBigIntLiteral, getTokenAtPosition, isNumericLiteral, textChanges, tryCast, } from "../_namespaces/edit.js";
|
|
3
|
+
import { codeFixAll, createCodeFixAction, registerCodeFix, } from "../_namespaces/ts.codefix.js";
|
|
4
|
+
const fixId = "useBigintLiteral";
|
|
5
|
+
const errorCodes = [
|
|
6
|
+
Diagnostics.Numeric_literals_with_absolute_values_equal_to_2_53_or_greater_are_too_large_to_be_represented_accurately_as_integers.code,
|
|
7
|
+
];
|
|
8
|
+
registerCodeFix({
|
|
9
|
+
errorCodes,
|
|
10
|
+
getCodeActions: context => {
|
|
11
|
+
const changes = textChanges.ChangeTracker.with(context, t => makeChange(t, context.sourceFile, context.span));
|
|
12
|
+
if (changes.length > 0) {
|
|
13
|
+
return [createCodeFixAction(fixId, changes, Diagnostics.Convert_to_a_bigint_numeric_literal, fixId, Diagnostics.Convert_all_to_bigint_numeric_literals)];
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
fixIds: [fixId],
|
|
17
|
+
getAllCodeActions: context => {
|
|
18
|
+
return codeFixAll(context, errorCodes, (changes, diag) => makeChange(changes, diag.file, diag));
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
function makeChange(changeTracker, sourceFile, span) {
|
|
22
|
+
const numericLiteral = tryCast(getTokenAtPosition(sourceFile, span.start), isNumericLiteral);
|
|
23
|
+
if (!numericLiteral) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
// We use .getText to overcome parser inaccuracies: https://github.com/microsoft/TypeScript/issues/33298
|
|
27
|
+
const newText = numericLiteral.getText(sourceFile) + "n";
|
|
28
|
+
changeTracker.replaceNode(sourceFile, numericLiteral, createBigIntLiteral(newText));
|
|
29
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { ScriptElementKind, ScriptTarget } from "./_namespaces/ts.js";
|
|
2
|
+
import type { CancellationToken, CheckResult, CodeAction, CompletionEntry, CompletionEntryDetails, CompletionInfo, CompletionsTriggerCharacter, FormatCodeSettings, Identifier, JSDocTagInfo, LanguageServiceHost, Node, PropertyAccessExpression, Push, SourceFile, Symbol, SymbolDisplayPart, TypeChecker, UserPreferences } from "./_namespaces/ts.js";
|
|
3
|
+
/**
|
|
4
|
+
* O auto-import do completion: o que lista os módulos de que se importa e o que monta a edição do import. Os dois são
|
|
5
|
+
* da edição (o `importFixes.ts` da tag, com o `textChanges` e o `formatting`), e a leitura não os carrega: a edição os
|
|
6
|
+
* registra ao carregar (CK-67). Sem ela, o completion não oferece o auto-import.
|
|
7
|
+
*/
|
|
8
|
+
export interface AutoImportProvider {
|
|
9
|
+
forEachExternalModuleToImportFrom(program: CheckResult, host: LanguageServiceHost, from: SourceFile, cb: (module: Symbol) => void): void;
|
|
10
|
+
getImportCompletionAction(exportedSymbol: Symbol, moduleSymbol: Symbol, sourceFile: SourceFile, symbolName: string, host: LanguageServiceHost, program: CheckResult, formatOptions: FormatCodeSettings | undefined, position: number, preferences: UserPreferences): {
|
|
11
|
+
readonly moduleSpecifier: string;
|
|
12
|
+
readonly codeAction: CodeAction;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/** Registra o auto-import do completion: quem o chama é a edição, ao carregar (CK-67). */
|
|
16
|
+
export declare function registerAutoImportProvider(provider: AutoImportProvider): void;
|
|
17
|
+
export declare enum SortText {
|
|
18
|
+
LocationPriority = "0",
|
|
19
|
+
OptionalMember = "1",
|
|
20
|
+
MemberDeclaredBySpreadAssignment = "2",
|
|
21
|
+
SuggestedClassMembers = "3",
|
|
22
|
+
GlobalsOrKeywords = "4",
|
|
23
|
+
AutoImportSuggestions = "5",
|
|
24
|
+
JavascriptIdentifiers = "6"
|
|
25
|
+
}
|
|
26
|
+
export type Log = (message: string) => void;
|
|
27
|
+
declare enum SymbolOriginInfoKind {
|
|
28
|
+
SymbolMember = 2,
|
|
29
|
+
Export = 4,
|
|
30
|
+
Promise = 8,
|
|
31
|
+
Nullable = 16,
|
|
32
|
+
SymbolMemberNoExport = 2,
|
|
33
|
+
SymbolMemberExport = 6
|
|
34
|
+
}
|
|
35
|
+
interface SymbolOriginInfo {
|
|
36
|
+
kind: SymbolOriginInfoKind;
|
|
37
|
+
}
|
|
38
|
+
interface SymbolOriginInfoExport extends SymbolOriginInfo {
|
|
39
|
+
kind: SymbolOriginInfoKind;
|
|
40
|
+
moduleSymbol: Symbol;
|
|
41
|
+
isDefaultExport: boolean;
|
|
42
|
+
}
|
|
43
|
+
interface UniqueNameSet {
|
|
44
|
+
add(name: string): void;
|
|
45
|
+
has(name: string): boolean;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Map from symbol id -> SymbolOriginInfo.
|
|
49
|
+
* Only populated for symbols that come from other modules.
|
|
50
|
+
*/
|
|
51
|
+
type SymbolOriginInfoMap = (SymbolOriginInfo | SymbolOriginInfoExport | undefined)[];
|
|
52
|
+
type SymbolSortTextMap = (SortText | undefined)[];
|
|
53
|
+
export interface AutoImportSuggestion {
|
|
54
|
+
symbol: Symbol;
|
|
55
|
+
symbolName: string;
|
|
56
|
+
skipFilter: boolean;
|
|
57
|
+
origin: SymbolOriginInfoExport;
|
|
58
|
+
}
|
|
59
|
+
export declare function getCompletionsAtPosition(host: LanguageServiceHost, program: CheckResult, log: Log, sourceFile: SourceFile, position: number, preferences: UserPreferences, triggerCharacter: CompletionsTriggerCharacter | undefined): CompletionInfo | undefined;
|
|
60
|
+
export declare function getCompletionEntriesFromSymbols(symbols: readonly Symbol[], entries: Push<CompletionEntry>, contextToken: Node | undefined, location: Node | undefined, sourceFile: SourceFile, typeChecker: TypeChecker, target: ScriptTarget, log: Log, kind: CompletionKind, preferences: UserPreferences, propertyAccessToConvert?: PropertyAccessExpression, jsxIdentifierExpected?: boolean, isJsxInitializer?: IsJsxInitializer, symbolToOriginInfoMap?: SymbolOriginInfoMap, symbolToSortTextMap?: SymbolSortTextMap): UniqueNameSet;
|
|
61
|
+
export interface CompletionEntryIdentifier {
|
|
62
|
+
name: string;
|
|
63
|
+
source?: string;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* O detalhe de um item do completion. Na tag, quem chama monta o contexto de formatação, que só a ação do auto-import
|
|
67
|
+
* usa; aqui, as opções de formatação seguem cruas até o auto-import da edição, que monta o contexto (CK-67).
|
|
68
|
+
*/
|
|
69
|
+
export declare function getCompletionEntryDetails(program: CheckResult, log: Log, sourceFile: SourceFile, position: number, entryId: CompletionEntryIdentifier, host: LanguageServiceHost, formatOptions: FormatCodeSettings | undefined, preferences: UserPreferences, cancellationToken: CancellationToken): CompletionEntryDetails | undefined;
|
|
70
|
+
export declare function createCompletionDetailsForSymbol(symbol: Symbol, checker: TypeChecker, sourceFile: SourceFile, location: Node, cancellationToken: CancellationToken, codeActions?: CodeAction[], sourceDisplay?: SymbolDisplayPart[]): CompletionEntryDetails;
|
|
71
|
+
export declare function createCompletionDetails(name: string, kindModifiers: string, kind: ScriptElementKind, displayParts: SymbolDisplayPart[], documentation?: SymbolDisplayPart[], tags?: JSDocTagInfo[], codeActions?: CodeAction[], source?: SymbolDisplayPart[]): CompletionEntryDetails;
|
|
72
|
+
export declare function getCompletionEntrySymbol(program: CheckResult, log: Log, sourceFile: SourceFile, position: number, entryId: CompletionEntryIdentifier, host: LanguageServiceHost, preferences: UserPreferences): Symbol | undefined;
|
|
73
|
+
/** true: after the `=` sign but no identifier has been typed yet. Else is the Identifier after the initializer. */
|
|
74
|
+
type IsJsxInitializer = boolean | Identifier;
|
|
75
|
+
export declare enum CompletionKind {
|
|
76
|
+
ObjectPropertyDeclaration = 0,
|
|
77
|
+
Global = 1,
|
|
78
|
+
PropertyAccess = 2,
|
|
79
|
+
MemberLike = 3,
|
|
80
|
+
String = 4,
|
|
81
|
+
None = 5
|
|
82
|
+
}
|
|
83
|
+
export {};
|