@tslite/services 0.0.0-stage → 1.12.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 (176) hide show
  1. package/LICENSE +55 -0
  2. package/NOTICE +13 -0
  3. package/dist/_namespaces/edit.d.ts +8 -0
  4. package/dist/_namespaces/edit.js +11 -0
  5. package/dist/_namespaces/ts.Completions.StringCompletions.d.ts +1 -0
  6. package/dist/_namespaces/ts.Completions.StringCompletions.js +2 -0
  7. package/dist/_namespaces/ts.Completions.d.ts +2 -0
  8. package/dist/_namespaces/ts.Completions.js +3 -0
  9. package/dist/_namespaces/ts.FindAllReferences.d.ts +2 -0
  10. package/dist/_namespaces/ts.FindAllReferences.js +3 -0
  11. package/dist/_namespaces/ts.GoToDefinition.d.ts +1 -0
  12. package/dist/_namespaces/ts.GoToDefinition.js +2 -0
  13. package/dist/_namespaces/ts.NavigationBar.d.ts +1 -0
  14. package/dist/_namespaces/ts.NavigationBar.js +2 -0
  15. package/dist/_namespaces/ts.OrganizeImports.d.ts +1 -0
  16. package/dist/_namespaces/ts.OrganizeImports.js +2 -0
  17. package/dist/_namespaces/ts.OutliningElementsCollector.d.ts +1 -0
  18. package/dist/_namespaces/ts.OutliningElementsCollector.js +2 -0
  19. package/dist/_namespaces/ts.Rename.d.ts +1 -0
  20. package/dist/_namespaces/ts.Rename.js +2 -0
  21. package/dist/_namespaces/ts.SignatureHelp.d.ts +1 -0
  22. package/dist/_namespaces/ts.SignatureHelp.js +2 -0
  23. package/dist/_namespaces/ts.SmartSelectionRange.d.ts +1 -0
  24. package/dist/_namespaces/ts.SmartSelectionRange.js +2 -0
  25. package/dist/_namespaces/ts.SymbolDisplay.d.ts +1 -0
  26. package/dist/_namespaces/ts.SymbolDisplay.js +2 -0
  27. package/dist/_namespaces/ts.codefix.d.ts +26 -0
  28. package/dist/_namespaces/ts.codefix.js +27 -0
  29. package/dist/_namespaces/ts.d.ts +17 -0
  30. package/dist/_namespaces/ts.formatting.d.ts +7 -0
  31. package/dist/_namespaces/ts.formatting.js +8 -0
  32. package/dist/_namespaces/ts.js +20 -0
  33. package/dist/_namespaces/ts.refactor.addOrRemoveBracesToArrowFunction.d.ts +1 -0
  34. package/dist/_namespaces/ts.refactor.addOrRemoveBracesToArrowFunction.js +2 -0
  35. package/dist/_namespaces/ts.refactor.convertParamsToDestructuredObject.d.ts +1 -0
  36. package/dist/_namespaces/ts.refactor.convertParamsToDestructuredObject.js +2 -0
  37. package/dist/_namespaces/ts.refactor.convertStringOrTemplateLiteral.d.ts +1 -0
  38. package/dist/_namespaces/ts.refactor.convertStringOrTemplateLiteral.js +2 -0
  39. package/dist/_namespaces/ts.refactor.d.ts +9 -0
  40. package/dist/_namespaces/ts.refactor.extractSymbol.d.ts +1 -0
  41. package/dist/_namespaces/ts.refactor.extractSymbol.js +2 -0
  42. package/dist/_namespaces/ts.refactor.js +10 -0
  43. package/dist/_namespaces/ts.textChanges.d.ts +1 -0
  44. package/dist/_namespaces/ts.textChanges.js +2 -0
  45. package/dist/classifier.d.ts +5 -0
  46. package/dist/classifier.js +439 -0
  47. package/dist/codeFixProvider.d.ts +13 -0
  48. package/dist/codeFixProvider.js +84 -0
  49. package/dist/codefixes/addConvertToUnknownForNonOverlappingTypes.d.ts +1 -0
  50. package/dist/codefixes/addConvertToUnknownForNonOverlappingTypes.js +21 -0
  51. package/dist/codefixes/addEmptyExportDeclaration.d.ts +1 -0
  52. package/dist/codefixes/addEmptyExportDeclaration.js +17 -0
  53. package/dist/codefixes/addMissingAsync.d.ts +1 -0
  54. package/dist/codefixes/addMissingAsync.js +75 -0
  55. package/dist/codefixes/addMissingAwait.d.ts +1 -0
  56. package/dist/codefixes/addMissingAwait.js +236 -0
  57. package/dist/codefixes/addMissingConst.d.ts +1 -0
  58. package/dist/codefixes/addMissingConst.js +91 -0
  59. package/dist/codefixes/addNameToNamelessParameter.d.ts +1 -0
  60. package/dist/codefixes/addNameToNamelessParameter.js +29 -0
  61. package/dist/codefixes/convertConstToLet.d.ts +1 -0
  62. package/dist/codefixes/convertConstToLet.js +30 -0
  63. package/dist/codefixes/convertToAsyncFunction.d.ts +1 -0
  64. package/dist/codefixes/convertToAsyncFunction.js +495 -0
  65. package/dist/codefixes/convertToMappedObjectType.d.ts +1 -0
  66. package/dist/codefixes/convertToMappedObjectType.js +48 -0
  67. package/dist/codefixes/correctQualifiedNameToIndexedAccessType.d.ts +1 -0
  68. package/dist/codefixes/correctQualifiedNameToIndexedAccessType.js +33 -0
  69. package/dist/codefixes/fixAddModuleReferTypeMissingTypeof.d.ts +1 -0
  70. package/dist/codefixes/fixAddModuleReferTypeMissingTypeof.js +27 -0
  71. package/dist/codefixes/fixAwaitInSyncFunction.d.ts +1 -0
  72. package/dist/codefixes/fixAwaitInSyncFunction.js +69 -0
  73. package/dist/codefixes/fixExpectedComma.d.ts +1 -0
  74. package/dist/codefixes/fixExpectedComma.js +35 -0
  75. package/dist/codefixes/fixInvalidJsxCharacters.d.ts +1 -0
  76. package/dist/codefixes/fixInvalidJsxCharacters.js +41 -0
  77. package/dist/codefixes/fixMissingCallParentheses.d.ts +1 -0
  78. package/dist/codefixes/fixMissingCallParentheses.js +42 -0
  79. package/dist/codefixes/fixSpelling.d.ts +1 -0
  80. package/dist/codefixes/fixSpelling.js +94 -0
  81. package/dist/codefixes/fixUnreachableCode.d.ts +1 -0
  82. package/dist/codefixes/fixUnreachableCode.js +65 -0
  83. package/dist/codefixes/fixUnusedIdentifier.d.ts +1 -0
  84. package/dist/codefixes/fixUnusedIdentifier.js +224 -0
  85. package/dist/codefixes/helpers.d.ts +8 -0
  86. package/dist/codefixes/helpers.js +53 -0
  87. package/dist/codefixes/importFixes.d.ts +14 -0
  88. package/dist/codefixes/importFixes.js +441 -0
  89. package/dist/codefixes/inferFromUsage.d.ts +1 -0
  90. package/dist/codefixes/inferFromUsage.js +742 -0
  91. package/dist/codefixes/removeUnnecessaryAwait.d.ts +1 -0
  92. package/dist/codefixes/removeUnnecessaryAwait.js +41 -0
  93. package/dist/codefixes/returnValueCorrect.d.ts +1 -0
  94. package/dist/codefixes/returnValueCorrect.js +132 -0
  95. package/dist/codefixes/splitTypeOnlyImport.d.ts +1 -0
  96. package/dist/codefixes/splitTypeOnlyImport.js +32 -0
  97. package/dist/codefixes/useBigintLiteral.d.ts +1 -0
  98. package/dist/codefixes/useBigintLiteral.js +29 -0
  99. package/dist/completions.d.ts +83 -0
  100. package/dist/completions.js +1720 -0
  101. package/dist/documentHighlights.d.ts +8 -0
  102. package/dist/documentHighlights.js +367 -0
  103. package/dist/documentRegistry.d.ts +36 -0
  104. package/dist/documentRegistry.js +63 -0
  105. package/dist/editingServices.d.ts +1 -0
  106. package/dist/editingServices.js +4 -0
  107. package/dist/findAllReferences.d.ts +113 -0
  108. package/dist/findAllReferences.js +1366 -0
  109. package/dist/formatting/formatting.d.ts +26 -0
  110. package/dist/formatting/formatting.js +1021 -0
  111. package/dist/formatting/formattingContext.d.ts +34 -0
  112. package/dist/formatting/formattingContext.js +78 -0
  113. package/dist/formatting/formattingScanner.d.ts +14 -0
  114. package/dist/formatting/formattingScanner.js +228 -0
  115. package/dist/formatting/rule.d.ts +31 -0
  116. package/dist/formatting/rule.js +22 -0
  117. package/dist/formatting/rules.d.ts +7 -0
  118. package/dist/formatting/rules.js +610 -0
  119. package/dist/formatting/rulesMap.d.ts +5 -0
  120. package/dist/formatting/rulesMap.js +127 -0
  121. package/dist/formatting/smartIndenter.d.ts +44 -0
  122. package/dist/formatting/smartIndenter.js +518 -0
  123. package/dist/getEditsForFileRename.d.ts +6 -0
  124. package/dist/getEditsForFileRename.js +86 -0
  125. package/dist/goToDefinition.d.ts +8 -0
  126. package/dist/goToDefinition.js +246 -0
  127. package/dist/importTracker.d.ts +50 -0
  128. package/dist/importTracker.js +422 -0
  129. package/dist/index.d.ts +1 -0
  130. package/dist/index.js +3 -0
  131. package/dist/navigationBar.d.ts +3 -0
  132. package/dist/navigationBar.js +549 -0
  133. package/dist/organizeImports.d.ts +18 -0
  134. package/dist/organizeImports.js +290 -0
  135. package/dist/outliningElementsCollector.d.ts +2 -0
  136. package/dist/outliningElementsCollector.js +261 -0
  137. package/dist/refactorProvider.d.ts +5 -0
  138. package/dist/refactorProvider.js +16 -0
  139. package/dist/refactors/addOrRemoveBracesToArrowFunction.d.ts +1 -0
  140. package/dist/refactors/addOrRemoveBracesToArrowFunction.js +86 -0
  141. package/dist/refactors/convertExport.d.ts +1 -0
  142. package/dist/refactors/convertExport.js +126 -0
  143. package/dist/refactors/convertImport.d.ts +1 -0
  144. package/dist/refactors/convertImport.js +116 -0
  145. package/dist/refactors/convertParamsToDestructuredObject.d.ts +1 -0
  146. package/dist/refactors/convertParamsToDestructuredObject.js +282 -0
  147. package/dist/refactors/convertStringOrTemplateLiteral.d.ts +1 -0
  148. package/dist/refactors/convertStringOrTemplateLiteral.js +148 -0
  149. package/dist/refactors/extractSymbol.d.ts +60 -0
  150. package/dist/refactors/extractSymbol.js +1281 -0
  151. package/dist/refactors/extractType.d.ts +1 -0
  152. package/dist/refactors/extractType.js +102 -0
  153. package/dist/refactors/moveToNewFile.d.ts +1 -0
  154. package/dist/refactors/moveToNewFile.js +477 -0
  155. package/dist/rename.d.ts +2 -0
  156. package/dist/rename.js +100 -0
  157. package/dist/services.d.ts +48 -0
  158. package/dist/services.js +1480 -0
  159. package/dist/signatureHelp.d.ts +8 -0
  160. package/dist/signatureHelp.js +414 -0
  161. package/dist/smartSelection.d.ts +2 -0
  162. package/dist/smartSelection.js +243 -0
  163. package/dist/stringCompletions.d.ts +4 -0
  164. package/dist/stringCompletions.js +220 -0
  165. package/dist/suggestionDiagnostics.d.ts +6 -0
  166. package/dist/suggestionDiagnostics.js +92 -0
  167. package/dist/symbolDisplay.d.ts +16 -0
  168. package/dist/symbolDisplay.js +400 -0
  169. package/dist/textChanges.d.ts +161 -0
  170. package/dist/textChanges.js +1163 -0
  171. package/dist/types.d.ts +908 -0
  172. package/dist/types.js +263 -0
  173. package/dist/utilities.d.ts +283 -0
  174. package/dist/utilities.js +1981 -0
  175. package/package.json +45 -3
  176. package/README.md +0 -3
@@ -0,0 +1,69 @@
1
+ // Modificado de microsoft/TypeScript v3.9.10, src/services/codefixes/fixAwaitInSyncFunction.ts: o namespace virou módulo ES, com os imports explícitos.
2
+ import { Diagnostics, SyntaxKind, addToSeen, createMap, createNodeArray, createTypeReferenceNode, findChildOfKind, first, getContainingFunction, getEntityNameFromTypeNode, getNodeId, getTokenAtPosition, isFunctionTypeNode, isVariableDeclaration, textChanges, } from "../_namespaces/edit.js";
3
+ import { codeFixAll, createCodeFixAction, registerCodeFix, } from "../_namespaces/ts.codefix.js";
4
+ const fixId = "fixAwaitInSyncFunction";
5
+ const errorCodes = [
6
+ Diagnostics.await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules.code,
7
+ Diagnostics.A_for_await_of_statement_is_only_allowed_within_an_async_function_or_async_generator.code,
8
+ ];
9
+ registerCodeFix({
10
+ errorCodes,
11
+ getCodeActions(context) {
12
+ const { sourceFile, span } = context;
13
+ const nodes = getNodes(sourceFile, span.start);
14
+ if (!nodes)
15
+ return undefined;
16
+ const changes = textChanges.ChangeTracker.with(context, t => doChange(t, sourceFile, nodes));
17
+ return [createCodeFixAction(fixId, changes, Diagnostics.Add_async_modifier_to_containing_function, fixId, Diagnostics.Add_all_missing_async_modifiers)];
18
+ },
19
+ fixIds: [fixId],
20
+ getAllCodeActions: context => {
21
+ const seen = createMap();
22
+ return codeFixAll(context, errorCodes, (changes, diag) => {
23
+ const nodes = getNodes(diag.file, diag.start);
24
+ if (!nodes || !addToSeen(seen, getNodeId(nodes.insertBefore)))
25
+ return;
26
+ doChange(changes, context.sourceFile, nodes);
27
+ });
28
+ },
29
+ });
30
+ // Na tag, também a `function` declarada, o método e a function expression (CK-02).
31
+ function getReturnType(expr) {
32
+ if (expr.type) {
33
+ return expr.type;
34
+ }
35
+ if (isVariableDeclaration(expr.parent) &&
36
+ expr.parent.type &&
37
+ isFunctionTypeNode(expr.parent.type)) {
38
+ return expr.parent.type.type;
39
+ }
40
+ }
41
+ function getNodes(sourceFile, start) {
42
+ const token = getTokenAtPosition(sourceFile, start);
43
+ const containingFunction = getContainingFunction(token);
44
+ if (!containingFunction) {
45
+ return;
46
+ }
47
+ let insertBefore;
48
+ // Na tag, o `async` entrava também antes do nome de um método e antes do `function` (CK-02).
49
+ switch (containingFunction.kind) {
50
+ case SyntaxKind.ArrowFunction:
51
+ insertBefore = findChildOfKind(containingFunction, SyntaxKind.OpenParenToken, sourceFile) || first(containingFunction.parameters);
52
+ break;
53
+ default:
54
+ return;
55
+ }
56
+ return insertBefore && {
57
+ insertBefore,
58
+ returnType: getReturnType(containingFunction)
59
+ };
60
+ }
61
+ function doChange(changes, sourceFile, { insertBefore, returnType }) {
62
+ if (returnType) {
63
+ const entityName = getEntityNameFromTypeNode(returnType);
64
+ if (!entityName || entityName.kind !== SyntaxKind.Identifier || entityName.text !== "Promise") {
65
+ changes.replaceNode(sourceFile, returnType, createTypeReferenceNode("Promise", createNodeArray([returnType])));
66
+ }
67
+ }
68
+ changes.insertModifierBefore(sourceFile, SyntaxKind.AsyncKeyword, insertBefore);
69
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,35 @@
1
+ // Modificado de microsoft/TypeScript v3.9.10, src/services/codefixes/fixExpectedComma.ts: o namespace virou módulo ES, com os imports explícitos.
2
+ import { Diagnostics, SyntaxKind, createNode, getTokenAtPosition, isArrayLiteralExpression, isObjectLiteralExpression, textChanges, } from "../_namespaces/edit.js";
3
+ import { codeFixAll, createCodeFixAction, registerCodeFix, } from "../_namespaces/ts.codefix.js";
4
+ const fixId = "fixExpectedComma";
5
+ const expectedErrorCode = Diagnostics._0_expected.code;
6
+ const errorCodes = [expectedErrorCode];
7
+ registerCodeFix({
8
+ errorCodes,
9
+ getCodeActions(context) {
10
+ const { sourceFile } = context;
11
+ const info = getInfo(sourceFile, context.span.start, context.errorCode);
12
+ if (!info) {
13
+ return undefined;
14
+ }
15
+ const changes = textChanges.ChangeTracker.with(context, t => doChange(t, sourceFile, info));
16
+ return [createCodeFixAction(fixId, changes, [Diagnostics.Change_0_to_1, ";", ","], fixId, [Diagnostics.Change_0_to_1, ";", ","])];
17
+ },
18
+ fixIds: [fixId],
19
+ getAllCodeActions: context => codeFixAll(context, errorCodes, (changes, diag) => {
20
+ const info = getInfo(diag.file, diag.start, diag.code);
21
+ if (info)
22
+ doChange(changes, context.sourceFile, info);
23
+ }),
24
+ });
25
+ function getInfo(sourceFile, pos, _) {
26
+ const node = getTokenAtPosition(sourceFile, pos);
27
+ return (node.kind === SyntaxKind.SemicolonToken &&
28
+ node.parent &&
29
+ (isObjectLiteralExpression(node.parent) ||
30
+ isArrayLiteralExpression(node.parent))) ? { node } : undefined;
31
+ }
32
+ function doChange(changes, sourceFile, { node }) {
33
+ const newNode = createNode(SyntaxKind.CommaToken);
34
+ changes.replaceNode(sourceFile, node, newNode);
35
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,41 @@
1
+ // Modificado de microsoft/TypeScript v3.9.10, src/services/codefixes/fixInvalidJsxCharacters.ts: o namespace virou módulo ES, com os imports explícitos.
2
+ import { Diagnostics, hasProperty, quote, textChanges, } from "../_namespaces/edit.js";
3
+ import { codeFixAll, createCodeFixAction, registerCodeFix, } from "../_namespaces/ts.codefix.js";
4
+ const fixIdExpression = "fixInvalidJsxCharacters_expression";
5
+ const fixIdHtmlEntity = "fixInvalidJsxCharacters_htmlEntity";
6
+ const errorCodes = [
7
+ Diagnostics.Unexpected_token_Did_you_mean_or_gt.code,
8
+ Diagnostics.Unexpected_token_Did_you_mean_or_rbrace.code
9
+ ];
10
+ registerCodeFix({
11
+ errorCodes,
12
+ fixIds: [fixIdExpression, fixIdHtmlEntity],
13
+ getCodeActions(context) {
14
+ const { sourceFile, preferences, span } = context;
15
+ const changeToExpression = textChanges.ChangeTracker.with(context, t => doChange(t, preferences, sourceFile, span.start, /* useHtmlEntity */ false));
16
+ const changeToHtmlEntity = textChanges.ChangeTracker.with(context, t => doChange(t, preferences, sourceFile, span.start, /* useHtmlEntity */ true));
17
+ return [
18
+ createCodeFixAction(fixIdExpression, changeToExpression, Diagnostics.Wrap_invalid_character_in_an_expression_container, fixIdExpression, Diagnostics.Wrap_all_invalid_characters_in_an_expression_container),
19
+ createCodeFixAction(fixIdHtmlEntity, changeToHtmlEntity, Diagnostics.Convert_invalid_character_to_its_html_entity_code, fixIdHtmlEntity, Diagnostics.Convert_all_invalid_characters_to_HTML_entity_code)
20
+ ];
21
+ },
22
+ getAllCodeActions(context) {
23
+ return codeFixAll(context, errorCodes, (changes, diagnostic) => doChange(changes, context.preferences, diagnostic.file, diagnostic.start, context.fixId === fixIdHtmlEntity));
24
+ }
25
+ });
26
+ const htmlEntity = {
27
+ ">": ">",
28
+ "}": "}",
29
+ };
30
+ function isValidCharacter(character) {
31
+ return hasProperty(htmlEntity, character);
32
+ }
33
+ function doChange(changes, preferences, sourceFile, start, useHtmlEntity) {
34
+ const character = sourceFile.getText()[start];
35
+ // sanity check
36
+ if (!isValidCharacter(character)) {
37
+ return;
38
+ }
39
+ const replacement = useHtmlEntity ? htmlEntity[character] : `{${quote(character, preferences)}}`;
40
+ changes.replaceRangeWithText(sourceFile, { pos: start, end: start + 1 }, replacement);
41
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,42 @@
1
+ // Modificado de microsoft/TypeScript v3.9.10, src/services/codefixes/fixMissingCallParentheses.ts: o namespace virou módulo ES, com os imports explícitos.
2
+ import { Diagnostics, getTokenAtPosition, isIdentifier, isPropertyAccessExpression, textChanges, } from "../_namespaces/edit.js";
3
+ import { codeFixAll, createCodeFixAction, registerCodeFix, } from "../_namespaces/ts.codefix.js";
4
+ const fixId = "fixMissingCallParentheses";
5
+ const errorCodes = [
6
+ Diagnostics.This_condition_will_always_return_true_since_the_function_is_always_defined_Did_you_mean_to_call_it_instead.code,
7
+ ];
8
+ registerCodeFix({
9
+ errorCodes,
10
+ fixIds: [fixId],
11
+ getCodeActions(context) {
12
+ const { sourceFile, span } = context;
13
+ const callName = getCallName(sourceFile, span.start);
14
+ if (!callName)
15
+ return;
16
+ const changes = textChanges.ChangeTracker.with(context, t => doChange(t, context.sourceFile, callName));
17
+ return [createCodeFixAction(fixId, changes, Diagnostics.Add_missing_call_parentheses, fixId, Diagnostics.Add_all_missing_call_parentheses)];
18
+ },
19
+ getAllCodeActions: context => codeFixAll(context, errorCodes, (changes, diag) => {
20
+ const callName = getCallName(diag.file, diag.start);
21
+ if (callName)
22
+ doChange(changes, diag.file, callName);
23
+ })
24
+ });
25
+ // Na tag, o nome podia ser também um `#private` (CK-02).
26
+ function doChange(changes, sourceFile, name) {
27
+ changes.replaceNodeWithText(sourceFile, name, `${name.text}()`);
28
+ }
29
+ function getCallName(sourceFile, start) {
30
+ const token = getTokenAtPosition(sourceFile, start);
31
+ if (isPropertyAccessExpression(token.parent)) {
32
+ let current = token.parent;
33
+ while (isPropertyAccessExpression(current.parent)) {
34
+ current = current.parent;
35
+ }
36
+ return current.name;
37
+ }
38
+ if (isIdentifier(token)) {
39
+ return token;
40
+ }
41
+ return undefined;
42
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,94 @@
1
+ // Modificado de microsoft/TypeScript v3.9.10, src/services/codefixes/fixSpelling.ts: o namespace virou módulo ES, com os imports explícitos.
2
+ import { Debug, Diagnostics, NodeFlags, ScriptTarget, SymbolFlags, createElementAccess, createIdentifier, createLiteral, findAncestor, getMeaningFromLocation, getResolvedModule, getTextOfNode, getTokenAtPosition, isIdentifier, isIdentifierText, isImportDeclaration, isImportSpecifier, isPropertyAccessExpression, isStringLiteralLike, symbolName, textChanges, } from "../_namespaces/edit.js";
3
+ import { codeFixAll, createCodeFixAction, registerCodeFix, } from "../_namespaces/ts.codefix.js";
4
+ const fixId = "fixSpelling";
5
+ // Na tag, também o nome que seria um membro do `this` ou um membro estático (CK-02): a cópia não acusa esses erros.
6
+ const errorCodes = [
7
+ Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2.code,
8
+ Diagnostics.Cannot_find_name_0_Did_you_mean_1.code,
9
+ Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_2.code,
10
+ ];
11
+ // O alvo da configuração fixa (CK-24): na tag, ele vinha das opções do host.
12
+ const languageVersion = ScriptTarget.ES2020;
13
+ registerCodeFix({
14
+ errorCodes,
15
+ getCodeActions(context) {
16
+ const { sourceFile } = context;
17
+ const info = getInfo(sourceFile, context.span.start, context);
18
+ if (!info)
19
+ return undefined;
20
+ const { node, suggestedSymbol } = info;
21
+ const changes = textChanges.ChangeTracker.with(context, t => doChange(t, sourceFile, node, suggestedSymbol, languageVersion));
22
+ return [createCodeFixAction("spelling", changes, [Diagnostics.Change_spelling_to_0, symbolName(suggestedSymbol)], fixId, Diagnostics.Fix_all_detected_spelling_errors)];
23
+ },
24
+ fixIds: [fixId],
25
+ getAllCodeActions: context => codeFixAll(context, errorCodes, (changes, diag) => {
26
+ const info = getInfo(diag.file, diag.start, context);
27
+ if (info)
28
+ doChange(changes, context.sourceFile, info.node, info.suggestedSymbol, languageVersion);
29
+ }),
30
+ });
31
+ function getInfo(sourceFile, pos, context) {
32
+ // This is the identifier of the misspelled word. eg:
33
+ // this.speling = 1;
34
+ // ^^^^^^^
35
+ const node = getTokenAtPosition(sourceFile, pos);
36
+ const parent = node.parent;
37
+ const checker = context.program.getTypeChecker();
38
+ let suggestedSymbol;
39
+ if (isPropertyAccessExpression(parent) && parent.name === node) {
40
+ // Na tag, o nome podia ser também um `#private` (CK-02).
41
+ Debug.assert(isIdentifier(node), "Expected an identifier for spelling (property access)");
42
+ let containingType = checker.getTypeAtLocation(parent.expression);
43
+ if (parent.flags & NodeFlags.OptionalChain) {
44
+ containingType = checker.getNonNullableType(containingType);
45
+ }
46
+ suggestedSymbol = checker.getSuggestedSymbolForNonexistentProperty(node, containingType);
47
+ }
48
+ else if (isImportSpecifier(parent) && parent.name === node) {
49
+ Debug.assertNode(node, isIdentifier, "Expected an identifier for spelling (import)");
50
+ const importDeclaration = findAncestor(node, isImportDeclaration);
51
+ const resolvedSourceFile = getResolvedSourceFileFromImportDeclaration(sourceFile, context, importDeclaration);
52
+ if (resolvedSourceFile && resolvedSourceFile.symbol) {
53
+ suggestedSymbol = checker.getSuggestedSymbolForNonexistentModule(node, resolvedSourceFile.symbol);
54
+ }
55
+ }
56
+ else {
57
+ const meaning = getMeaningFromLocation(node);
58
+ const name = getTextOfNode(node);
59
+ Debug.assert(name !== undefined, "name should be defined");
60
+ suggestedSymbol = checker.getSuggestedSymbolForNonexistentSymbol(node, name, convertSemanticMeaningToSymbolFlags(meaning));
61
+ }
62
+ return suggestedSymbol === undefined ? undefined : { node, suggestedSymbol };
63
+ }
64
+ function doChange(changes, sourceFile, node, suggestedSymbol, target) {
65
+ const suggestion = symbolName(suggestedSymbol);
66
+ if (!isIdentifierText(suggestion, target) && isPropertyAccessExpression(node.parent)) {
67
+ // Na tag, o `#private` sugerido trocava só o nome (CK-02).
68
+ changes.replaceNode(sourceFile, node.parent, createElementAccess(node.parent.expression, createLiteral(suggestion)));
69
+ }
70
+ else {
71
+ changes.replaceNode(sourceFile, node, createIdentifier(suggestion));
72
+ }
73
+ }
74
+ function convertSemanticMeaningToSymbolFlags(meaning) {
75
+ let flags = 0;
76
+ if (meaning & 4 /* SemanticMeaning.Namespace */) {
77
+ flags |= SymbolFlags.Namespace;
78
+ }
79
+ if (meaning & 2 /* SemanticMeaning.Type */) {
80
+ flags |= SymbolFlags.Type;
81
+ }
82
+ if (meaning & 1 /* SemanticMeaning.Value */) {
83
+ flags |= SymbolFlags.Value;
84
+ }
85
+ return flags;
86
+ }
87
+ function getResolvedSourceFileFromImportDeclaration(sourceFile, context, importDeclaration) {
88
+ if (!importDeclaration || !isStringLiteralLike(importDeclaration.moduleSpecifier))
89
+ return undefined;
90
+ const resolvedModule = getResolvedModule(sourceFile, importDeclaration.moduleSpecifier.text);
91
+ if (!resolvedModule)
92
+ return undefined;
93
+ return context.program.getSourceFile(resolvedModule.resolvedFileName);
94
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,65 @@
1
+ // Modificado de microsoft/TypeScript v3.9.10, src/services/codefixes/fixUnreachableCode.ts: o namespace virou módulo ES, com os imports explícitos.
2
+ import { Debug, Diagnostics, SyntaxKind, createBlock, emptyArray, findAncestor, first, getTokenAtPosition, isBlock, isStatement, sliceAfter, textChanges, } from "../_namespaces/edit.js";
3
+ import { codeFixAll, createCodeFixAction, registerCodeFix, } from "../_namespaces/ts.codefix.js";
4
+ const fixId = "fixUnreachableCode";
5
+ const errorCodes = [Diagnostics.Unreachable_code_detected.code];
6
+ registerCodeFix({
7
+ errorCodes,
8
+ getCodeActions(context) {
9
+ const changes = textChanges.ChangeTracker.with(context, t => doChange(t, context.sourceFile, context.span.start, context.span.length, context.errorCode));
10
+ return [createCodeFixAction(fixId, changes, Diagnostics.Remove_unreachable_code, fixId, Diagnostics.Remove_all_unreachable_code)];
11
+ },
12
+ fixIds: [fixId],
13
+ getAllCodeActions: context => codeFixAll(context, errorCodes, (changes, diag) => doChange(changes, diag.file, diag.start, diag.length, diag.code)),
14
+ });
15
+ function doChange(changes, sourceFile, start, length, errorCode) {
16
+ const token = getTokenAtPosition(sourceFile, start);
17
+ const statement = findAncestor(token, isStatement);
18
+ if (statement.getStart(sourceFile) !== token.getStart(sourceFile)) {
19
+ const logData = JSON.stringify({
20
+ statementKind: Debug.formatSyntaxKind(statement.kind),
21
+ tokenKind: Debug.formatSyntaxKind(token.kind),
22
+ errorCode,
23
+ start,
24
+ length
25
+ });
26
+ Debug.fail("Token and statement should start at the same point. " + logData);
27
+ }
28
+ const container = (isBlock(statement.parent) ? statement.parent : statement).parent;
29
+ if (!isBlock(statement.parent) || statement === first(statement.parent.statements)) {
30
+ switch (container.kind) {
31
+ case SyntaxKind.IfStatement:
32
+ if (container.elseStatement) {
33
+ if (isBlock(statement.parent)) {
34
+ break;
35
+ }
36
+ else {
37
+ changes.replaceNode(sourceFile, statement, createBlock(emptyArray));
38
+ }
39
+ return;
40
+ }
41
+ // falls through
42
+ case SyntaxKind.WhileStatement:
43
+ case SyntaxKind.ForStatement:
44
+ changes.delete(sourceFile, container);
45
+ return;
46
+ }
47
+ }
48
+ if (isBlock(statement.parent)) {
49
+ const end = start + length;
50
+ const lastStatement = Debug.checkDefined(lastWhere(sliceAfter(statement.parent.statements, statement), s => s.pos < end), "Some statement should be last");
51
+ changes.deleteNodeRange(sourceFile, statement, lastStatement);
52
+ }
53
+ else {
54
+ changes.delete(sourceFile, statement);
55
+ }
56
+ }
57
+ function lastWhere(a, pred) {
58
+ let last;
59
+ for (const value of a) {
60
+ if (!pred(value))
61
+ break;
62
+ last = value;
63
+ }
64
+ return last;
65
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,224 @@
1
+ // Modificado de microsoft/TypeScript v3.9.10, src/services/codefixes/fixUnusedIdentifier.ts: o namespace virou módulo ES, com os imports explícitos.
2
+ import { Debug, Diagnostics, FindAllReferences, SyntaxKind, cast, createIdentifier, createKeywordTypeNode, getTokenAtPosition, isBinaryExpression, isComputedPropertyName, isDeclarationWithTypeParameterChildren, isExpressionStatement, isIdentifier, isImportClause, isImportDeclaration, isInferTypeNode, isObjectBindingPattern, isParameter, isPropertyAccessExpression, isVariableDeclarationList, showModuleSpecifier, textChanges, tryCast, } from "../_namespaces/edit.js";
3
+ import { codeFixAll, createCodeFixAction, registerCodeFix, } from "../_namespaces/ts.codefix.js";
4
+ const fixName = "unusedIdentifier";
5
+ const fixIdPrefix = "unusedIdentifier_prefix";
6
+ const fixIdDelete = "unusedIdentifier_delete";
7
+ const fixIdInfer = "unusedIdentifier_infer";
8
+ const errorCodes = [
9
+ Diagnostics._0_is_declared_but_its_value_is_never_read.code,
10
+ Diagnostics._0_is_declared_but_never_used.code,
11
+ Diagnostics.Property_0_is_declared_but_its_value_is_never_read.code,
12
+ Diagnostics.All_imports_in_import_declaration_are_unused.code,
13
+ Diagnostics.All_destructured_elements_are_unused.code,
14
+ Diagnostics.All_variables_are_unused.code,
15
+ Diagnostics.All_type_parameters_are_unused.code,
16
+ ];
17
+ registerCodeFix({
18
+ errorCodes,
19
+ getCodeActions(context) {
20
+ const { errorCode, sourceFile, program } = context;
21
+ const checker = program.getTypeChecker();
22
+ const sourceFiles = program.getSourceFiles();
23
+ const token = getTokenAtPosition(sourceFile, context.span.start);
24
+ // Na tag, também a remoção de um `@template` do JSDoc (CK-03).
25
+ if (token.kind === SyntaxKind.LessThanToken) {
26
+ const changes = textChanges.ChangeTracker.with(context, t => deleteTypeParameters(t, sourceFile, token));
27
+ return [createDeleteFix(changes, Diagnostics.Remove_type_parameters)];
28
+ }
29
+ const importDecl = tryGetFullImport(token);
30
+ if (importDecl) {
31
+ const changes = textChanges.ChangeTracker.with(context, t => t.delete(sourceFile, importDecl));
32
+ return [createDeleteFix(changes, [Diagnostics.Remove_import_from_0, showModuleSpecifier(importDecl)])];
33
+ }
34
+ const delDestructure = textChanges.ChangeTracker.with(context, t => tryDeleteFullDestructure(token, t, sourceFile, checker, sourceFiles, /*isFixAll*/ false));
35
+ if (delDestructure.length) {
36
+ return [createDeleteFix(delDestructure, Diagnostics.Remove_destructuring)];
37
+ }
38
+ const delVar = textChanges.ChangeTracker.with(context, t => tryDeleteFullVariableStatement(sourceFile, token, t));
39
+ if (delVar.length) {
40
+ return [createDeleteFix(delVar, Diagnostics.Remove_variable_statement)];
41
+ }
42
+ const result = [];
43
+ if (token.kind === SyntaxKind.InferKeyword) {
44
+ const changes = textChanges.ChangeTracker.with(context, t => changeInferToUnknown(t, sourceFile, token));
45
+ const name = cast(token.parent, isInferTypeNode).typeParameter.name.text;
46
+ result.push(createCodeFixAction(fixName, changes, [Diagnostics.Replace_infer_0_with_unknown, name], fixIdInfer, Diagnostics.Replace_all_unused_infer_with_unknown));
47
+ }
48
+ else {
49
+ const deletion = textChanges.ChangeTracker.with(context, t => tryDeleteDeclaration(sourceFile, token, t, checker, sourceFiles, /*isFixAll*/ false));
50
+ if (deletion.length) {
51
+ const name = isComputedPropertyName(token.parent) ? token.parent : token;
52
+ result.push(createDeleteFix(deletion, [Diagnostics.Remove_unused_declaration_for_Colon_0, name.getText(sourceFile)]));
53
+ }
54
+ }
55
+ const prefix = textChanges.ChangeTracker.with(context, t => tryPrefixDeclaration(t, errorCode, sourceFile, token));
56
+ if (prefix.length) {
57
+ result.push(createCodeFixAction(fixName, prefix, [Diagnostics.Prefix_0_with_an_underscore, token.getText(sourceFile)], fixIdPrefix, Diagnostics.Prefix_all_unused_declarations_with_where_possible));
58
+ }
59
+ return result;
60
+ },
61
+ fixIds: [fixIdPrefix, fixIdDelete, fixIdInfer],
62
+ getAllCodeActions: context => {
63
+ const { sourceFile, program } = context;
64
+ const checker = program.getTypeChecker();
65
+ const sourceFiles = program.getSourceFiles();
66
+ return codeFixAll(context, errorCodes, (changes, diag) => {
67
+ const token = getTokenAtPosition(sourceFile, diag.start);
68
+ switch (context.fixId) {
69
+ case fixIdPrefix:
70
+ tryPrefixDeclaration(changes, diag.code, sourceFile, token);
71
+ break;
72
+ case fixIdDelete: {
73
+ if (token.kind === SyntaxKind.InferKeyword)
74
+ break; // Can't delete
75
+ const importDecl = tryGetFullImport(token);
76
+ if (importDecl) {
77
+ changes.delete(sourceFile, importDecl);
78
+ }
79
+ // Na tag, também a remoção de um `@template` do JSDoc (CK-03).
80
+ else if (token.kind === SyntaxKind.LessThanToken) {
81
+ deleteTypeParameters(changes, sourceFile, token);
82
+ }
83
+ else if (!tryDeleteFullDestructure(token, changes, sourceFile, checker, sourceFiles, /*isFixAll*/ true) &&
84
+ !tryDeleteFullVariableStatement(sourceFile, token, changes)) {
85
+ tryDeleteDeclaration(sourceFile, token, changes, checker, sourceFiles, /*isFixAll*/ true);
86
+ }
87
+ break;
88
+ }
89
+ case fixIdInfer:
90
+ if (token.kind === SyntaxKind.InferKeyword) {
91
+ changeInferToUnknown(changes, sourceFile, token);
92
+ }
93
+ break;
94
+ default:
95
+ Debug.fail(JSON.stringify(context.fixId));
96
+ }
97
+ });
98
+ },
99
+ });
100
+ function changeInferToUnknown(changes, sourceFile, token) {
101
+ changes.replaceNode(sourceFile, token.parent, createKeywordTypeNode(SyntaxKind.UnknownKeyword));
102
+ }
103
+ function createDeleteFix(changes, diag) {
104
+ return createCodeFixAction(fixName, changes, diag, fixIdDelete, Diagnostics.Delete_all_unused_declarations);
105
+ }
106
+ function deleteTypeParameters(changes, sourceFile, token) {
107
+ changes.delete(sourceFile, Debug.checkDefined(cast(token.parent, isDeclarationWithTypeParameterChildren).typeParameters, "The type parameter to delete should exist"));
108
+ }
109
+ // Sometimes the diagnostic span is an entire ImportDeclaration, so we should remove the whole thing.
110
+ function tryGetFullImport(token) {
111
+ return token.kind === SyntaxKind.ImportKeyword ? tryCast(token.parent, isImportDeclaration) : undefined;
112
+ }
113
+ function tryDeleteFullDestructure(token, changes, sourceFile, checker, sourceFiles, isFixAll) {
114
+ if (token.kind !== SyntaxKind.OpenBraceToken || !isObjectBindingPattern(token.parent))
115
+ return false;
116
+ const decl = token.parent.parent;
117
+ if (decl.kind === SyntaxKind.Parameter) {
118
+ tryDeleteParameter(changes, sourceFile, decl, checker, sourceFiles, isFixAll);
119
+ }
120
+ else {
121
+ changes.delete(sourceFile, decl);
122
+ }
123
+ return true;
124
+ }
125
+ function tryDeleteFullVariableStatement(sourceFile, token, changes) {
126
+ const declarationList = tryCast(token.parent, isVariableDeclarationList);
127
+ if (declarationList && declarationList.getChildren(sourceFile)[0] === token) {
128
+ changes.delete(sourceFile, declarationList.parent.kind === SyntaxKind.VariableStatement ? declarationList.parent : declarationList);
129
+ return true;
130
+ }
131
+ return false;
132
+ }
133
+ function tryPrefixDeclaration(changes, errorCode, sourceFile, token) {
134
+ // Don't offer to prefix a property.
135
+ if (errorCode === Diagnostics.Property_0_is_declared_but_its_value_is_never_read.code)
136
+ return;
137
+ if (token.kind === SyntaxKind.InferKeyword) {
138
+ token = cast(token.parent, isInferTypeNode).typeParameter.name;
139
+ }
140
+ if (isIdentifier(token) && canPrefix(token)) {
141
+ changes.replaceNode(sourceFile, token, createIdentifier(`_${token.text}`));
142
+ // Na tag, o parâmetro renomeado renomeava também o `@param` dele no JSDoc (CK-03).
143
+ }
144
+ }
145
+ function canPrefix(token) {
146
+ switch (token.parent.kind) {
147
+ case SyntaxKind.Parameter:
148
+ case SyntaxKind.TypeParameter:
149
+ return true;
150
+ case SyntaxKind.VariableDeclaration: {
151
+ const varDecl = token.parent;
152
+ switch (varDecl.parent.parent.kind) {
153
+ case SyntaxKind.ForOfStatement:
154
+ case SyntaxKind.ForInStatement:
155
+ return true;
156
+ }
157
+ }
158
+ }
159
+ return false;
160
+ }
161
+ function tryDeleteDeclaration(sourceFile, token, changes, checker, sourceFiles, isFixAll) {
162
+ tryDeleteDeclarationWorker(token, changes, sourceFile, checker, sourceFiles, isFixAll);
163
+ if (isIdentifier(token))
164
+ deleteAssignments(changes, sourceFile, token, checker);
165
+ }
166
+ function deleteAssignments(changes, sourceFile, token, checker) {
167
+ FindAllReferences.Core.eachSymbolReferenceInFile(token, checker, sourceFile, (ref) => {
168
+ if (isPropertyAccessExpression(ref.parent) && ref.parent.name === ref)
169
+ ref = ref.parent;
170
+ if (isBinaryExpression(ref.parent) && isExpressionStatement(ref.parent.parent) && ref.parent.left === ref) {
171
+ changes.delete(sourceFile, ref.parent.parent);
172
+ }
173
+ });
174
+ }
175
+ function tryDeleteDeclarationWorker(token, changes, sourceFile, checker, sourceFiles, isFixAll) {
176
+ const { parent } = token;
177
+ if (isParameter(parent)) {
178
+ tryDeleteParameter(changes, sourceFile, parent, checker, sourceFiles, isFixAll);
179
+ }
180
+ else {
181
+ changes.delete(sourceFile, isImportClause(parent) ? token : isComputedPropertyName(parent) ? parent.parent : parent);
182
+ }
183
+ }
184
+ function tryDeleteParameter(changes, sourceFile, p, checker, sourceFiles, isFixAll) {
185
+ if (mayDeleteParameter(p, isFixAll)) {
186
+ if (p.modifiers && p.modifiers.length > 0
187
+ && (!isIdentifier(p.name) || FindAllReferences.Core.isSymbolReferencedInFile(p.name, checker, sourceFile))) {
188
+ p.modifiers.forEach(modifier => {
189
+ changes.deleteModifier(sourceFile, modifier);
190
+ });
191
+ }
192
+ else {
193
+ changes.delete(sourceFile, p);
194
+ deleteUnusedArguments(changes, sourceFile, p, sourceFiles, checker);
195
+ }
196
+ }
197
+ }
198
+ // Na tag, recebia também o checker, que só o método usava.
199
+ function mayDeleteParameter(p, isFixAll) {
200
+ const { parent } = p;
201
+ // Na tag, também o método (que não perdia o parâmetro quando sobrescrevia o de um tipo base), o construtor, a
202
+ // `function` declarada, a function expression e o setter, que não perdia o parâmetro dele (CK-02).
203
+ switch (parent.kind) {
204
+ case SyntaxKind.ArrowFunction: {
205
+ // Can't remove a non-last parameter in a callback. Can remove a parameter in code-fix-all if future parameters are also unused.
206
+ const { parameters } = parent;
207
+ const index = parameters.indexOf(p);
208
+ Debug.assert(index !== -1, "The parameter should already be in the list");
209
+ return isFixAll
210
+ ? parameters.slice(index + 1).every(p => p.name.kind === SyntaxKind.Identifier && !p.symbol.isReferenced)
211
+ : index === parameters.length - 1;
212
+ }
213
+ default:
214
+ return Debug.failBadSyntaxKind(parent);
215
+ }
216
+ }
217
+ function deleteUnusedArguments(changes, sourceFile, deletedParameter, sourceFiles, checker) {
218
+ FindAllReferences.Core.eachSignatureCall(deletedParameter.parent, sourceFiles, checker, call => {
219
+ const index = deletedParameter.parent.parameters.indexOf(deletedParameter);
220
+ if (call.arguments.length > index) { // Just in case the call didn't provide enough arguments.
221
+ changes.delete(sourceFile, call.arguments[index]);
222
+ }
223
+ });
224
+ }
@@ -0,0 +1,8 @@
1
+ import type { Node, NodeBuilderFlags, ScriptTarget, Symbol, SymbolTracker, Type, TypeChecker, TypeNode } from "../_namespaces/edit.js";
2
+ import type { ImportAdder } from "../_namespaces/ts.codefix.js";
3
+ export declare function typeToAutoImportableTypeNode(checker: TypeChecker, importAdder: ImportAdder, type: Type, contextNode: Node, scriptTarget: ScriptTarget, flags?: NodeBuilderFlags, tracker?: SymbolTracker): TypeNode | undefined;
4
+ export declare function tryGetAutoImportableReferenceFromImportTypeNode(importTypeNode: TypeNode | undefined, type: Type | undefined, scriptTarget: ScriptTarget): {
5
+ symbols: Symbol[];
6
+ typeReference: import("@tslite/parser").TypeReferenceNode;
7
+ } | undefined;
8
+ export declare function importSymbols(importAdder: ImportAdder, symbols: readonly Symbol[]): void;
@@ -0,0 +1,53 @@
1
+ // Modificado de microsoft/TypeScript v3.9.10, src/services/codefixes/helpers.ts: o namespace virou módulo ES, com os imports explícitos.
2
+ // O arquivo entra com o que os code fixes que já vieram usam (a troca do `import("./a").T` por uma referência que se
3
+ // importa, que o `inferFromUsage` pede, e o nó de tipo que importa o que nomeia, que o `extractSymbol` pede); o resto dele
4
+ // vem com o fix que o usa (o docs/ARCHITECTURE.md do pacote).
5
+ import { SyntaxKind, createIdentifier, createQualifiedName, createTypeReferenceNode, getFirstIdentifier, getNameForExportedSymbol, isImportTypeNode, isLiteralImportTypeNode, } from "../_namespaces/edit.js";
6
+ export function typeToAutoImportableTypeNode(checker, importAdder, type, contextNode, scriptTarget, flags, tracker) {
7
+ const typeNode = checker.typeToTypeNode(type, contextNode, flags, tracker);
8
+ if (typeNode && isImportTypeNode(typeNode)) {
9
+ const importableReference = tryGetAutoImportableReferenceFromImportTypeNode(typeNode, type, scriptTarget);
10
+ if (importableReference) {
11
+ importSymbols(importAdder, importableReference.symbols);
12
+ return importableReference.typeReference;
13
+ }
14
+ }
15
+ return typeNode;
16
+ }
17
+ export function tryGetAutoImportableReferenceFromImportTypeNode(importTypeNode, type, scriptTarget) {
18
+ if (importTypeNode && isLiteralImportTypeNode(importTypeNode) && importTypeNode.qualifier && (!type || type.symbol)) {
19
+ // Symbol for the left-most thing after the dot
20
+ const firstIdentifier = getFirstIdentifier(importTypeNode.qualifier);
21
+ const name = getNameForExportedSymbol(firstIdentifier.symbol, scriptTarget);
22
+ const qualifier = name !== firstIdentifier.text
23
+ ? replaceFirstIdentifierOfEntityName(importTypeNode.qualifier, createIdentifier(name))
24
+ : importTypeNode.qualifier;
25
+ const symbols = [firstIdentifier.symbol];
26
+ const typeArguments = [];
27
+ if (importTypeNode.typeArguments) {
28
+ importTypeNode.typeArguments.forEach(arg => {
29
+ const ref = tryGetAutoImportableReferenceFromImportTypeNode(arg, /*undefined*/ type, scriptTarget);
30
+ if (ref) {
31
+ symbols.push(...ref.symbols);
32
+ typeArguments.push(ref.typeReference);
33
+ }
34
+ else {
35
+ typeArguments.push(arg);
36
+ }
37
+ });
38
+ }
39
+ return {
40
+ symbols,
41
+ typeReference: createTypeReferenceNode(qualifier, typeArguments)
42
+ };
43
+ }
44
+ }
45
+ function replaceFirstIdentifierOfEntityName(name, newIdentifier) {
46
+ if (name.kind === SyntaxKind.Identifier) {
47
+ return newIdentifier;
48
+ }
49
+ return createQualifiedName(replaceFirstIdentifierOfEntityName(name.left, newIdentifier), name.right);
50
+ }
51
+ export function importSymbols(importAdder, symbols) {
52
+ symbols.forEach(s => importAdder.addImportFromExportedSymbol(s, /*usageIsTypeOnly*/ true));
53
+ }