22 * `SourceCode` methods related to scopes.
33 */
44
5- import type * as ESTree from '../generated/types.d.ts' ;
6-
75import {
86 analyze ,
97 type AnalyzeOptions ,
108 type ScopeManager as TSESLintScopeManager ,
119} from '@typescript-eslint/scope-manager' ;
1210import { ast , initAst } from './source_code.js' ;
1311
12+ import type * as ESTree from '../generated/types.d.ts' ;
13+
1414type Identifier =
1515 | ESTree . IdentifierName
1616 | ESTree . IdentifierReference
@@ -192,19 +192,12 @@ export type DefinitionType =
192192 */
193193export function isGlobalReference ( node : ESTree . Node ) : boolean {
194194 // ref: https://github.com/eslint/eslint/blob/e7cda3bdf1bdd664e6033503a3315ad81736b200/lib/languages/js/source-code/source-code.js#L934-L962
195- if ( ! node ) {
196- throw new TypeError ( 'Missing required argument: node.' ) ;
197- }
198-
199- if ( node . type !== 'Identifier' ) {
200- return false ;
201- }
195+ if ( ! node ) throw new TypeError ( 'Missing required argument: node.' ) ;
196+ if ( node . type !== 'Identifier' ) return false ;
202197
203198 const { name } = node ;
204199 // TODO: Is this check required? Isn't an `Identifier`'s `name` property always a string?
205- if ( typeof name !== 'string' ) {
206- return false ;
207- }
200+ if ( typeof name !== 'string' ) return false ;
208201
209202 if ( tsScopeManager === null ) initTsScopeManager ( ) ;
210203
@@ -216,17 +209,13 @@ export function isGlobalReference(node: ESTree.Node): boolean {
216209 const variable = globalScope . set . get ( name ) ;
217210
218211 // Global variables are not defined by any node, so they should have no definitions
219- if ( variable === undefined || variable . defs . length > 0 ) {
220- return false ;
221- }
212+ if ( variable === undefined || variable . defs . length > 0 ) return false ;
222213
223214 // If there is a variable by the same name exists in the global scope,
224215 // we need to check our node is one of its references
225216 const { references } = variable ;
226217 for ( let i = 0 , len = references . length ; i < len ; i ++ ) {
227- if ( references [ i ] . identifier === node ) {
228- return true ;
229- }
218+ if ( references [ i ] . identifier === node ) return true ;
230219 }
231220
232221 return false ;
@@ -252,9 +241,7 @@ export function getDeclaredVariables(node: ESTree.Node): Variable[] {
252241 */
253242export function getScope ( node : ESTree . Node ) : Scope {
254243 // ref: https://github.com/eslint/eslint/blob/e7cda3bdf1bdd664e6033503a3315ad81736b200/lib/languages/js/source-code/source-code.js#L862-L892
255- if ( ! node ) {
256- throw new TypeError ( 'Missing required argument: node.' ) ;
257- }
244+ if ( ! node ) throw new TypeError ( 'Missing required argument: `node`' ) ;
258245
259246 if ( tsScopeManager === null ) initTsScopeManager ( ) ;
260247
0 commit comments