Browse Source

Merge pull request #271 from rollup/gh-270-alt

Disregard re-export statements
better-aggressive
Rich Harris 9 years ago
parent
commit
a1f13cd93e
  1. 2
      src/Module.js
  2. 3
      src/Statement.js
  3. 8
      test/function/export-from-no-local-binding-var/_config.js
  4. 1
      test/function/export-from-no-local-binding-var/foo.js
  5. 3
      test/function/export-from-no-local-binding-var/main.js

2
src/Module.js

@ -344,7 +344,7 @@ export default class Module {
if ( declaration ) {
declaration.addReference( reference );
} else if ( statement.node.type !== 'ExportNamedDeclaration' || !this.reexports[ reference.name ] ) {
} else {
// TODO handle globals
this.bundle.assumedGlobals[ reference.name ] = true;
}

3
src/Statement.js

@ -100,6 +100,9 @@ export default class Statement {
module.bundle.onwarn( `Use of \`eval\` (in ${module.id}) is discouraged, as it may cause issues with minification. See https://github.com/rollup/rollup/wiki/Troubleshooting#avoiding-eval for more details` );
}
// skip re-export declarations
if ( node.type === 'ExportNamedDeclaration' && node.source ) return this.skip();
if ( node.type === 'TemplateElement' ) stringLiteralRanges.push([ node.start, node.end ]);
if ( node.type === 'Literal' && typeof node.value === 'string' && /\n/.test( node.raw ) ) {
stringLiteralRanges.push([ node.start + 1, node.end - 1 ]);

8
test/function/export-from-no-local-binding-var/_config.js

@ -0,0 +1,8 @@
var assert = require( 'assert' );
module.exports = {
description: 'export from does not create a local binding',
runtimeError: function ( err ) {
assert.ok( /foo is not defined/.test( err.message ) );
}
};

1
test/function/export-from-no-local-binding-var/foo.js

@ -0,0 +1 @@
export default function() {}

3
test/function/export-from-no-local-binding-var/main.js

@ -0,0 +1,3 @@
export {default as foo} from './foo';
export var foo1 = foo(); // This should fail as foo lacks a local binding.
Loading…
Cancel
Save