@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,246 @@
1
+ // Modificado de microsoft/TypeScript v3.9.10, src/services/goToDefinition.ts: o namespace virou módulo ES, com os imports explícitos.
2
+ import { FindAllReferences, IndexKind, SymbolDisplay, SymbolFlags, SyntaxKind, createTextSpan, createTextSpanFromNode, emptyArray, filter, first, flatMap, getContainingObjectLiteralElement, getInvokedExpression, getNameFromPropertyName, getNameOfDeclaration, getPropertySymbolsFromContextualType, getTouchingPropertyName, isAssignmentDeclaration, isBindingElement, isCallExpressionTarget, isCallLikeExpression, isFunctionLike, isFunctionTypeNode, isObjectBindingPattern, isPropertyAccessExpression, isPropertyName, isRightSideOfPropertyAccess, isVariableDeclaration, last, map, mapDefined, tryCast, } from "./_namespaces/ts.js";
3
+ /**
4
+ * Na tag, também a referência `/// <reference path>`, `<reference types>` e `<reference lib>` na posição, que dava o
5
+ * arquivo referido (CK-03, CK-46, CK-39), e o label de um `break` ou `continue` (CK-02).
6
+ */
7
+ export function getDefinitionAtPosition(program, sourceFile, position) {
8
+ const node = getTouchingPropertyName(sourceFile, position);
9
+ if (node === sourceFile) {
10
+ return undefined;
11
+ }
12
+ const { parent } = node;
13
+ const typeChecker = program.getTypeChecker();
14
+ const symbol = getSymbol(node, typeChecker);
15
+ // Could not find a symbol e.g. node is string or number keyword,
16
+ // or the symbol was an internal symbol and does not have a declaration e.g. undefined symbol
17
+ if (!symbol) {
18
+ return getDefinitionInfoForIndexSignatures(node, typeChecker);
19
+ }
20
+ const calledDeclaration = tryGetSignatureDeclaration(typeChecker, node);
21
+ // Na tag, a chamada de um elemento JSX não ia ao construtor do componente (CK-02).
22
+ if (calledDeclaration) {
23
+ const sigInfo = createDefinitionFromSignatureDeclaration(typeChecker, calledDeclaration);
24
+ // For a function, if this is the original function definition, return just sigInfo.
25
+ // Na tag, também a variável inicializada por um `require()` (CK-03).
26
+ if (typeChecker.getRootSymbols(symbol).some(s => symbolMatchesSignature(s, calledDeclaration))) {
27
+ return [sigInfo];
28
+ }
29
+ else {
30
+ const defs = getDefinitionFromSymbol(typeChecker, symbol, node, calledDeclaration) || emptyArray;
31
+ // A variável primeiro. Na tag, a assinatura vinha primeiro na chamada do `super()` (CK-02).
32
+ return [...defs, sigInfo];
33
+ }
34
+ }
35
+ // Because name in short-hand property assignment has two different meanings: property name and property value,
36
+ // using go-to-definition at such position should go to the variable declaration of the property value rather than
37
+ // go to the declaration of the property name (in this case stay at the same position). However, if go-to-definition
38
+ // is performed at the location of property access, we would like to go to definition of the property in the short-hand
39
+ // assignment. This case and others are handled by the following code.
40
+ if (node.parent.kind === SyntaxKind.ShorthandPropertyAssignment) {
41
+ const shorthandSymbol = typeChecker.getShorthandAssignmentValueSymbol(symbol.valueDeclaration);
42
+ return shorthandSymbol ? shorthandSymbol.declarations.map(decl => createDefinitionInfo(decl, typeChecker, shorthandSymbol, node)) : [];
43
+ }
44
+ // If the node is the name of a BindingElement within an ObjectBindingPattern instead of just returning the
45
+ // declaration the symbol (which is itself), we should try to get to the original type of the ObjectBindingPattern
46
+ // and return the property declaration for the referenced property.
47
+ // For example:
48
+ // import('./foo').then(({ b/*goto*/ar }) => undefined); => should get use to the declaration in file "./foo"
49
+ //
50
+ // function bar<T>(onfulfilled: (value: T) => void) { //....}
51
+ // interface Test {
52
+ // pr/*destination*/op1: number
53
+ // }
54
+ // bar<Test>(({pr/*goto*/op1})=>{});
55
+ if (isPropertyName(node) && isBindingElement(parent) && isObjectBindingPattern(parent.parent) &&
56
+ (node === (parent.propertyName || parent.name))) {
57
+ const name = getNameFromPropertyName(node);
58
+ const type = typeChecker.getTypeAtLocation(parent.parent);
59
+ return name === undefined ? emptyArray : flatMap(type.isUnion() ? type.types : [type], t => {
60
+ const prop = t.getProperty(name);
61
+ return prop && getDefinitionFromSymbol(typeChecker, prop, node);
62
+ });
63
+ }
64
+ // If the current location we want to find its definition is in an object literal, try to get the contextual type for the
65
+ // object literal, lookup the property symbol in the contextual type, and use this for goto-definition.
66
+ // For example
67
+ // interface Props{
68
+ // /*first*/prop1: number
69
+ // prop2: boolean
70
+ // }
71
+ // function Foo(arg: Props) {}
72
+ // Foo( { pr/*1*/op1: 10, prop2: true })
73
+ const element = getContainingObjectLiteralElement(node);
74
+ if (element) {
75
+ const contextualType = element && typeChecker.getContextualType(element.parent);
76
+ if (contextualType) {
77
+ return flatMap(getPropertySymbolsFromContextualType(element, typeChecker, contextualType, /*unionSymbolOk*/ false), propertySymbol => getDefinitionFromSymbol(typeChecker, propertySymbol, node));
78
+ }
79
+ }
80
+ return getDefinitionFromSymbol(typeChecker, symbol, node);
81
+ }
82
+ /**
83
+ * True if we should not add definitions for both the signature symbol and the definition symbol.
84
+ * True for `const |f = |() => 0`, false for `function |f() {} const |g = f;`.
85
+ */
86
+ function symbolMatchesSignature(s, calledDeclaration) {
87
+ return s === calledDeclaration.symbol || s === calledDeclaration.symbol.parent ||
88
+ !isCallLikeExpression(calledDeclaration.parent) && s === calledDeclaration.parent.symbol;
89
+ }
90
+ /// Goto type
91
+ export function getTypeDefinitionAtPosition(typeChecker, sourceFile, position) {
92
+ const node = getTouchingPropertyName(sourceFile, position);
93
+ if (node === sourceFile) {
94
+ return undefined;
95
+ }
96
+ const symbol = typeChecker.getSymbolAtLocation(node);
97
+ if (!symbol)
98
+ return undefined;
99
+ const typeAtLocation = typeChecker.getTypeOfSymbolAtLocation(symbol, node);
100
+ const returnType = tryGetReturnTypeOfFunction(symbol, typeAtLocation, typeChecker);
101
+ const fromReturnType = returnType && definitionFromType(returnType, typeChecker, node);
102
+ // If a function returns 'void' or some other type with no definition, just return the function definition.
103
+ return fromReturnType && fromReturnType.length !== 0 ? fromReturnType : definitionFromType(typeAtLocation, typeChecker, node);
104
+ }
105
+ /** Na tag, a união de um enum ficava inteira, e não membro a membro (CK-02). */
106
+ function definitionFromType(type, checker, node) {
107
+ return flatMap(type.isUnion() ? type.types : [type], t => t.symbol && getDefinitionFromSymbol(checker, t.symbol, node));
108
+ }
109
+ function tryGetReturnTypeOfFunction(symbol, type, checker) {
110
+ // If the type is just a function's inferred type,
111
+ // go-to-type should go to the return type instead, since go-to-definition takes you to the function anyway.
112
+ if (type.symbol === symbol ||
113
+ // At `const f = () => {}`, the symbol is `f` and the type symbol is at `() => {}`
114
+ symbol.valueDeclaration && type.symbol && isVariableDeclaration(symbol.valueDeclaration) && symbol.valueDeclaration.initializer === type.symbol.valueDeclaration) {
115
+ const sigs = type.getCallSignatures();
116
+ if (sigs.length === 1)
117
+ return checker.getReturnTypeOfSignature(first(sigs));
118
+ }
119
+ return undefined;
120
+ }
121
+ export function getDefinitionAndBoundSpan(program, sourceFile, position) {
122
+ const definitions = getDefinitionAtPosition(program, sourceFile, position);
123
+ if (!definitions || definitions.length === 0) {
124
+ return undefined;
125
+ }
126
+ // Na tag, a posição numa referência `/// <reference …>` dava o trecho dela (CK-03, CK-46, CK-39).
127
+ const node = getTouchingPropertyName(sourceFile, position);
128
+ const textSpan = createTextSpan(node.getStart(), node.getWidth());
129
+ return { definitions, textSpan };
130
+ }
131
+ // At 'x.foo', see if the type of 'x' has an index signature, and if so find its declarations.
132
+ function getDefinitionInfoForIndexSignatures(node, checker) {
133
+ if (!isPropertyAccessExpression(node.parent) || node.parent.name !== node)
134
+ return;
135
+ const type = checker.getTypeAtLocation(node.parent.expression);
136
+ return mapDefined(type.isUnionOrIntersection() ? type.types : [type], nonUnionType => {
137
+ const info = checker.getIndexInfoOfType(nonUnionType, IndexKind.String);
138
+ return info && info.declaration && createDefinitionFromSignatureDeclaration(checker, info.declaration);
139
+ });
140
+ }
141
+ function getSymbol(node, checker) {
142
+ const symbol = checker.getSymbolAtLocation(node);
143
+ // If this is an alias, and the request came at the declaration location
144
+ // get the aliased symbol instead. This allows for goto def on an import e.g.
145
+ // import {A, B} from "mod";
146
+ // to jump to the implementation directly.
147
+ if (symbol && symbol.flags & SymbolFlags.Alias && shouldSkipAlias(node, symbol.declarations[0])) {
148
+ const aliased = checker.getAliasedSymbol(symbol);
149
+ if (aliased.declarations) {
150
+ return aliased;
151
+ }
152
+ }
153
+ // Na tag, a variável de um arquivo JavaScript inicializada por um `require()` dava o módulo (CK-03).
154
+ return symbol;
155
+ }
156
+ // Go to the original declaration for cases:
157
+ //
158
+ // (1) when the aliased symbol was declared in the location(parent).
159
+ // (2) when the aliased symbol is originating from an import.
160
+ //
161
+ function shouldSkipAlias(node, declaration) {
162
+ if (node.kind !== SyntaxKind.Identifier) {
163
+ return false;
164
+ }
165
+ if (node.parent === declaration) {
166
+ return true;
167
+ }
168
+ // Na tag, também o `import =` (CK-03).
169
+ switch (declaration.kind) {
170
+ case SyntaxKind.ImportClause:
171
+ return true;
172
+ case SyntaxKind.ImportSpecifier:
173
+ return declaration.parent.kind === SyntaxKind.NamedImports;
174
+ default:
175
+ return false;
176
+ }
177
+ }
178
+ function getDefinitionFromSymbol(typeChecker, symbol, node, declarationNode) {
179
+ // There are cases when you extend a function by adding properties to it afterwards,
180
+ // we want to strip those extra properties.
181
+ // For deduping purposes, we also want to exclude any declarationNodes if provided.
182
+ const filteredDeclarations = filter(symbol.declarations, d => d !== declarationNode && (!isAssignmentDeclaration(d) || d === symbol.valueDeclaration)) || undefined;
183
+ // Na tag, primeiro a construct signature da classe, no alvo de um `new` ou no `constructor` (CK-02).
184
+ return getCallSignatureDefinition() || map(filteredDeclarations, declaration => createDefinitionInfo(declaration, typeChecker, symbol, node));
185
+ /** Na tag, também no alvo de um `new` e no nome de uma `function` declarada (CK-02). */
186
+ function getCallSignatureDefinition() {
187
+ return isCallExpressionTarget(node)
188
+ ? getSignatureDefinition(filteredDeclarations)
189
+ : undefined;
190
+ }
191
+ /** Na tag, também os construtores de uma classe (o `selectConstructors`, CK-02). */
192
+ function getSignatureDefinition(signatureDeclarations) {
193
+ if (!signatureDeclarations) {
194
+ return undefined;
195
+ }
196
+ const declarations = signatureDeclarations.filter(isFunctionLike);
197
+ const declarationsWithBody = declarations.filter(d => !!d.body);
198
+ // declarations defined on the global scope can be defined on multiple files. Get all of them.
199
+ return declarations.length
200
+ ? declarationsWithBody.length !== 0
201
+ ? declarationsWithBody.map(x => createDefinitionInfo(x, typeChecker, symbol, node))
202
+ : [createDefinitionInfo(last(declarations), typeChecker, symbol, node)]
203
+ : undefined;
204
+ }
205
+ }
206
+ /** Creates a DefinitionInfo from a Declaration, using the declaration's name if possible. */
207
+ function createDefinitionInfo(declaration, checker, symbol, node) {
208
+ const symbolName = checker.symbolToString(symbol); // Do not get scoped name, just the name of the symbol
209
+ const symbolKind = SymbolDisplay.getSymbolKind(checker, symbol, node);
210
+ const containerName = symbol.parent ? checker.symbolToString(symbol.parent, node) : "";
211
+ return createDefinitionInfoFromName(checker, declaration, symbolKind, symbolName, containerName);
212
+ }
213
+ /** Creates a DefinitionInfo directly from the name of a declaration. */
214
+ function createDefinitionInfoFromName(checker, declaration, symbolKind, symbolName, containerName) {
215
+ const name = getNameOfDeclaration(declaration) || declaration;
216
+ const sourceFile = name.getSourceFile();
217
+ const textSpan = createTextSpanFromNode(name, sourceFile);
218
+ return {
219
+ fileName: sourceFile.fileName,
220
+ textSpan,
221
+ kind: symbolKind,
222
+ name: symbolName,
223
+ containerKind: undefined,
224
+ containerName,
225
+ ...FindAllReferences.toContextSpan(textSpan, sourceFile, FindAllReferences.getContextNode(declaration)),
226
+ isLocal: !checker.isDeclarationVisible(declaration)
227
+ };
228
+ }
229
+ function createDefinitionFromSignatureDeclaration(typeChecker, decl) {
230
+ return createDefinitionInfo(decl, typeChecker, decl.symbol, decl);
231
+ }
232
+ /** Returns a CallLikeExpression where `node` is the target being invoked. */
233
+ function getAncestorCallLikeExpression(node) {
234
+ const target = climbPastManyPropertyAccesses(node);
235
+ const callLike = target.parent;
236
+ return callLike && isCallLikeExpression(callLike) && getInvokedExpression(callLike) === target ? callLike : undefined;
237
+ }
238
+ function climbPastManyPropertyAccesses(node) {
239
+ return isRightSideOfPropertyAccess(node) ? climbPastManyPropertyAccesses(node.parent) : node;
240
+ }
241
+ function tryGetSignatureDeclaration(typeChecker, node) {
242
+ const callLike = getAncestorCallLikeExpression(node);
243
+ const signature = callLike && typeChecker.getResolvedSignature(callLike);
244
+ // Don't go to a function type, go to the value having that type.
245
+ return tryCast(signature && signature.declaration, (d) => isFunctionLike(d) && !isFunctionTypeNode(d));
246
+ }
@@ -0,0 +1,50 @@
1
+ import type { CancellationToken, CheckResult, Identifier, Node, ReadonlyMap, SourceFile, StringLiteral, StringLiteralLike, Symbol, TypeChecker } from "./_namespaces/ts.js";
2
+ export interface ImportsResult {
3
+ /** For every import of the symbol, the location and local symbol for the import. */
4
+ importSearches: readonly [Identifier, Symbol][];
5
+ /** For rename imports/exports `{ foo as bar }`, `foo` is not a local, so it may be added as a reference immediately without further searching. */
6
+ singleReferences: readonly (Identifier | StringLiteral)[];
7
+ /** Os arquivos que podem usar o símbolo por um namespace. Na tag, todo arquivo quando o módulo era UMD (CK-03). */
8
+ indirectUsers: readonly SourceFile[];
9
+ }
10
+ export type ImportTracker = (exportSymbol: Symbol, exportInfo: ExportInfo, isForRename: boolean) => ImportsResult;
11
+ /** Creates the imports map and returns an ImportTracker that uses it. Call this lazily to avoid calling `getDirectImportsMap` unnecessarily. */
12
+ export declare function createImportTracker(sourceFiles: readonly SourceFile[], sourceFilesSet: ReadonlyMap<true>, checker: TypeChecker, cancellationToken: CancellationToken | undefined): ImportTracker;
13
+ /** Info about an exported symbol to perform recursive search on. */
14
+ export interface ExportInfo {
15
+ exportingModuleSymbol: Symbol;
16
+ exportKind: ExportKind;
17
+ }
18
+ /** Na tag, também o `export =` (CK-03). */
19
+ export declare enum ExportKind {
20
+ Named = 0,
21
+ Default = 1
22
+ }
23
+ export declare enum ImportExport {
24
+ Import = 0,
25
+ Export = 1
26
+ }
27
+ /** O import de um módulo (também o `require()`). Na tag, também a referência `/// <reference path>` e `<reference types>` (CK-03). */
28
+ export type ModuleReference = {
29
+ kind: "import";
30
+ literal: StringLiteralLike;
31
+ };
32
+ export declare function findModuleReferences(program: CheckResult, sourceFiles: readonly SourceFile[], searchModuleSymbol: Symbol): ModuleReference[];
33
+ export interface ImportedSymbol {
34
+ kind: ImportExport.Import;
35
+ symbol: Symbol;
36
+ }
37
+ export interface ExportedSymbol {
38
+ kind: ImportExport.Export;
39
+ symbol: Symbol;
40
+ exportInfo: ExportInfo;
41
+ }
42
+ /**
43
+ * Given a local reference, we might notice that it's an import/export and recursively search for references of that.
44
+ * If at an import, look locally for the symbol it imports.
45
+ * If at an export, look for all imports of it.
46
+ * This doesn't handle export specifiers; that is done in `getReferencesAtExportSpecifier`.
47
+ * @param comingFromExport If we are doing a search for all exports, don't bother looking backwards for the imported symbol, since that's the reason we're here.
48
+ */
49
+ export declare function getImportOrExportSymbol(node: Node, symbol: Symbol, checker: TypeChecker, comingFromExport: boolean): ImportedSymbol | ExportedSymbol | undefined;
50
+ export declare function getExportInfo(exportSymbol: Symbol, exportKind: ExportKind, checker: TypeChecker): ExportInfo | undefined;