Browse Source

Added `Scope.getNames()` to avoid exposing internals.

gh-109
Oskar Segersvärd 10 years ago
parent
commit
f680aae304
  1. 15
      src/Bundle.js
  2. 13
      src/Scope.js
  3. 3
      src/finalisers/es6.js

15
src/Bundle.js

@ -196,7 +196,7 @@ export default class Bundle {
});
if ( format !== 'es6' && exportMode === 'named' ) {
keys( this.exports.names )
this.exports.getNames()
.forEach( name => {
const canonicalName = this.exports.lookup( name ).name;
@ -216,7 +216,7 @@ export default class Bundle {
// since we're rewriting variable exports, we want to
// ensure we don't try and export them again at the bottom
this.toExport = keys( this.exports.names )
this.toExport = this.exports.getNames()
.filter( key => !varExports[ key ] );
let magicString = new MagicString.Bundle({ separator: '\n\n' });
@ -280,12 +280,17 @@ export default class Bundle {
}
sort () {
let seen = {};
// Set of visited module ids.
let seen = blank();
let ordered = [];
let hasCycles;
let strongDeps = {};
let stronglyDependsOn = {};
// Map from module id to list of modules.
let strongDeps = blank();
// Map from module id to boolean.
let stronglyDependsOn = blank();
function visit ( module ) {
seen[ module.id ] = true;

13
src/Scope.js

@ -62,7 +62,7 @@ export default class Scope {
this.ids.filter( isntReference ).forEach( id => {
if ( typeof id === 'string' ) {
throw new Error( `Required name ${id} undefined!` );
throw new Error( `Required name "${id}" is undefined!` );
}
let name = id.name;
@ -78,8 +78,8 @@ export default class Scope {
// Defines `name` in the scope to be `id`.
// If no `id` is supplied, a plain `Identifier` is created.
define ( name, id = new Identifier( name ) ) {
this.ids[ this.index( name ) ] = id;
define ( name, id ) {
this.ids[ this.index( name ) ] = id || new Identifier( name );
}
// TODO: rename! Too similar to `define`.
@ -87,13 +87,18 @@ export default class Scope {
return name in this.names;
}
// Return the names referenced to in the scope.
getNames () {
return keys( this.names );
}
// *private, don't use*
//
// Return `name`'s index in the `ids` array if it exists,
// otherwise returns the index to a new placeholder slot.
index ( name ) {
if ( !( name in this.names ) ) {
return this.names[ name ] = this.ids.push( `"${name}"` ) - 1;
return this.names[ name ] = this.ids.push( name ) - 1;
}
return this.names[ name ];

3
src/finalisers/es6.js

@ -1,7 +1,6 @@
import { keys } from '../utils/object';
function specifiersFor ( scope ) {
return keys( scope.names )
return scope.getNames()
.filter( notDefault )
.map( name => {
const id = scope.lookup( name );

Loading…
Cancel
Save