mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
Add declaration emit support
This commit is contained in:
parent
64d269885c
commit
cd185f2cf6
@ -416,7 +416,9 @@ namespace ts {
|
||||
case SyntaxKind.TypeOperator:
|
||||
return emitTypeOperator(<TypeOperatorNode>type);
|
||||
case SyntaxKind.IndexedAccessType:
|
||||
return emitPropertyAccessType(<IndexedAccessTypeNode>type);
|
||||
return emitIndexedAccessType(<IndexedAccessTypeNode>type);
|
||||
case SyntaxKind.MappedType:
|
||||
return emitMappedType(<MappedTypeNode>type);
|
||||
case SyntaxKind.FunctionType:
|
||||
case SyntaxKind.ConstructorType:
|
||||
return emitSignatureDeclarationWithJsDocComments(<FunctionOrConstructorTypeNode>type);
|
||||
@ -516,13 +518,39 @@ namespace ts {
|
||||
emitType(type.type);
|
||||
}
|
||||
|
||||
function emitPropertyAccessType(node: IndexedAccessTypeNode) {
|
||||
function emitIndexedAccessType(node: IndexedAccessTypeNode) {
|
||||
emitType(node.objectType);
|
||||
write("[");
|
||||
emitType(node.indexType);
|
||||
write("]");
|
||||
}
|
||||
|
||||
function emitMappedType(node: MappedTypeNode) {
|
||||
const prevEnclosingDeclaration = enclosingDeclaration;
|
||||
enclosingDeclaration = node;
|
||||
write("{");
|
||||
writeLine();
|
||||
increaseIndent();
|
||||
if (node.readonlyToken) {
|
||||
write("readonly ");
|
||||
}
|
||||
write("[");
|
||||
writeEntityName(node.typeParameter.name);
|
||||
write(" in ");
|
||||
emitType(node.typeParameter.constraint);
|
||||
write("]");
|
||||
if (node.questionToken) {
|
||||
write("?");
|
||||
}
|
||||
write(": ");
|
||||
emitType(node.type);
|
||||
write(";");
|
||||
writeLine();
|
||||
decreaseIndent();
|
||||
write("}");
|
||||
enclosingDeclaration = prevEnclosingDeclaration;
|
||||
}
|
||||
|
||||
function emitTypeLiteral(type: TypeLiteralNode) {
|
||||
write("{");
|
||||
if (type.members.length) {
|
||||
|
||||
@ -606,7 +606,9 @@ const _super = (function (geti, seti) {
|
||||
case SyntaxKind.TypeOperator:
|
||||
return emitTypeOperator(<TypeOperatorNode>node);
|
||||
case SyntaxKind.IndexedAccessType:
|
||||
return emitPropertyAccessType(<IndexedAccessTypeNode>node);
|
||||
return emitIndexedAccessType(<IndexedAccessTypeNode>node);
|
||||
case SyntaxKind.MappedType:
|
||||
return emitMappedType(<MappedTypeNode>node);
|
||||
case SyntaxKind.LiteralType:
|
||||
return emitLiteralType(<LiteralTypeNode>node);
|
||||
|
||||
@ -1109,13 +1111,36 @@ const _super = (function (geti, seti) {
|
||||
emit(node.type);
|
||||
}
|
||||
|
||||
function emitPropertyAccessType(node: IndexedAccessTypeNode) {
|
||||
function emitIndexedAccessType(node: IndexedAccessTypeNode) {
|
||||
emit(node.objectType);
|
||||
write("[");
|
||||
emit(node.indexType);
|
||||
write("]");
|
||||
}
|
||||
|
||||
function emitMappedType(node: MappedTypeNode) {
|
||||
write("{");
|
||||
writeLine();
|
||||
increaseIndent();
|
||||
if (node.readonlyToken) {
|
||||
write("readonly ");
|
||||
}
|
||||
write("[");
|
||||
emit(node.typeParameter.name);
|
||||
write(" in ");
|
||||
emit(node.typeParameter.constraint);
|
||||
write("]");
|
||||
if (node.questionToken) {
|
||||
write("?");
|
||||
}
|
||||
write(": ");
|
||||
emit(node.type);
|
||||
write(";");
|
||||
writeLine();
|
||||
decreaseIndent();
|
||||
write("}");
|
||||
}
|
||||
|
||||
function emitLiteralType(node: LiteralTypeNode) {
|
||||
emitExpression(node.literal);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user