fix esModule error for realsies now

This commit is contained in:
Sebastian McKenzie 2015-07-29 04:21:34 +01:00
parent f1d42e7beb
commit 2c197a508d
2 changed files with 14 additions and 12 deletions

View File

@ -438,10 +438,10 @@ export default class File {
errorWithNode(node, msg, Error = SyntaxError) {
var err;
if (node && node.loc) {
var loc = node.loc.start;
err = new Error(`Line ${loc.line}: ${msg}`);
err.loc = loc;
var loc = node && (node.loc || node._loc);
if (loc) {
err = new Error(`Line ${loc.start.line}: ${msg}`);
err.loc = loc.start;
} else {
// todo: find errors with nodes inside to at least point to something
err = new Error("There's been an error on a dynamic node. This is almost certainly an internal error. Please report it.");

View File

@ -23,7 +23,13 @@ function getDeclar(node) {
*/
function buildExportSpecifier(id) {
return t.exportSpecifier(t.identifier(id.name), t.identifier(id.name));
return t.exportSpecifier(cloneIdentifier(id), cloneIdentifier(id));
}
function cloneIdentifier({ name, loc }) {
var id = t.identifier(name);
id._loc = loc;
return id;
}
export var metadata = {
@ -84,13 +90,9 @@ export var visitor = {
return nodes;
} else if (t.isFunctionDeclaration(declar)) {
// export function Foo() {}
let nodes = [
getDeclar(node),
t.exportNamedDeclaration(null, [buildExportSpecifier(declar.id)])
];
nodes[1]._blockHoist = 2; // ensure it's hoisted
return nodes;
var newExport = t.exportNamedDeclaration(null, [buildExportSpecifier(declar.id)]);
newExport._blockHoist = 2;
return [getDeclar(node), newExport];
} else if (t.isVariableDeclaration(declar)) {
// export var foo = "bar";
var specifiers = [];