diff --git a/internal/bundler/bundler_default_test.go b/internal/bundler/bundler_default_test.go index 82e6b8f7142..855abfd9bec 100644 --- a/internal/bundler/bundler_default_test.go +++ b/internal/bundler/bundler_default_test.go @@ -79,6 +79,27 @@ func TestNestedCommonJS(t *testing.T) { }) } +// This test makes sure that NewExpressions containing require() calls aren't +// broken. +func TestNewExpressionCommonJS(t *testing.T) { + default_suite.expectBundled(t, bundled{ + files: map[string]string{ + "/entry.js": ` + new (require("./foo.js")).Foo(); + `, + "/foo.js": ` + class Foo {} + module.exports = {Foo}; + `, + }, + entryPaths: []string{"/entry.js"}, + options: config.Options{ + IsBundling: true, + AbsOutputFile: "/out.js", + }, + }) +} + func TestCommonJSFromES6(t *testing.T) { default_suite.expectBundled(t, bundled{ files: map[string]string{ diff --git a/internal/bundler/snapshots/snapshots_default.txt b/internal/bundler/snapshots/snapshots_default.txt index fab18086c42..97e0fb025f1 100644 --- a/internal/bundler/snapshots/snapshots_default.txt +++ b/internal/bundler/snapshots/snapshots_default.txt @@ -1203,6 +1203,19 @@ TestNestedScopeBug a(); })(); +================================================================================ +TestNewExpressionCommonJS +---------- /out.js ---------- +// /foo.js +var require_foo = __commonJS((exports, module) => { + class Foo { + } + module.exports = {Foo}; +}); + +// /entry.js +new (require_foo()).Foo(); + ================================================================================ TestNodeModules ---------- /Users/user/project/out.js ----------