@tslite/services 0.0.0-stage → 1.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,439 @@
1
+ // Modificado de microsoft/TypeScript v3.9.10, src/services/classifier.ts: o namespace virou módulo ES, com os imports explícitos.
2
+ // O arquivo entra com o que os serviços que já vieram usam (a classificação sintática e a semântica); o classificador
3
+ // léxico (o `createClassifier`) vem com o grupo que o usar (o docs/ARCHITECTURE.md do pacote).
4
+ import { CharacterCodes, Debug, ModuleInstanceState, ScriptTarget, SymbolFlags, SyntaxKind, commentPragmas, couldStartTrivia, createScanner, createTextSpan, decodedTextSpanIntersectsWith, getMeaningFromLocation, getModuleInstanceState, getTypeArgumentOrTypeParameterList, isIdentifier, isKeyword, isLineBreak, isModuleDeclaration, isPunctuation, isTemplateLiteralKind, isToken, isTrivia, nodeIsMissing, some, textSpanIntersectsWith, } from "./_namespaces/ts.js";
5
+ export function getSemanticClassifications(typeChecker, cancellationToken, sourceFile, classifiableNames, span) {
6
+ return convertClassificationsToSpans(getEncodedSemanticClassifications(typeChecker, cancellationToken, sourceFile, classifiableNames, span));
7
+ }
8
+ function checkForClassificationCancellation(cancellationToken, kind) {
9
+ // We don't want to actually call back into our host on every node to find out if we've
10
+ // been canceled. That would be an enormous amount of chattyness, along with the all
11
+ // the overhead of marshalling the data to/from the host. So instead we pick a few
12
+ // reasonable node kinds to bother checking on. These node kinds represent high level
13
+ // constructs that we would expect to see commonly, but just at a far less frequent
14
+ // interval.
15
+ //
16
+ // For example, in checker.ts (around 750k) we only have around 600 of these constructs.
17
+ // That means we're calling back into the host around every 1.2k of the file we process.
18
+ // Lib.d.ts has similar numbers.
19
+ // Na tag, também a classe, a interface e a `function` declaradas (CK-02).
20
+ switch (kind) {
21
+ case SyntaxKind.ModuleDeclaration:
22
+ cancellationToken.throwIfCancellationRequested();
23
+ }
24
+ }
25
+ export function getEncodedSemanticClassifications(typeChecker, cancellationToken, sourceFile, classifiableNames, span) {
26
+ const spans = [];
27
+ sourceFile.forEachChild(function cb(node) {
28
+ // Only walk into nodes that intersect the requested span.
29
+ if (!node || !textSpanIntersectsWith(span, node.pos, node.getFullWidth())) {
30
+ return;
31
+ }
32
+ checkForClassificationCancellation(cancellationToken, node.kind);
33
+ // Only bother calling into the typechecker if this is an identifier that
34
+ // could possibly resolve to a type name. This makes classification run
35
+ // in a third of the time it would normally take.
36
+ if (isIdentifier(node) && !nodeIsMissing(node) && classifiableNames.has(node.escapedText)) {
37
+ const symbol = typeChecker.getSymbolAtLocation(node);
38
+ const type = symbol && classifySymbol(symbol, getMeaningFromLocation(node), typeChecker);
39
+ if (type) {
40
+ pushClassification(node.getStart(sourceFile), node.getEnd(), type);
41
+ }
42
+ }
43
+ node.forEachChild(cb);
44
+ });
45
+ return { spans, endOfLineState: 0 /* EndOfLineState.None */ };
46
+ function pushClassification(start, end, type) {
47
+ const length = end - start;
48
+ Debug.assert(length > 0, `Classification had non-positive length of ${length}`);
49
+ spans.push(start);
50
+ spans.push(length);
51
+ spans.push(type);
52
+ }
53
+ }
54
+ function classifySymbol(symbol, meaningAtPosition, checker) {
55
+ const flags = symbol.getFlags();
56
+ // Na tag, também a classe e o enum (CK-02). A interface que fica é a do embutido (CK-48).
57
+ if ((flags & SymbolFlags.Classifiable) === SymbolFlags.None) {
58
+ return undefined;
59
+ }
60
+ else if (flags & SymbolFlags.TypeAlias) {
61
+ return 16 /* ClassificationType.typeAliasName */;
62
+ }
63
+ else if (flags & SymbolFlags.Module) {
64
+ // Only classify a module as such if
65
+ // - It appears in a namespace context.
66
+ // - There exists a module declaration which actually impacts the value side.
67
+ return meaningAtPosition & 4 /* SemanticMeaning.Namespace */ || meaningAtPosition & 1 /* SemanticMeaning.Value */ && hasValueSideModule(symbol) ? 14 /* ClassificationType.moduleName */ : undefined;
68
+ }
69
+ else if (flags & SymbolFlags.Alias) {
70
+ return classifySymbol(checker.getAliasedSymbol(symbol), meaningAtPosition, checker);
71
+ }
72
+ else if (meaningAtPosition & 2 /* SemanticMeaning.Type */) {
73
+ return flags & SymbolFlags.Interface ? 13 /* ClassificationType.interfaceName */ : flags & SymbolFlags.TypeParameter ? 15 /* ClassificationType.typeParameterName */ : undefined;
74
+ }
75
+ else {
76
+ return undefined;
77
+ }
78
+ }
79
+ /** Returns true if there exists a module that introduces entities on the value side. */
80
+ function hasValueSideModule(symbol) {
81
+ return some(symbol.declarations, declaration => isModuleDeclaration(declaration) && getModuleInstanceState(declaration) === ModuleInstanceState.Instantiated);
82
+ }
83
+ function getClassificationTypeName(type) {
84
+ switch (type) {
85
+ case 1 /* ClassificationType.comment */: return "comment" /* ClassificationTypeNames.comment */;
86
+ case 2 /* ClassificationType.identifier */: return "identifier" /* ClassificationTypeNames.identifier */;
87
+ case 3 /* ClassificationType.keyword */: return "keyword" /* ClassificationTypeNames.keyword */;
88
+ case 4 /* ClassificationType.numericLiteral */: return "number" /* ClassificationTypeNames.numericLiteral */;
89
+ case 25 /* ClassificationType.bigintLiteral */: return "bigint" /* ClassificationTypeNames.bigintLiteral */;
90
+ case 5 /* ClassificationType.operator */: return "operator" /* ClassificationTypeNames.operator */;
91
+ case 6 /* ClassificationType.stringLiteral */: return "string" /* ClassificationTypeNames.stringLiteral */;
92
+ case 8 /* ClassificationType.whiteSpace */: return "whitespace" /* ClassificationTypeNames.whiteSpace */;
93
+ case 9 /* ClassificationType.text */: return "text" /* ClassificationTypeNames.text */;
94
+ case 10 /* ClassificationType.punctuation */: return "punctuation" /* ClassificationTypeNames.punctuation */;
95
+ case 11 /* ClassificationType.className */: return "class name" /* ClassificationTypeNames.className */;
96
+ case 12 /* ClassificationType.enumName */: return "enum name" /* ClassificationTypeNames.enumName */;
97
+ case 13 /* ClassificationType.interfaceName */: return "interface name" /* ClassificationTypeNames.interfaceName */;
98
+ case 14 /* ClassificationType.moduleName */: return "module name" /* ClassificationTypeNames.moduleName */;
99
+ case 15 /* ClassificationType.typeParameterName */: return "type parameter name" /* ClassificationTypeNames.typeParameterName */;
100
+ case 16 /* ClassificationType.typeAliasName */: return "type alias name" /* ClassificationTypeNames.typeAliasName */;
101
+ case 17 /* ClassificationType.parameterName */: return "parameter name" /* ClassificationTypeNames.parameterName */;
102
+ case 18 /* ClassificationType.docCommentTagName */: return "doc comment tag name" /* ClassificationTypeNames.docCommentTagName */;
103
+ case 19 /* ClassificationType.jsxOpenTagName */: return "jsx open tag name" /* ClassificationTypeNames.jsxOpenTagName */;
104
+ case 20 /* ClassificationType.jsxCloseTagName */: return "jsx close tag name" /* ClassificationTypeNames.jsxCloseTagName */;
105
+ case 21 /* ClassificationType.jsxSelfClosingTagName */: return "jsx self closing tag name" /* ClassificationTypeNames.jsxSelfClosingTagName */;
106
+ case 22 /* ClassificationType.jsxAttribute */: return "jsx attribute" /* ClassificationTypeNames.jsxAttribute */;
107
+ case 23 /* ClassificationType.jsxText */: return "jsx text" /* ClassificationTypeNames.jsxText */;
108
+ case 24 /* ClassificationType.jsxAttributeStringLiteralValue */: return "jsx attribute string literal value" /* ClassificationTypeNames.jsxAttributeStringLiteralValue */;
109
+ default: return undefined;
110
+ }
111
+ }
112
+ function convertClassificationsToSpans(classifications) {
113
+ Debug.assert(classifications.spans.length % 3 === 0);
114
+ const dense = classifications.spans;
115
+ const result = [];
116
+ for (let i = 0; i < dense.length; i += 3) {
117
+ result.push({
118
+ textSpan: createTextSpan(dense[i], dense[i + 1]),
119
+ classificationType: getClassificationTypeName(dense[i + 2])
120
+ });
121
+ }
122
+ return result;
123
+ }
124
+ export function getSyntacticClassifications(cancellationToken, sourceFile, span) {
125
+ return convertClassificationsToSpans(getEncodedSyntacticClassifications(cancellationToken, sourceFile, span));
126
+ }
127
+ export function getEncodedSyntacticClassifications(cancellationToken, sourceFile, span) {
128
+ const spanStart = span.start;
129
+ const spanLength = span.length;
130
+ // Make a scanner we can get trivia from.
131
+ const triviaScanner = createScanner(ScriptTarget.Latest, /*skipTrivia*/ false, sourceFile.languageVariant, sourceFile.text);
132
+ const mergeConflictScanner = createScanner(ScriptTarget.Latest, /*skipTrivia*/ false, sourceFile.languageVariant, sourceFile.text);
133
+ const result = [];
134
+ processElement(sourceFile);
135
+ return { spans: result, endOfLineState: 0 /* EndOfLineState.None */ };
136
+ function pushClassification(start, length, type) {
137
+ result.push(start);
138
+ result.push(length);
139
+ result.push(type);
140
+ }
141
+ function classifyLeadingTriviaAndGetTokenStart(token) {
142
+ triviaScanner.setTextPos(token.pos);
143
+ while (true) {
144
+ const start = triviaScanner.getTextPos();
145
+ // only bother scanning if we have something that could be trivia.
146
+ if (!couldStartTrivia(sourceFile.text, start)) {
147
+ return start;
148
+ }
149
+ const kind = triviaScanner.scan();
150
+ const end = triviaScanner.getTextPos();
151
+ const width = end - start;
152
+ // The moment we get something that isn't trivia, then stop processing.
153
+ if (!isTrivia(kind)) {
154
+ return start;
155
+ }
156
+ switch (kind) {
157
+ case SyntaxKind.NewLineTrivia:
158
+ case SyntaxKind.WhitespaceTrivia:
159
+ // Don't bother with newlines/whitespace.
160
+ continue;
161
+ case SyntaxKind.SingleLineCommentTrivia:
162
+ case SyntaxKind.MultiLineCommentTrivia:
163
+ // Only bother with the trivia if it at least intersects the span of interest.
164
+ classifyComment(kind, start, width);
165
+ // Classifying a comment might cause us to reuse the trivia scanner
166
+ // (because of jsdoc comments). So after we classify the comment make
167
+ // sure we set the scanner position back to where it needs to be.
168
+ triviaScanner.setTextPos(end);
169
+ continue;
170
+ case SyntaxKind.ConflictMarkerTrivia:
171
+ const text = sourceFile.text;
172
+ const ch = text.charCodeAt(start);
173
+ // for the <<<<<<< and >>>>>>> markers, we just add them in as comments
174
+ // in the classification stream.
175
+ if (ch === CharacterCodes.lessThan || ch === CharacterCodes.greaterThan) {
176
+ pushClassification(start, width, 1 /* ClassificationType.comment */);
177
+ continue;
178
+ }
179
+ // for the ||||||| and ======== markers, add a comment for the first line,
180
+ // and then lex all subsequent lines up until the end of the conflict marker.
181
+ Debug.assert(ch === CharacterCodes.bar || ch === CharacterCodes.equals);
182
+ classifyDisabledMergeCode(text, start, end);
183
+ break;
184
+ case SyntaxKind.ShebangTrivia:
185
+ // TODO: Maybe we should classify these.
186
+ break;
187
+ default:
188
+ Debug.assertNever(kind);
189
+ }
190
+ }
191
+ }
192
+ /**
193
+ * Na tag, o comentário JSDoc se classificava por partes (a tag, o nome do parâmetro, o tipo), pelo nó que o parser do
194
+ * JSDoc montava, e o nó que o comentário documenta era o `token`; sem o JSDoc (CK-03), ele é um comentário como os
195
+ * outros.
196
+ */
197
+ function classifyComment(kind, start, width) {
198
+ if (kind === SyntaxKind.SingleLineCommentTrivia) {
199
+ if (tryClassifyTripleSlashComment(start, width)) {
200
+ return;
201
+ }
202
+ }
203
+ // Simple comment. Just add as is.
204
+ pushCommentRange(start, width);
205
+ }
206
+ function pushCommentRange(start, width) {
207
+ pushClassification(start, width, 1 /* ClassificationType.comment */);
208
+ }
209
+ function tryClassifyTripleSlashComment(start, width) {
210
+ const tripleSlashXMLCommentRegEx = /^(\/\/\/\s*)(<)(?:(\S+)((?:[^/]|\/[^>])*)(\/>)?)?/im;
211
+ const attributeRegex = /(\S+)(\s*)(=)(\s*)('[^']+'|"[^"]+")/img;
212
+ const text = sourceFile.text.substr(start, width);
213
+ const match = tripleSlashXMLCommentRegEx.exec(text);
214
+ if (!match) {
215
+ return false;
216
+ }
217
+ // Limiting classification to exactly the elements and attributes
218
+ // defined in `ts.commentPragmas` would be excessive, but we can avoid
219
+ // some obvious false positives (e.g. in XML-like doc comments) by
220
+ // checking the element name.
221
+ // eslint-disable-next-line no-in-operator
222
+ if (!match[3] || !(match[3] in commentPragmas)) {
223
+ return false;
224
+ }
225
+ let pos = start;
226
+ pushCommentRange(pos, match[1].length); // ///
227
+ pos += match[1].length;
228
+ pushClassification(pos, match[2].length, 10 /* ClassificationType.punctuation */); // <
229
+ pos += match[2].length;
230
+ pushClassification(pos, match[3].length, 21 /* ClassificationType.jsxSelfClosingTagName */); // element name
231
+ pos += match[3].length;
232
+ const attrText = match[4];
233
+ let attrPos = pos;
234
+ while (true) {
235
+ const attrMatch = attributeRegex.exec(attrText);
236
+ if (!attrMatch) {
237
+ break;
238
+ }
239
+ const newAttrPos = pos + attrMatch.index;
240
+ if (newAttrPos > attrPos) {
241
+ pushCommentRange(attrPos, newAttrPos - attrPos);
242
+ attrPos = newAttrPos;
243
+ }
244
+ pushClassification(attrPos, attrMatch[1].length, 22 /* ClassificationType.jsxAttribute */); // attribute name
245
+ attrPos += attrMatch[1].length;
246
+ if (attrMatch[2].length) {
247
+ pushCommentRange(attrPos, attrMatch[2].length); // whitespace
248
+ attrPos += attrMatch[2].length;
249
+ }
250
+ pushClassification(attrPos, attrMatch[3].length, 5 /* ClassificationType.operator */); // =
251
+ attrPos += attrMatch[3].length;
252
+ if (attrMatch[4].length) {
253
+ pushCommentRange(attrPos, attrMatch[4].length); // whitespace
254
+ attrPos += attrMatch[4].length;
255
+ }
256
+ pushClassification(attrPos, attrMatch[5].length, 24 /* ClassificationType.jsxAttributeStringLiteralValue */); // attribute value
257
+ attrPos += attrMatch[5].length;
258
+ }
259
+ pos += match[4].length;
260
+ if (pos > attrPos) {
261
+ pushCommentRange(attrPos, pos - attrPos);
262
+ }
263
+ if (match[5]) {
264
+ pushClassification(pos, match[5].length, 10 /* ClassificationType.punctuation */); // />
265
+ pos += match[5].length;
266
+ }
267
+ const end = start + width;
268
+ if (pos < end) {
269
+ pushCommentRange(pos, end - pos);
270
+ }
271
+ return true;
272
+ }
273
+ function classifyDisabledMergeCode(text, start, end) {
274
+ // Classify the line that the ||||||| or ======= marker is on as a comment.
275
+ // Then just lex all further tokens and add them to the result.
276
+ let i;
277
+ for (i = start; i < end; i++) {
278
+ if (isLineBreak(text.charCodeAt(i))) {
279
+ break;
280
+ }
281
+ }
282
+ pushClassification(start, i - start, 1 /* ClassificationType.comment */);
283
+ mergeConflictScanner.setTextPos(i);
284
+ while (mergeConflictScanner.getTextPos() < end) {
285
+ classifyDisabledCodeToken();
286
+ }
287
+ }
288
+ function classifyDisabledCodeToken() {
289
+ const start = mergeConflictScanner.getTextPos();
290
+ const tokenKind = mergeConflictScanner.scan();
291
+ const end = mergeConflictScanner.getTextPos();
292
+ const type = classifyTokenType(tokenKind);
293
+ if (type) {
294
+ pushClassification(start, end - start, type);
295
+ }
296
+ }
297
+ /**
298
+ * Returns true if node should be treated as classified and no further processing is required.
299
+ * False will mean that node is not classified and traverse routine should recurse into node contents.
300
+ * Na tag, também o nó de JSDoc, que a parse tree da cópia não tem (CK-03).
301
+ */
302
+ function tryClassifyNode(node) {
303
+ if (nodeIsMissing(node)) {
304
+ return true;
305
+ }
306
+ const classifiedElementName = tryClassifyJsxElementName(node);
307
+ if (!isToken(node) && node.kind !== SyntaxKind.JsxText && classifiedElementName === undefined) {
308
+ return false;
309
+ }
310
+ const tokenStart = node.kind === SyntaxKind.JsxText ? node.pos : classifyLeadingTriviaAndGetTokenStart(node);
311
+ const tokenWidth = node.end - tokenStart;
312
+ Debug.assert(tokenWidth >= 0);
313
+ if (tokenWidth > 0) {
314
+ const type = classifiedElementName || classifyTokenType(node.kind, node);
315
+ if (type) {
316
+ pushClassification(tokenStart, tokenWidth, type);
317
+ }
318
+ }
319
+ return true;
320
+ }
321
+ function tryClassifyJsxElementName(token) {
322
+ switch (token.parent && token.parent.kind) {
323
+ case SyntaxKind.JsxOpeningElement:
324
+ if (token.parent.tagName === token) {
325
+ return 19 /* ClassificationType.jsxOpenTagName */;
326
+ }
327
+ break;
328
+ case SyntaxKind.JsxClosingElement:
329
+ if (token.parent.tagName === token) {
330
+ return 20 /* ClassificationType.jsxCloseTagName */;
331
+ }
332
+ break;
333
+ case SyntaxKind.JsxSelfClosingElement:
334
+ if (token.parent.tagName === token) {
335
+ return 21 /* ClassificationType.jsxSelfClosingTagName */;
336
+ }
337
+ break;
338
+ case SyntaxKind.JsxAttribute:
339
+ if (token.parent.name === token) {
340
+ return 22 /* ClassificationType.jsxAttribute */;
341
+ }
342
+ break;
343
+ }
344
+ return undefined;
345
+ }
346
+ // for accurate classification, the actual token should be passed in. however, for
347
+ // cases like 'disabled merge code' classification, we just get the token kind and
348
+ // classify based on that instead.
349
+ function classifyTokenType(tokenKind, token) {
350
+ if (isKeyword(tokenKind)) {
351
+ return 3 /* ClassificationType.keyword */;
352
+ }
353
+ // Special case `<` and `>`: If they appear in a generic context they are punctuation,
354
+ // not operators.
355
+ if (tokenKind === SyntaxKind.LessThanToken || tokenKind === SyntaxKind.GreaterThanToken) {
356
+ // If the node owning the token has a type argument list or type parameter list, then
357
+ // we can effectively assume that a '<' and '>' belong to those lists.
358
+ if (token && getTypeArgumentOrTypeParameterList(token.parent)) {
359
+ return 10 /* ClassificationType.punctuation */;
360
+ }
361
+ }
362
+ if (isPunctuation(tokenKind)) {
363
+ if (token) {
364
+ const parent = token.parent;
365
+ if (tokenKind === SyntaxKind.EqualsToken) {
366
+ // the '=' in a variable declaration is special cased here.
367
+ // Na tag, também o de uma propriedade de classe (CK-02).
368
+ if (parent.kind === SyntaxKind.VariableDeclaration ||
369
+ parent.kind === SyntaxKind.Parameter ||
370
+ parent.kind === SyntaxKind.JsxAttribute) {
371
+ return 5 /* ClassificationType.operator */;
372
+ }
373
+ }
374
+ if (parent.kind === SyntaxKind.BinaryExpression ||
375
+ parent.kind === SyntaxKind.PrefixUnaryExpression ||
376
+ parent.kind === SyntaxKind.PostfixUnaryExpression ||
377
+ parent.kind === SyntaxKind.ConditionalExpression) {
378
+ return 5 /* ClassificationType.operator */;
379
+ }
380
+ }
381
+ return 10 /* ClassificationType.punctuation */;
382
+ }
383
+ else if (tokenKind === SyntaxKind.NumericLiteral) {
384
+ return 4 /* ClassificationType.numericLiteral */;
385
+ }
386
+ else if (tokenKind === SyntaxKind.BigIntLiteral) {
387
+ return 25 /* ClassificationType.bigintLiteral */;
388
+ }
389
+ else if (tokenKind === SyntaxKind.StringLiteral) {
390
+ return token && token.parent.kind === SyntaxKind.JsxAttribute ? 24 /* ClassificationType.jsxAttributeStringLiteralValue */ : 6 /* ClassificationType.stringLiteral */;
391
+ }
392
+ // Na tag, também o literal de regex, como string (CK-02).
393
+ else if (isTemplateLiteralKind(tokenKind)) {
394
+ return 6 /* ClassificationType.stringLiteral */;
395
+ }
396
+ else if (tokenKind === SyntaxKind.JsxText) {
397
+ return 23 /* ClassificationType.jsxText */;
398
+ }
399
+ else if (tokenKind === SyntaxKind.Identifier) {
400
+ if (token) {
401
+ // Na tag, também o nome de uma classe, de uma interface e de um enum declarados, e o parâmetro `this`, que
402
+ // era palavra-chave (CK-02).
403
+ switch (token.parent.kind) {
404
+ case SyntaxKind.TypeParameter:
405
+ if (token.parent.name === token) {
406
+ return 15 /* ClassificationType.typeParameterName */;
407
+ }
408
+ return;
409
+ case SyntaxKind.ModuleDeclaration:
410
+ if (token.parent.name === token) {
411
+ return 14 /* ClassificationType.moduleName */;
412
+ }
413
+ return;
414
+ case SyntaxKind.Parameter:
415
+ if (token.parent.name === token) {
416
+ return 17 /* ClassificationType.parameterName */;
417
+ }
418
+ return;
419
+ }
420
+ }
421
+ return 2 /* ClassificationType.identifier */;
422
+ }
423
+ }
424
+ function processElement(element) {
425
+ if (!element) {
426
+ return;
427
+ }
428
+ // Ignore nodes that don't intersect the original span to classify.
429
+ if (decodedTextSpanIntersectsWith(spanStart, spanLength, element.pos, element.getFullWidth())) {
430
+ checkForClassificationCancellation(cancellationToken, element.kind);
431
+ for (const child of element.getChildren(sourceFile)) {
432
+ if (!tryClassifyNode(child)) {
433
+ // Recurse into our child nodes.
434
+ processElement(child);
435
+ }
436
+ }
437
+ }
438
+ }
439
+ }
@@ -0,0 +1,13 @@
1
+ import { textChanges } from "./_namespaces/edit.js";
2
+ import type { CodeFixAction, CodeFixAllContext, CodeFixContext, CodeFixRegistration, CombinedCodeActions, DiagnosticMessage, DiagnosticWithLocation, FileTextChanges, TextChange } from "./_namespaces/edit.js";
3
+ export type DiagnosticAndArguments = DiagnosticMessage | [DiagnosticMessage, string] | [DiagnosticMessage, string, string];
4
+ export declare function createCodeFixActionWithoutFixAll(fixName: string, changes: FileTextChanges[], description: DiagnosticAndArguments): CodeFixAction;
5
+ export declare function createCodeFixAction(fixName: string, changes: FileTextChanges[], description: DiagnosticAndArguments, fixId: {}, fixAllDescription: DiagnosticAndArguments): CodeFixAction;
6
+ export declare function registerCodeFix(reg: CodeFixRegistration): void;
7
+ export declare function getSupportedErrorCodes(): string[];
8
+ export declare function getFixes(context: CodeFixContext): readonly CodeFixAction[];
9
+ export declare function getAllFixes(context: CodeFixAllContext): CombinedCodeActions;
10
+ export declare function createCombinedCodeActions(changes: FileTextChanges[]): CombinedCodeActions;
11
+ export declare function createFileTextChanges(fileName: string, textChanges: TextChange[]): FileTextChanges;
12
+ export declare function codeFixAll(context: CodeFixAllContext, errorCodes: number[], use: (changes: textChanges.ChangeTracker, error: DiagnosticWithLocation) => void): CombinedCodeActions;
13
+ export declare function eachDiagnostic(context: CodeFixAllContext, errorCodes: readonly number[], cb: (diag: DiagnosticWithLocation) => void): void;
@@ -0,0 +1,84 @@
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
+ }
@@ -0,0 +1,21 @@
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
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
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
+ });
@@ -0,0 +1 @@
1
+ export {};