Skip to content

Commit 8d4e08f

Browse files
committed
refactor(compat-eslint): hoist remaining lazy requires in lib + index
Three places the previous sweep missed because they imported different names from already-hoisted modules or different modules entirely: - `index.ts:buildScanPredicate` — `predicateForTriggerSet`, `predicateAllKinds` from `./lib/ts-ast-scan` (had `tsScanTraverse` only). - `lib/lazy-estree.ts` — `xhtmlEntities` from `./xhtml-entities`, used inside `unescapeJsxText`. - `lib/lazy-source-code.ts` and `lib/ts-scope-manager.ts` — both reach into `./lazy-estree` for `materialize` from a fallback path. No cycle: `lazy-estree` doesn't import either file. Production code is now `as typeof import`-free; every dep is at top of file. All four test suites still clean.
1 parent a723c4d commit 8d4e08f

4 files changed

Lines changed: 4 additions & 9 deletions

File tree

packages/compat-eslint/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { convertLazy } from './lib/lazy-estree';
66
import { LazySourceCode } from './lib/lazy-source-code';
77
import { decomposeSimple, isCodePathListener } from './lib/selector-analysis';
88
import { convertComments, convertTokens } from './lib/tokens';
9-
import { tsScanTraverse } from './lib/ts-ast-scan';
9+
import { predicateAllKinds, predicateForTriggerSet, tsScanTraverse } from './lib/ts-ast-scan';
1010
import { applyEslintGlobals, TsScopeManager } from './lib/ts-scope-manager';
1111
import { visitorKeys } from './lib/visitor-keys';
1212

@@ -488,9 +488,6 @@ function buildFastDispatch(
488488
// if any type lacks a registered predicate (same philosophy as
489489
// decomposeSimple — surface coverage gaps as hard errors).
490490
function buildScanPredicate(fast: FastDispatch) {
491-
const { predicateForTriggerSet, predicateAllKinds } = require(
492-
'./lib/ts-ast-scan',
493-
) as typeof import('./lib/ts-ast-scan');
494491
const usesCodePath = fast.codePath.size > 0;
495492
const usesWildcard = fast.enterAll.length > 0 || fast.exitAll.length > 0;
496493
if (usesCodePath || usesWildcard) {

packages/compat-eslint/lib/lazy-estree.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
// these positions.
3434

3535
import * as ts from 'typescript';
36+
import { xhtmlEntities } from './xhtml-entities';
3637

3738
const SK = ts.SyntaxKind;
3839

@@ -4938,7 +4939,6 @@ function convertJSXNamespaceOrIdentifier(node: ts.Node, parent: LazyNode): LazyN
49384939
// `.value` (react/no-unescaped-entities, jsx-a11y accessibility checks,
49394940
// whitespace detectors) need this parity — partial decoding silently
49404941
// hides real entities behind their `&name;` source form.
4941-
const { xhtmlEntities } = require('./xhtml-entities.js') as { xhtmlEntities: Record<string, string> };
49424942
function unescapeJsxText(text: string): string {
49434943
if (!text.includes('&')) return text;
49444944
return text.replace(/&(?:#\d+|#x[\da-fA-F]+|[0-9a-zA-Z]+);/g, entity => {

packages/compat-eslint/lib/lazy-source-code.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
// returning undefined.
2727

2828
import * as ts from 'typescript';
29+
import { materialize } from './lazy-estree';
2930
import { buildCommentObject, walkInnerCommentsOf } from './tokens';
3031

3132
const SK = ts.SyntaxKind;
@@ -587,7 +588,6 @@ export class LazySourceCode {
587588
// holds the converter context.
588589
const ctx = (this.ast as { _ctx?: unknown })._ctx;
589590
if (!ctx) return null;
590-
const { materialize } = require('./lazy-estree') as typeof import('./lazy-estree');
591591
// Walk up to find a ts.Node that has an ESTree wrapper kind.
592592
// Tokens / SyntaxList / etc. get folded into their parent's
593593
// ESTree shape, so they don't have their own wrappers.

packages/compat-eslint/lib/ts-scope-manager.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import type { TSESTree } from '@typescript-eslint/types';
1414
import ts = require('typescript');
15+
import { materialize } from './lazy-estree';
1516

1617
type AstMaps = {
1718
esTreeNodeToTSNodeMap: WeakMap<TSESTree.Node, ts.Node>;
@@ -1480,9 +1481,6 @@ export class TsScopeManager {
14801481
// Builds a real ESTree counterpart with proper parent chain. Lazy
14811482
// has a generic-fallback for unsupported kinds and null returns,
14821483
// so this never throws.
1483-
const { materialize } = require(
1484-
'./lazy-estree',
1485-
) as typeof import('./lazy-estree');
14861484
return materialize(tsNode, {
14871485
ast: this.tsFile,
14881486
maps: this.astMaps,

0 commit comments

Comments
 (0)