Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
feat: remove partial type-information program#6066
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
5ab70f1
3182b1c
7c9d865
a984658
932fbc3
2a80442
526c1d1
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,4 @@ | ||
import type { TSESLint, TSESTree } from '@typescript-eslint/utils'; | ||
import { AST_NODE_TYPES } from '@typescript-eslint/utils'; | ||
import { SymbolFlags } from 'typescript'; | ||
@@ -75,6 +71,28 @@ export default util.createRule<Options, MessageIds>({ | ||
const sourceExportsMap: { [key: string]: SourceExports } = {}; | ||
const parserServices = util.getParserServices(context); | ||
/** | ||
* Helper for identifying if an export specifier resolves to a | ||
* JavaScript value or a TypeScript type. | ||
* | ||
* @returns True/false if is a type or not, or undefined if the specifier | ||
* can't be resolved. | ||
*/ | ||
function isSpecifierTypeBased( | ||
specifier: TSESTree.ExportSpecifier, | ||
): boolean | undefined { | ||
const checker = parserServices.program.getTypeChecker(); | ||
const node = parserServices.esTreeNodeToTSNodeMap.get(specifier.exported); | ||
const symbol = checker.getSymbolAtLocation(node); | ||
const aliasedSymbol = checker.getAliasedSymbol(symbol!); | ||
if (!aliasedSymbol || aliasedSymbol.escapedName === 'unknown') { | ||
return undefined; | ||
} | ||
return !(aliasedSymbol.flags & SymbolFlags.Value); | ||
} | ||
return { | ||
ExportNamedDeclaration(node: TSESTree.ExportNamedDeclaration): void { | ||
// Coerce the source into a string for use as a lookup entry. | ||
@@ -112,7 +130,7 @@ export default util.createRule<Options, MessageIds>({ | ||
continue; | ||
} | ||
const isTypeBased = isSpecifierTypeBased(specifier); | ||
if (isTypeBased === true) { | ||
typeBasedSpecifiers.push(specifier); | ||
@@ -199,29 +217,6 @@ export default util.createRule<Options, MessageIds>({ | ||
}, | ||
}); | ||
JoshuaKGoldberg marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
/** | ||
* Inserts "type" into an export. | ||
* | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { | ||
ParserServices, | ||
ParserServicesWithTypeInformation, | ||
} from '@typescript-eslint/typescript-estree'; | ||
export function expectToHaveParserServices( | ||
services: ParserServices | null | undefined, | ||
): asserts services is ParserServicesWithTypeInformation { | ||
expect(services?.program).toBeDefined(); | ||
expect(services?.esTreeNodeToTSNodeMap).toBeDefined(); | ||
expect(services?.tsNodeToESTreeNodeMap).toBeDefined(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -4,6 +4,7 @@ import * as ts from 'typescript'; | ||
import type { ParseSettings } from '../parseSettings'; | ||
import { isSourceFile } from '../source-files'; | ||
import { getScriptKind } from './getScriptKind'; | ||
import type { ASTAndNoProgram } from './shared'; | ||
const log = debug('typescript-eslint:typescript-estree:createSourceFile'); | ||
@@ -25,4 +26,11 @@ function createSourceFile(parseSettings: ParseSettings): ts.SourceFile { | ||
); | ||
} | ||
function createNoProgram(parseSettings: ParseSettings): ASTAndNoProgram { | ||
return { | ||
ast: createSourceFile(parseSettings), | ||
program: null, | ||
}; | ||
} | ||
bradzacher marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
export { createSourceFile, createNoProgram }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -182,12 +182,21 @@ export interface ParserWeakMapESTreeToTSNode< | ||
has(key: unknown): boolean; | ||
} | ||
export interface ParserServicesNodeMaps { | ||
esTreeNodeToTSNodeMap: ParserWeakMapESTreeToTSNode; | ||
tsNodeToESTreeNodeMap: ParserWeakMap<TSNode | TSToken, TSESTree.Node>; | ||
} | ||
export interface ParserServicesWithTypeInformation | ||
extends ParserServicesNodeMaps { | ||
program: ts.Program; | ||
} | ||
export interface ParserServicesWithoutTypeInformation | ||
extends ParserServicesNodeMaps { | ||
program: null; | ||
JoshuaKGoldberg marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
} | ||
export type ParserServices = | ||
| ParserServicesWithTypeInformation | ||
| ParserServicesWithoutTypeInformation; | ||
export interface ModuleResolver { | ||
version: 1; | ||
Uh oh!
There was an error while loading.Please reload this page.