Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions examples/basic/src/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ export interface IPrintNameInterface extends INameInterface, IPrintInterface
*
* [[include:class-example.md]]
*/
export class BaseClass implements INameInterface
export abstract class BaseClass implements INameInterface
{
/**
* This is a simple public member.
*/
public name:string;
public abstract name:string;

/**
* This is a simple protected member.
Expand Down Expand Up @@ -90,6 +90,7 @@ export class BaseClass implements INameInterface
this.checkName();
}

public abstract abstractMethod(): void;

/**
* This is a simple member function.
Expand Down Expand Up @@ -197,6 +198,8 @@ class InternalClass
*/
export class SubClassA extends BaseClass implements IPrintNameInterface
{
public name:string;

/**
* This is a simple interface function.
*/
Expand Down Expand Up @@ -250,6 +253,10 @@ export class SubClassA extends BaseClass implements IPrintNameInterface
public set writeOnlyNameProperty(value:string) {
this.name = value;
}

public abstractMethod(): void {

}
}


Expand All @@ -260,10 +267,16 @@ export class SubClassA extends BaseClass implements IPrintNameInterface
*/
export class SubClassB extends BaseClass
{
public name: string;

constructor(name:string) {
super(name);
}

abstractMethod(): void {

}

doSomething(value:[string, SubClassA, SubClassB]) {
}
}
Expand Down
14 changes: 14 additions & 0 deletions examples/basic/src/variables.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* A const variable
*/
export const constVariable = 'const';

/**
* A let variable
*/
export let letVariable = 'let';

/**
* A var variable
*/
export var varVariable= 'var';
6 changes: 5 additions & 1 deletion src/lib/converter/nodes/class.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as ts from 'typescript';
import * as _ts from '../../ts-internal';

import { Reflection, ReflectionKind, DeclarationReflection } from '../../models/index';
import { Reflection, ReflectionFlag, ReflectionKind, DeclarationReflection } from '../../models/index';
import { createDeclaration } from '../factories/index';
import { Context } from '../context';
import { Component, ConverterNodeComponent } from '../components';
Expand Down Expand Up @@ -29,6 +29,10 @@ export class ClassConverter extends ConverterNodeComponent<ts.ClassDeclaration>
reflection = <DeclarationReflection> context.scope;
} else {
reflection = createDeclaration(context, node, ReflectionKind.Class);
// set possible abstract flag here, where node is not the inherited parent
if (node.modifiers && node.modifiers.some( m => m.kind === ts.SyntaxKind.AbstractKeyword )) {
reflection.setFlag(ReflectionFlag.Abstract, true);
}
}

context.withScope(reflection, node.typeParameters, () => {
Expand Down
9 changes: 8 additions & 1 deletion src/lib/converter/nodes/function.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as ts from 'typescript';

import { Reflection, ReflectionKind } from '../../models/index';
import { Reflection, ReflectionFlag, ReflectionKind } from '../../models/index';
import { createDeclaration, createSignature } from '../factories/index';
import { Context } from '../context';
import { Converter } from '../converter';
Expand Down Expand Up @@ -30,6 +30,13 @@ export class FunctionConverter extends ConverterNodeComponent<ts.FunctionDeclara
const hasBody = !!node.body;
const method = createDeclaration(context, <ts.Node> node, kind);

if (method // child inheriting will return null on createDeclaration
&& kind & ReflectionKind.Method
&& node.modifiers
&& node.modifiers.some( m => m.kind === ts.SyntaxKind.AbstractKeyword )) {
method.setFlag(ReflectionFlag.Abstract, true);
}

context.withScope(method, () => {
if (!hasBody || !method.signatures) {
const signature = createSignature(context, <ts.SignatureDeclaration> node, method.name, ReflectionKind.CallSignature);
Expand Down
20 changes: 19 additions & 1 deletion src/lib/converter/nodes/variable.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as ts from 'typescript';
import * as _ts from '../../ts-internal';

import { Reflection, ReflectionKind, IntrinsicType } from '../../models/index';
import { Reflection, ReflectionFlag, ReflectionKind, IntrinsicType } from '../../models/index';
import { createDeclaration, createComment } from '../factories/index';
import { Context } from '../context';
import { Component, ConverterNodeComponent } from '../components';
Expand Down Expand Up @@ -61,6 +61,24 @@ export class VariableConverter extends ConverterNodeComponent<ts.VariableDeclara
const scope = context.scope;
const kind = scope.kind & ReflectionKind.ClassOrInterface ? ReflectionKind.Property : ReflectionKind.Variable;
const variable = createDeclaration(context, node, kind, name);

switch (kind) {
case ReflectionKind.Variable:
if (node.parent.flags & ts.NodeFlags.Const) {
variable.setFlag(ReflectionFlag.Const, true);
} else if (node.parent.flags & ts.NodeFlags.Let) {
variable.setFlag(ReflectionFlag.Let, true);
}
break;
case ReflectionKind.Property:
if (variable // child inheriting will return null on createDeclaration
&& node.modifiers
&& node.modifiers.some( m => m.kind === ts.SyntaxKind.AbstractKeyword )) {
variable.setFlag(ReflectionFlag.Abstract, true);
}
break;
}

context.withScope(variable, () => {
if (node.initializer) {
switch (node.initializer.kind) {
Expand Down
25 changes: 23 additions & 2 deletions src/lib/models/reflections/abstract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ export enum ReflectionFlag {
Optional = 128,
DefaultValue = 256,
Rest = 512,
ConstructorProperty = 1024
ConstructorProperty = 1024,
Abstract = 2048,
Const = 4096,
Let = 8192
}

const relevantFlags: ReflectionFlag[] = [
Expand All @@ -86,7 +89,10 @@ const relevantFlags: ReflectionFlag[] = [
ReflectionFlag.ExportAssignment,
ReflectionFlag.Optional,
ReflectionFlag.DefaultValue,
ReflectionFlag.Rest
ReflectionFlag.Rest,
ReflectionFlag.Abstract,
ReflectionFlag.Let,
ReflectionFlag.Const
];

export interface ReflectionFlags extends Array<string> {
Expand Down Expand Up @@ -140,6 +146,12 @@ export interface ReflectionFlags extends Array<string> {
hasExportAssignment?: boolean;

isConstructorProperty?: boolean;

isAbstract?: boolean;

isConst?: boolean;

isLet?: boolean;
}

export interface DefaultValueContainer extends Reflection {
Expand Down Expand Up @@ -405,6 +417,15 @@ export abstract class Reflection {
case ReflectionFlag.ConstructorProperty:
this.flags.isConstructorProperty = value;
break;
case ReflectionFlag.Abstract:
this.flags.isAbstract = value;
break;
case ReflectionFlag.Let:
this.flags.isLet = value;
break;
case ReflectionFlag.Const:
this.flags.isConst = value;
break;
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/test/converter/access/specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@
"kindString": "Variable",
"flags": {
"isPrivate": true,
"isExported": true
"isExported": true,
"isConst": true
},
"comment": {
"shortText": "A variable that is made private via comment."
Expand All @@ -204,7 +205,8 @@
"kindString": "Variable",
"flags": {
"isExported": true,
"isProtected": true
"isProtected": true,
"isConst": true
},
"comment": {
"shortText": "A variable that is made protected via comment."
Expand Down
6 changes: 4 additions & 2 deletions src/test/converter/array/specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"kind": 32,
"kindString": "Variable",
"flags": {
"isExported": true
"isExported": true,
"isConst": true
},
"comment": {
"shortText": "A const of a complex type."
Expand Down Expand Up @@ -112,7 +113,8 @@
"kind": 32,
"kindString": "Variable",
"flags": {
"isExported": true
"isExported": true,
"isConst": true
},
"comment": {
"shortText": "An exported const of the custom array type."
Expand Down
13 changes: 13 additions & 0 deletions src/test/converter/class/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,16 @@ export class TestSubClass extends TestClass
super();
}
}


export abstract class TestAbstractClass {
abstract myAbstractProperty: string;

protected abstract myAbstractMethod(): void;
}

export class TestAbstractClassImplementation extends TestAbstractClass {
myAbstractProperty: string;

protected myAbstractMethod(): void { }
}
Loading