From cf7cf5a1f2520c68772be4a669235fe4bbb38730 Mon Sep 17 00:00:00 2001 From: yoyo930021 Date: Sun, 7 Jul 2019 16:42:02 +0800 Subject: [PATCH] Fix isClass function undefined in Typescript 2.8 --- server/src/modes/script/childComponents.ts | 5 +++-- server/src/modes/script/componentInfo.ts | 20 ++++++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/server/src/modes/script/childComponents.ts b/server/src/modes/script/childComponents.ts index 7c1aae4428..a5abed873b 100644 --- a/server/src/modes/script/childComponents.ts +++ b/server/src/modes/script/childComponents.ts @@ -3,7 +3,8 @@ import { getLastChild, buildDocumentation, getNodeFromExportNode, - getClassDecoratorArgumentType + getClassDecoratorArgumentType, + isClassType } from './componentInfo'; import { T_TypeScript } from '../../services/dependencyService'; @@ -25,7 +26,7 @@ export function getChildComponents( tagCasing = 'kebab' ): InternalChildComponent[] | undefined { let type = defaultExportType; - if (defaultExportType.isClass()) { + if (isClassType(tsModule, type)) { // get decorator argument type when class const classDecoratorArgumentType = getClassDecoratorArgumentType(tsModule, defaultExportType, checker); if (!classDecoratorArgumentType) { diff --git a/server/src/modes/script/componentInfo.ts b/server/src/modes/script/componentInfo.ts index 3ba15916e5..0821567cee 100644 --- a/server/src/modes/script/componentInfo.ts +++ b/server/src/modes/script/componentInfo.ts @@ -100,7 +100,7 @@ function getDefaultExportNode( function getProps(tsModule: T_TypeScript, defaultExportType: ts.Type, checker: ts.TypeChecker): PropInfo[] | undefined { const result: PropInfo[] = []; - if (defaultExportType.isClass()) { + if (isClassType(tsModule, defaultExportType)) { result.push.apply(result, getClassProps(defaultExportType) || []); const decoratorArgumentType = getClassDecoratorArgumentType(tsModule, defaultExportType, checker); @@ -196,7 +196,7 @@ function getProps(tsModule: T_TypeScript, defaultExportType: ts.Type, checker: t */ function getData(tsModule: T_TypeScript, defaultExportType: ts.Type, checker: ts.TypeChecker): DataInfo[] | undefined { const result: DataInfo[] = []; - if (defaultExportType.isClass()) { + if (isClassType(tsModule, defaultExportType)) { result.push.apply(result, getClassData(defaultExportType) || []); const decoratorArgumentType = getClassDecoratorArgumentType(tsModule, defaultExportType, checker); @@ -261,7 +261,7 @@ function getComputed( checker: ts.TypeChecker ): ComputedInfo[] | undefined { const result: ComputedInfo[] = []; - if (defaultExportType.isClass()) { + if (isClassType(tsModule, defaultExportType)) { result.push.apply(result, getClassComputed(defaultExportType) || []); const decoratorArgumentType = getClassDecoratorArgumentType(tsModule, defaultExportType, checker); @@ -345,7 +345,7 @@ function getMethods( checker: ts.TypeChecker ): MethodInfo[] | undefined { const result: MethodInfo[] = []; - if (defaultExportType.isClass()) { + if (isClassType(tsModule, defaultExportType)) { result.push.apply(result, getClassMethods(defaultExportType) || []); const decoratorArgumentType = getClassDecoratorArgumentType(tsModule, defaultExportType, checker); @@ -429,6 +429,18 @@ export function getLastChild(d: ts.Declaration) { return children[children.length - 1]; } +export function isClassType ( + tsModule: T_TypeScript, + type: ts.Type +) { + if (type.isClass === undefined) { + return !!((type.flags & tsModule.TypeFlags.Object ? (type as ts.ObjectType).objectFlags : 0) + & tsModule.ObjectFlags.Class); + } else { + return type.isClass(); + } +} + export function getClassDecoratorArgumentType( tsModule: T_TypeScript, type: ts.Type,