Skip to content

Commit

Permalink
fix(ssr): fix binding overwrite at nested function, fix #3856 (#3869)
Browse files Browse the repository at this point in the history
  • Loading branch information
underfin authored Jun 24, 2021
1 parent dd46cd1 commit 85f51c1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ test('overwrite bindings', async () => {
`function c() { const { test: inject } = { test: true }; console.log(inject) }\n` +
`const d = inject \n` +
`function f() { console.log(inject) }\n` +
`function e() { const { inject } = { inject: true } }\n`,
`function e() { const { inject } = { inject: true } }\n` +
`function g() { const f = () => { const inject = true }; console.log(inject) }\n`,
null,
null
)
Expand All @@ -237,6 +238,7 @@ test('overwrite bindings', async () => {
const d = __vite_ssr_import_0__.inject
function f() { console.log(__vite_ssr_import_0__.inject) }
function e() { const { inject } = { inject: true } }
function g() { const f = () => { const inject = true }; console.log(__vite_ssr_import_0__.inject) }
"
`)
})
3 changes: 2 additions & 1 deletion packages/vite/src/node/ssr/ssrTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,8 @@ function isFunction(node: _Node): node is FunctionNode {
}

function findParentFunction(parentStack: _Node[]): FunctionNode | undefined {
for (const node of parentStack) {
for (let i = parentStack.length - 1; i >= 0; i--) {
const node = parentStack[i]
if (isFunction(node)) {
return node
}
Expand Down

0 comments on commit 85f51c1

Please sign in to comment.