Skip to content

Commit

Permalink
Set TypeScript option esModuleInterop to true by default (#971)
Browse files Browse the repository at this point in the history
  • Loading branch information
fathyb authored and devongovett committed Mar 20, 2018
1 parent e3c90c4 commit 8002684
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"sinon": "^4.2.2",
"sourcemap-validator": "^1.0.6",
"stylus": "^0.54.5",
"typescript": "^2.6.2"
"typescript": "^2.7.0"
},
"scripts": {
"test": "cross-env NODE_ENV=test mocha",
Expand Down
6 changes: 5 additions & 1 deletion src/assets/TypeScriptAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ class TypeScriptAsset extends JSAsset {
let transpilerOptions = {
compilerOptions: {
module: typescript.ModuleKind.CommonJS,
jsx: typescript.JsxEmit.Preserve
jsx: typescript.JsxEmit.Preserve,

// it brings the generated output from TypeScript closer to that generated by Babel
// see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-7.html
esModuleInterop: true
},
fileName: this.relativeName
};
Expand Down
1 change: 1 addition & 0 deletions test/integration/typescript-interop/commonjs-module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = () => 'test passed'
3 changes: 3 additions & 0 deletions test/integration/typescript-interop/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import testModule from './commonjs-module'

export const test = testModule
20 changes: 20 additions & 0 deletions test/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,24 @@ describe('typescript', function() {
let file = fs.readFileSync(__dirname + '/dist/index.js', 'utf8');
assert(file.includes('React.createElement("div"'));
});

it('should use esModuleInterop by default', async function() {
let b = await bundle(
__dirname + '/integration/typescript-interop/index.ts'
);

assertBundleTree(b, {
name: 'index.js',
assets: ['index.ts', 'commonjs-module.js'],
childBundles: [
{
type: 'map'
}
]
});

let output = run(b);
assert.equal(typeof output.test, 'function');
assert.equal(output.test(), 'test passed');
});
});
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6087,7 +6087,7 @@ typedarray@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"

typescript@^2.6.2:
typescript@^2.7.0:
version "2.7.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.7.2.tgz#2d615a1ef4aee4f574425cdff7026edf81919836"

Expand Down

0 comments on commit 8002684

Please sign in to comment.