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

fix(ssr): handle default arguments properly in ssrTransform #5040

Merged
merged 1 commit into from
Sep 23, 2021

Conversation

aleclarson
Copy link
Member

Previously, any Identifier nodes that were both (1) used in a default argument expression and (2) referenced an import binding would not be rewritten to point to the transformed import binding.

For example:

import Foo from './foo'

export function hello(arg = Foo.foo) {}

…would be transformed into something like:

const __vite_ssr_import_0__ = __vite_ssr_import__('./foo')

function hello(arg = Foo.foo) {}

Object.defineProperty(__vite_ssr_exports__, "hello", { enumerable: true, value: hello })

…so the Foo.foo reference would result in a runtime error.

Previously, any Identifier nodes that were both (1) used in a default argument expression and (2) referenced an import binding would not be rewritten to point to the transformed import binding.

For example:

```ts
import Foo from './foo'

export function hello(arg = Foo.foo) {}
```

…would be transformed into something like:

```ts
const __vite_ssr_import_0__ = __vite_ssr_import__('./foo')

function hello(arg = Foo.foo) {}

Object.defineProperty(__vite_ssr_exports__, "hello", { enumerable: true, value: hello })
```

…so the `Foo.foo` reference would result in a runtime error.
@patak-dev patak-dev merged commit 6a60080 into vitejs:main Sep 23, 2021
aleclarson added a commit to aleclarson/vite that referenced this pull request Nov 8, 2021
@aleclarson aleclarson deleted the fix/ssr-transform-1 branch February 25, 2022 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants