create new export named declaration when we're splitting it up - fixes #2092

This commit is contained in:
Sebastian McKenzie 2015-07-28 19:58:51 +01:00
parent 90fb36d3ea
commit bda0d5cc68
6 changed files with 29 additions and 6 deletions

View File

@ -4,7 +4,6 @@
// a generator function as a default then regenerator will destroy the export // a generator function as a default then regenerator will destroy the export
// declaration and leave a variable declaration in it's place... yeah, handy. // declaration and leave a variable declaration in it's place... yeah, handy.
import clone from "lodash/lang/clone";
import * as t from "../../../types"; import * as t from "../../../types";
/** /**
@ -85,11 +84,12 @@ export var visitor = {
return nodes; return nodes;
} else if (t.isFunctionDeclaration(declar)) { } else if (t.isFunctionDeclaration(declar)) {
// export function Foo() {} // export function Foo() {}
node.specifiers = [buildExportSpecifier(declar.id)];
node._blockHoist = 2;
let nodes = [getDeclar(node), node]; let nodes = [
node.declaration = null; getDeclar(node),
t.exportNamedDeclaration(null, [buildExportSpecifier(declar.id)])
];
nodes[1]._blockHoist = 2; // ensure it's hoisted
return nodes; return nodes;
} else if (t.isVariableDeclaration(declar)) { } else if (t.isVariableDeclaration(declar)) {
// export var foo = "bar"; // export var foo = "bar";

View File

@ -0,0 +1,11 @@
export function foo() {
console.log(1);
console.log(2);
console.log(3);
}
export function bar() {
console.log(1);
console.log(2);
console.log(3);
}

View File

@ -0,0 +1,10 @@
"use strict";export { foo };export { bar };function foo() {
console.log(1);
console.log(2);
console.log(3);}
function bar() {
console.log(1);
console.log(2);
console.log(3);}

View File

@ -0,0 +1,3 @@
{
"retainLines": true
}

View File

@ -1,7 +1,6 @@
"use strict"; "use strict";
export { foo }; export { foo };
export { bar }; export { bar };
function foo() {} function foo() {}