Skip to content

Commit

Permalink
fix(ssr): fix semicolon injection
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Dec 30, 2024
1 parent b3aaae2 commit c308bb5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
20 changes: 18 additions & 2 deletions packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,14 @@ switch (1) {
f()
break
}
if(0){}f()
if(0){}else{}f()
switch(1){}f()
{}f(1)
`),
).toMatchInlineSnapshot(`
"
Expand Down Expand Up @@ -1346,7 +1354,15 @@ switch (1) {
x;
(0,__vite_ssr_import_0__.f)();
break
}
};
if(0){};(0,__vite_ssr_import_0__.f)();
if(0){}else{};(0,__vite_ssr_import_0__.f)();
switch(1){};(0,__vite_ssr_import_0__.f)();
{}(0,__vite_ssr_import_0__.f)(1)
"
`)
})
Expand All @@ -1364,7 +1380,7 @@ const c = () => {
`
"const __vite_ssr_import_0__ = await __vite_ssr_import__("a", {"importedNames":["default"]});
const c = () => {
if(true){return}(0,__vite_ssr_import_0__.default)(1,{})
if(true){return};(0,__vite_ssr_import_0__.default)(1,{})
}"
`,
)
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/ssr/ssrTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ async function ssrTransformScript(
stmt.type !== 'BlockStatement' &&
stmt.type !== 'ImportDeclaration'
) {
s.appendRight(stmt.end, ';')
s.appendLeft(stmt.end, ';')
}
}
},
Expand Down

0 comments on commit c308bb5

Please # to comment.