Browse Source

support export from

contingency-plan
Rich Harris 10 years ago
parent
commit
8b5dee744f
  1. 19
      src/Module.js
  2. 7
      test/samples/export-from-internal-module/_config.js
  3. 1
      test/samples/export-from-internal-module/foo.js
  4. 1
      test/samples/export-from-internal-module/main.js

19
src/Module.js

@ -12,7 +12,9 @@ export default class Module {
constructor ({ path, code, bundle }) {
this.path = path;
this.relativePath = relative( bundle.base, path ).slice( 0, -3 ); // remove .js
this.code = new MagicString( code );
this.code = new MagicString( code, {
filename: path
});
this.bundle = bundle;
this.ast = parse( code, {
@ -56,10 +58,12 @@ export default class Module {
this.exportStatements = [];
this.ast.body.forEach( node => {
let source;
// import foo from './foo';
// import { bar } from './bar';
if ( node.type === 'ImportDeclaration' ) {
const source = node.source.value;
source = node.source.value;
node.specifiers.forEach( specifier => {
const isDefault = specifier.type === 'ImportDefaultSpecifier';
@ -97,6 +101,9 @@ export default class Module {
// export var foo = 42;
// export function foo () {}
else if ( node.type === 'ExportNamedDeclaration' ) {
// export { foo } from './foo';
source = node.source && node.source.value;
if ( node.specifiers.length ) {
// export { foo, bar, baz }
node.specifiers.forEach( specifier => {
@ -107,6 +114,14 @@ export default class Module {
localName,
exportedName
};
if ( source ) {
this.imports[ localName ] = {
source,
localName,
name: exportedName
};
}
});
}

7
test/samples/export-from-internal-module/_config.js

@ -0,0 +1,7 @@
module.exports = {
description: 'exports from an internal module',
exports: function ( exports, assert ) {
assert.equal( exports.foo, 42 );
},
solo: true
};

1
test/samples/export-from-internal-module/foo.js

@ -0,0 +1 @@
export var foo = 42;

1
test/samples/export-from-internal-module/main.js

@ -0,0 +1 @@
export { foo } from './foo';
Loading…
Cancel
Save