Skip to content

Commit

Permalink
fix(browser): esm injector doesn't replace class expressions (#3641)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Jun 21, 2023
1 parent 36c06d1 commit 5c0ac4a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/browser/src/node/esmInjector.ts
Expand Up @@ -241,7 +241,7 @@ export function injectVitestModule(code: string, id: string, parse: (code: strin
s.prependRight(topNode.start, `const ${id.name} = ${binding};\n`)
}
}
else {
else if (parent.type !== 'ClassExpression') {
s.update(id.start, id.end, binding)
}
},
Expand Down
10 changes: 10 additions & 0 deletions test/core/test/injector-esm.test.ts
Expand Up @@ -933,3 +933,13 @@ function test() {
}"
`)
})

test('avoid binding ClassExpression', () => {
const result = injectSimpleCode(
'import Foo, {Bar} from \'./foo\';console.log(Foo, Bar);const obj = {foo: class Foo{}, bar: class Bar{}}',
)
expect(result).toMatchInlineSnapshot(`
"import { __vi_inject__ as __vi_esm_0__ } from './foo'
console.log(__vi_esm_0__.default, __vi_esm_0__.Bar);const obj = {foo: class Foo{}, bar: class Bar{}}"
`)
})

0 comments on commit 5c0ac4a

Please sign in to comment.