mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge pull request #2547 from Microsoft/exportDefault
Export default fixes
This commit is contained in:
+8
-10
@@ -2424,11 +2424,11 @@ module ts {
|
||||
if (node.flags & NodeFlags.Export) {
|
||||
writeLine();
|
||||
emitStart(node);
|
||||
if (node.name) {
|
||||
emitModuleMemberName(node);
|
||||
if (node.flags & NodeFlags.Default) {
|
||||
write("exports.default");
|
||||
}
|
||||
else {
|
||||
write("exports.default");
|
||||
emitModuleMemberName(node);
|
||||
}
|
||||
write(" = ");
|
||||
emitDeclarationName(node);
|
||||
@@ -2919,16 +2919,14 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
function shouldEmitFunctionName(node: Declaration): boolean {
|
||||
// Emit a declaration name for the function iff:
|
||||
// it is a function expression with a name provided
|
||||
// it is a function declaration with a name provided
|
||||
// it is a function declaration is not the default export, and is missing a name (emit a generated name for it)
|
||||
function shouldEmitFunctionName(node: FunctionLikeDeclaration) {
|
||||
if (node.kind === SyntaxKind.FunctionExpression) {
|
||||
// Emit name if one is present
|
||||
return !!node.name;
|
||||
}
|
||||
else if (node.kind === SyntaxKind.FunctionDeclaration) {
|
||||
return !!node.name || (languageVersion >= ScriptTarget.ES6 && !(node.flags & NodeFlags.Default));
|
||||
if (node.kind === SyntaxKind.FunctionDeclaration) {
|
||||
// Emit name if one is present, or emit generated name in down-level case (for export default case)
|
||||
return !!node.name || languageVersion < ScriptTarget.ES6;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ var C = (function () {
|
||||
C.prototype.method = function () { };
|
||||
return C;
|
||||
})();
|
||||
exports.C = C;
|
||||
exports.default = C;
|
||||
|
||||
|
||||
//// [es5ExportDefaultClassDeclaration.d.ts]
|
||||
|
||||
@@ -5,7 +5,7 @@ export default function f() { }
|
||||
|
||||
//// [es5ExportDefaultFunctionDeclaration.js]
|
||||
function f() { }
|
||||
exports.f = f;
|
||||
exports.default = f;
|
||||
|
||||
|
||||
//// [es5ExportDefaultFunctionDeclaration.d.ts]
|
||||
|
||||
@@ -4,7 +4,7 @@ export default function () { }
|
||||
|
||||
|
||||
//// [es5ExportDefaultFunctionDeclaration2.js]
|
||||
function () { }
|
||||
function default_1() { }
|
||||
exports.default = default_1;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user