From 872fdee4a51a15be999ae42df1f2891dc23f641b Mon Sep 17 00:00:00 2001 From: Mohsen Azimi Date: Mon, 1 May 2017 12:55:40 -0700 Subject: [PATCH 1/3] Add createTypeAliasDeclaration and updateTypeAliasDeclaration factories --- src/compiler/factory.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index 95878917b3d..72f8e255cb4 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -1462,6 +1462,22 @@ namespace ts { : node; } + export function createTypeAliasDeclaration(name: string | Identifier, typeParameters: TypeParameterDeclaration[] | undefined, type: ts.TypeNode) { + const node = createSynthesizedNode(SyntaxKind.TypeAliasDeclaration); + node.name = asName(name); + node.typeParameters = asNodeArray(typeParameters); + node.type = type; + return node; + } + + export function updateTypeAliasDeclaration(node: TypeAliasDeclaration, name: string | Identifier, typeParameters: TypeParameterDeclaration[] | undefined, type: ts.TypeNode) { + return node.name !== name + || node.typeParameters !== typeParameters + || node.type !== type + ? updateNode(createTypeAliasDeclaration(name, typeParameters, type), node) + : node; + } + export function createEnumDeclaration(decorators: Decorator[] | undefined, modifiers: Modifier[] | undefined, name: string | Identifier, members: EnumMember[]) { const node = createSynthesizedNode(SyntaxKind.EnumDeclaration); node.decorators = asNodeArray(decorators); From f9c46b5f820d098ab64054055579ca7819259ce0 Mon Sep 17 00:00:00 2001 From: Mohsen Azimi Date: Mon, 1 May 2017 14:00:16 -0700 Subject: [PATCH 2/3] Fix issues raised in PR review --- src/compiler/factory.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index 72f8e255cb4..011cedcad81 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -1462,7 +1462,7 @@ namespace ts { : node; } - export function createTypeAliasDeclaration(name: string | Identifier, typeParameters: TypeParameterDeclaration[] | undefined, type: ts.TypeNode) { + export function createTypeAliasDeclaration(name: Identifier, typeParameters: TypeParameterDeclaration[] | undefined, type: TypeNode) { const node = createSynthesizedNode(SyntaxKind.TypeAliasDeclaration); node.name = asName(name); node.typeParameters = asNodeArray(typeParameters); @@ -1470,7 +1470,7 @@ namespace ts { return node; } - export function updateTypeAliasDeclaration(node: TypeAliasDeclaration, name: string | Identifier, typeParameters: TypeParameterDeclaration[] | undefined, type: ts.TypeNode) { + export function updateTypeAliasDeclaration(node: TypeAliasDeclaration, name: Identifier, typeParameters: TypeParameterDeclaration[] | undefined, type: TypeNode) { return node.name !== name || node.typeParameters !== typeParameters || node.type !== type From b27aec2247f5c104b52fec588f0274f4d47e5230 Mon Sep 17 00:00:00 2001 From: Mohsen Azimi Date: Mon, 1 May 2017 14:58:36 -0700 Subject: [PATCH 3/3] Allow string for name when creating a TypeAliasDeclaration --- src/compiler/factory.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index 011cedcad81..cce95c23c22 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -1462,7 +1462,7 @@ namespace ts { : node; } - export function createTypeAliasDeclaration(name: Identifier, typeParameters: TypeParameterDeclaration[] | undefined, type: TypeNode) { + export function createTypeAliasDeclaration(name: string | Identifier, typeParameters: TypeParameterDeclaration[] | undefined, type: TypeNode) { const node = createSynthesizedNode(SyntaxKind.TypeAliasDeclaration); node.name = asName(name); node.typeParameters = asNodeArray(typeParameters);