Skip to content

Commit

Permalink
change some magic numbers to hoist exports
Browse files Browse the repository at this point in the history
fixes #4753
  • Loading branch information
sokra committed May 4, 2017
1 parent bf3652b commit a952bb9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/dependencies/HarmonyCompatibilityDependency.js
Expand Up @@ -22,7 +22,7 @@ HarmonyCompatibilityDependency.Template = class HarmonyExportDependencyTemplate
if(usedExports && !Array.isArray(usedExports)) {
const exportName = dep.originModule.exportsArgument || "exports";
const content = `Object.defineProperty(${exportName}, \"__esModule\", { value: true });\n`;
source.insert(-1, content);
source.insert(-10, content);
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion lib/dependencies/HarmonyExportDependencyParserPlugin.js
Expand Up @@ -45,7 +45,7 @@ module.exports = class HarmonyExportDependencyParserPlugin {
} else {
const immutable = statement.declaration && isImmutableStatement(statement.declaration);
const hoisted = statement.declaration && isHoistedStatement(statement.declaration);
dep = new HarmonyExportSpecifierDependency(parser.state.module, id, name, !immutable || hoisted ? -0.5 : (statement.range[1] + 0.5), immutable);
dep = new HarmonyExportSpecifierDependency(parser.state.module, id, name, !immutable || hoisted ? -2 : (statement.range[1] + 0.5), immutable);
}
dep.loc = Object.create(statement.loc);
dep.loc.index = idx;
Expand Down
6 changes: 6 additions & 0 deletions test/cases/parsing/harmony-export-hoist/bar.js
@@ -0,0 +1,6 @@
import { foo, foo2 } from "./foo";

export default {
foo: foo,
foo2: foo2
};
12 changes: 12 additions & 0 deletions test/cases/parsing/harmony-export-hoist/foo.js
@@ -0,0 +1,12 @@
import {bar} from "./bar";

export function foo() {
return "ok";
}

function foo2() {
return "ok";
}
export { foo2 }

export { default } from "./bar";
9 changes: 9 additions & 0 deletions test/cases/parsing/harmony-export-hoist/index.js
@@ -0,0 +1,9 @@
"use strict";

it("should hoist exports", function() {
var result = require("./foo").default;
(typeof result.foo).should.have.eql("function");
(typeof result.foo2).should.have.eql("function");
result.foo().should.be.eql("ok");
result.foo2().should.be.eql("ok");
});

0 comments on commit a952bb9

Please sign in to comment.