simplify class default exports

This commit is contained in:
Sebastian McKenzie
2015-01-26 16:00:30 +11:00
parent 3db7811f00
commit 4b6203d1f4
7 changed files with 20 additions and 25 deletions

View File

@@ -7,21 +7,13 @@ exports.ExportDeclaration = function (node, parent, scope, context, file) {
if (node.default) {
if (t.isClassDeclaration(declar)) {
// we need to replace default class declarations with an assignment
// because VariableDeclaration nodes aren't allowed in `export default`
node.declaration = t.assignmentExpression("=", declar.id, t.toExpression(declar));
return [
t.variableDeclaration("let", [
t.variableDeclarator(declar.id)
]),
node
];
node.declaration = declar.id;
return [declar, node];
}
} else {
if (t.isFunctionDeclaration(declar)) {
node.specifiers = [t.importSpecifier(declar.id, declar.id)];
node.declaration = null;
node.specifiers = [t.importSpecifier(declar.id, declar.id)];
node._blockHoist = 2;
return [declar, node];
}

View File

@@ -100,7 +100,7 @@ var run = function (task, done) {
try {
chai.expect(actualCode).to.be.equal(expectCode, actual.loc + " !== " + expect.loc);
} catch (err) {
//require("fs").writeFileSync(expect.loc, actualCode);
require("fs").writeFileSync(expect.loc, actualCode);
throw err;
}
}

View File

@@ -11,6 +11,7 @@ define(["exports", "module"], function (exports, module) {
module.exports = function () {};
function foo() {}
var Foo = undefined;
module.exports = Foo = function Foo() {};
});
var Foo = function Foo() {};
module.exports = Foo;
});

View File

@@ -10,5 +10,6 @@ module.exports = function () {};
module.exports = function () {};
function foo() {}
var Foo = undefined;
module.exports = Foo = function Foo() {};
var Foo = function Foo() {};
module.exports = Foo;

View File

@@ -1,5 +1,4 @@
"use strict";
function foo() {}
var Foo = undefined;
Foo = function Foo() {};
var Foo = function Foo() {};

View File

@@ -20,8 +20,9 @@ System.register([], function (_export) {
_export("default", function () {});
Foo = undefined;
_export("default", Foo = function Foo() {});
Foo = function Foo() {};
_export("default", Foo);
}
};
});
});

View File

@@ -17,6 +17,7 @@
module.exports = function () {};
function foo() {}
var Foo = undefined;
module.exports = Foo = function Foo() {};
});
var Foo = function Foo() {};
module.exports = Foo;
});