@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,148 @@
1
+ // Modificado de microsoft/TypeScript v3.9.10, src/services/refactors/convertStringOrTemplateLiteral.ts: o namespace virou módulo ES, com os imports explícitos.
2
+ import { Debug, Diagnostics, SyntaxKind, copyTrailingAsLeadingComments, copyTrailingComments, createNoSubstitutionTemplateLiteral, createTemplateExpression, createTemplateHead, createTemplateMiddle, createTemplateSpan, createTemplateTail, emptyArray, getLocaleSpecificMessage, getTokenAtPosition, getTrailingCommentRanges, isBinaryExpression, isParenthesizedExpression, isStringLiteral, textChanges, } from "../_namespaces/edit.js";
3
+ import { registerRefactor, } from "../_namespaces/ts.refactor.js";
4
+ const refactorName = "Convert to template string";
5
+ const refactorDescription = getLocaleSpecificMessage(Diagnostics.Convert_to_template_string);
6
+ registerRefactor(refactorName, { getEditsForAction, getAvailableActions });
7
+ function getAvailableActions(context) {
8
+ const { file, startPosition } = context;
9
+ const node = getNodeOrParentOfParentheses(file, startPosition);
10
+ const maybeBinary = getParentBinaryExpression(node);
11
+ const refactorInfo = { name: refactorName, description: refactorDescription, actions: [] };
12
+ if (isBinaryExpression(maybeBinary) && isStringConcatenationValid(maybeBinary)) {
13
+ refactorInfo.actions.push({ name: refactorName, description: refactorDescription });
14
+ return [refactorInfo];
15
+ }
16
+ return emptyArray;
17
+ }
18
+ function getNodeOrParentOfParentheses(file, startPosition) {
19
+ const node = getTokenAtPosition(file, startPosition);
20
+ const nestedBinary = getParentBinaryExpression(node);
21
+ const isNonStringBinary = !isStringConcatenationValid(nestedBinary);
22
+ if (isNonStringBinary &&
23
+ isParenthesizedExpression(nestedBinary.parent) &&
24
+ isBinaryExpression(nestedBinary.parent.parent)) {
25
+ return nestedBinary.parent.parent;
26
+ }
27
+ return node;
28
+ }
29
+ function getEditsForAction(context, actionName) {
30
+ const { file, startPosition } = context;
31
+ const node = getNodeOrParentOfParentheses(file, startPosition);
32
+ switch (actionName) {
33
+ case refactorDescription:
34
+ return { edits: getEditsForToTemplateLiteral(context, node) };
35
+ default:
36
+ return Debug.fail("invalid action");
37
+ }
38
+ }
39
+ function getEditsForToTemplateLiteral(context, node) {
40
+ const maybeBinary = getParentBinaryExpression(node);
41
+ const file = context.file;
42
+ const templateLiteral = nodesToTemplate(treeToArray(maybeBinary), file);
43
+ const trailingCommentRanges = getTrailingCommentRanges(file.text, maybeBinary.end);
44
+ if (trailingCommentRanges) {
45
+ const lastComment = trailingCommentRanges[trailingCommentRanges.length - 1];
46
+ const trailingRange = { pos: trailingCommentRanges[0].pos, end: lastComment.end };
47
+ // since suppressTrailingTrivia(maybeBinary) does not work, the trailing comment is removed manually
48
+ // otherwise it would have the trailing comment twice
49
+ return textChanges.ChangeTracker.with(context, t => {
50
+ t.deleteRange(file, trailingRange);
51
+ t.replaceNode(file, maybeBinary, templateLiteral);
52
+ });
53
+ }
54
+ else {
55
+ return textChanges.ChangeTracker.with(context, t => t.replaceNode(file, maybeBinary, templateLiteral));
56
+ }
57
+ }
58
+ function isNotEqualsOperator(node) {
59
+ return node.operatorToken.kind !== SyntaxKind.EqualsToken;
60
+ }
61
+ function getParentBinaryExpression(expr) {
62
+ while (isBinaryExpression(expr.parent) && isNotEqualsOperator(expr.parent)) {
63
+ expr = expr.parent;
64
+ }
65
+ return expr;
66
+ }
67
+ function isStringConcatenationValid(node) {
68
+ const { containsString, areOperatorsValid } = treeToArray(node);
69
+ return containsString && areOperatorsValid;
70
+ }
71
+ function treeToArray(current) {
72
+ if (isBinaryExpression(current)) {
73
+ const { nodes, operators, containsString: leftHasString, areOperatorsValid: leftOperatorValid } = treeToArray(current.left);
74
+ if (!leftHasString && !isStringLiteral(current.right)) {
75
+ return { nodes: [current], operators: [], containsString: false, areOperatorsValid: true };
76
+ }
77
+ const currentOperatorValid = current.operatorToken.kind === SyntaxKind.PlusToken;
78
+ const areOperatorsValid = leftOperatorValid && currentOperatorValid;
79
+ nodes.push(current.right);
80
+ operators.push(current.operatorToken);
81
+ return { nodes, operators, containsString: true, areOperatorsValid };
82
+ }
83
+ return { nodes: [current], operators: [], containsString: isStringLiteral(current), areOperatorsValid: true };
84
+ }
85
+ // to copy comments following the operator
86
+ // "foo" + /* comment */ "bar"
87
+ const copyTrailingOperatorComments = (operators, file) => (index, targetNode) => {
88
+ if (index < operators.length) {
89
+ copyTrailingComments(operators[index], targetNode, file, SyntaxKind.MultiLineCommentTrivia, /* hasTrailingNewLine */ false);
90
+ }
91
+ };
92
+ // to copy comments following the string
93
+ // "foo" /* comment */ + "bar" /* comment */ + "bar2"
94
+ const copyCommentFromMultiNode = (nodes, file, copyOperatorComments) => (indexes, targetNode) => {
95
+ while (indexes.length > 0) {
96
+ const index = indexes.shift();
97
+ copyTrailingComments(nodes[index], targetNode, file, SyntaxKind.MultiLineCommentTrivia, /* hasTrailingNewLine */ false);
98
+ copyOperatorComments(index, targetNode);
99
+ }
100
+ };
101
+ function concatConsecutiveString(index, nodes) {
102
+ let text = "";
103
+ const indexes = [];
104
+ while (index < nodes.length && isStringLiteral(nodes[index])) {
105
+ const stringNode = nodes[index];
106
+ text = text + stringNode.text;
107
+ indexes.push(index);
108
+ index++;
109
+ }
110
+ return [index, text, indexes];
111
+ }
112
+ function nodesToTemplate({ nodes, operators }, file) {
113
+ const copyOperatorComments = copyTrailingOperatorComments(operators, file);
114
+ const copyCommentFromStringLiterals = copyCommentFromMultiNode(nodes, file, copyOperatorComments);
115
+ const [begin, headText, headIndexes] = concatConsecutiveString(0, nodes);
116
+ if (begin === nodes.length) {
117
+ const noSubstitutionTemplateLiteral = createNoSubstitutionTemplateLiteral(headText);
118
+ copyCommentFromStringLiterals(headIndexes, noSubstitutionTemplateLiteral);
119
+ return noSubstitutionTemplateLiteral;
120
+ }
121
+ const templateSpans = [];
122
+ const templateHead = createTemplateHead(headText);
123
+ copyCommentFromStringLiterals(headIndexes, templateHead);
124
+ for (let i = begin; i < nodes.length; i++) {
125
+ const currentNode = getExpressionFromParenthesesOrExpression(nodes[i]);
126
+ copyOperatorComments(i, currentNode);
127
+ const [newIndex, subsequentText, stringIndexes] = concatConsecutiveString(i + 1, nodes);
128
+ i = newIndex - 1;
129
+ const templatePart = i === nodes.length - 1 ? createTemplateTail(subsequentText) : createTemplateMiddle(subsequentText);
130
+ copyCommentFromStringLiterals(stringIndexes, templatePart);
131
+ templateSpans.push(createTemplateSpan(currentNode, templatePart));
132
+ }
133
+ return createTemplateExpression(templateHead, templateSpans);
134
+ }
135
+ // to copy comments following the opening & closing parentheses
136
+ // "foo" + ( /* comment */ 5 + 5 ) /* comment */ + "bar"
137
+ function copyCommentsWhenParenthesized(node) {
138
+ const file = node.getSourceFile();
139
+ copyTrailingComments(node, node.expression, file, SyntaxKind.MultiLineCommentTrivia, /* hasTrailingNewLine */ false);
140
+ copyTrailingAsLeadingComments(node.expression, node.expression, file, SyntaxKind.MultiLineCommentTrivia, /* hasTrailingNewLine */ false);
141
+ }
142
+ function getExpressionFromParenthesesOrExpression(node) {
143
+ if (isParenthesizedExpression(node)) {
144
+ copyCommentsWhenParenthesized(node);
145
+ node = node.expression;
146
+ }
147
+ return node;
148
+ }
@@ -0,0 +1,60 @@
1
+ import type { ApplicableRefactorInfo, Diagnostic, DiagnosticMessage, Expression, RefactorContext, RefactorEditInfo, SourceFile, Statement, Symbol, TextSpan } from "../_namespaces/edit.js";
2
+ /**
3
+ * Compute the associated code actions
4
+ * Exported for tests.
5
+ */
6
+ export declare function getAvailableActions(context: RefactorContext): readonly ApplicableRefactorInfo[];
7
+ export declare function getEditsForAction(context: RefactorContext, actionName: string): RefactorEditInfo | undefined;
8
+ export declare namespace Messages {
9
+ const cannotExtractRange: DiagnosticMessage;
10
+ const cannotExtractImport: DiagnosticMessage;
11
+ const cannotExtractEmpty: DiagnosticMessage;
12
+ const expressionExpected: DiagnosticMessage;
13
+ const uselessConstantType: DiagnosticMessage;
14
+ const statementOrExpressionExpected: DiagnosticMessage;
15
+ const cannotExtractRangeContainingConditionalBreakOrContinueStatements: DiagnosticMessage;
16
+ const cannotExtractRangeContainingConditionalReturnStatement: DiagnosticMessage;
17
+ const typeWillNotBeVisibleInTheNewScope: DiagnosticMessage;
18
+ const cannotExtractIdentifier: DiagnosticMessage;
19
+ const cannotExtractExportedEntity: DiagnosticMessage;
20
+ const cannotWriteInExpression: DiagnosticMessage;
21
+ const cannotExtractAmbientBlock: DiagnosticMessage;
22
+ const cannotAccessVariablesFromNestedScopes: DiagnosticMessage;
23
+ const cannotExtractToOtherFunctionLike: DiagnosticMessage;
24
+ const cannotExtractToExpressionArrowFunction: DiagnosticMessage;
25
+ }
26
+ declare enum RangeFacts {
27
+ None = 0,
28
+ HasReturn = 1,
29
+ IsAsyncFunction = 4
30
+ }
31
+ /**
32
+ * Represents an expression or a list of statements that should be extracted with some extra information
33
+ */
34
+ interface TargetRange {
35
+ readonly range: Expression | Statement[];
36
+ readonly facts: RangeFacts;
37
+ /**
38
+ * A list of symbols that are declared in the selected range which are visible in the containing lexical scope
39
+ * Used to ensure we don't turn something used outside the range free (or worse, resolve to a different entity).
40
+ */
41
+ readonly declarations: Symbol[];
42
+ }
43
+ /**
44
+ * Result of 'getRangeToExtract' operation: contains either a range or a list of errors
45
+ */
46
+ type RangeToExtract = {
47
+ readonly targetRange?: never;
48
+ readonly errors: readonly Diagnostic[];
49
+ } | {
50
+ readonly targetRange: TargetRange;
51
+ readonly errors?: never;
52
+ };
53
+ /**
54
+ * getRangeToExtract takes a span inside a text file and returns either an expression or an array
55
+ * of statements representing the minimum set of nodes needed to extract the entire span. This
56
+ * process may fail, in which case a set of errors is returned instead (these are currently
57
+ * not shown to the user, but can be used by us diagnostically)
58
+ */
59
+ export declare function getRangeToExtract(sourceFile: SourceFile, span: TextSpan): RangeToExtract;
60
+ export {};