Skip to content

Commit

Permalink
Fix isClass function undefined in Typescript 2.8
Browse files Browse the repository at this point in the history
  • Loading branch information
yoyo930021 committed Jul 7, 2019
1 parent c9ed049 commit a592bbd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
5 changes: 3 additions & 2 deletions server/src/modes/script/childComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
getLastChild,
buildDocumentation,
getNodeFromExportNode,
getClassDecoratorArgumentType
getClassDecoratorArgumentType,
isClassType
} from './componentInfo';
import { T_TypeScript } from '../../services/dependencyService';

Expand All @@ -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) {
Expand Down
20 changes: 16 additions & 4 deletions server/src/modes/script/componentInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit a592bbd

Please sign in to comment.