Skip to content

Commit

Permalink
fix(ssrTransform): use appendLeft instead of appendRight (#6407)
Browse files Browse the repository at this point in the history
  • Loading branch information
ygj6 committed Feb 26, 2022
1 parent 5818ac9 commit 3012541
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
34 changes: 29 additions & 5 deletions packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts
Expand Up @@ -304,8 +304,8 @@ test('should declare variable for imported super class', async () => {
const Foo = __vite_ssr_import_0__.Foo;
class A extends Foo {}
class B extends Foo {}
Object.defineProperty(__vite_ssr_exports__, \\"default\\", { enumerable: true, value: A });
Object.defineProperty(__vite_ssr_exports__, \\"B\\", { enumerable: true, configurable: true, get(){ return B }});"
Object.defineProperty(__vite_ssr_exports__, \\"B\\", { enumerable: true, configurable: true, get(){ return B }});
Object.defineProperty(__vite_ssr_exports__, \\"default\\", { enumerable: true, value: A });"
`)
})

Expand Down Expand Up @@ -351,8 +351,8 @@ test('should handle default export variants', async () => {
).toMatchInlineSnapshot(`
"class A {}
class B extends A {}
Object.defineProperty(__vite_ssr_exports__, \\"default\\", { enumerable: true, value: A });
Object.defineProperty(__vite_ssr_exports__, \\"B\\", { enumerable: true, configurable: true, get(){ return B }});"
Object.defineProperty(__vite_ssr_exports__, \\"B\\", { enumerable: true, configurable: true, get(){ return B }});
Object.defineProperty(__vite_ssr_exports__, \\"default\\", { enumerable: true, value: A });"
`)
})

Expand Down Expand Up @@ -610,7 +610,7 @@ test('jsx', async () => {
const code = `
import React from 'react'
import { Foo, Slot } from 'foo'
function Bar({ Slot = <Foo /> }) {
return (
<>
Expand All @@ -633,3 +633,27 @@ test('jsx', async () => {
"
`)
})

test('continuous exports', async () => {
expect(
(
await ssrTransform(
`
export function fn1() {
}export function fn2() {
}
`,
null,
null
)
).code
).toMatchInlineSnapshot(`
"
function fn1() {
}
Object.defineProperty(__vite_ssr_exports__, \\"fn1\\", { enumerable: true, configurable: true, get(){ return fn1 }});function fn2() {
}
Object.defineProperty(__vite_ssr_exports__, \\"fn2\\", { enumerable: true, configurable: true, get(){ return fn2 }});
"
`)
})
2 changes: 1 addition & 1 deletion packages/vite/src/node/ssr/ssrTransform.ts
Expand Up @@ -66,7 +66,7 @@ export async function ssrTransform(
}

function defineExport(position: number, name: string, local = name) {
s.appendRight(
s.appendLeft(
position,
`\nObject.defineProperty(${ssrModuleExportsKey}, "${name}", ` +
`{ enumerable: true, configurable: true, get(){ return ${local} }});`
Expand Down

0 comments on commit 3012541

Please sign in to comment.