From 1cce8cd955c5dad43fa111a12930b516caa8cdde Mon Sep 17 00:00:00 2001 From: makana Date: Sat, 14 Jan 2017 12:15:17 +0100 Subject: [PATCH 1/2] Converter for the "this" type Created a converter for the type "this" that is often used in chainable methods. --- src/lib/converter/types/index.ts | 1 + src/lib/converter/types/this.ts | 37 +++++++++++ test/converter/this/specs.json | 109 +++++++++++++++++++++++++++++++ test/converter/this/this.ts | 17 +++++ 4 files changed, 164 insertions(+) create mode 100644 src/lib/converter/types/this.ts create mode 100644 test/converter/this/specs.json create mode 100644 test/converter/this/this.ts diff --git a/src/lib/converter/types/index.ts b/src/lib/converter/types/index.ts index f577afc3d..a7326c9b3 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..ed3a65120 --- /dev/null +++ b/src/lib/converter/types/this.ts @@ -0,0 +1,37 @@ +import * as ts from "typescript"; + +import { Type, IntrinsicType } from "../../models/types/index"; +import { createReferenceType } from "../factories/index"; +import { Component, ConverterTypeComponent, ITypeNodeConverter } from "../components"; +import { Context } from "../context"; + + +@Component({ name: 'type:this' }) +export class ThisConverter extends ConverterTypeComponent implements ITypeNodeConverter +{ + /** + * 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/test/converter/this/specs.json b/test/converter/this/specs.json new file mode 100644 index 000000000..36870d4a0 --- /dev/null +++ b/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": 13, + "character": 13 + } + ] + } + ], + "groups": [ + { + "title": "Methods", + "kind": 2048, + "children": [ + 3 + ] + } + ], + "sources": [ + { + "fileName": "this.ts", + "line": 8, + "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/test/converter/this/this.ts b/test/converter/this/this.ts new file mode 100644 index 000000000..cf98b1f25 --- /dev/null +++ b/test/converter/this/this.ts @@ -0,0 +1,17 @@ +/// + +/** + * ChainClass comment short text. + * + * ChainClass comment text. + */ +export class ChainClass +{ + /** + * Chain method that returns this. + */ + public chain(): this + { + return this; + } +} From 6ee54aebdb79b1a9000161c9bd1d590b4591acae Mon Sep 17 00:00:00 2001 From: makana Date: Sun, 26 Mar 2017 10:05:59 +0200 Subject: [PATCH 2/2] Updated this converter to 0.5.9 --- src/lib/converter/types/this.ts | 15 ++++++--------- {test => src/test}/converter/this/specs.json | 4 ++-- {test => src/test}/converter/this/this.ts | 2 -- 3 files changed, 8 insertions(+), 13 deletions(-) rename {test => src/test}/converter/this/specs.json (97%) rename {test => src/test}/converter/this/this.ts (81%) diff --git a/src/lib/converter/types/this.ts b/src/lib/converter/types/this.ts index ed3a65120..2fd36cf0b 100644 --- a/src/lib/converter/types/this.ts +++ b/src/lib/converter/types/this.ts @@ -1,19 +1,16 @@ -import * as ts from "typescript"; - -import { Type, IntrinsicType } from "../../models/types/index"; -import { createReferenceType } from "../factories/index"; -import { Component, ConverterTypeComponent, ITypeNodeConverter } from "../components"; -import { Context } from "../context"; +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 ITypeNodeConverter -{ +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; + return node.kind === ts.SyntaxKind.ThisType; } /** diff --git a/test/converter/this/specs.json b/src/test/converter/this/specs.json similarity index 97% rename from test/converter/this/specs.json rename to src/test/converter/this/specs.json index 36870d4a0..5d1ac086e 100644 --- a/test/converter/this/specs.json +++ b/src/test/converter/this/specs.json @@ -55,7 +55,7 @@ "sources": [ { "fileName": "this.ts", - "line": 13, + "line": 11, "character": 13 } ] @@ -73,7 +73,7 @@ "sources": [ { "fileName": "this.ts", - "line": 8, + "line": 6, "character": 23 } ] diff --git a/test/converter/this/this.ts b/src/test/converter/this/this.ts similarity index 81% rename from test/converter/this/this.ts rename to src/test/converter/this/this.ts index cf98b1f25..2bd1b5bdb 100644 --- a/test/converter/this/this.ts +++ b/src/test/converter/this/this.ts @@ -1,5 +1,3 @@ -/// - /** * ChainClass comment short text. *