parent
1fce34be71
commit
3f266fb728
|
@ -541,7 +541,7 @@ namespace ts {
|
|||
*
|
||||
* @param node A ClassDeclaration node.
|
||||
*/
|
||||
function visitClassDeclaration(node: ClassDeclaration): Statement {
|
||||
function visitClassDeclaration(node: ClassDeclaration): VisitResult<Statement> {
|
||||
// [source]
|
||||
// class C { }
|
||||
//
|
||||
|
@ -552,8 +552,17 @@ namespace ts {
|
|||
// return C;
|
||||
// }());
|
||||
|
||||
const modifierFlags = getModifierFlags(node);
|
||||
const isExported = modifierFlags & ModifierFlags.Export;
|
||||
const isDefault = modifierFlags & ModifierFlags.Default;
|
||||
|
||||
// Add an `export` modifier to the statement if needed (for `--target es5 --module es6`)
|
||||
const modifiers = isExported && !isDefault
|
||||
? filter(node.modifiers, isExportModifier)
|
||||
: undefined;
|
||||
|
||||
const statement = createVariableStatement(
|
||||
/*modifiers*/ undefined,
|
||||
modifiers,
|
||||
createVariableDeclarationList([
|
||||
createVariableDeclaration(
|
||||
getDeclarationName(node, /*allowComments*/ true),
|
||||
|
@ -566,9 +575,26 @@ namespace ts {
|
|||
|
||||
setOriginalNode(statement, node);
|
||||
startOnNewLine(statement);
|
||||
|
||||
// Add an `export default` statement for default exports (for `--target es5 --module es6`)
|
||||
if (isExported && isDefault) {
|
||||
const statements: Statement[] = [statement];
|
||||
statements.push(createExportAssignment(
|
||||
/*decorators*/ undefined,
|
||||
/*modifiers*/ undefined,
|
||||
/*isExportEquals*/ false,
|
||||
getDeclarationName(node, /*allowComments*/ false)
|
||||
));
|
||||
return statements;
|
||||
}
|
||||
|
||||
return statement;
|
||||
}
|
||||
|
||||
function isExportModifier(node: Modifier) {
|
||||
return node.kind === SyntaxKind.ExportKeyword;
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a ClassExpression and transforms it into an expression.
|
||||
*
|
||||
|
|
|
@ -23,3 +23,4 @@ var A = (function () {
|
|||
};
|
||||
return A;
|
||||
}());
|
||||
export default A;
|
||||
|
|
|
@ -27,7 +27,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var C = (function () {
|
||||
export var C = (function () {
|
||||
function C() {
|
||||
this.p = 1;
|
||||
}
|
||||
|
|
|
@ -15,4 +15,5 @@ var C = (function () {
|
|||
C.prototype.method = function () { };
|
||||
return C;
|
||||
}());
|
||||
export default C;
|
||||
C.s = 0;
|
||||
|
|
|
@ -43,7 +43,7 @@ n=XDate.UTC(1964,2,1);
|
|||
declare;
|
||||
module;
|
||||
{
|
||||
var XDate = (function () {
|
||||
export var XDate = (function () {
|
||||
function XDate() {
|
||||
}
|
||||
return XDate;
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
}
|
||||
return C;
|
||||
}());
|
||||
export default C;
|
||||
function bee() { }
|
||||
import I2 = require("foo");
|
||||
import * as Foo from "ambient";
|
||||
|
|
|
@ -44,6 +44,7 @@ function blah() {
|
|||
}
|
||||
return C;
|
||||
}());
|
||||
export default C;
|
||||
function bee() { }
|
||||
import I2 = require("foo");
|
||||
import * as Foo from "ambient";
|
||||
|
|
Loading…
Reference in a new issue