88 type ScopeManager as TSESLintScopeManager ,
99} from '@typescript-eslint/scope-manager' ;
1010import { ast , initAst } from './source_code.js' ;
11- import { assertIs } from './utils.js' ;
11+ import { assertIs , assertIsNonNull } from './utils.js' ;
1212
1313import type * as ESTree from '../generated/types.d.ts' ;
1414import type { SetNullable } from './utils.ts' ;
@@ -109,6 +109,7 @@ const analyzeOptions: SetNullable<AnalyzeOptions, 'sourceType'> = {
109109 */
110110function initTsScopeManager ( ) {
111111 if ( ast === null ) initAst ( ) ;
112+ assertIsNonNull ( ast ) ;
112113
113114 analyzeOptions . sourceType = ast . sourceType ;
114115 assertIs < AnalyzeOptions > ( analyzeOptions ) ;
@@ -199,6 +200,7 @@ export function isGlobalReference(node: ESTree.Node): boolean {
199200 if ( node . type !== 'Identifier' ) return false ;
200201
201202 if ( tsScopeManager === null ) initTsScopeManager ( ) ;
203+ assertIsNonNull ( tsScopeManager ) ;
202204
203205 const { scopes } = tsScopeManager ;
204206 if ( scopes . length === 0 ) return false ;
@@ -229,6 +231,8 @@ export function isGlobalReference(node: ESTree.Node): boolean {
229231export function getDeclaredVariables ( node : ESTree . Node ) : Variable [ ] {
230232 // ref: https://github.com/eslint/eslint/blob/e7cda3bdf1bdd664e6033503a3315ad81736b200/lib/languages/js/source-code/source-code.js#L904
231233 if ( tsScopeManager === null ) initTsScopeManager ( ) ;
234+ assertIsNonNull ( tsScopeManager ) ;
235+
232236 // @ts -expect-error // TODO: Our types don't quite align yet
233237 return tsScopeManager . getDeclaredVariables ( node ) ;
234238}
@@ -243,6 +247,7 @@ export function getScope(node: ESTree.Node): Scope {
243247 if ( ! node ) throw new TypeError ( 'Missing required argument: `node`' ) ;
244248
245249 if ( tsScopeManager === null ) initTsScopeManager ( ) ;
250+ assertIsNonNull ( tsScopeManager ) ;
246251
247252 const inner = node . type !== 'Program' ;
248253
@@ -254,6 +259,7 @@ export function getScope(node: ESTree.Node): Scope {
254259 return scope . type === 'function-expression-name' ? scope . childScopes [ 0 ] : scope ;
255260 }
256261
262+ // @ts -expect-error - Don't want to create a new variable just to make it nullable
257263 node = node . parent ;
258264 } while ( node !== null ) ;
259265
0 commit comments