@@ -5,11 +5,7 @@ import type * as ts from 'typescript';
5
5
export { create as createDisableNextLinePlugin } from './lib/plugins/disableNextLine.js' ;
6
6
export { create as createShowDocsActionPlugin } from './lib/plugins/showDocsAction.js' ;
7
7
8
- import ScopeManager = require( '@typescript-eslint/scope-manager' ) ;
9
-
10
- // TS-ESLint internal scripts
11
- const astConverter : typeof import ( './node_modules/@typescript-eslint/typescript-estree/dist/ast-converter.js' ) . astConverter = require ( '../../@typescript-eslint/typescript-estree/dist/ast-converter.js' ) . astConverter ;
12
- const createParseSettings : typeof import ( './node_modules/@typescript-eslint/typescript-estree/dist/parseSettings/createParseSettings.js' ) . createParseSettings = require ( '../../@typescript-eslint/typescript-estree/dist/parseSettings/createParseSettings.js' ) . createParseSettings ;
8
+ import Parser = require( '@typescript-eslint/parser' ) ;
13
9
14
10
// ESLint internal scripts
15
11
const SourceCode = require ( '../../eslint/lib/languages/js/source-code/source-code.js' ) ;
@@ -421,67 +417,30 @@ function getEstree(
421
417
return Reflect . get ( program , p , receiver ) ;
422
418
} ,
423
419
} ) ;
424
- const { estree, astMaps } = astConverter (
425
- sourceFile ,
426
- createParseSettings ( sourceFile , {
427
- comment : true ,
428
- tokens : true ,
429
- range : true ,
430
- loc : true ,
431
- preserveNodeMaps : true ,
432
- filePath : sourceFile . fileName ,
433
- } ) ,
434
- true
435
- ) ;
436
- const scopeManager = ScopeManager . analyze ( estree ) ;
420
+ const { ast, scopeManager, visitorKeys, services } = Parser . parseForESLint ( sourceFile , {
421
+ tokens : true ,
422
+ comment : true ,
423
+ loc : true ,
424
+ range : true ,
425
+ preserveNodeMaps : true ,
426
+ filePath : sourceFile . fileName ,
427
+ emitDecoratorMetadata : getCompilationSettings ( ) . emitDecoratorMetadata ?? false ,
428
+ experimentalDecorators : getCompilationSettings ( ) . experimentalDecorators ?? false ,
429
+ } ) ;
437
430
const sourceCode = new SourceCode ( {
438
- ast : estree as ESLint . AST . Program ,
439
431
text : sourceFile . text ,
440
- scopeManager : scopeManager as ESLint . Scope . ScopeManager ,
432
+ ast,
433
+ scopeManager,
434
+ visitorKeys,
441
435
parserServices : {
436
+ ...services ,
442
437
program : programProxy ,
443
- // not set in the config is the same as off
444
- get emitDecoratorMetadata ( ) : boolean {
445
- return getCompilationSettings ( ) . emitDecoratorMetadata ?? false ;
446
- } ,
447
- get experimentalDecorators ( ) : boolean {
448
- return getCompilationSettings ( ) . experimentalDecorators ?? false ;
449
- } ,
450
- ...astMaps ,
451
- getSymbolAtLocation : ( node : any ) => programProxy . getTypeChecker ( ) . getSymbolAtLocation ( astMaps . esTreeNodeToTSNodeMap . get ( node ) ) ,
452
- getTypeAtLocation : ( node : any ) => programProxy . getTypeChecker ( ) . getTypeAtLocation ( astMaps . esTreeNodeToTSNodeMap . get ( node ) ) ,
438
+ getSymbolAtLocation : ( node : any ) => programProxy . getTypeChecker ( ) . getSymbolAtLocation ( services . esTreeNodeToTSNodeMap . get ( node ) ) ,
439
+ getTypeAtLocation : ( node : any ) => programProxy . getTypeChecker ( ) . getTypeAtLocation ( services . esTreeNodeToTSNodeMap . get ( node ) ) ,
453
440
} ,
454
441
} ) ;
455
- const eventQueue = sourceCode . traverse ( ) ; // parent should fill in this call, but don't consistent-type-imports rule is still broken, and fillParent is still needed
456
- fillParent ( estree ) ;
457
- estrees . set ( sourceFile , { estree, sourceCode, eventQueue } ) ;
442
+ const eventQueue = sourceCode . traverse ( ) ;
443
+ estrees . set ( sourceFile , { estree : ast , sourceCode, eventQueue } ) ;
458
444
}
459
445
return estrees . get ( sourceFile ) ! ;
460
446
}
461
-
462
- function fillParent ( target : any , currentParent ?: any ) : any {
463
- if ( 'type' in target ) {
464
- if ( ! target . parent ) {
465
- target . parent = currentParent ;
466
- }
467
- currentParent = target ;
468
- }
469
- for ( const key of Object . keys ( target ) ) {
470
- if ( key === 'parent' ) {
471
- continue ;
472
- }
473
- const value = target [ key ] ;
474
- if ( value && typeof value === 'object' ) {
475
- if ( Array . isArray ( value ) ) {
476
- for ( const element of value ) {
477
- if ( element && typeof element === 'object' ) {
478
- fillParent ( element , currentParent ) ;
479
- }
480
- }
481
- }
482
- else {
483
- fillParent ( value , currentParent ) ;
484
- }
485
- }
486
- }
487
- }
0 commit comments