@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,86 +0,0 @@
1
- // Modificado de microsoft/TypeScript v3.9.10, src/services/getEditsForFileRename.ts: o namespace virou módulo ES, com os imports explícitos.
2
- // Saem a atualização do `tsconfig` (o `files`, o `include`, o `exclude` e as opções de caminho) e o mapa de fontes (o
3
- // `sourceMapper`, que achava o `.ts` de um `.d.ts`), que são do host (CK-47, CK-06); e a referência `/// <reference
4
- // path>` (CK-03). A resolução de um import é do host (CK-46): onde a tag refazia a resolução do Node a partir do lugar
5
- // antigo de quem importa, o language service pergunta ao `resolveModule` do host; e o import que não resolve mais, que a
6
- // tag achava pelos caminhos que a resolução tentou (os `failedLookupLocations`), não tem o que perguntar.
7
- import { createGetCanonicalFileName, createModuleSpecifierResolutionHost, createRange, find, getResolvedModule, hostUsesCaseSensitiveFileNames, isAmbientModule, isSourceFile, moduleSpecifiers, pathIsRelative, textChanges, tryRemoveDirectoryPrefix, } from "./_namespaces/edit.js";
8
- export function getEditsForFileRename(program, oldFileOrDirPath, newFileOrDirPath, host, formatContext, preferences) {
9
- const useCaseSensitiveFileNames = hostUsesCaseSensitiveFileNames(host);
10
- const getCanonicalFileName = createGetCanonicalFileName(useCaseSensitiveFileNames);
11
- const oldToNew = getPathUpdater(oldFileOrDirPath, newFileOrDirPath, getCanonicalFileName);
12
- const newToOld = getPathUpdater(newFileOrDirPath, oldFileOrDirPath, getCanonicalFileName);
13
- return textChanges.ChangeTracker.with({ host, formatContext, preferences }, changeTracker => {
14
- updateImports(program, changeTracker, oldToNew, newToOld, host);
15
- });
16
- }
17
- // exported for tests
18
- export function getPathUpdater(oldFileOrDirPath, newFileOrDirPath, getCanonicalFileName) {
19
- const canonicalOldPath = getCanonicalFileName(oldFileOrDirPath);
20
- return path => getUpdatedPath(path);
21
- function getUpdatedPath(pathToUpdate) {
22
- if (getCanonicalFileName(pathToUpdate) === canonicalOldPath)
23
- return newFileOrDirPath;
24
- const suffix = tryRemoveDirectoryPrefix(pathToUpdate, canonicalOldPath, getCanonicalFileName);
25
- return suffix === undefined ? undefined : newFileOrDirPath + "/" + suffix;
26
- }
27
- }
28
- function updateImports(program, changeTracker, oldToNew, newToOld, host) {
29
- const allFiles = program.getSourceFiles();
30
- for (const sourceFile of allFiles) {
31
- const newFromOld = oldToNew(sourceFile.path);
32
- const newImportFromPath = newFromOld !== undefined ? newFromOld : sourceFile.path;
33
- const oldFromNew = newToOld(sourceFile.fileName);
34
- const oldImportFromPath = oldFromNew || sourceFile.fileName;
35
- const importingSourceFileMoved = newFromOld !== undefined || oldFromNew !== undefined;
36
- updateImportsWorker(sourceFile, changeTracker, importLiteral => {
37
- const importedModuleSymbol = program.getTypeChecker().getSymbolAtLocation(importLiteral);
38
- // No need to update if it's an ambient module
39
- if (importedModuleSymbol && importedModuleSymbol.declarations.some(d => isAmbientModule(d)))
40
- return undefined;
41
- const toImport = oldFromNew !== undefined
42
- // If we're at the new location (file was already renamed), need to redo module resolution starting from the old location.
43
- ? getSourceFileToImportFromResolved(host.resolveModule(importLiteral.text, oldImportFromPath), oldToNew)
44
- : getSourceFileToImport(importedModuleSymbol, importLiteral, sourceFile, oldToNew);
45
- // Need an update if the imported file moved, or the importing file moved and was using a relative path.
46
- return toImport !== undefined && (toImport.updated || (importingSourceFileMoved && pathIsRelative(importLiteral.text)))
47
- ? moduleSpecifiers.updateModuleSpecifier(newImportFromPath, toImport.newFileName, createModuleSpecifierResolutionHost(host), importLiteral.text)
48
- : undefined;
49
- });
50
- }
51
- }
52
- function getSourceFileToImport(importedModuleSymbol, importLiteral, importingSourceFile, oldToNew) {
53
- if (importedModuleSymbol) {
54
- // `find` should succeed because we checked for ambient modules before calling this function.
55
- const oldFileName = find(importedModuleSymbol.declarations, isSourceFile).fileName;
56
- const newFileName = oldToNew(oldFileName);
57
- return newFileName === undefined ? { newFileName: oldFileName, updated: false } : { newFileName, updated: true };
58
- }
59
- else {
60
- // O arquivo a que o import resolve sem dar um símbolo de módulo (o que não tem `import` nem `export`). Na tag, a
61
- // resolução vinha do cache do host, com os caminhos que ela tentou; aqui, é a que o `check` gravou no arquivo,
62
- // o arquivo que o host deu ou nada (CK-46).
63
- const resolved = getResolvedModule(importingSourceFile, importLiteral.text);
64
- return getSourceFileToImportFromResolved(resolved && resolved.resolvedFileName, oldToNew);
65
- }
66
- }
67
- // Na tag, a resolução vinha com os caminhos que ela tentou e não achou, e eles se procuravam entre os que mudaram; o
68
- // `resolveModule` do host dá só o arquivo (CK-46).
69
- function getSourceFileToImportFromResolved(resolvedFileName, oldToNew) {
70
- if (!resolvedFileName)
71
- return undefined;
72
- const newFileName = oldToNew(resolvedFileName);
73
- return newFileName ? { newFileName, updated: true } : { newFileName: resolvedFileName, updated: false };
74
- }
75
- // Na tag, também as referências `/// <reference path>` do arquivo (CK-03). Com elas, saíram o caminho que a referência daria
76
- // e os auxiliares de caminho que ela e o `tsconfig` usavam.
77
- function updateImportsWorker(sourceFile, changeTracker, updateImport) {
78
- for (const importStringLiteral of sourceFile.imports) {
79
- const updated = updateImport(importStringLiteral);
80
- if (updated !== undefined && updated !== importStringLiteral.text)
81
- changeTracker.replaceRangeWithText(sourceFile, createStringRange(importStringLiteral, sourceFile), updated);
82
- }
83
- }
84
- function createStringRange(node, sourceFile) {
85
- return createRange(node.getStart(sourceFile) + 1, node.end - 1);
86
- }
@@ -1,246 +0,0 @@
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
- }