|
1 | | -import type { |
2 | | - ParserServices, |
3 | | - TSESLint, |
4 | | - TSESTree, |
5 | | -} from '@typescript-eslint/utils'; |
| 1 | +import type { TSESLint, TSESTree } from '@typescript-eslint/utils'; |
6 | 2 | import { AST_NODE_TYPES } from '@typescript-eslint/utils'; |
7 | 3 | import { SymbolFlags } from 'typescript'; |
8 | 4 |
|
@@ -75,6 +71,28 @@ export default util.createRule<Options, MessageIds>({ |
75 | 71 | const sourceExportsMap: { [key: string]: SourceExports } = {}; |
76 | 72 | const parserServices = util.getParserServices(context); |
77 | 73 |
|
| 74 | + /** |
| 75 | + * Helper for identifying if an export specifier resolves to a |
| 76 | + * JavaScript value or a TypeScript type. |
| 77 | + * |
| 78 | + * @returns True/false if is a type or not, or undefined if the specifier |
| 79 | + * can't be resolved. |
| 80 | + */ |
| 81 | + function isSpecifierTypeBased( |
| 82 | + specifier: TSESTree.ExportSpecifier, |
| 83 | + ): boolean | undefined { |
| 84 | + const checker = parserServices.program.getTypeChecker(); |
| 85 | + const node = parserServices.esTreeNodeToTSNodeMap.get(specifier.exported); |
| 86 | + const symbol = checker.getSymbolAtLocation(node); |
| 87 | + const aliasedSymbol = checker.getAliasedSymbol(symbol!); |
| 88 | + |
| 89 | + if (!aliasedSymbol || aliasedSymbol.escapedName === 'unknown') { |
| 90 | + return undefined; |
| 91 | + } |
| 92 | + |
| 93 | + return !(aliasedSymbol.flags & SymbolFlags.Value); |
| 94 | + } |
| 95 | + |
78 | 96 | return { |
79 | 97 | ExportNamedDeclaration(node: TSESTree.ExportNamedDeclaration): void { |
80 | 98 | // Coerce the source into a string for use as a lookup entry. |
@@ -112,7 +130,7 @@ export default util.createRule<Options, MessageIds>({ |
112 | 130 | continue; |
113 | 131 | } |
114 | 132 |
|
115 | | - const isTypeBased = isSpecifierTypeBased(parserServices, specifier); |
| 133 | + const isTypeBased = isSpecifierTypeBased(specifier); |
116 | 134 |
|
117 | 135 | if (isTypeBased === true) { |
118 | 136 | typeBasedSpecifiers.push(specifier); |
@@ -199,29 +217,6 @@ export default util.createRule<Options, MessageIds>({ |
199 | 217 | }, |
200 | 218 | }); |
201 | 219 |
|
202 | | -/** |
203 | | - * Helper for identifying if an export specifier resolves to a |
204 | | - * JavaScript value or a TypeScript type. |
205 | | - * |
206 | | - * @returns True/false if is a type or not, or undefined if the specifier |
207 | | - * can't be resolved. |
208 | | - */ |
209 | | -function isSpecifierTypeBased( |
210 | | - parserServices: ParserServices, |
211 | | - specifier: TSESTree.ExportSpecifier, |
212 | | -): boolean | undefined { |
213 | | - const checker = parserServices.program.getTypeChecker(); |
214 | | - const node = parserServices.esTreeNodeToTSNodeMap.get(specifier.exported); |
215 | | - const symbol = checker.getSymbolAtLocation(node); |
216 | | - const aliasedSymbol = checker.getAliasedSymbol(symbol!); |
217 | | - |
218 | | - if (!aliasedSymbol || aliasedSymbol.escapedName === 'unknown') { |
219 | | - return undefined; |
220 | | - } |
221 | | - |
222 | | - return !(aliasedSymbol.flags & SymbolFlags.Value); |
223 | | -} |
224 | | - |
225 | 220 | /** |
226 | 221 | * Inserts "type" into an export. |
227 | 222 | * |
|
0 commit comments