Browse Source

use arrays, not objects, to track variable declarations

contingency-plan
Rich Harris 9 years ago
parent
commit
f1d35aad7e
  1. 2
      src/Bundle.js
  2. 7
      src/Module.js
  3. 5
      src/Statement.js
  4. 5
      src/ast/Scope.js

2
src/Bundle.js

@ -295,7 +295,7 @@ export default class Bundle {
let getterExports = [];
this.orderedModules.forEach( module => {
keys( module.varDeclarations ).forEach( name => {
module.varDeclarations.forEach( name => {
varDeclarations[ module.replacements[ name ] || name ] = true;
});
});

7
src/Module.js

@ -64,8 +64,9 @@ export default class Module {
this.replacements = blank();
this.varDeclarations = [];
this.definitions = blank();
this.varDeclarations = blank();
this.definitionPromises = blank();
this.modifications = blank();
@ -201,8 +202,8 @@ export default class Module {
this.definitions[ name ] = statement;
});
keys( statement.declaresVar ).forEach( name => {
this.varDeclarations[ name ] = statement;
statement.scope.varDeclarations.forEach( name => {
this.varDeclarations.push( name );
});
keys( statement.modifies ).forEach( name => {

5
src/Statement.js

@ -18,7 +18,6 @@ export default class Statement {
this.scope = new Scope();
this.defines = blank();
this.declaresVar = blank();
this.modifies = blank();
this.dependsOn = blank();
this.stronglyDependsOn = blank();
@ -143,10 +142,6 @@ export default class Statement {
keys( scope.declarations ).forEach( name => {
this.defines[ name ] = true;
});
keys( scope.varDeclarations ).forEach( name => {
this.declaresVar[ name ] = true;
});
}
checkForReads ( scope, node, parent, strong ) {

5
src/ast/Scope.js

@ -12,9 +12,10 @@ export default class Scope {
this.parent = options.parent;
this.depth = this.parent ? this.parent.depth + 1 : 0;
this.declarations = blank();
this.varDeclarations = blank();
this.isBlockScope = !!options.block;
this.varDeclarations = [];
if ( options.params ) {
options.params.forEach( param => {
this.declarations[ param.name ] = param;
@ -31,7 +32,7 @@ export default class Scope {
this.parent.addDeclaration( name, declaration, isVar );
} else {
this.declarations[ name ] = declaration;
if ( isVar ) this.varDeclarations[ name ] = true;
if ( isVar ) this.varDeclarations.push( name )
}
}

Loading…
Cancel
Save