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