Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSC: Better typings for acorn-loose usage #10681

Merged
merged 1 commit into from
May 24, 2024
Merged
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 packages/vite/modules.d.ts
Original file line number Diff line number Diff line change
@@ -106,5 +106,4 @@ declare module 'react-server-dom-webpack/server' {
): PipeableStream
}

declare module 'acorn-loose'
declare module 'vite-plugin-cjs-interop'
7 changes: 4 additions & 3 deletions packages/vite/src/plugins/vite-plugin-rsc-transform-client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'node:path'

import type { Statement, ModuleDeclaration } from 'acorn'
import * as acorn from 'acorn-loose'
import type { Plugin } from 'vite'

@@ -26,7 +27,7 @@ export function rscTransformUseClientPlugin(
return code
}

let body
let body: (Statement | ModuleDeclaration)[]

try {
body = acorn.parse(code, {
@@ -125,7 +126,7 @@ function addExportNames(names: Array<string>, node: any) {
*/
async function parseExportNamesIntoNames(
code: string,
body: any,
body: (Statement | ModuleDeclaration)[],
names: Array<string>,
): Promise<void> {
for (let i = 0; i < body.length; i++) {
@@ -186,7 +187,7 @@ async function parseExportNamesIntoNames(

async function transformClientModule(
code: string,
body: any,
body: (Statement | ModuleDeclaration)[],
url: string,
clientEntryFiles: Record<string, string>,
): Promise<string> {