Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"node",
"typescript",
"@rollup/plugin-dynamic-import-vars", // prefer version using tinyglobby
"@oxc-project/types", // align version with rolldown

// pinned
"slash3",
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"@types/babel__preset-env": "^7.10.0",
"@types/convert-source-map": "^2.0.3",
"@types/cross-spawn": "^6.0.6",
"@types/estree": "^1.0.8",
"@types/etag": "^1.8.4",
"@types/less": "^3.0.8",
"@types/node": "^24.10.15",
Expand Down
3 changes: 1 addition & 2 deletions packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
"@babel/parser": "^7.29.0",
"@jridgewell/remapping": "^2.3.5",
"@jridgewell/trace-mapping": "^0.3.31",
"@oxc-project/types": "0.115.0",
"@polka/compression": "^1.0.0-next.25",
"@rollup/plugin-alias": "^6.0.0",
"@rollup/plugin-dynamic-import-vars": "2.1.4",
Expand All @@ -103,7 +102,6 @@
"convert-source-map": "^2.0.0",
"cors": "^2.8.6",
"cross-spawn": "^7.0.6",
"obug": "^1.0.2",
"dotenv-expand": "^12.0.3",
"es-module-lexer": "^1.7.0",
"esbuild": "^0.27.3",
Expand All @@ -117,6 +115,7 @@
"mlly": "^1.8.0",
"mrmime": "^2.0.1",
"nanoid": "^5.1.6",
"obug": "^1.0.2",
"open": "^10.2.0",
"parse5": "^8.0.0",
"pathe": "^2.0.3",
Expand Down
12 changes: 6 additions & 6 deletions packages/vite/rolldown.dts.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import type {
PluginContext,
RenderedChunk,
} from 'rolldown'
import type { ESTree } from 'rolldown/utils'
import { parseAst } from 'rolldown/parseAst'
import { dts } from 'rolldown-plugin-dts'
import { parse as parseWithBabel } from '@babel/parser'
import { walk } from 'estree-walker'
import MagicString from 'magic-string'
import type {
Directive,
ModuleExportName,
Program,
Statement,
} from '@oxc-project/types'

type Directive = ESTree.Directive
type ModuleExportName = ESTree.ModuleExportName
type Program = ESTree.Program
type Statement = ESTree.Statement

const pkg = JSON.parse(
readFileSync(new URL('./package.json', import.meta.url)).toString(),
Expand Down
20 changes: 7 additions & 13 deletions packages/vite/src/node/plugins/importAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type { StaticImport } from 'mlly'
import { ESM_STATIC_IMPORT_RE, parseStaticImport } from 'mlly'
import { makeLegalIdentifier } from '@rollup/pluginutils'
import type { PartialResolvedId, RollupError } from 'rolldown'
import type { Identifier, Literal, Program } from 'estree'
import type { ESTree } from 'rolldown/utils'
import {
CLIENT_DIR,
CLIENT_PUBLIC_PATH,
Expand Down Expand Up @@ -1010,7 +1010,7 @@ export function transformCjsImport(
isNodeMode: boolean,
config: ResolvedConfig,
): string | undefined {
const node = (parseAst(importExp) as Program).body[0]
const node = parseAst(importExp).body[0]

// `export * from '...'` may cause unexpected problem, so give it a warning
if (
Expand All @@ -1036,9 +1036,7 @@ export function transformCjsImport(
let defaultExports: string = ''
for (const spec of node.specifiers) {
if (spec.type === 'ImportSpecifier') {
const importedName = getIdentifierNameOrLiteralValue(
spec.imported,
) as string
const importedName = getIdentifierNameOrLiteralValue(spec.imported)
const localName = spec.local.name
importNames.push({ importedName, localName })
} else if (spec.type === 'ImportDefaultSpecifier') {
Expand All @@ -1051,13 +1049,9 @@ export function transformCjsImport(
} else if (spec.type === 'ExportSpecifier') {
// for ExportSpecifier, local name is same as imported name
// prefix the variable name to avoid clashing with other local variables
const importedName = getIdentifierNameOrLiteralValue(
spec.local,
) as string
const importedName = getIdentifierNameOrLiteralValue(spec.local)
// we want to specify exported name as variable and re-export it
const exportedName = getIdentifierNameOrLiteralValue(
spec.exported,
) as string
const exportedName = getIdentifierNameOrLiteralValue(spec.exported)
if (exportedName === 'default') {
defaultExports = makeLegalIdentifier(
`__vite__cjsExportDefault_${importIndex}`,
Expand All @@ -1066,7 +1060,7 @@ export function transformCjsImport(
} else {
const localName = `__vite__cjsExport${
spec.exported.type === 'Literal'
? `L_${getHash(spec.exported.value as string)}`
? `L_${getHash(spec.exported.value)}`
: 'I_' + spec.exported.name
}`
importNames.push({ importedName, localName })
Expand Down Expand Up @@ -1111,7 +1105,7 @@ export function transformCjsImport(
}
}

function getIdentifierNameOrLiteralValue(node: Identifier | Literal) {
function getIdentifierNameOrLiteralValue(node: ESTree.ModuleExportName) {
return node.type === 'Identifier' ? node.name : node.value
}

Expand Down
19 changes: 6 additions & 13 deletions packages/vite/src/node/plugins/importMetaGlob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@ import { isAbsolute, posix } from 'node:path'
import picomatch from 'picomatch'
import { stripLiteral } from 'strip-literal'
import colors from 'picocolors'
import type {
ArrayExpression,
Expression,
Literal,
Node,
SpreadElement,
TemplateLiteral,
} from 'estree'
import type { ESTree } from 'rolldown/utils'
import type { CustomPluginOptions, RollupError } from 'rolldown'
import MagicString from 'magic-string'
import { stringifyQuery } from 'ufo'
Expand Down Expand Up @@ -289,14 +282,14 @@ export async function parseImportGlob(
if (ast.arguments.length < 1 || ast.arguments.length > 2)
throw err(`Expected 1-2 arguments, but got ${ast.arguments.length}`)

const arg1 = ast.arguments[0] as ArrayExpression | Literal | TemplateLiteral
const arg2 = ast.arguments[1] as
| (Node & { start: number; end: number })
| undefined
const arg1 = ast.arguments[0]
const arg2 = ast.arguments[1]

const globs: string[] = []

const validateLiteral = (element: Expression | SpreadElement | null) => {
const validateLiteral = (
element: ESTree.Expression | ESTree.SpreadElement | null,
) => {
if (!element) return
if (element.type === 'Literal') {
if (typeof element.value !== 'string')
Expand Down
7 changes: 4 additions & 3 deletions packages/vite/src/node/plugins/workerImportMetaUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import MagicString from 'magic-string'
import type { RollupError } from 'rolldown'
import { parseAstAsync } from 'rolldown/parseAst'
import { stripLiteral } from 'strip-literal'
import type { Expression, ExpressionStatement } from 'estree'
import type { ESTree } from 'rolldown/utils'
import type { ResolvedConfig } from '../config'
import type { Plugin } from '../plugin'
import { evalValue, injectQuery, transformStableResult } from '../utils'
Expand Down Expand Up @@ -40,7 +40,7 @@ function findClosingParen(input: string, fromIndex: number) {
}

function extractWorkerTypeFromAst(
expression: Expression,
expression: ESTree.Expression,
optsStartIndex: number,
): 'classic' | 'module' | undefined {
if (expression.type !== 'ObjectExpression') {
Expand Down Expand Up @@ -102,7 +102,8 @@ async function parseWorkerOptions(
opts = evalValue<WorkerOptions>(rawOpts)
} catch {
const optsNode = (
(await parseAstAsync(`(${rawOpts})`)).body[0] as ExpressionStatement
(await parseAstAsync(`(${rawOpts})`))
.body[0] as ESTree.ExpressionStatement
).expression

const type = extractWorkerTypeFromAst(optsNode, optsStartIndex)
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/server/pluginContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import fsp from 'node:fs/promises'
import { join } from 'node:path'
import { performance } from 'node:perf_hooks'
import { parseAst as rolldownParseAst } from 'rolldown/parseAst'
import type { Program } from '@oxc-project/types'
import type { ESTree } from 'rolldown/utils'
import type {
AsyncPluginHooks,
CustomPluginOptions,
Expand Down Expand Up @@ -765,7 +765,7 @@ class PluginContext

fs: RollupFsModule = fsModule

parse(code: string, opts: any): Program {
parse(code: string, opts: any): ESTree.Program {
return rolldownParseAst(code, opts)
}

Expand Down
Loading