Move destructuring statements off export statements before processing - fixes T6720

This commit is contained in:
Logan Smyth
2015-12-05 14:27:42 -08:00
parent 412c65deb3
commit 29a3176276
3 changed files with 29 additions and 0 deletions

View File

@@ -325,6 +325,25 @@ export default function ({ types: t }) {
return {
visitor: {
ExportNamedDeclaration(path){
let declaration = path.get("declaration");
if (!declaration.isVariableDeclaration()) return;
if (!variableDeclarationHasPattern(declaration.node)) return;
let specifiers = [];
for (let name in path.getOuterBindingIdentifiers(path)){
let id = t.identifier(name);
specifiers.push(t.exportSpecifier(id, id));
}
// Split the declaration and export list into two declarations so that the variable
// declaration can be split up later without needing to worry about not being a
// top-level statement.
path.replaceWith(declaration.node);
path.insertAfter(t.exportNamedDeclaration(null, specifiers));
},
ForXStatement(path, file) {
let { node, scope } = path;
let left = node.left;