@@ -250,83 +250,11 @@ function wrapContextToOverrideTokenMethods(context, tokenStore, options) {
250250 get tokensAndComments ( ) {
251251 return getTokensAndComments ( )
252252 } ,
253- getNodeByRangeIndex,
254- // @ts -expect-error -- Added in ESLint v8.38.0
255- getDeclaredVariables
253+ getNodeByRangeIndex
256254 } ,
257255 tokenStore
258256 )
259-
260- /** @type {WeakMap<ASTNode, import('eslint').Scope.ScopeManager> } */
261- const containerScopes = new WeakMap ( )
262-
263- /**
264- * @param {ASTNode } node
265- * @returns {import('eslint').Scope.ScopeManager|null }
266- */
267- function getContainerScope ( node ) {
268- const exprContainer = getVExpressionContainer ( node )
269- if ( ! exprContainer ) {
270- return null
271- }
272- const cache = containerScopes . get ( exprContainer )
273- if ( cache ) {
274- return cache
275- }
276- const programNode = eslintSourceCode . ast
277- const parserOptions =
278- context . languageOptions ?. parserOptions ?? context . parserOptions ?? { }
279- const ecmaFeatures = parserOptions . ecmaFeatures || { }
280- const ecmaVersion =
281- context . languageOptions ?. ecmaVersion ?? parserOptions . ecmaVersion ?? 2020
282- const sourceType = programNode . sourceType
283- try {
284- const eslintScope = createRequire ( require . resolve ( 'eslint' ) ) (
285- 'eslint-scope'
286- )
287- const expStmt = newProxy ( exprContainer , {
288- // @ts -expect-error
289- type : 'ExpressionStatement'
290- } )
291- const scopeProgram = newProxy ( programNode , {
292- // @ts -expect-error
293- body : [ expStmt ]
294- } )
295- const scope = eslintScope . analyze ( scopeProgram , {
296- ignoreEval : true ,
297- nodejsScope : false ,
298- impliedStrict : ecmaFeatures . impliedStrict ,
299- ecmaVersion,
300- sourceType,
301- fallback : getFallbackKeys
302- } )
303- containerScopes . set ( exprContainer , scope )
304- return scope
305- } catch {
306- // ignore
307- // console.log(error)
308- }
309-
310- return null
311- }
312- return newProxy ( context , {
313- getSourceCode ( ) {
314- return sourceCode
315- } ,
316- get sourceCode ( ) {
317- return sourceCode
318- } ,
319- getDeclaredVariables
320- } )
321-
322- /**
323- * @param {ESNode } node
324- * @returns {Variable[] }
325- */
326- function getDeclaredVariables ( node ) {
327- const scope = getContainerScope ( node )
328- return scope ?. getDeclaredVariables ( node ) ?? [ ]
329- }
257+ return newProxy ( context , { sourceCode } )
330258}
331259
332260/**
0 commit comments