From e08c3b3a155739f42d0535a222381ea701707138 Mon Sep 17 00:00:00 2001 From: makana Date: Mon, 3 Apr 2017 22:28:45 +0200 Subject: [PATCH] Converter for "this" type (#383) --- src/lib/converter/types/index.ts | 1 + src/lib/converter/types/this.ts | 34 +++++++++ src/test/converter/this/specs.json | 109 +++++++++++++++++++++++++++++ src/test/converter/this/this.ts | 15 ++++ 4 files changed, 159 insertions(+) create mode 100644 src/lib/converter/types/this.ts create mode 100644 src/test/converter/this/specs.json create mode 100644 src/test/converter/this/this.ts diff --git a/src/lib/converter/types/index.ts b/src/lib/converter/types/index.ts index ede95d9c6..97965cf62 100644 --- a/src/lib/converter/types/index.ts +++ b/src/lib/converter/types/index.ts @@ -6,6 +6,7 @@ export {EnumConverter} from './enum'; export {IntrinsicConverter} from './intrinsic' export {StringLiteralConverter} from './string-literal'; export {ReferenceConverter} from './reference'; +export {ThisConverter} from './this'; export {TupleConverter} from './tuple'; export {TypeParameterConverter} from './type-parameter'; export {UnionConverter} from './union'; diff --git a/src/lib/converter/types/this.ts b/src/lib/converter/types/this.ts new file mode 100644 index 000000000..2fd36cf0b --- /dev/null +++ b/src/lib/converter/types/this.ts @@ -0,0 +1,34 @@ +import * as ts from 'typescript'; + +import { Type, IntrinsicType } from '../../models/types/index'; +import { Component, ConverterTypeComponent, TypeNodeConverter } from '../components'; +import { Context } from '../context'; + +@Component({ name: 'type:this' }) +export class ThisConverter extends ConverterTypeComponent implements TypeNodeConverter { + /** + * Test whether this converter can handle the given TypeScript node. + */ + public supportsNode(context: Context, node: ts.ThisTypeNode, type: ts.Type): boolean { + return node.kind === ts.SyntaxKind.ThisType; + } + + /** + * Convert the type reference node to its type reflection. + * + * This is a node based converter, see [[convertTypeReferenceType]] for the type equivalent. + * + * ``` + * class SomeClass { } + * var someValue:SomeClass; + * ``` + * + * @param context The context object describing the current state the converter is in. + * @param node The type reference node that should be converted. + * @param type The type of the type reference node. + * @returns The type reflection representing the given reference node. + */ + public convertNode(context: Context, node: ts.ThisTypeNode, type: ts.Type): Type { + return new IntrinsicType('this'); + } +} diff --git a/src/test/converter/this/specs.json b/src/test/converter/this/specs.json new file mode 100644 index 000000000..5d1ac086e --- /dev/null +++ b/src/test/converter/this/specs.json @@ -0,0 +1,109 @@ +{ + "id": 0, + "name": "typedoc", + "kind": 0, + "flags": {}, + "children": [ + { + "id": 1, + "name": "\"this\"", + "kind": 1, + "kindString": "External module", + "flags": { + "isExported": true + }, + "originalName": "%BASE%/this/this.ts", + "children": [ + { + "id": 2, + "name": "ChainClass", + "kind": 128, + "kindString": "Class", + "flags": { + "isExported": true + }, + "comment": { + "shortText": "ChainClass comment short text.", + "text": "ChainClass comment text.\n" + }, + "children": [ + { + "id": 3, + "name": "chain", + "kind": 2048, + "kindString": "Method", + "flags": { + "isExported": true, + "isPublic": true + }, + "signatures": [ + { + "id": 4, + "name": "chain", + "kind": 4096, + "kindString": "Call signature", + "flags": {}, + "comment": { + "shortText": "Chain method that returns this." + }, + "type": { + "type": "instrinct", + "name": "this" + } + } + ], + "sources": [ + { + "fileName": "this.ts", + "line": 11, + "character": 13 + } + ] + } + ], + "groups": [ + { + "title": "Methods", + "kind": 2048, + "children": [ + 3 + ] + } + ], + "sources": [ + { + "fileName": "this.ts", + "line": 6, + "character": 23 + } + ] + } + ], + "groups": [ + { + "title": "Classes", + "kind": 128, + "children": [ + 2 + ] + } + ], + "sources": [ + { + "fileName": "this.ts", + "line": 1, + "character": 0 + } + ] + } + ], + "groups": [ + { + "title": "External modules", + "kind": 1, + "children": [ + 1 + ] + } + ] +} \ No newline at end of file diff --git a/src/test/converter/this/this.ts b/src/test/converter/this/this.ts new file mode 100644 index 000000000..2bd1b5bdb --- /dev/null +++ b/src/test/converter/this/this.ts @@ -0,0 +1,15 @@ +/** + * ChainClass comment short text. + * + * ChainClass comment text. + */ +export class ChainClass +{ + /** + * Chain method that returns this. + */ + public chain(): this + { + return this; + } +}