simplify class default exports
This commit is contained in:
@@ -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];
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
@@ -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;
|
||||
@@ -1,5 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
function foo() {}
|
||||
var Foo = undefined;
|
||||
Foo = function Foo() {};
|
||||
var Foo = function Foo() {};
|
||||
@@ -20,8 +20,9 @@ System.register([], function (_export) {
|
||||
|
||||
_export("default", function () {});
|
||||
|
||||
Foo = undefined;
|
||||
_export("default", Foo = function Foo() {});
|
||||
Foo = function Foo() {};
|
||||
|
||||
_export("default", Foo);
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
||||
@@ -17,6 +17,7 @@
|
||||
module.exports = function () {};
|
||||
|
||||
function foo() {}
|
||||
var Foo = undefined;
|
||||
module.exports = Foo = function Foo() {};
|
||||
});
|
||||
var Foo = function Foo() {};
|
||||
|
||||
module.exports = Foo;
|
||||
});
|
||||
Reference in New Issue
Block a user