Skip to content

Commit

Permalink
hoist imports
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Jun 15, 2016
1 parent 7109be5 commit 64972f2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
15 changes: 14 additions & 1 deletion lib/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,21 @@ Parser.prototype.walkMethodDefinition = function walkMethodDefinition(methodDefi

Parser.prototype.walkStatements = function walkStatements(statements) {
statements.forEach(function(statement) {
this.walkStatement(statement);
if(this.isHoistedStatement(statement))
this.walkStatement(statement);
}, this);
statements.forEach(function(statement) {
if(!this.isHoistedStatement(statement))
this.walkStatement(statement);
}, this);
};

Parser.prototype.isHoistedStatement = function isHoistedStatement(statement) {
switch(statement.type) {
case "ImportDeclaration":
return true;
}
return false;
};

Parser.prototype.walkStatement = function walkStatement(statement) {
Expand Down
5 changes: 3 additions & 2 deletions test/cases/parsing/harmony-spec/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { value, add } from "./live";
import { value as value2, add as add2 } from "./live-es5";
import { value as valueEval, evalInModule } from "./eval";
import { getLog } from "./order-tracker";
import "./order-c";
import cycleValue from "./export-cycle-a";
Expand Down Expand Up @@ -29,4 +28,6 @@ it("should execute modules in the correct order", function() {

it("should bind exports before the module executes", function() {
cycleValue.should.be.eql(true);
});
});

import { value as valueEval, evalInModule } from "./eval";
3 changes: 3 additions & 0 deletions test/cases/parsing/issue-2528-2/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
foo();

import { foo } from './module';
3 changes: 3 additions & 0 deletions test/cases/parsing/issue-2528-2/module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function foo() {
it("should run", function() {});
}

0 comments on commit 64972f2

Please sign in to comment.