Browse Source

fix misnamed exports of default imports in ES bundles (#513)

gh-669
Rich-Harris 9 years ago
parent
commit
c7be553684
  1. 5
      src/finalisers/es6.js
  2. 6
      test/form/export-default-import/_config.js
  3. 9
      test/form/export-default-import/_expected/amd.js
  4. 9
      test/form/export-default-import/_expected/cjs.js
  5. 5
      test/form/export-default-import/_expected/es6.js
  6. 10
      test/form/export-default-import/_expected/iife.js
  7. 13
      test/form/export-default-import/_expected/umd.js
  8. 3
      test/form/export-default-import/main.js

5
src/finalisers/es6.js

@ -47,10 +47,11 @@ export default function es6 ( bundle, magicString ) {
const specifiers = module.getExports().filter( notDefault ).map( name => { const specifiers = module.getExports().filter( notDefault ).map( name => {
const declaration = module.traceExport( name ); const declaration = module.traceExport( name );
const rendered = declaration.render( true );
return declaration.name === name ? return rendered === name ?
name : name :
`${declaration.name} as ${name}`; `${rendered} as ${name}`;
}); });
let exportBlock = specifiers.length ? `export { ${specifiers.join(', ')} };` : ''; let exportBlock = specifiers.length ? `export { ${specifiers.join(', ')} };` : '';

6
test/form/export-default-import/_config.js

@ -0,0 +1,6 @@
module.exports = {
description: 'correctly exports a default import, even in ES mode (#513)',
options: {
moduleName: 'myBundle'
}
};

9
test/form/export-default-import/_expected/amd.js

@ -0,0 +1,9 @@
define(['exports', 'x'], function (exports, x) { 'use strict';
x = 'default' in x ? x['default'] : x;
exports.x = x;
});

9
test/form/export-default-import/_expected/cjs.js

@ -0,0 +1,9 @@
'use strict';
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var x = _interopDefault(require('x'));
exports.x = x;

5
test/form/export-default-import/_expected/es6.js

@ -0,0 +1,5 @@
import x from 'x';
export { x };

10
test/form/export-default-import/_expected/iife.js

@ -0,0 +1,10 @@
(function (exports,x) {
'use strict';
x = 'default' in x ? x['default'] : x;
exports.x = x;
}((this.myBundle = this.myBundle || {}),x));

13
test/form/export-default-import/_expected/umd.js

@ -0,0 +1,13 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('x')) :
typeof define === 'function' && define.amd ? define(['exports', 'x'], factory) :
(factory((global.myBundle = global.myBundle || {}),global.x));
}(this, function (exports,x) { 'use strict';
x = 'default' in x ? x['default'] : x;
exports.x = x;
}));

3
test/form/export-default-import/main.js

@ -0,0 +1,3 @@
import x from 'x';
export { x };
Loading…
Cancel
Save