Skip to content

Commit

Permalink
don't need __toModule when not bundling
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed May 25, 2020
1 parent 5e9d45c commit bd6c82b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
14 changes: 7 additions & 7 deletions internal/bundler/bundler_test.go
Expand Up @@ -614,15 +614,15 @@ func TestImportFormsWithMinifyIdentifiersAndNoBundle(t *testing.T) {
expected: map[string]string{
"/out.js": `import "foo";
import {} from "foo";
import * as e from "foo";
import {a as f, b as g} from "foo";
import h from "foo";
import j, * as i from "foo";
import k, {a2 as l, b as m} from "foo";
const n = [import("foo"), function a() {
import * as a from "foo";
import {a as b, b as c} from "foo";
import d from "foo";
import f, * as e from "foo";
import g, {a2 as h, b as i} from "foo";
const j = [import("foo"), function C() {
return import("foo");
}];
console.log(e, f, g, h, j, i, k, l, m, n);
console.log(a, b, c, d, f, e, g, h, i, j);
`,
},
})
Expand Down
2 changes: 1 addition & 1 deletion internal/bundler/linker.go
Expand Up @@ -983,7 +983,7 @@ func (c *linkerContext) includeFile(sourceIndex uint32, entryPoint uint, distanc
// This is an ES6 import of a module that's potentially CommonJS
needsToModule = true
}
} else {
} else if !c.options.OutputFormat.KeepES6ImportExportSyntax() {
// This is an ES6 import of an external module that may be CommonJS
needsToModule = true
}
Expand Down
20 changes: 20 additions & 0 deletions scripts/js-api-tests.js
Expand Up @@ -47,6 +47,26 @@ let buildTests = {
}

let transformTests = {
async cjs_require({ service }) {
const { js } = await service.transform(`const {foo} = require('path')`, {})
assert.strictEqual(js, `const {foo} = require("path");\n`)
},

async cjs_exports({ service }) {
const { js } = await service.transform(`exports.foo = 123`, {})
assert.strictEqual(js, `exports.foo = 123;\n`)
},

async es6_import({ service }) {
const { js } = await service.transform(`import {foo} from 'path'`, {})
assert.strictEqual(js, `import {foo} from "path";\n`)
},

async es6_export({ service }) {
const { js } = await service.transform(`export const foo = 123`, {})
assert.strictEqual(js, `export const foo = 123;\n`)
},

async jsx({ service }) {
const { js } = await service.transform(`console.log(<div/>)`, { loader: 'jsx' })
assert.strictEqual(js, `console.log(React.createElement("div", null));\n`)
Expand Down

0 comments on commit bd6c82b

Please sign in to comment.