-
-
Notifications
You must be signed in to change notification settings - Fork 592
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(commonjs): correctly wrap a default class export from cjs module (#β¦
β¦1350) * fix: correctly wraps the default export from a CommonJS module when it is a class Fixes https://github.com/vitejs/vite/issues/10853 Since 3c00191 the namespace became callable when requiring ESM with function default, but it isn't newable, leading to errors when the function is actually a class. * test: update snapshots as the helper code has changed
- Loading branch information
1 parent
19ad1b6
commit ab05216
Showing
8 changed files
with
138 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/commonjs/test/fixtures/samples/es-module-with-class-as-default-export/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const Foo = require('./other.js'); | ||
|
||
new Foo(1, 2) |
7 changes: 7 additions & 0 deletions
7
packages/commonjs/test/fixtures/samples/es-module-with-class-as-default-export/other.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default class Foo { | ||
constructor(...args) { | ||
if (args.length !== 2) { | ||
throw new Error(`new Foo(...) requires exactly 2 arguments, received ${args.length}`); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters