@tslite/services 1.16.0 → 1.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/NOTICE +3 -1
  2. package/dist/_namespaces/edit.d.ts +1 -1
  3. package/dist/_namespaces/edit.js +10759 -11
  4. package/dist/_namespaces/ts.codefix.d.ts +0 -1
  5. package/dist/_namespaces/ts.js +10196 -19
  6. package/dist/classifier.d.ts +3 -1
  7. package/dist/codeFixProvider.d.ts +2 -1
  8. package/dist/codefixes/helpers.d.ts +3 -1
  9. package/dist/codefixes/importFixes.d.ts +3 -1
  10. package/dist/completions.d.ts +5 -2
  11. package/dist/documentHighlights.d.ts +3 -1
  12. package/dist/documentRegistry.d.ts +2 -1
  13. package/dist/findAllReferences.d.ts +3 -1
  14. package/dist/formatting/formatting.d.ts +3 -2
  15. package/dist/formatting/formattingContext.d.ts +2 -1
  16. package/dist/formatting/formattingScanner.d.ts +2 -2
  17. package/dist/formatting/rule.d.ts +1 -1
  18. package/dist/formatting/rulesMap.d.ts +1 -1
  19. package/dist/formatting/smartIndenter.d.ts +2 -1
  20. package/dist/getEditsForFileRename.d.ts +4 -1
  21. package/dist/goToDefinition.d.ts +3 -1
  22. package/dist/importTracker.d.ts +2 -1
  23. package/dist/navigationBar.d.ts +3 -1
  24. package/dist/organizeImports.d.ts +4 -2
  25. package/dist/outliningElementsCollector.d.ts +3 -1
  26. package/dist/refactorProvider.d.ts +1 -1
  27. package/dist/refactors/extractSymbol.d.ts +2 -1
  28. package/dist/rename.d.ts +3 -1
  29. package/dist/services.d.ts +5 -2
  30. package/dist/signatureHelp.d.ts +3 -1
  31. package/dist/smartSelection.d.ts +2 -1
  32. package/dist/stringCompletions.d.ts +3 -1
  33. package/dist/suggestionDiagnostics.d.ts +4 -3
  34. package/dist/symbolDisplay.d.ts +3 -1
  35. package/dist/textChanges.d.ts +4 -2
  36. package/dist/types.d.ts +3 -3
  37. package/dist/utilities.d.ts +7 -2
  38. package/package.json +7 -5
  39. package/dist/_namespaces/ts.Completions.StringCompletions.js +0 -2
  40. package/dist/_namespaces/ts.Completions.js +0 -3
  41. package/dist/_namespaces/ts.FindAllReferences.js +0 -3
  42. package/dist/_namespaces/ts.GoToDefinition.js +0 -2
  43. package/dist/_namespaces/ts.NavigationBar.js +0 -2
  44. package/dist/_namespaces/ts.OrganizeImports.js +0 -2
  45. package/dist/_namespaces/ts.OutliningElementsCollector.js +0 -2
  46. package/dist/_namespaces/ts.Rename.js +0 -2
  47. package/dist/_namespaces/ts.SignatureHelp.js +0 -2
  48. package/dist/_namespaces/ts.SmartSelectionRange.js +0 -2
  49. package/dist/_namespaces/ts.SymbolDisplay.js +0 -2
  50. package/dist/_namespaces/ts.codefix.js +0 -27
  51. package/dist/_namespaces/ts.formatting.js +0 -8
  52. package/dist/_namespaces/ts.refactor.addOrRemoveBracesToArrowFunction.js +0 -2
  53. package/dist/_namespaces/ts.refactor.convertParamsToDestructuredObject.js +0 -2
  54. package/dist/_namespaces/ts.refactor.convertStringOrTemplateLiteral.js +0 -2
  55. package/dist/_namespaces/ts.refactor.extractSymbol.js +0 -2
  56. package/dist/_namespaces/ts.refactor.js +0 -10
  57. package/dist/_namespaces/ts.textChanges.js +0 -2
  58. package/dist/classifier.js +0 -715
  59. package/dist/codeFixProvider.js +0 -84
  60. package/dist/codefixes/addConvertToUnknownForNonOverlappingTypes.d.ts +0 -1
  61. package/dist/codefixes/addConvertToUnknownForNonOverlappingTypes.js +0 -21
  62. package/dist/codefixes/addEmptyExportDeclaration.js +0 -17
  63. package/dist/codefixes/addMissingAsync.js +0 -75
  64. package/dist/codefixes/addMissingAwait.js +0 -236
  65. package/dist/codefixes/addMissingConst.js +0 -91
  66. package/dist/codefixes/addNameToNamelessParameter.js +0 -29
  67. package/dist/codefixes/convertConstToLet.js +0 -30
  68. package/dist/codefixes/convertToAsyncFunction.js +0 -495
  69. package/dist/codefixes/convertToMappedObjectType.js +0 -48
  70. package/dist/codefixes/correctQualifiedNameToIndexedAccessType.js +0 -33
  71. package/dist/codefixes/fixAddModuleReferTypeMissingTypeof.js +0 -27
  72. package/dist/codefixes/fixAwaitInSyncFunction.js +0 -69
  73. package/dist/codefixes/fixExpectedComma.js +0 -35
  74. package/dist/codefixes/fixInvalidJsxCharacters.js +0 -41
  75. package/dist/codefixes/fixMissingCallParentheses.js +0 -42
  76. package/dist/codefixes/fixSpelling.js +0 -94
  77. package/dist/codefixes/fixUnreachableCode.js +0 -65
  78. package/dist/codefixes/fixUnusedIdentifier.js +0 -224
  79. package/dist/codefixes/helpers.js +0 -53
  80. package/dist/codefixes/importFixes.js +0 -441
  81. package/dist/codefixes/inferFromUsage.js +0 -742
  82. package/dist/codefixes/removeUnnecessaryAwait.js +0 -41
  83. package/dist/codefixes/returnValueCorrect.js +0 -132
  84. package/dist/codefixes/splitTypeOnlyImport.js +0 -32
  85. package/dist/codefixes/useBigintLiteral.js +0 -29
  86. package/dist/completions.js +0 -1720
  87. package/dist/documentHighlights.js +0 -367
  88. package/dist/documentRegistry.js +0 -63
  89. package/dist/editingServices.js +0 -4
  90. package/dist/findAllReferences.js +0 -1366
  91. package/dist/formatting/formatting.js +0 -1021
  92. package/dist/formatting/formattingContext.js +0 -78
  93. package/dist/formatting/formattingScanner.js +0 -228
  94. package/dist/formatting/rule.js +0 -22
  95. package/dist/formatting/rules.js +0 -610
  96. package/dist/formatting/rulesMap.js +0 -127
  97. package/dist/formatting/smartIndenter.js +0 -518
  98. package/dist/getEditsForFileRename.js +0 -86
  99. package/dist/goToDefinition.js +0 -246
  100. package/dist/importTracker.js +0 -422
  101. package/dist/index.js +0 -3
  102. package/dist/navigationBar.js +0 -549
  103. package/dist/organizeImports.js +0 -290
  104. package/dist/outliningElementsCollector.js +0 -261
  105. package/dist/refactorProvider.js +0 -16
  106. package/dist/refactors/addOrRemoveBracesToArrowFunction.js +0 -86
  107. package/dist/refactors/convertExport.js +0 -126
  108. package/dist/refactors/convertImport.js +0 -116
  109. package/dist/refactors/convertParamsToDestructuredObject.js +0 -282
  110. package/dist/refactors/convertStringOrTemplateLiteral.js +0 -148
  111. package/dist/refactors/extractSymbol.js +0 -1281
  112. package/dist/refactors/extractType.js +0 -102
  113. package/dist/refactors/moveToNewFile.js +0 -477
  114. package/dist/rename.js +0 -100
  115. package/dist/services.js +0 -1480
  116. package/dist/signatureHelp.js +0 -414
  117. package/dist/smartSelection.js +0 -243
  118. package/dist/stringCompletions.js +0 -220
  119. package/dist/suggestionDiagnostics.js +0 -92
  120. package/dist/symbolDisplay.js +0 -400
  121. package/dist/textChanges.js +0 -1163
  122. package/dist/types.js +0 -263
  123. package/dist/utilities.js +0 -1981
@@ -1,367 +0,0 @@
1
- // Modificado de microsoft/TypeScript v3.9.10, src/services/documentHighlights.ts: o namespace virou módulo ES, com os imports explícitos.
2
- import { Debug, FindAllReferences, SyntaxKind, arrayFrom, arrayToMultiMap, arrayToSet, cast, concatenate, contains, createTextSpanFromBounds, createTextSpanFromNode, findAncestor, findChildOfKind, findModifier, forEach, forEachChild, forEachReturnStatement, getContainingFunction, getTouchingPropertyName, isAwaitExpression, isBlock, isBreakOrContinueStatement, isCaseClause, isDeclaration, isDefaultClause, isFunctionBlock, isFunctionLike, isIfStatement, isIterationStatement, isJsxClosingElement, isJsxOpeningElement, isModifierKind, isModuleDeclaration, isReturnStatement, isSwitchStatement, isThrowStatement, isTryStatement, isTypeAliasDeclaration, isTypeNode, isVariableStatement, isWhiteSpaceSingleLine, mapDefined, modifierToFlag, toArray, } from "./_namespaces/ts.js";
3
- export var DocumentHighlights;
4
- (function (DocumentHighlights) {
5
- function getDocumentHighlights(program, cancellationToken, sourceFile, position, sourceFilesToSearch) {
6
- const node = getTouchingPropertyName(sourceFile, position);
7
- if (node.parent && (isJsxOpeningElement(node.parent) && node.parent.tagName === node || isJsxClosingElement(node.parent))) {
8
- // For a JSX element, just highlight the matching tag, not all references.
9
- const { openingElement, closingElement } = node.parent.parent;
10
- const highlightSpans = [openingElement, closingElement].map(({ tagName }) => getHighlightSpanForNode(tagName, sourceFile));
11
- return [{ fileName: sourceFile.fileName, highlightSpans }];
12
- }
13
- return getSemanticDocumentHighlights(position, node, program, cancellationToken, sourceFilesToSearch) || getSyntacticDocumentHighlights(node, sourceFile);
14
- }
15
- DocumentHighlights.getDocumentHighlights = getDocumentHighlights;
16
- function getHighlightSpanForNode(node, sourceFile) {
17
- return {
18
- fileName: sourceFile.fileName,
19
- textSpan: createTextSpanFromNode(node, sourceFile),
20
- kind: "none" /* HighlightSpanKind.none */
21
- };
22
- }
23
- function getSemanticDocumentHighlights(position, node, program, cancellationToken, sourceFilesToSearch) {
24
- const sourceFilesSet = arrayToSet(sourceFilesToSearch, f => f.fileName);
25
- const referenceEntries = FindAllReferences.getReferenceEntriesForNode(position, node, program, sourceFilesToSearch, cancellationToken, /*options*/ undefined, sourceFilesSet);
26
- if (!referenceEntries)
27
- return undefined;
28
- const map = arrayToMultiMap(referenceEntries.map(FindAllReferences.toHighlightSpan), e => e.fileName, e => e.span);
29
- // Na tag, o arquivo fora dos pesquisados era o redirecionado por um pacote, que o `Program` criava (o host, CK-47).
30
- return arrayFrom(map.entries(), ([fileName, highlightSpans]) => ({ fileName, highlightSpans }));
31
- }
32
- function getSyntacticDocumentHighlights(node, sourceFile) {
33
- const highlightSpans = getHighlightSpans(node, sourceFile);
34
- return highlightSpans && [{ fileName: sourceFile.fileName, highlightSpans }];
35
- }
36
- function getHighlightSpans(node, sourceFile) {
37
- switch (node.kind) {
38
- case SyntaxKind.IfKeyword:
39
- case SyntaxKind.ElseKeyword:
40
- return isIfStatement(node.parent) ? getIfElseOccurrences(node.parent, sourceFile) : undefined;
41
- case SyntaxKind.ReturnKeyword:
42
- return useParent(node.parent, isReturnStatement, getReturnOccurrences);
43
- case SyntaxKind.ThrowKeyword:
44
- return useParent(node.parent, isThrowStatement, getThrowOccurrences);
45
- case SyntaxKind.TryKeyword:
46
- case SyntaxKind.CatchKeyword:
47
- case SyntaxKind.FinallyKeyword:
48
- const tryStatement = node.kind === SyntaxKind.CatchKeyword ? node.parent.parent : node.parent;
49
- return useParent(tryStatement, isTryStatement, getTryCatchFinallyOccurrences);
50
- case SyntaxKind.SwitchKeyword:
51
- return useParent(node.parent, isSwitchStatement, getSwitchCaseDefaultOccurrences);
52
- case SyntaxKind.CaseKeyword:
53
- case SyntaxKind.DefaultKeyword: {
54
- if (isDefaultClause(node.parent) || isCaseClause(node.parent)) {
55
- return useParent(node.parent.parent.parent, isSwitchStatement, getSwitchCaseDefaultOccurrences);
56
- }
57
- return undefined;
58
- }
59
- case SyntaxKind.BreakKeyword:
60
- case SyntaxKind.ContinueKeyword:
61
- return useParent(node.parent, isBreakOrContinueStatement, getBreakOrContinueStatementOccurrences);
62
- case SyntaxKind.ForKeyword:
63
- case SyntaxKind.WhileKeyword:
64
- case SyntaxKind.DoKeyword:
65
- // Na tag, o laço com label também (CK-02).
66
- return useParent(node.parent, (n) => isIterationStatement(n), getLoopBreakContinueOccurrences);
67
- // Na tag, também o `constructor`, o `get` e o `set` de todas as declarações do símbolo, e o `yield` da função
68
- // (CK-02, CK-56).
69
- case SyntaxKind.AwaitKeyword:
70
- return useParent(node.parent, isAwaitExpression, getAsyncAndAwaitOccurrences);
71
- case SyntaxKind.AsyncKeyword:
72
- return highlightSpans(getAsyncAndAwaitOccurrences(node));
73
- default:
74
- return isModifierKind(node.kind) && (isDeclaration(node.parent) || isVariableStatement(node.parent))
75
- ? highlightSpans(getModifierOccurrences(node.kind, node.parent))
76
- : undefined;
77
- }
78
- function useParent(node, nodeTest, getNodes) {
79
- return nodeTest(node) ? highlightSpans(getNodes(node, sourceFile)) : undefined;
80
- }
81
- function highlightSpans(nodes) {
82
- return nodes && nodes.map(node => getHighlightSpanForNode(node, sourceFile));
83
- }
84
- }
85
- /**
86
- * Aggregates all throw-statements within this node *without* crossing
87
- * into function boundaries and try-blocks with catch-clauses.
88
- */
89
- function aggregateOwnedThrowStatements(node) {
90
- if (isThrowStatement(node)) {
91
- return [node];
92
- }
93
- else if (isTryStatement(node)) {
94
- // Exceptions thrown within a try block lacking a catch clause are "owned" in the current context.
95
- return concatenate(node.catchClause ? aggregateOwnedThrowStatements(node.catchClause) : node.tryBlock && aggregateOwnedThrowStatements(node.tryBlock), node.finallyBlock && aggregateOwnedThrowStatements(node.finallyBlock));
96
- }
97
- // Do not cross function boundaries.
98
- return isFunctionLike(node) ? undefined : flatMapChildren(node, aggregateOwnedThrowStatements);
99
- }
100
- /**
101
- * For lack of a better name, this function takes a throw statement and returns the
102
- * nearest ancestor that is a try-block (whose try statement has a catch clause),
103
- * function-block, or source file.
104
- */
105
- function getThrowStatementOwner(throwStatement) {
106
- let child = throwStatement;
107
- while (child.parent) {
108
- const parent = child.parent;
109
- if (isFunctionBlock(parent) || parent.kind === SyntaxKind.SourceFile) {
110
- return parent;
111
- }
112
- // A throw-statement is only owned by a try-statement if the try-statement has
113
- // a catch clause, and if the throw-statement occurs within the try block.
114
- if (isTryStatement(parent) && parent.tryBlock === child && parent.catchClause) {
115
- return child;
116
- }
117
- child = parent;
118
- }
119
- return undefined;
120
- }
121
- function aggregateAllBreakAndContinueStatements(node) {
122
- return isBreakOrContinueStatement(node) ? [node] : isFunctionLike(node) ? undefined : flatMapChildren(node, aggregateAllBreakAndContinueStatements);
123
- }
124
- function flatMapChildren(node, cb) {
125
- const result = [];
126
- node.forEachChild(child => {
127
- const value = cb(child);
128
- if (value !== undefined) {
129
- result.push(...toArray(value));
130
- }
131
- });
132
- return result;
133
- }
134
- function ownsBreakOrContinueStatement(owner, statement) {
135
- const actualOwner = getBreakOrContinueOwner(statement);
136
- return !!actualOwner && actualOwner === owner;
137
- }
138
- function getBreakOrContinueOwner(statement) {
139
- return findAncestor(statement, node => {
140
- switch (node.kind) {
141
- case SyntaxKind.SwitchStatement:
142
- if (statement.kind === SyntaxKind.ContinueStatement) {
143
- return false;
144
- }
145
- // falls through
146
- case SyntaxKind.ForStatement:
147
- case SyntaxKind.ForInStatement:
148
- case SyntaxKind.ForOfStatement:
149
- case SyntaxKind.WhileStatement:
150
- case SyntaxKind.DoStatement:
151
- // Na tag, o `break` e o `continue` com label só eram do laço do label (CK-02).
152
- return true;
153
- default:
154
- // Não atravessa a fronteira de uma função.
155
- return isFunctionLike(node) && "quit";
156
- }
157
- });
158
- }
159
- function getModifierOccurrences(modifier, declaration) {
160
- return mapDefined(getNodesToSearchForModifier(declaration, modifierToFlag(modifier)), node => findModifier(node, modifier));
161
- }
162
- /**
163
- * Os nós em que se procura o mesmo modificador: os statements em volta, ou os membros do type literal. Na tag, também
164
- * os parâmetros e os membros da classe, do construtor, do método e da `function`, os da interface, o `abstract` e
165
- * os parâmetros do construtor de um modificador de acesso (CK-02).
166
- */
167
- function getNodesToSearchForModifier(declaration, _modifierFlag) {
168
- const container = declaration.parent;
169
- switch (container.kind) {
170
- case SyntaxKind.ModuleBlock:
171
- case SyntaxKind.SourceFile:
172
- case SyntaxKind.Block:
173
- case SyntaxKind.CaseClause:
174
- case SyntaxKind.DefaultClause:
175
- return container.statements;
176
- case SyntaxKind.TypeLiteral:
177
- return container.members;
178
- default:
179
- Debug.assertNever(container, "Invalid container kind.");
180
- }
181
- }
182
- function pushKeywordIf(keywordList, token, ...expected) {
183
- if (token && contains(expected, token.kind)) {
184
- keywordList.push(token);
185
- return true;
186
- }
187
- return false;
188
- }
189
- function getLoopBreakContinueOccurrences(loopNode) {
190
- const keywords = [];
191
- if (pushKeywordIf(keywords, loopNode.getFirstToken(), SyntaxKind.ForKeyword, SyntaxKind.WhileKeyword, SyntaxKind.DoKeyword)) {
192
- // If we succeeded and got a do-while loop, then start looking for a 'while' keyword.
193
- if (loopNode.kind === SyntaxKind.DoStatement) {
194
- const loopTokens = loopNode.getChildren();
195
- for (let i = loopTokens.length - 1; i >= 0; i--) {
196
- if (pushKeywordIf(keywords, loopTokens[i], SyntaxKind.WhileKeyword)) {
197
- break;
198
- }
199
- }
200
- }
201
- }
202
- forEach(aggregateAllBreakAndContinueStatements(loopNode.statement), statement => {
203
- if (ownsBreakOrContinueStatement(loopNode, statement)) {
204
- pushKeywordIf(keywords, statement.getFirstToken(), SyntaxKind.BreakKeyword, SyntaxKind.ContinueKeyword);
205
- }
206
- });
207
- return keywords;
208
- }
209
- function getBreakOrContinueStatementOccurrences(breakOrContinueStatement) {
210
- const owner = getBreakOrContinueOwner(breakOrContinueStatement);
211
- if (owner) {
212
- switch (owner.kind) {
213
- case SyntaxKind.ForStatement:
214
- case SyntaxKind.ForInStatement:
215
- case SyntaxKind.ForOfStatement:
216
- case SyntaxKind.DoStatement:
217
- case SyntaxKind.WhileStatement:
218
- return getLoopBreakContinueOccurrences(owner);
219
- case SyntaxKind.SwitchStatement:
220
- return getSwitchCaseDefaultOccurrences(owner);
221
- }
222
- }
223
- return undefined;
224
- }
225
- function getSwitchCaseDefaultOccurrences(switchStatement) {
226
- const keywords = [];
227
- pushKeywordIf(keywords, switchStatement.getFirstToken(), SyntaxKind.SwitchKeyword);
228
- // Go through each clause in the switch statement, collecting the 'case'/'default' keywords.
229
- forEach(switchStatement.caseBlock.clauses, clause => {
230
- pushKeywordIf(keywords, clause.getFirstToken(), SyntaxKind.CaseKeyword, SyntaxKind.DefaultKeyword);
231
- forEach(aggregateAllBreakAndContinueStatements(clause), statement => {
232
- if (ownsBreakOrContinueStatement(switchStatement, statement)) {
233
- pushKeywordIf(keywords, statement.getFirstToken(), SyntaxKind.BreakKeyword);
234
- }
235
- });
236
- });
237
- return keywords;
238
- }
239
- function getTryCatchFinallyOccurrences(tryStatement, sourceFile) {
240
- const keywords = [];
241
- pushKeywordIf(keywords, tryStatement.getFirstToken(), SyntaxKind.TryKeyword);
242
- if (tryStatement.catchClause) {
243
- pushKeywordIf(keywords, tryStatement.catchClause.getFirstToken(), SyntaxKind.CatchKeyword);
244
- }
245
- if (tryStatement.finallyBlock) {
246
- const finallyKeyword = findChildOfKind(tryStatement, SyntaxKind.FinallyKeyword, sourceFile);
247
- pushKeywordIf(keywords, finallyKeyword, SyntaxKind.FinallyKeyword);
248
- }
249
- return keywords;
250
- }
251
- function getThrowOccurrences(throwStatement, sourceFile) {
252
- const owner = getThrowStatementOwner(throwStatement);
253
- if (!owner) {
254
- return undefined;
255
- }
256
- const keywords = [];
257
- forEach(aggregateOwnedThrowStatements(owner), throwStatement => {
258
- keywords.push(findChildOfKind(throwStatement, SyntaxKind.ThrowKeyword, sourceFile));
259
- });
260
- // If the "owner" is a function, then we equate 'return' and 'throw' statements in their
261
- // ability to "jump out" of the function, and include occurrences for both.
262
- if (isFunctionBlock(owner)) {
263
- forEachReturnStatement(owner, returnStatement => {
264
- keywords.push(findChildOfKind(returnStatement, SyntaxKind.ReturnKeyword, sourceFile));
265
- });
266
- }
267
- return keywords;
268
- }
269
- function getReturnOccurrences(returnStatement, sourceFile) {
270
- const func = getContainingFunction(returnStatement);
271
- if (!func) {
272
- return undefined;
273
- }
274
- const keywords = [];
275
- forEachReturnStatement(cast(func.body, isBlock), returnStatement => {
276
- keywords.push(findChildOfKind(returnStatement, SyntaxKind.ReturnKeyword, sourceFile));
277
- });
278
- // Include 'throw' statements that do not occur within a try block.
279
- forEach(aggregateOwnedThrowStatements(func.body), throwStatement => {
280
- keywords.push(findChildOfKind(throwStatement, SyntaxKind.ThrowKeyword, sourceFile));
281
- });
282
- return keywords;
283
- }
284
- function getAsyncAndAwaitOccurrences(node) {
285
- const func = getContainingFunction(node);
286
- if (!func) {
287
- return undefined;
288
- }
289
- const keywords = [];
290
- if (func.modifiers) {
291
- func.modifiers.forEach(modifier => {
292
- pushKeywordIf(keywords, modifier, SyntaxKind.AsyncKeyword);
293
- });
294
- }
295
- forEachChild(func, child => {
296
- traverseWithoutCrossingFunction(child, node => {
297
- if (isAwaitExpression(node)) {
298
- pushKeywordIf(keywords, node.getFirstToken(), SyntaxKind.AwaitKeyword);
299
- }
300
- });
301
- });
302
- return keywords;
303
- }
304
- // Não atravessa a fronteira de uma função, de um namespace ou de um tipo. Na tag, também a da classe e a da interface
305
- // (CK-02), e o `yield` de um generator tinha a mesma travessia (o `getYieldOccurrences`, CK-02).
306
- function traverseWithoutCrossingFunction(node, cb) {
307
- cb(node);
308
- if (!isFunctionLike(node) && !isModuleDeclaration(node) && !isTypeAliasDeclaration(node) && !isTypeNode(node)) {
309
- forEachChild(node, child => traverseWithoutCrossingFunction(child, cb));
310
- }
311
- }
312
- function getIfElseOccurrences(ifStatement, sourceFile) {
313
- const keywords = getIfElseKeywords(ifStatement, sourceFile);
314
- const result = [];
315
- // We'd like to highlight else/ifs together if they are only separated by whitespace
316
- // (i.e. the keywords are separated by no comments, no newlines).
317
- for (let i = 0; i < keywords.length; i++) {
318
- if (keywords[i].kind === SyntaxKind.ElseKeyword && i < keywords.length - 1) {
319
- const elseKeyword = keywords[i];
320
- const ifKeyword = keywords[i + 1]; // this *should* always be an 'if' keyword.
321
- let shouldCombineElseAndIf = true;
322
- // Avoid recalculating getStart() by iterating backwards.
323
- for (let j = ifKeyword.getStart(sourceFile) - 1; j >= elseKeyword.end; j--) {
324
- if (!isWhiteSpaceSingleLine(sourceFile.text.charCodeAt(j))) {
325
- shouldCombineElseAndIf = false;
326
- break;
327
- }
328
- }
329
- if (shouldCombineElseAndIf) {
330
- result.push({
331
- fileName: sourceFile.fileName,
332
- textSpan: createTextSpanFromBounds(elseKeyword.getStart(), ifKeyword.end),
333
- kind: "reference" /* HighlightSpanKind.reference */
334
- });
335
- i++; // skip the next keyword
336
- continue;
337
- }
338
- }
339
- // Ordinary case: just highlight the keyword.
340
- result.push(getHighlightSpanForNode(keywords[i], sourceFile));
341
- }
342
- return result;
343
- }
344
- function getIfElseKeywords(ifStatement, sourceFile) {
345
- const keywords = [];
346
- // Traverse upwards through all parent if-statements linked by their else-branches.
347
- while (isIfStatement(ifStatement.parent) && ifStatement.parent.elseStatement === ifStatement) {
348
- ifStatement = ifStatement.parent;
349
- }
350
- // Now traverse back down through the else branches, aggregating if/else keywords of if-statements.
351
- while (true) {
352
- const children = ifStatement.getChildren(sourceFile);
353
- pushKeywordIf(keywords, children[0], SyntaxKind.IfKeyword);
354
- // Generally the 'else' keyword is second-to-last, so we traverse backwards.
355
- for (let i = children.length - 1; i >= 0; i--) {
356
- if (pushKeywordIf(keywords, children[i], SyntaxKind.ElseKeyword)) {
357
- break;
358
- }
359
- }
360
- if (!ifStatement.elseStatement || !isIfStatement(ifStatement.elseStatement)) {
361
- break;
362
- }
363
- ifStatement = ifStatement.elseStatement;
364
- }
365
- return keywords;
366
- }
367
- })(DocumentHighlights || (DocumentHighlights = {}));
@@ -1,63 +0,0 @@
1
- // Modificado de microsoft/TypeScript v3.9.10, src/services/documentRegistry.ts: o namespace virou módulo ES, com os imports explícitos.
2
- import { Debug, ScriptTarget, createGetCanonicalFileName, createLanguageServiceSourceFile, createMap, toPath, updateLanguageServiceSourceFile, } from "./_namespaces/ts.js";
3
- export function createDocumentRegistry(useCaseSensitiveFileNames, currentDirectory = "") {
4
- const entries = createMap();
5
- const getCanonicalFileName = createGetCanonicalFileName(!!useCaseSensitiveFileNames);
6
- function acquireDocument(fileName, scriptSnapshot, version, scriptKind) {
7
- const path = toPath(fileName, currentDirectory, getCanonicalFileName);
8
- return acquireDocumentWithKey(fileName, path, scriptSnapshot, version, scriptKind);
9
- }
10
- function acquireDocumentWithKey(fileName, path, scriptSnapshot, version, scriptKind) {
11
- return acquireOrUpdateDocument(fileName, path, scriptSnapshot, version, /*acquiring*/ true, scriptKind);
12
- }
13
- function updateDocument(fileName, scriptSnapshot, version, scriptKind) {
14
- const path = toPath(fileName, currentDirectory, getCanonicalFileName);
15
- return updateDocumentWithKey(fileName, path, scriptSnapshot, version, scriptKind);
16
- }
17
- function updateDocumentWithKey(fileName, path, scriptSnapshot, version, scriptKind) {
18
- return acquireOrUpdateDocument(fileName, path, scriptSnapshot, version, /*acquiring*/ false, scriptKind);
19
- }
20
- function acquireOrUpdateDocument(fileName, path, scriptSnapshot, version, acquiring, scriptKind) {
21
- let entry = entries.get(path);
22
- // O alvo da configuração fixa (CK-24).
23
- const scriptTarget = ScriptTarget.ES2020;
24
- if (!entry) {
25
- const sourceFile = createLanguageServiceSourceFile(fileName, scriptSnapshot, scriptTarget, version, /*setNodeParents*/ false, scriptKind);
26
- entry = {
27
- sourceFile,
28
- languageServiceRefCount: 1,
29
- };
30
- entries.set(path, entry);
31
- }
32
- else {
33
- if (entry.sourceFile.version !== version) {
34
- entry.sourceFile = updateLanguageServiceSourceFile(entry.sourceFile, scriptSnapshot, version, scriptSnapshot.getChangeRange(entry.sourceFile.scriptSnapshot));
35
- }
36
- if (acquiring) {
37
- entry.languageServiceRefCount++;
38
- }
39
- }
40
- Debug.assert(entry.languageServiceRefCount !== 0);
41
- return entry.sourceFile;
42
- }
43
- function releaseDocument(fileName) {
44
- const path = toPath(fileName, currentDirectory, getCanonicalFileName);
45
- return releaseDocumentWithKey(path);
46
- }
47
- function releaseDocumentWithKey(path) {
48
- const entry = Debug.checkDefined(entries.get(path));
49
- entry.languageServiceRefCount--;
50
- Debug.assert(entry.languageServiceRefCount >= 0);
51
- if (entry.languageServiceRefCount === 0) {
52
- entries.delete(path);
53
- }
54
- }
55
- return {
56
- acquireDocument,
57
- acquireDocumentWithKey,
58
- updateDocument,
59
- updateDocumentWithKey,
60
- releaseDocument,
61
- releaseDocumentWithKey,
62
- };
63
- }
@@ -1,4 +0,0 @@
1
- // A edição se registra na casca ao carregar (CK-67). A casca da leitura alcança a edição só por este registro, e não a
2
- // importa: quem só lê não baixa a edição, e o método de edição de um language service sem ela falha.
3
- import { OrganizeImports, codefix, formatting, getEditsForFileRename, refactor, registerEditingServices, } from "./_namespaces/edit.js";
4
- registerEditingServices({ formatting, codefix, refactor, OrganizeImports, getEditsForFileRename });