33 * SPDX-License-Identifier: AGPL-3.0-only
44 */
55
6- import { parseAst } from 'vite ' ;
6+ import { parseAst } from 'rolldown/parseAst ' ;
77import * as estreeWalker from 'estree-walker' ;
88import { assertNever , assertType } from '../utils.js' ;
9- import type { AstNode , ProgramNode } from 'rollup' ;
9+ import type { ESTree as RolldownESTree } from 'rolldown/utils' ;
10+ import type { AstNode } from 'rollup' ;
1011import type * as estree from 'estree' ;
1112import type { LocaleInliner , TextModification } from '../locale-inliner.js' ;
1213import type { Logger } from '../logger.js' ;
@@ -17,7 +18,7 @@ interface WalkerContext {
1718}
1819
1920export function collectModifications ( sourceCode : string , fileName : string , fileLogger : Logger , inliner : LocaleInliner ) : TextModification [ ] {
20- let programNode : ProgramNode ;
21+ let programNode : RolldownESTree . Program ;
2122 try {
2223 programNode = parseAst ( sourceCode ) ;
2324 } catch ( err ) {
@@ -35,7 +36,8 @@ export function collectModifications(sourceCode: string, fileName: string, fileL
3536 // 1) replace all `scripts/` path literals with locale code
3637 // 2) replace all `localStorage.getItem("lang")` with `localeName` variable
3738 // 3) replace all `await window.fetch(`/assets/locales/${d}.${x}.json`).then(u=>u.json())` with `localeJson` variable
38- estreeWalker . walk ( programNode , {
39+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
40+ ( estreeWalker . walk as any ) ( programNode , {
3941 enter ( this : WalkerContext , node : Node ) {
4042 assertType < AstNode > ( node ) ;
4143
@@ -118,8 +120,9 @@ export function collectModifications(sourceCode: string, fileName: string, fileL
118120 // Check if the identifier is already declared in the file.
119121 // If it is, we may overwrite it and cause issues so we skip inlining
120122 let isSupported = true ;
121- estreeWalker . walk ( programNode , {
122- enter ( node ) {
123+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
124+ ( estreeWalker . walk as any ) ( programNode , {
125+ enter ( node : Node ) {
123126 if ( node . type === 'VariableDeclaration' ) {
124127 assertType < estree . VariableDeclaration > ( node ) ;
125128 for ( const id of node . declarations . flatMap ( x => declsOfPattern ( x . id ) ) ) {
@@ -145,8 +148,9 @@ export function collectModifications(sourceCode: string, fileName: string, fileL
145148
146149 const toSkip = new Set ( ) ;
147150 toSkip . add ( i18nImport ) ;
148- estreeWalker . walk ( programNode , {
149- enter ( this : WalkerContext , node , parent , property ) {
151+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
152+ ( estreeWalker . walk as any ) ( programNode , {
153+ enter ( this : WalkerContext , node : Node , parent : Node | null , property : string | number | symbol | null | undefined ) {
150154 assertType < AstNode > ( node ) ;
151155 assertType < AstNode > ( parent ) ;
152156 if ( toSkip . has ( node ) ) {
@@ -379,7 +383,7 @@ type SpecifierResult =
379383 | { type : 'specifier' , localI18nIdentifier : string , importNode : estree . ImportDeclaration & AstNode }
380384 ;
381385
382- function findImportSpecifier ( programNode : ProgramNode , i18nFileName : string , i18nSymbol : string ) : SpecifierResult {
386+ function findImportSpecifier ( programNode : RolldownESTree . Program , i18nFileName : string , i18nSymbol : string ) : SpecifierResult {
383387 const imports = programNode . body . filter ( x => x . type === 'ImportDeclaration' ) ;
384388 const importNode = imports . find ( x => x . source . value === `./${ i18nFileName } ` ) as estree . ImportDeclaration | undefined ;
385389 if ( ! importNode ) return { type : 'no-import' } ;
0 commit comments