Browse Source

check that _interopDefault's input is a non-null object fixes #474

gh-669
Boris Sirota 9 years ago
parent
commit
b1658066ed
  1. 2
      src/finalisers/cjs.js
  2. 2
      test/form/external-imports-custom-names/_expected/cjs.js
  3. 2
      test/form/external-imports/_expected/cjs.js

2
src/finalisers/cjs.js

@ -6,7 +6,7 @@ export default function cjs ( bundle, magicString, { exportMode }, options ) {
const hasDefaultImport = bundle.externalModules.some( mod => mod.declarations.default); const hasDefaultImport = bundle.externalModules.some( mod => mod.declarations.default);
if (hasDefaultImport) { if (hasDefaultImport) {
intro += `function _interopDefault (ex) { return 'default' in ex ? ex['default'] : ex; }\n\n`; intro += `function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }\n\n`;
} }
// TODO handle empty imports, once they're supported // TODO handle empty imports, once they're supported

2
test/form/external-imports-custom-names/_expected/cjs.js

@ -1,6 +1,6 @@
'use strict'; 'use strict';
function _interopDefault (ex) { return 'default' in ex ? ex['default'] : ex; } function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var $ = _interopDefault(require('jquery')); var $ = _interopDefault(require('jquery'));

2
test/form/external-imports/_expected/cjs.js

@ -1,6 +1,6 @@
'use strict'; 'use strict';
function _interopDefault (ex) { return 'default' in ex ? ex['default'] : ex; } function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var factory = _interopDefault(require('factory')); var factory = _interopDefault(require('factory'));
var baz = require('baz'); var baz = require('baz');

Loading…
Cancel
Save