From f1d35aad7e9b0567cf54cb55e339a097bfa3ac07 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 19 Aug 2015 10:28:37 -0400 Subject: [PATCH] use arrays, not objects, to track variable declarations --- src/Bundle.js | 2 +- src/Module.js | 7 ++++--- src/Statement.js | 5 ----- src/ast/Scope.js | 5 +++-- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/Bundle.js b/src/Bundle.js index 5688d20..c70cfc1 100644 --- a/src/Bundle.js +++ b/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; }); }); diff --git a/src/Module.js b/src/Module.js index a3ad6c8..9964ae2 100644 --- a/src/Module.js +++ b/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 => { diff --git a/src/Statement.js b/src/Statement.js index 228e5f1..d4117e1 100644 --- a/src/Statement.js +++ b/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 ) { diff --git a/src/ast/Scope.js b/src/ast/Scope.js index 4c88967..6cbc6ce 100644 --- a/src/ast/Scope.js +++ b/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 ) } }