File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44/* eslint-disable @typescript-eslint/no-explicit-any */
55
66import * as ts from 'typescript' ;
7+ import { InternalError } from '@microsoft/node-core-library' ;
8+
9+ /**
10+ * Exposes the TypeScript compiler internals for detecting global variable names.
11+ */
12+ export interface IGlobalVariableAnalyzer {
13+ hasGlobalName ( name : string ) : boolean ;
14+ }
715
816export class TypeScriptInternals {
917
@@ -92,4 +100,19 @@ export class TypeScriptInternals {
92100 return ( declaration as any ) . localSymbol ;
93101 }
94102
103+ public static getGlobalVariableAnalyzer ( program : ts . Program ) : IGlobalVariableAnalyzer {
104+ const anyProgram : any = program ;
105+ if ( ! anyProgram . getDiagnosticsProducingTypeChecker ) {
106+ throw new InternalError ( 'Missing Program.getDiagnosticsProducingTypeChecker' ) ;
107+ }
108+ const typeChecker : any = anyProgram . getDiagnosticsProducingTypeChecker ( ) ;
109+ if ( ! typeChecker . getEmitResolver ) {
110+ throw new InternalError ( 'Missing TypeChecker.getEmitResolver' ) ;
111+ }
112+ const resolver : any = typeChecker . getEmitResolver ( ) ;
113+ if ( ! resolver . hasGlobalName ) {
114+ throw new InternalError ( 'Missing EmitResolver.hasGlobalName' ) ;
115+ }
116+ return resolver ;
117+ }
95118}
You can’t perform that action at this time.
0 commit comments