Browse Source

Merge pull request #205 from rollup/use-all-export-declarations

Use all export declarations
better-aggressive
Rich Harris 9 years ago
parent
commit
6cfa0a9564
  1. 2
      src/Bundle.js
  2. 2
      src/Module.js
  3. 35
      test/function/namespaces-are-frozen/_config.js
  4. 3
      test/function/namespaces-are-frozen/main.js
  5. 2
      test/function/namespaces-are-frozen/mod.js

2
src/Bundle.js

@ -58,7 +58,7 @@ export default class Bundle {
const declaration = entryModule.traceExport( name );
declaration.isExported = true;
if ( declaration.statement ) declaration.use();
declaration.use();
});
let settled = false;

2
src/Module.js

@ -111,7 +111,7 @@ class SyntheticNamespaceDeclaration {
return `${indentString}${name}: ${original.render()}`;
});
return `var ${this.render()} = {\n${members.join( ',\n' )}\n};\n\n`;
return `var ${this.render()} = Object.freeze({\n${members.join( ',\n' )}\n});\n\n`;
}
render () {

35
test/function/namespaces-are-frozen/_config.js

@ -0,0 +1,35 @@
var assert = require( 'assert' );
module.exports = {
description: 'namespaces should be non-extensible and its properties immutatable and non-configurable',
exports: function ( exports ) {
const ns = exports.ns;
function extend ( obj ) {
'use strict';
obj.newProperty = true;
}
function reconfigure ( obj ) {
Object.defineProperty( obj, 'a', { value: null } );
}
function mutate ( obj ) {
'use strict';
obj.a = 2;
}
assert.throws(function () {
extend( ns );
});
assert.throws(function () {
reconfigure( ns );
});
assert.throws(function () {
mutate( ns );
});
}
};

3
test/function/namespaces-are-frozen/main.js

@ -0,0 +1,3 @@
import * as ns from './mod';
export { ns };

2
test/function/namespaces-are-frozen/mod.js

@ -0,0 +1,2 @@
export var a = 1;
export var b = 2;
Loading…
Cancel
Save