Skip to content

Commit

Permalink
fix(ssr): handle default arguments properly in ssrTransform
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aleclarson committed Sep 23, 2021
1 parent 18d4124 commit 94ecc91
Showing 1 changed file with 1 addition and 1 deletion.
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 @@ -354,7 +354,7 @@ function walk(
// walk function expressions and add its arguments to known identifiers
// so that we don't prefix them
node.params.forEach((p) =>
(eswalk as any)(p, {
(eswalk as any)(p.type === 'AssignmentPattern' ? p.left : p, {
enter(child: Node, parent: Node) {
if (
child.type === 'Identifier' &&
Expand Down

0 comments on commit 94ecc91

Please sign in to comment.