Closed
Description
TypeScript Version: 2.3.3
Input Code
My example is from a .js
file with --allowJs. I've tried with and without --allowSyntheticDefaultImports, doesn't seem to make a difference.
import chai from 'chai'
const should = chai.should();
Expected behavior:
I think this should generate something like:
var chai_1 = require("chai");
var should = chai_1.__esModule ? chai_1.default.should() : chai_1.should();
Actual behavior:
var chai_1 = require("chai");
var should = chai_1.default.should();
babel's output
Here's what I've seen babel generate.
var _chai = require('chai');
var _chai2 = _interopRequireDefault(_chai);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var should = _chai2.default.should();
workaround
Obviously I can work around this with a change to the input code:
import * as chai from 'chai'
const should = chai.should();
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
aluanhaddad commentedon May 26, 2017
Yes it should! See #16093 🎉 🎉
fatcerberus commentedon May 27, 2017
It'll be great to see this change. I recently switched from Babel to TS as my transpiler for miniSphere as it's so much faster, but since I support both CommonJS and ES modules, my standard library is entirely CJS. The change broke a few modules as a result.
[-]Should default import check __esModule flag at runtime?[/-][+]Please make default import check __esModule flag at runtime![/+]BurtHarris commentedon May 27, 2017
Updated title to make it a request rather than a question.
mhegazy commentedon Aug 23, 2017
tracked by #16093
mhegazy commentedon Sep 7, 2017
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.