Skip to content
Draft
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
4 changes: 3 additions & 1 deletion packages/vite/src/node/ssr/ssrTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ async function ssrTransformScript(
}

// 3. convert references to import bindings & import.meta references
walk(ast, {
walk(ast, idToImportMap, {
onStatements(statements) {
// ensure ";" between statements
for (let i = 0; i < statements.length - 1; i++) {
Expand Down Expand Up @@ -451,6 +451,7 @@ const isNodeInPattern = (node: ESTree.Node): node is ESTreeProperty =>
*/
function walk(
root: ESTree.Node,
idToImportMap: Map<string, string>,
{ onIdentifier, onImportMeta, onDynamicImport, onStatements }: Visitors,
) {
const parentStack: ESTree.Node[] = []
Expand Down Expand Up @@ -541,6 +542,7 @@ function walk(

if (node.type === 'Identifier') {
if (
idToImportMap.has(node.name) &&
!isInScope(node.name, parentStack) &&
isRefIdentifier(node, parent!, parentStack)
) {
Expand Down