Browse Source

remove some unused code, add some additional tests

better-aggressive
Rich Harris 9 years ago
parent
commit
313b108f41
  1. 13
      src/Module.js
  2. 18
      src/Statement.js
  3. 30
      test/test.js

13
src/Module.js

@ -586,19 +586,6 @@ export default class Module {
magicString.remove( statement.start, statement.next );
return;
}
// skip `export var foo;` if foo is exported
if ( isEmptyExportedVarDeclaration( statement.node.declaration, this.exports, toExport ) ) {
magicString.remove( statement.start, statement.next );
return;
}
}
// skip empty var declarations for exported bindings
// (otherwise we're left with `exports.foo;`, which is useless)
if ( isEmptyExportedVarDeclaration( statement.node, this.exports, toExport ) ) {
magicString.remove( statement.start, statement.next );
return;
}
// split up/remove var declarations as necessary

18
src/Statement.js

@ -459,24 +459,6 @@ export default class Statement {
magicString.overwrite( node.start, id.end, bundleExports[ name ], true );
id._skip = true;
}
// otherwise, we insert the `exports.foo = foo` after the declaration
else {
const exportInitialisers = node.declarations
.map( declarator => declarator.id.name )
.filter( name => !!bundleExports[ name ] )
.map( name => `\n${bundleExports[name]} = ${name};` )
.join( '' );
if ( exportInitialisers ) {
// TODO clean this up
try {
magicString.insert( node.end, exportInitialisers );
} catch ( err ) {
magicString.append( exportInitialisers );
}
}
}
}
}

30
test/test.js

@ -45,6 +45,36 @@ describe( 'rollup', function () {
it( 'has a rollup method', function () {
assert.equal( typeof rollup.rollup, 'function' );
});
it( 'fails without options or options.entry', function () {
assert.throws( function () {
rollup.rollup();
}, /must supply options\.entry/ );
assert.throws( function () {
rollup.rollup({});
}, /must supply options\.entry/ );
});
});
describe( 'bundle.write()', function () {
it( 'fails without options or options.dest', function () {
return rollup.rollup({
entry: 'x',
resolveId: function () { return 'test'; },
load: function () {
return '// empty';
}
}).then( function ( bundle ) {
assert.throws( function () {
bundle.write();
}, /must supply options\.dest/ );
assert.throws( function () {
bundle.write({});
}, /must supply options\.dest/ );
});
});
});
describe( 'function', function () {

Loading…
Cancel
Save