Skip to content

Commit

Permalink
Add failing test case
Browse files Browse the repository at this point in the history
  • Loading branch information
rtsao committed Aug 20, 2020
1 parent 9f93961 commit 1bf97e6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
21 changes: 21 additions & 0 deletions internal/bundler/bundler_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
13 changes: 13 additions & 0 deletions internal/bundler/snapshots/snapshots_default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ----------
Expand Down

0 comments on commit 1bf97e6

Please sign in to comment.