@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.
Files changed (123) hide show
  1. package/NOTICE +3 -1
  2. package/dist/_namespaces/edit.d.ts +1 -1
  3. package/dist/_namespaces/edit.js +10759 -11
  4. package/dist/_namespaces/ts.codefix.d.ts +0 -1
  5. package/dist/_namespaces/ts.js +10196 -19
  6. package/dist/classifier.d.ts +3 -1
  7. package/dist/codeFixProvider.d.ts +2 -1
  8. package/dist/codefixes/helpers.d.ts +3 -1
  9. package/dist/codefixes/importFixes.d.ts +3 -1
  10. package/dist/completions.d.ts +5 -2
  11. package/dist/documentHighlights.d.ts +3 -1
  12. package/dist/documentRegistry.d.ts +2 -1
  13. package/dist/findAllReferences.d.ts +3 -1
  14. package/dist/formatting/formatting.d.ts +3 -2
  15. package/dist/formatting/formattingContext.d.ts +2 -1
  16. package/dist/formatting/formattingScanner.d.ts +2 -2
  17. package/dist/formatting/rule.d.ts +1 -1
  18. package/dist/formatting/rulesMap.d.ts +1 -1
  19. package/dist/formatting/smartIndenter.d.ts +2 -1
  20. package/dist/getEditsForFileRename.d.ts +4 -1
  21. package/dist/goToDefinition.d.ts +3 -1
  22. package/dist/importTracker.d.ts +2 -1
  23. package/dist/navigationBar.d.ts +3 -1
  24. package/dist/organizeImports.d.ts +4 -2
  25. package/dist/outliningElementsCollector.d.ts +3 -1
  26. package/dist/refactorProvider.d.ts +1 -1
  27. package/dist/refactors/extractSymbol.d.ts +2 -1
  28. package/dist/rename.d.ts +3 -1
  29. package/dist/services.d.ts +5 -2
  30. package/dist/signatureHelp.d.ts +3 -1
  31. package/dist/smartSelection.d.ts +2 -1
  32. package/dist/stringCompletions.d.ts +3 -1
  33. package/dist/suggestionDiagnostics.d.ts +4 -3
  34. package/dist/symbolDisplay.d.ts +3 -1
  35. package/dist/textChanges.d.ts +4 -2
  36. package/dist/types.d.ts +3 -3
  37. package/dist/utilities.d.ts +7 -2
  38. package/package.json +7 -5
  39. package/dist/_namespaces/ts.Completions.StringCompletions.js +0 -2
  40. package/dist/_namespaces/ts.Completions.js +0 -3
  41. package/dist/_namespaces/ts.FindAllReferences.js +0 -3
  42. package/dist/_namespaces/ts.GoToDefinition.js +0 -2
  43. package/dist/_namespaces/ts.NavigationBar.js +0 -2
  44. package/dist/_namespaces/ts.OrganizeImports.js +0 -2
  45. package/dist/_namespaces/ts.OutliningElementsCollector.js +0 -2
  46. package/dist/_namespaces/ts.Rename.js +0 -2
  47. package/dist/_namespaces/ts.SignatureHelp.js +0 -2
  48. package/dist/_namespaces/ts.SmartSelectionRange.js +0 -2
  49. package/dist/_namespaces/ts.SymbolDisplay.js +0 -2
  50. package/dist/_namespaces/ts.codefix.js +0 -27
  51. package/dist/_namespaces/ts.formatting.js +0 -8
  52. package/dist/_namespaces/ts.refactor.addOrRemoveBracesToArrowFunction.js +0 -2
  53. package/dist/_namespaces/ts.refactor.convertParamsToDestructuredObject.js +0 -2
  54. package/dist/_namespaces/ts.refactor.convertStringOrTemplateLiteral.js +0 -2
  55. package/dist/_namespaces/ts.refactor.extractSymbol.js +0 -2
  56. package/dist/_namespaces/ts.refactor.js +0 -10
  57. package/dist/_namespaces/ts.textChanges.js +0 -2
  58. package/dist/classifier.js +0 -715
  59. package/dist/codeFixProvider.js +0 -84
  60. package/dist/codefixes/addConvertToUnknownForNonOverlappingTypes.d.ts +0 -1
  61. package/dist/codefixes/addConvertToUnknownForNonOverlappingTypes.js +0 -21
  62. package/dist/codefixes/addEmptyExportDeclaration.js +0 -17
  63. package/dist/codefixes/addMissingAsync.js +0 -75
  64. package/dist/codefixes/addMissingAwait.js +0 -236
  65. package/dist/codefixes/addMissingConst.js +0 -91
  66. package/dist/codefixes/addNameToNamelessParameter.js +0 -29
  67. package/dist/codefixes/convertConstToLet.js +0 -30
  68. package/dist/codefixes/convertToAsyncFunction.js +0 -495
  69. package/dist/codefixes/convertToMappedObjectType.js +0 -48
  70. package/dist/codefixes/correctQualifiedNameToIndexedAccessType.js +0 -33
  71. package/dist/codefixes/fixAddModuleReferTypeMissingTypeof.js +0 -27
  72. package/dist/codefixes/fixAwaitInSyncFunction.js +0 -69
  73. package/dist/codefixes/fixExpectedComma.js +0 -35
  74. package/dist/codefixes/fixInvalidJsxCharacters.js +0 -41
  75. package/dist/codefixes/fixMissingCallParentheses.js +0 -42
  76. package/dist/codefixes/fixSpelling.js +0 -94
  77. package/dist/codefixes/fixUnreachableCode.js +0 -65
  78. package/dist/codefixes/fixUnusedIdentifier.js +0 -224
  79. package/dist/codefixes/helpers.js +0 -53
  80. package/dist/codefixes/importFixes.js +0 -441
  81. package/dist/codefixes/inferFromUsage.js +0 -742
  82. package/dist/codefixes/removeUnnecessaryAwait.js +0 -41
  83. package/dist/codefixes/returnValueCorrect.js +0 -132
  84. package/dist/codefixes/splitTypeOnlyImport.js +0 -32
  85. package/dist/codefixes/useBigintLiteral.js +0 -29
  86. package/dist/completions.js +0 -1720
  87. package/dist/documentHighlights.js +0 -367
  88. package/dist/documentRegistry.js +0 -63
  89. package/dist/editingServices.js +0 -4
  90. package/dist/findAllReferences.js +0 -1366
  91. package/dist/formatting/formatting.js +0 -1021
  92. package/dist/formatting/formattingContext.js +0 -78
  93. package/dist/formatting/formattingScanner.js +0 -228
  94. package/dist/formatting/rule.js +0 -22
  95. package/dist/formatting/rules.js +0 -610
  96. package/dist/formatting/rulesMap.js +0 -127
  97. package/dist/formatting/smartIndenter.js +0 -518
  98. package/dist/getEditsForFileRename.js +0 -86
  99. package/dist/goToDefinition.js +0 -246
  100. package/dist/importTracker.js +0 -422
  101. package/dist/index.js +0 -3
  102. package/dist/navigationBar.js +0 -549
  103. package/dist/organizeImports.js +0 -290
  104. package/dist/outliningElementsCollector.js +0 -261
  105. package/dist/refactorProvider.js +0 -16
  106. package/dist/refactors/addOrRemoveBracesToArrowFunction.js +0 -86
  107. package/dist/refactors/convertExport.js +0 -126
  108. package/dist/refactors/convertImport.js +0 -116
  109. package/dist/refactors/convertParamsToDestructuredObject.js +0 -282
  110. package/dist/refactors/convertStringOrTemplateLiteral.js +0 -148
  111. package/dist/refactors/extractSymbol.js +0 -1281
  112. package/dist/refactors/extractType.js +0 -102
  113. package/dist/refactors/moveToNewFile.js +0 -477
  114. package/dist/rename.js +0 -100
  115. package/dist/services.js +0 -1480
  116. package/dist/signatureHelp.js +0 -414
  117. package/dist/smartSelection.js +0 -243
  118. package/dist/stringCompletions.js +0 -220
  119. package/dist/suggestionDiagnostics.js +0 -92
  120. package/dist/symbolDisplay.js +0 -400
  121. package/dist/textChanges.js +0 -1163
  122. package/dist/types.js +0 -263
  123. package/dist/utilities.js +0 -1981
@@ -1,84 +0,0 @@
1
- // Modificado de microsoft/TypeScript v3.9.10, src/services/codeFixProvider.ts: o namespace virou módulo ES, com os imports explícitos.
2
- import { Debug, arrayFrom, cast, computeSuggestionDiagnostics, contains, createMap, createMultiMap, flatMap, formatStringFromArgs, getLocaleSpecificMessage, isArray, isString, map, textChanges, } from "./_namespaces/edit.js";
3
- const errorCodeToFixes = createMultiMap();
4
- const fixIdToRegistration = createMap();
5
- function diagnosticToString(diag) {
6
- return isArray(diag)
7
- ? formatStringFromArgs(getLocaleSpecificMessage(diag[0]), diag.slice(1))
8
- : getLocaleSpecificMessage(diag);
9
- }
10
- export function createCodeFixActionWithoutFixAll(fixName, changes, description) {
11
- return createCodeFixActionWorker(fixName, diagnosticToString(description), changes, /*fixId*/ undefined, /*fixAllDescription*/ undefined);
12
- }
13
- // Na tag, a ação e o worker dela recebiam também o `command`, o pedido ao host de instalar um pacote de tipos (CK-47).
14
- export function createCodeFixAction(fixName, changes, description, fixId, fixAllDescription) {
15
- return createCodeFixActionWorker(fixName, diagnosticToString(description), changes, fixId, diagnosticToString(fixAllDescription));
16
- }
17
- function createCodeFixActionWorker(fixName, description, changes, fixId, fixAllDescription) {
18
- return { fixName, description, changes, fixId, fixAllDescription };
19
- }
20
- export function registerCodeFix(reg) {
21
- for (const error of reg.errorCodes) {
22
- errorCodeToFixes.add(String(error), reg);
23
- }
24
- if (reg.fixIds) {
25
- for (const fixId of reg.fixIds) {
26
- Debug.assert(!fixIdToRegistration.has(fixId));
27
- fixIdToRegistration.set(fixId, reg);
28
- }
29
- }
30
- }
31
- export function getSupportedErrorCodes() {
32
- return arrayFrom(errorCodeToFixes.keys());
33
- }
34
- function removeFixIdIfFixAllUnavailable(registration, diagnostics) {
35
- const { errorCodes } = registration;
36
- let maybeFixableDiagnostics = 0;
37
- for (const diag of diagnostics) {
38
- if (contains(errorCodes, diag.code))
39
- maybeFixableDiagnostics++;
40
- if (maybeFixableDiagnostics > 1)
41
- break;
42
- }
43
- const fixAllUnavailable = maybeFixableDiagnostics < 2;
44
- return ({ fixId, fixAllDescription, ...action }) => {
45
- return fixAllUnavailable ? action : { ...action, fixId, fixAllDescription };
46
- };
47
- }
48
- export function getFixes(context) {
49
- const diagnostics = getDiagnostics(context);
50
- const registrations = errorCodeToFixes.get(String(context.errorCode));
51
- return flatMap(registrations, f => map(f.getCodeActions(context), removeFixIdIfFixAllUnavailable(f, diagnostics)));
52
- }
53
- export function getAllFixes(context) {
54
- // Currently fixId is always a string.
55
- return fixIdToRegistration.get(cast(context.fixId, isString)).getAllCodeActions(context);
56
- }
57
- // Na tag, também os `commands` da ação combinada (CK-47).
58
- export function createCombinedCodeActions(changes) {
59
- return { changes };
60
- }
61
- export function createFileTextChanges(fileName, textChanges) {
62
- return { fileName, textChanges };
63
- }
64
- export function codeFixAll(context, errorCodes,
65
- // Na tag, o `use` recebia também os `commands` que a ação combinada levava ao host (CK-47).
66
- use) {
67
- const changes = textChanges.ChangeTracker.with(context, t => eachDiagnostic(context, errorCodes, diag => use(t, diag)));
68
- return createCombinedCodeActions(changes);
69
- }
70
- export function eachDiagnostic(context, errorCodes, cb) {
71
- for (const diag of getDiagnostics(context)) {
72
- if (contains(errorCodes, diag.code)) {
73
- cb(diag);
74
- }
75
- }
76
- }
77
- function getDiagnostics({ program, sourceFile, cancellationToken }) {
78
- return [
79
- ...program.getSemanticDiagnostics(sourceFile, cancellationToken),
80
- // Na tag, com o cancelamento; os diagnósticos de parse do `check` da cópia não o perguntam, como na casca.
81
- ...program.getSyntacticDiagnostics(sourceFile),
82
- ...computeSuggestionDiagnostics(sourceFile, program, cancellationToken)
83
- ];
84
- }
@@ -1,21 +0,0 @@
1
- // Modificado de microsoft/TypeScript v3.9.10, src/services/codefixes/addConvertToUnknownForNonOverlappingTypes.ts: o namespace virou módulo ES, com os imports explícitos.
2
- import { Debug, Diagnostics, SyntaxKind, createAsExpression, createKeywordTypeNode, findAncestor, getTokenAtPosition, isAsExpression, textChanges, } from "../_namespaces/edit.js";
3
- import { codeFixAll, createCodeFixAction, registerCodeFix, } from "../_namespaces/ts.codefix.js";
4
- const fixId = "addConvertToUnknownForNonOverlappingTypes";
5
- const errorCodes = [Diagnostics.Conversion_of_type_0_to_type_1_may_be_a_mistake_because_neither_type_sufficiently_overlaps_with_the_other_If_this_was_intentional_convert_the_expression_to_unknown_first.code];
6
- registerCodeFix({
7
- errorCodes,
8
- getCodeActions: (context) => {
9
- const changes = textChanges.ChangeTracker.with(context, t => makeChange(t, context.sourceFile, context.span.start));
10
- return [createCodeFixAction(fixId, changes, Diagnostics.Add_unknown_conversion_for_non_overlapping_types, fixId, Diagnostics.Add_unknown_to_all_conversions_of_non_overlapping_types)];
11
- },
12
- fixIds: [fixId],
13
- getAllCodeActions: context => codeFixAll(context, errorCodes, (changes, diag) => makeChange(changes, diag.file, diag.start)),
14
- });
15
- function makeChange(changeTracker, sourceFile, pos) {
16
- const token = getTokenAtPosition(sourceFile, pos);
17
- // Na tag, também a asserção `<T>x`, que ganhava o `<unknown>` (CK-62).
18
- const assertion = Debug.checkDefined(findAncestor(token, (n) => isAsExpression(n)), "Expected to find an assertion expression");
19
- const replacement = createAsExpression(assertion.expression, createKeywordTypeNode(SyntaxKind.UnknownKeyword));
20
- changeTracker.replaceNode(sourceFile, assertion.expression, replacement);
21
- }
@@ -1,17 +0,0 @@
1
- // Modificado de microsoft/TypeScript v3.9.10, src/services/codefixes/addEmptyExportDeclaration.ts: o namespace virou módulo ES, com os imports explícitos.
2
- import { Diagnostics, createExportDeclaration, createNamedExports, textChanges, } from "../_namespaces/edit.js";
3
- import { createCodeFixActionWithoutFixAll, registerCodeFix, } from "../_namespaces/ts.codefix.js";
4
- registerCodeFix({
5
- errorCodes: [Diagnostics.await_expressions_are_only_allowed_at_the_top_level_of_a_file_when_that_file_is_a_module_but_this_file_has_no_imports_or_exports_Consider_adding_an_empty_export_to_make_this_file_a_module.code],
6
- getCodeActions: context => {
7
- const { sourceFile } = context;
8
- const changes = textChanges.ChangeTracker.with(context, changes => {
9
- const exportDeclaration = createExportDeclaration(
10
- /*modifiers*/ undefined, createNamedExports([]),
11
- /*moduleSpecifier*/ undefined,
12
- /*isTypeOnly*/ false);
13
- changes.insertNodeAtEndOfScope(sourceFile, sourceFile, exportDeclaration);
14
- });
15
- return [createCodeFixActionWithoutFixAll("addEmptyExportDeclaration", changes, Diagnostics.Add_export_to_make_this_file_into_a_module)];
16
- },
17
- });
@@ -1,75 +0,0 @@
1
- // Modificado de microsoft/TypeScript v3.9.10, src/services/codefixes/addMissingAsync.ts: o namespace virou módulo ES, com os imports explícitos.
2
- import { Diagnostics, ModifierFlags, createMap, createModifiersFromModifierFlags, createNodeArray, createTextSpanFromNode, find, findAncestor, getModifierFlags, getNodeId, getSynthesizedDeepClone, getTokenAtPosition, isArrowFunction, isNumber, some, textChanges, textSpanEnd, textSpansEqual, } from "../_namespaces/edit.js";
3
- import { codeFixAll, createCodeFixAction, registerCodeFix, } from "../_namespaces/ts.codefix.js";
4
- const fixId = "addMissingAsync";
5
- const errorCodes = [
6
- Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1.code,
7
- Diagnostics.Type_0_is_not_assignable_to_type_1.code,
8
- Diagnostics.Type_0_is_not_comparable_to_type_1.code
9
- ];
10
- registerCodeFix({
11
- fixIds: [fixId],
12
- errorCodes,
13
- getCodeActions: context => {
14
- const { sourceFile, errorCode, cancellationToken, program, span } = context;
15
- // Na tag, o checker que produz os diagnósticos do `Program`; o do `check` é um só (CK-47).
16
- const diagnostic = find(program.getTypeChecker().getDiagnostics(sourceFile, cancellationToken), getIsMatchingAsyncError(span, errorCode));
17
- const directSpan = diagnostic && diagnostic.relatedInformation && find(diagnostic.relatedInformation, r => r.code === Diagnostics.Did_you_mean_to_mark_this_function_as_async.code);
18
- const decl = getFixableErrorSpanDeclaration(sourceFile, directSpan);
19
- if (!decl) {
20
- return;
21
- }
22
- const trackChanges = cb => textChanges.ChangeTracker.with(context, cb);
23
- return [getFix(context, decl, trackChanges)];
24
- },
25
- getAllCodeActions: context => {
26
- const { sourceFile } = context;
27
- const fixedDeclarations = createMap();
28
- return codeFixAll(context, errorCodes, (t, diagnostic) => {
29
- const span = diagnostic.relatedInformation && find(diagnostic.relatedInformation, r => r.code === Diagnostics.Did_you_mean_to_mark_this_function_as_async.code);
30
- const decl = getFixableErrorSpanDeclaration(sourceFile, span);
31
- if (!decl) {
32
- return;
33
- }
34
- const trackChanges = cb => (cb(t), []);
35
- return getFix(context, decl, trackChanges, fixedDeclarations);
36
- });
37
- },
38
- });
39
- function getFix(context, decl, trackChanges, fixedDeclarations) {
40
- const changes = trackChanges(t => makeChange(t, context.sourceFile, decl, fixedDeclarations));
41
- return createCodeFixAction(fixId, changes, Diagnostics.Add_async_modifier_to_containing_function, fixId, Diagnostics.Add_all_missing_async_modifiers);
42
- }
43
- function makeChange(changeTracker, sourceFile, insertionSite, fixedDeclarations) {
44
- if (fixedDeclarations) {
45
- if (fixedDeclarations.has(getNodeId(insertionSite).toString())) {
46
- return;
47
- }
48
- }
49
- fixedDeclarations?.set(getNodeId(insertionSite).toString(), true);
50
- const cloneWithModifier = getSynthesizedDeepClone(insertionSite, /*includeTrivia*/ true);
51
- cloneWithModifier.modifiers = createNodeArray(createModifiersFromModifierFlags(getModifierFlags(insertionSite) | ModifierFlags.Async));
52
- cloneWithModifier.modifierFlagsCache = 0;
53
- changeTracker.replaceNode(sourceFile, insertionSite, cloneWithModifier);
54
- }
55
- function getFixableErrorSpanDeclaration(sourceFile, span) {
56
- if (!span)
57
- return undefined;
58
- const token = getTokenAtPosition(sourceFile, span.start);
59
- // Checker has already done work to determine that async might be possible, and has attached
60
- // related info to the node, so start by finding the signature that exactly matches up
61
- // with the diagnostic range.
62
- const decl = findAncestor(token, node => {
63
- if (node.getStart(sourceFile) < span.start || node.getEnd() > textSpanEnd(span)) {
64
- return "quit";
65
- }
66
- return isArrowFunction(node) && textSpansEqual(span, createTextSpanFromNode(node, sourceFile));
67
- });
68
- return decl;
69
- }
70
- function getIsMatchingAsyncError(span, errorCode) {
71
- return ({ start, length, relatedInformation, code }) => isNumber(start) && isNumber(length) && textSpansEqual({ start, length }, span) &&
72
- code === errorCode &&
73
- !!relatedInformation &&
74
- some(relatedInformation, related => related.code === Diagnostics.Did_you_mean_to_mark_this_function_as_async.code);
75
- }
@@ -1,236 +0,0 @@
1
- // Modificado de microsoft/TypeScript v3.9.10, src/services/codefixes/addMissingAwait.ts: o namespace virou módulo ES, com os imports explícitos.
2
- import { Diagnostics, FindAllReferences, ModifierFlags, NodeFlags, SyntaxKind, TypeFlags, addToSeen, compact, contains, createAwait, createMap, createParen, createTextSpanFromNode, find, findAncestor, findPrecedingToken, forEach, getAncestor, getSymbolId, getTokenAtPosition, hasModifier, isArrowFunction, isBinaryExpression, isBlock, isCallOrNewExpression, isExpression, isIdentifier, isNumber, isPropertyAccessExpression, isVariableDeclaration, positionIsASICandidate, some, textChanges, textSpanEnd, textSpansEqual, tryCast, } from "../_namespaces/edit.js";
3
- import { codeFixAll, createCodeFixAction, createCodeFixActionWithoutFixAll, registerCodeFix, } from "../_namespaces/ts.codefix.js";
4
- const fixId = "addMissingAwait";
5
- const propertyAccessCode = Diagnostics.Property_0_does_not_exist_on_type_1.code;
6
- // Na tag, também o que não se constrói (o `new`, CK-02).
7
- const callableConstructableErrorCodes = [
8
- Diagnostics.This_expression_is_not_callable.code,
9
- ];
10
- // Na tag, também as mensagens do `for…of` que a cópia não acusa: as do alvo abaixo do ES2015 e do `downlevelIteration`
11
- // (CK-24), e as do `Symbol.iterator` e do `Symbol.asyncIterator`, do protocolo de iteração (CK-55).
12
- const errorCodes = [
13
- Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_bigint_or_an_enum_type.code,
14
- Diagnostics.The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type.code,
15
- Diagnostics.The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type.code,
16
- Diagnostics.Operator_0_cannot_be_applied_to_type_1.code,
17
- Diagnostics.Operator_0_cannot_be_applied_to_types_1_and_2.code,
18
- Diagnostics.This_condition_will_always_return_0_since_the_types_1_and_2_have_no_overlap.code,
19
- Diagnostics.Type_0_is_not_an_array_type.code,
20
- Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1.code,
21
- propertyAccessCode,
22
- ...callableConstructableErrorCodes,
23
- ];
24
- registerCodeFix({
25
- fixIds: [fixId],
26
- errorCodes,
27
- getCodeActions: context => {
28
- const { sourceFile, errorCode, span, cancellationToken, program } = context;
29
- const expression = getFixableErrorSpanExpression(sourceFile, errorCode, span, cancellationToken, program);
30
- if (!expression) {
31
- return;
32
- }
33
- const checker = context.program.getTypeChecker();
34
- const trackChanges = cb => textChanges.ChangeTracker.with(context, cb);
35
- return compact([
36
- getDeclarationSiteFix(context, expression, errorCode, checker, trackChanges),
37
- getUseSiteFix(context, expression, errorCode, checker, trackChanges)
38
- ]);
39
- },
40
- getAllCodeActions: context => {
41
- const { sourceFile, program, cancellationToken } = context;
42
- const checker = context.program.getTypeChecker();
43
- const fixedDeclarations = createMap();
44
- return codeFixAll(context, errorCodes, (t, diagnostic) => {
45
- const expression = getFixableErrorSpanExpression(sourceFile, diagnostic.code, diagnostic, cancellationToken, program);
46
- if (!expression) {
47
- return;
48
- }
49
- const trackChanges = cb => (cb(t), []);
50
- return getDeclarationSiteFix(context, expression, diagnostic.code, checker, trackChanges, fixedDeclarations)
51
- || getUseSiteFix(context, expression, diagnostic.code, checker, trackChanges, fixedDeclarations);
52
- });
53
- },
54
- });
55
- function getDeclarationSiteFix(context, expression, errorCode, checker, trackChanges, fixedDeclarations) {
56
- const { sourceFile, program, cancellationToken } = context;
57
- const awaitableInitializers = findAwaitableInitializers(expression, sourceFile, cancellationToken, program, checker);
58
- if (awaitableInitializers) {
59
- const initializerChanges = trackChanges(t => {
60
- forEach(awaitableInitializers.initializers, ({ expression }) => makeChange(t, errorCode, sourceFile, checker, expression, fixedDeclarations));
61
- if (fixedDeclarations && awaitableInitializers.needsSecondPassForFixAll) {
62
- makeChange(t, errorCode, sourceFile, checker, expression, fixedDeclarations);
63
- }
64
- });
65
- // No fix-all because it will already be included once with the use site fix,
66
- // and for simplicity the fix-all doesn‘t let the user choose between use-site and declaration-site fixes.
67
- return createCodeFixActionWithoutFixAll("addMissingAwaitToInitializer", initializerChanges, awaitableInitializers.initializers.length === 1
68
- ? [Diagnostics.Add_await_to_initializer_for_0, awaitableInitializers.initializers[0].declarationSymbol.name]
69
- : Diagnostics.Add_await_to_initializers);
70
- }
71
- }
72
- function getUseSiteFix(context, expression, errorCode, checker, trackChanges, fixedDeclarations) {
73
- const changes = trackChanges(t => makeChange(t, errorCode, context.sourceFile, checker, expression, fixedDeclarations));
74
- return createCodeFixAction(fixId, changes, Diagnostics.Add_await, fixId, Diagnostics.Fix_all_expressions_possibly_missing_await);
75
- }
76
- function isMissingAwaitError(sourceFile, errorCode, span, cancellationToken, program) {
77
- // Na tag, o checker que produz os diagnósticos do `Program`; o do `check` é um só (CK-47).
78
- const checker = program.getTypeChecker();
79
- const diagnostics = checker.getDiagnostics(sourceFile, cancellationToken);
80
- return some(diagnostics, ({ start, length, relatedInformation, code }) => isNumber(start) && isNumber(length) && textSpansEqual({ start, length }, span) &&
81
- code === errorCode &&
82
- !!relatedInformation &&
83
- some(relatedInformation, related => related.code === Diagnostics.Did_you_forget_to_use_await.code));
84
- }
85
- function getFixableErrorSpanExpression(sourceFile, errorCode, span, cancellationToken, program) {
86
- const token = getTokenAtPosition(sourceFile, span.start);
87
- // Checker has already done work to determine that await might be possible, and has attached
88
- // related info to the node, so start by finding the expression that exactly matches up
89
- // with the diagnostic range.
90
- const expression = findAncestor(token, node => {
91
- if (node.getStart(sourceFile) < span.start || node.getEnd() > textSpanEnd(span)) {
92
- return "quit";
93
- }
94
- return isExpression(node) && textSpansEqual(span, createTextSpanFromNode(node, sourceFile));
95
- });
96
- return expression
97
- && isMissingAwaitError(sourceFile, errorCode, span, cancellationToken, program)
98
- && isInsideAwaitableBody(expression) ? expression : undefined;
99
- }
100
- function findAwaitableInitializers(expression, sourceFile, cancellationToken, program, checker) {
101
- const identifiers = getIdentifiersFromErrorSpanExpression(expression, checker);
102
- if (!identifiers) {
103
- return;
104
- }
105
- let isCompleteFix = identifiers.isCompleteFix;
106
- let initializers;
107
- for (const identifier of identifiers.identifiers) {
108
- const symbol = checker.getSymbolAtLocation(identifier);
109
- if (!symbol) {
110
- continue;
111
- }
112
- const declaration = tryCast(symbol.valueDeclaration, isVariableDeclaration);
113
- const variableName = declaration && tryCast(declaration.name, isIdentifier);
114
- const variableStatement = getAncestor(declaration, SyntaxKind.VariableStatement);
115
- if (!declaration || !variableStatement ||
116
- declaration.type ||
117
- !declaration.initializer ||
118
- variableStatement.getSourceFile() !== sourceFile ||
119
- hasModifier(variableStatement, ModifierFlags.Export) ||
120
- !variableName ||
121
- !isInsideAwaitableBody(declaration.initializer)) {
122
- isCompleteFix = false;
123
- continue;
124
- }
125
- const diagnostics = program.getSemanticDiagnostics(sourceFile, cancellationToken);
126
- const isUsedElsewhere = FindAllReferences.Core.eachSymbolReferenceInFile(variableName, checker, sourceFile, reference => {
127
- return identifier !== reference && !symbolReferenceIsAlsoMissingAwait(reference, diagnostics, sourceFile, checker);
128
- });
129
- if (isUsedElsewhere) {
130
- isCompleteFix = false;
131
- continue;
132
- }
133
- (initializers || (initializers = [])).push({
134
- expression: declaration.initializer,
135
- declarationSymbol: symbol,
136
- });
137
- }
138
- return initializers && {
139
- initializers,
140
- needsSecondPassForFixAll: !isCompleteFix,
141
- };
142
- }
143
- function getIdentifiersFromErrorSpanExpression(expression, checker) {
144
- if (isPropertyAccessExpression(expression.parent) && isIdentifier(expression.parent.expression)) {
145
- return { identifiers: [expression.parent.expression], isCompleteFix: true };
146
- }
147
- if (isIdentifier(expression)) {
148
- return { identifiers: [expression], isCompleteFix: true };
149
- }
150
- if (isBinaryExpression(expression)) {
151
- let sides;
152
- let isCompleteFix = true;
153
- for (const side of [expression.left, expression.right]) {
154
- const type = checker.getTypeAtLocation(side);
155
- if (checker.getPromisedTypeOfPromise(type)) {
156
- if (!isIdentifier(side)) {
157
- isCompleteFix = false;
158
- continue;
159
- }
160
- (sides || (sides = [])).push(side);
161
- }
162
- }
163
- return sides && { identifiers: sides, isCompleteFix };
164
- }
165
- }
166
- function symbolReferenceIsAlsoMissingAwait(reference, diagnostics, sourceFile, checker) {
167
- const errorNode = isPropertyAccessExpression(reference.parent) ? reference.parent.name :
168
- isBinaryExpression(reference.parent) ? reference.parent :
169
- reference;
170
- const diagnostic = find(diagnostics, diagnostic => diagnostic.start === errorNode.getStart(sourceFile) &&
171
- (diagnostic.start + diagnostic.length) === errorNode.getEnd());
172
- return diagnostic && contains(errorCodes, diagnostic.code) ||
173
- // A Promise is usually not correct in a binary expression (it’s not valid
174
- // in an arithmetic expression and an equality comparison seems unusual),
175
- // but if the other side of the binary expression has an error, the side
176
- // is typed `any` which will squash the error that would identify this
177
- // Promise as an invalid operand. So if the whole binary expression is
178
- // typed `any` as a result, there is a strong likelihood that this Promise
179
- // is accidentally missing `await`.
180
- checker.getTypeAtLocation(errorNode).flags & TypeFlags.Any;
181
- }
182
- // Na tag, também o bloco de uma `function` declarada, de uma function expression e de um método (CK-02).
183
- function isInsideAwaitableBody(node) {
184
- return node.kind & NodeFlags.AwaitContext || !!findAncestor(node, ancestor => ancestor.parent && isArrowFunction(ancestor.parent) && ancestor.parent.body === ancestor ||
185
- isBlock(ancestor) && (ancestor.parent.kind === SyntaxKind.ArrowFunction));
186
- }
187
- function makeChange(changeTracker, errorCode, sourceFile, checker, insertionSite, fixedDeclarations) {
188
- if (isBinaryExpression(insertionSite)) {
189
- for (const side of [insertionSite.left, insertionSite.right]) {
190
- if (fixedDeclarations && isIdentifier(side)) {
191
- const symbol = checker.getSymbolAtLocation(side);
192
- if (symbol && fixedDeclarations.has(getSymbolId(symbol).toString())) {
193
- continue;
194
- }
195
- }
196
- const type = checker.getTypeAtLocation(side);
197
- const newNode = checker.getPromisedTypeOfPromise(type) ? createAwait(side) : side;
198
- changeTracker.replaceNode(sourceFile, side, newNode);
199
- }
200
- }
201
- else if (errorCode === propertyAccessCode && isPropertyAccessExpression(insertionSite.parent)) {
202
- if (fixedDeclarations && isIdentifier(insertionSite.parent.expression)) {
203
- const symbol = checker.getSymbolAtLocation(insertionSite.parent.expression);
204
- if (symbol && fixedDeclarations.has(getSymbolId(symbol).toString())) {
205
- return;
206
- }
207
- }
208
- changeTracker.replaceNode(sourceFile, insertionSite.parent.expression, createParen(createAwait(insertionSite.parent.expression)));
209
- insertLeadingSemicolonIfNeeded(changeTracker, insertionSite.parent.expression, sourceFile);
210
- }
211
- else if (contains(callableConstructableErrorCodes, errorCode) && isCallOrNewExpression(insertionSite.parent)) {
212
- if (fixedDeclarations && isIdentifier(insertionSite)) {
213
- const symbol = checker.getSymbolAtLocation(insertionSite);
214
- if (symbol && fixedDeclarations.has(getSymbolId(symbol).toString())) {
215
- return;
216
- }
217
- }
218
- changeTracker.replaceNode(sourceFile, insertionSite, createParen(createAwait(insertionSite)));
219
- insertLeadingSemicolonIfNeeded(changeTracker, insertionSite, sourceFile);
220
- }
221
- else {
222
- if (fixedDeclarations && isVariableDeclaration(insertionSite.parent) && isIdentifier(insertionSite.parent.name)) {
223
- const symbol = checker.getSymbolAtLocation(insertionSite.parent.name);
224
- if (symbol && !addToSeen(fixedDeclarations, getSymbolId(symbol))) {
225
- return;
226
- }
227
- }
228
- changeTracker.replaceNode(sourceFile, insertionSite, createAwait(insertionSite));
229
- }
230
- }
231
- function insertLeadingSemicolonIfNeeded(changeTracker, beforeNode, sourceFile) {
232
- const precedingToken = findPrecedingToken(beforeNode.pos, sourceFile);
233
- if (precedingToken && positionIsASICandidate(precedingToken.end, precedingToken.parent, sourceFile)) {
234
- changeTracker.insertText(sourceFile, beforeNode.getStart(sourceFile), ";");
235
- }
236
- }
@@ -1,91 +0,0 @@
1
- // Modificado de microsoft/TypeScript v3.9.10, src/services/codefixes/addMissingConst.ts: o namespace virou módulo ES, com os imports explícitos.
2
- import { Diagnostics, NodeSet, SyntaxKind, every, findAncestor, getTokenAtPosition, isArrayLiteralExpression, isAssignmentExpression, isBinaryExpression, isExpressionStatement, isForInOrOfStatement, isIdentifier, textChanges, } from "../_namespaces/edit.js";
3
- import { codeFixAll, createCodeFixAction, registerCodeFix, } from "../_namespaces/ts.codefix.js";
4
- const fixId = "addMissingConst";
5
- const errorCodes = [
6
- Diagnostics.Cannot_find_name_0.code,
7
- Diagnostics.No_value_exists_in_scope_for_the_shorthand_property_0_Either_declare_one_or_provide_an_initializer.code
8
- ];
9
- registerCodeFix({
10
- errorCodes,
11
- getCodeActions: (context) => {
12
- const changes = textChanges.ChangeTracker.with(context, t => makeChange(t, context.sourceFile, context.span.start, context.program));
13
- if (changes.length > 0) {
14
- return [createCodeFixAction(fixId, changes, Diagnostics.Add_const_to_unresolved_variable, fixId, Diagnostics.Add_const_to_all_unresolved_variables)];
15
- }
16
- },
17
- fixIds: [fixId],
18
- getAllCodeActions: context => {
19
- const fixedNodes = new NodeSet();
20
- return codeFixAll(context, errorCodes, (changes, diag) => makeChange(changes, diag.file, diag.start, context.program, fixedNodes));
21
- },
22
- });
23
- function makeChange(changeTracker, sourceFile, pos, program, fixedNodes) {
24
- const token = getTokenAtPosition(sourceFile, pos);
25
- const forInitializer = findAncestor(token, node => isForInOrOfStatement(node.parent) ? node.parent.initializer === node :
26
- isPossiblyPartOfDestructuring(node) ? false : "quit");
27
- if (forInitializer)
28
- return applyChange(changeTracker, forInitializer, sourceFile, fixedNodes);
29
- const parent = token.parent;
30
- if (isBinaryExpression(parent) && parent.operatorToken.kind === SyntaxKind.EqualsToken && isExpressionStatement(parent.parent)) {
31
- return applyChange(changeTracker, token, sourceFile, fixedNodes);
32
- }
33
- if (isArrayLiteralExpression(parent)) {
34
- const checker = program.getTypeChecker();
35
- if (!every(parent.elements, element => arrayElementCouldBeVariableDeclaration(element, checker))) {
36
- return;
37
- }
38
- return applyChange(changeTracker, parent, sourceFile, fixedNodes);
39
- }
40
- const commaExpression = findAncestor(token, node => isExpressionStatement(node.parent) ? true :
41
- isPossiblyPartOfCommaSeperatedInitializer(node) ? false : "quit");
42
- if (commaExpression) {
43
- const checker = program.getTypeChecker();
44
- if (!expressionCouldBeVariableDeclaration(commaExpression, checker)) {
45
- return;
46
- }
47
- return applyChange(changeTracker, commaExpression, sourceFile, fixedNodes);
48
- }
49
- }
50
- function applyChange(changeTracker, initializer, sourceFile, fixedNodes) {
51
- if (!fixedNodes || fixedNodes.tryAdd(initializer)) {
52
- changeTracker.insertModifierBefore(sourceFile, SyntaxKind.ConstKeyword, initializer);
53
- }
54
- }
55
- function isPossiblyPartOfDestructuring(node) {
56
- switch (node.kind) {
57
- case SyntaxKind.Identifier:
58
- case SyntaxKind.ArrayLiteralExpression:
59
- case SyntaxKind.ObjectLiteralExpression:
60
- case SyntaxKind.PropertyAssignment:
61
- case SyntaxKind.ShorthandPropertyAssignment:
62
- return true;
63
- default:
64
- return false;
65
- }
66
- }
67
- function arrayElementCouldBeVariableDeclaration(expression, checker) {
68
- const identifier = isIdentifier(expression) ? expression :
69
- isAssignmentExpression(expression, /*excludeCompoundAssignment*/ true) && isIdentifier(expression.left) ? expression.left :
70
- undefined;
71
- return !!identifier && !checker.getSymbolAtLocation(identifier);
72
- }
73
- // Na tag, também a vírgula do operador vírgula (CK-02).
74
- function isPossiblyPartOfCommaSeperatedInitializer(node) {
75
- switch (node.kind) {
76
- case SyntaxKind.Identifier:
77
- case SyntaxKind.BinaryExpression:
78
- return true;
79
- default:
80
- return false;
81
- }
82
- }
83
- function expressionCouldBeVariableDeclaration(expression, checker) {
84
- if (!isBinaryExpression(expression)) {
85
- return false;
86
- }
87
- // Na tag, os dois lados de um operador vírgula, cada um como uma declaração (CK-02).
88
- return expression.operatorToken.kind === SyntaxKind.EqualsToken
89
- && isIdentifier(expression.left)
90
- && !checker.getSymbolAtLocation(expression.left);
91
- }
@@ -1,29 +0,0 @@
1
- // Modificado de microsoft/TypeScript v3.9.10, src/services/codefixes/addNameToNamelessParameter.ts: o namespace virou módulo ES, com os imports explícitos.
2
- import { Debug, Diagnostics, createParameter, createTypeReferenceNode, getTokenAtPosition, isIdentifier, isParameter, textChanges, } from "../_namespaces/edit.js";
3
- import { codeFixAll, createCodeFixAction, registerCodeFix, } from "../_namespaces/ts.codefix.js";
4
- const fixId = "addNameToNamelessParameter";
5
- const errorCodes = [Diagnostics.Parameter_has_a_name_but_no_type_Did_you_mean_0_Colon_1.code];
6
- registerCodeFix({
7
- errorCodes,
8
- getCodeActions: (context) => {
9
- const changes = textChanges.ChangeTracker.with(context, t => makeChange(t, context.sourceFile, context.span.start));
10
- return [createCodeFixAction(fixId, changes, Diagnostics.Add_parameter_name, fixId, Diagnostics.Add_names_to_all_parameters_without_names)];
11
- },
12
- fixIds: [fixId],
13
- getAllCodeActions: context => codeFixAll(context, errorCodes, (changes, diag) => makeChange(changes, diag.file, diag.start)),
14
- });
15
- function makeChange(changeTracker, sourceFile, pos) {
16
- const token = getTokenAtPosition(sourceFile, pos);
17
- if (!isIdentifier(token)) {
18
- return Debug.fail("add-name-to-nameless-parameter operates on identifiers, but got a " + Debug.formatSyntaxKind(token.kind));
19
- }
20
- const param = token.parent;
21
- if (!isParameter(param)) {
22
- return Debug.fail("Tried to add a parameter name to a non-parameter: " + Debug.formatSyntaxKind(token.kind));
23
- }
24
- const i = param.parent.parameters.indexOf(param);
25
- Debug.assert(!param.type, "Tried to add a parameter name to a parameter that already had one.");
26
- Debug.assert(i > -1, "Parameter not found in parent parameter list.");
27
- const replacement = createParameter(param.modifiers, param.dotDotDotToken, "arg" + i, param.questionToken, createTypeReferenceNode(token, /*typeArguments*/ undefined), param.initializer);
28
- changeTracker.replaceNode(sourceFile, token, replacement);
29
- }
@@ -1,30 +0,0 @@
1
- // Modificado de microsoft/TypeScript v3.9.10, src/services/codefixes/convertConstToLet.ts: o namespace virou módulo ES, com os imports explícitos.
2
- import { Diagnostics, getTokenAtPosition, textChanges, } from "../_namespaces/edit.js";
3
- import { createCodeFixAction, registerCodeFix, } from "../_namespaces/ts.codefix.js";
4
- const fixId = "fixConvertConstToLet";
5
- const errorCodes = [Diagnostics.Cannot_assign_to_0_because_it_is_a_constant.code];
6
- registerCodeFix({
7
- errorCodes,
8
- getCodeActions: context => {
9
- const { sourceFile, span, program } = context;
10
- const variableStatement = getVariableStatement(sourceFile, span.start, program);
11
- const changes = textChanges.ChangeTracker.with(context, t => doChange(t, sourceFile, variableStatement));
12
- return [createCodeFixAction(fixId, changes, Diagnostics.Convert_const_to_let, fixId, Diagnostics.Convert_const_to_let)];
13
- },
14
- fixIds: [fixId]
15
- });
16
- function getVariableStatement(sourceFile, pos, program) {
17
- const token = getTokenAtPosition(sourceFile, pos);
18
- const checker = program.getTypeChecker();
19
- const symbol = checker.getSymbolAtLocation(token);
20
- if (symbol) {
21
- return symbol.valueDeclaration.parent.parent;
22
- }
23
- }
24
- function doChange(changes, sourceFile, variableStatement) {
25
- if (!variableStatement) {
26
- return;
27
- }
28
- const start = variableStatement.getStart();
29
- changes.replaceRangeWithText(sourceFile, { pos: start, end: start + 5 }, "let");
30
- }