diff --git a/scripts/rebuild_specs.js b/scripts/rebuild_specs.js index 267ed6e05..79ec6dcc9 100644 --- a/scripts/rebuild_specs.js +++ b/scripts/rebuild_specs.js @@ -4,13 +4,14 @@ const assert = require('assert'); const fs = require('fs-extra'); const path = require('path'); const TypeDoc = require('..'); +const ts = require('typescript'); const app = new TypeDoc.Application({ mode: 'Modules', - target: 'ES5', - module: 'CommonJS', + target: ts.ScriptTarget.ES5, + module: ts.ModuleKind.CommonJS, experimentalDecorators: true, - jsx: 'react', + jsx: ts.JsxEmit.React, lib: [ "lib.dom.d.ts", "lib.es5.d.ts", @@ -56,11 +57,7 @@ function rebuildConverterTests(dirs) { TypeDoc.resetReflectionID(); before(); const result = app.convert(src); - // Until GH#936 lands, removing toObject, ensure toObject remains consistent - // with the serializers. - const serialized = result.toObject(); - const serialized2 = app.serializer.toObject(result); - assert.deepStrictEqual(serialized, serialized2); + const serialized = app.serializer.toObject(result); const data = JSON.stringify(serialized, null, ' ') .split(TypeDoc.normalizePath(base)) diff --git a/src/index.ts b/src/index.ts index 63fbf0855..150fcbf29 100644 --- a/src/index.ts +++ b/src/index.ts @@ -20,3 +20,5 @@ export { ParameterType, TypeDocOptions } from './lib/utils/options'; + +export { JSONOutput } from './lib/serialization'; diff --git a/src/lib/application.ts b/src/lib/application.ts index b5b1629c9..87e9982db 100644 --- a/src/lib/application.ts +++ b/src/lib/application.ts @@ -133,10 +133,10 @@ export class Application extends ChildableComponent< this.logger = new ConsoleLogger(); this.options = new Options(this.logger); this.options.addDefaultDeclarations(); + this.serializer = new Serializer(); this.converter = this.addComponent('converter', Converter); - this.serializer = this.addComponent('serializer', Serializer); - this.renderer = this.addComponent('renderer', Renderer); - this.plugins = this.addComponent('plugins', PluginHost); + this.renderer = this.addComponent('renderer', Renderer); + this.plugins = this.addComponent('plugins', PluginHost); this.bootstrap(options); } diff --git a/src/lib/models/ReflectionCategory.ts b/src/lib/models/ReflectionCategory.ts index 1b26bf182..9ceb9cc1f 100644 --- a/src/lib/models/ReflectionCategory.ts +++ b/src/lib/models/ReflectionCategory.ts @@ -48,25 +48,4 @@ export class ReflectionCategory { return onlyOwnDocuments; } - - /** - * Return a raw object representation of this reflection category. - * @deprecated Use serializers instead - */ - toObject(): any { - const result = { - title: this.title - }; - - if (this.children) { - const children: any[] = []; - this.children.forEach((child) => { - children.push(child.id); - }); - - result['children'] = children; - } - - return result; - } } diff --git a/src/lib/models/ReflectionGroup.ts b/src/lib/models/ReflectionGroup.ts index 97da1ae7c..e5f96b57d 100644 --- a/src/lib/models/ReflectionGroup.ts +++ b/src/lib/models/ReflectionGroup.ts @@ -92,35 +92,4 @@ export class ReflectionGroup { return onlyOwnDocuments; } - - /** - * Return a raw object representation of this reflection group. - * @deprecated Use serializers instead - */ - toObject(): any { - const result = { - title: this.title, - kind: this.kind - }; - - if (this.children) { - const children: any[] = []; - this.children.forEach((child) => { - children.push(child.id); - }); - - result['children'] = children; - } - - if (this.categories) { - const categories: any[] = []; - this.categories.forEach((category) => { - categories.push(category.toObject()); - }); - - result['categories'] = categories; - } - - return result; - } } diff --git a/src/lib/models/comments/comment.ts b/src/lib/models/comments/comment.ts index 6c0a78bd5..5685ca17f 100644 --- a/src/lib/models/comments/comment.ts +++ b/src/lib/models/comments/comment.ts @@ -89,28 +89,4 @@ export class Comment { this.returns = comment.returns; this.tags = comment.tags ? comment.tags.map((tag) => new CommentTag(tag.tagName, tag.paramName, tag.text)) : undefined; } - - /** - * Return a raw object representation of this comment. - * @deprecated Use serializers instead - */ - toObject(): any { - const result: any = {}; - if (this.shortText) { - result.shortText = this.shortText; - } - if (this.text) { - result.text = this.text; - } - if (this.returns) { - result.returns = this.returns; - } - - if (this.tags && this.tags.length) { - result.tags = []; - this.tags.forEach((tag) => result.tags.push(tag.toObject())); - } - - return result; - } } diff --git a/src/lib/models/comments/tag.ts b/src/lib/models/comments/tag.ts index 3995f3305..8d59a61de 100644 --- a/src/lib/models/comments/tag.ts +++ b/src/lib/models/comments/tag.ts @@ -27,21 +27,4 @@ export class CommentTag { this.paramName = paramName || ''; this.text = text || ''; } - - /** - * Return a raw object representation of this tag. - * @deprecated Use serializers instead - */ - toObject(): any { - const result: any = { - tag: this.tagName, - text: this.text - }; - - if (this.paramName) { - result.param = this.paramName; - } - - return result; - } } diff --git a/src/lib/models/index.ts b/src/lib/models/index.ts index da48d254d..cc2592725 100644 --- a/src/lib/models/index.ts +++ b/src/lib/models/index.ts @@ -2,3 +2,5 @@ export * from './reflections/index'; export * from './types/index'; export * from './comments/index'; export * from './sources/index'; +export * from './ReflectionGroup'; +export * from './ReflectionCategory'; diff --git a/src/lib/models/reflections/abstract.ts b/src/lib/models/reflections/abstract.ts index a9ecf0f91..162097aa9 100644 --- a/src/lib/models/reflections/abstract.ts +++ b/src/lib/models/reflections/abstract.ts @@ -545,66 +545,6 @@ export abstract class Reflection { */ traverse(callback: TraverseCallback) { } - /** - * Return a raw object representation of this reflection. - * @deprecated Use serializers instead - */ - toObject(): any { - const result: any = { - id: this.id, - name: this.name, - kind: this.kind, - kindString: this.kindString, - flags: {} - }; - - if (this.originalName !== this.name) { - result.originalName = this.originalName; - } - - if (this.comment) { - result.comment = this.comment.toObject(); - } - - Object.getOwnPropertyNames(ReflectionFlags.prototype).forEach(name => { - const descriptor = Object.getOwnPropertyDescriptor(ReflectionFlags.prototype, name)!; - if (typeof descriptor.get === 'function' && this.flags[name] === true) { - result.flags[name] = true; - } - }); - - if (this.decorates) { - result.decorates = this.decorates.map((type) => type.toObject()); - } - - if (this.decorators) { - result.decorators = this.decorators.map((decorator) => { - const result: any = { name: decorator.name }; - if (decorator.type) { - result.type = decorator.type.toObject(); - } - if (decorator.arguments) { - result.arguments = decorator.arguments; - } - return result; - }); - } - - this.traverse((child, property) => { - if (property === TraverseProperty.TypeLiteral) { - return; - } - let name = TraverseProperty[property]; - name = name.substr(0, 1).toLowerCase() + name.substr(1); - if (!result[name]) { - result[name] = []; - } - result[name].push(child.toObject()); - }); - - return result; - } - /** * Return a string representation of this reflection. */ diff --git a/src/lib/models/reflections/container.ts b/src/lib/models/reflections/container.ts index 866bfbf79..036f82ca7 100644 --- a/src/lib/models/reflections/container.ts +++ b/src/lib/models/reflections/container.ts @@ -45,47 +45,4 @@ export class ContainerReflection extends Reflection { } } } - - /** - * Return a raw object representation of this reflection. - * @deprecated Use serializers instead - */ - toObject(): any { - const result = super.toObject(); - - if (this.groups) { - const groups: any[] = []; - this.groups.forEach((group) => { - groups.push(group.toObject()); - }); - - result['groups'] = groups; - } - - if (this.categories) { - const categories: any[] = []; - this.categories.forEach((category) => { - categories.push(category.toObject()); - }); - - if (categories.length > 0) { - result['categories'] = categories; - } - } - - if (this.sources) { - const sources: any[] = []; - this.sources.forEach((source) => { - sources.push({ - fileName: source.fileName, - line: source.line, - character: source.character - }); - }); - - result['sources'] = sources; - } - - return result; - } } diff --git a/src/lib/models/reflections/declaration.ts b/src/lib/models/reflections/declaration.ts index ca02b35c7..d02d00d6b 100644 --- a/src/lib/models/reflections/declaration.ts +++ b/src/lib/models/reflections/declaration.ts @@ -192,52 +192,6 @@ export class DeclarationReflection extends ContainerReflection implements Defaul super.traverse(callback); } - /** - * Return a raw object representation of this reflection. - * @deprecated Use serializers instead - */ - toObject(): any { - const result = super.toObject(); - - if (this.type) { - result.type = this.type.toObject(); - } - - if (this.defaultValue) { - result.defaultValue = this.defaultValue; - } - - if (this.overwrites) { - result.overwrites = this.overwrites.toObject(); - } - - if (this.inheritedFrom) { - result.inheritedFrom = this.inheritedFrom.toObject(); - } - - if (this.extendedTypes) { - result.extendedTypes = this.extendedTypes.map((t) => t.toObject()); - } - - if (this.extendedBy) { - result.extendedBy = this.extendedBy.map((t) => t.toObject()); - } - - if (this.implementedTypes) { - result.implementedTypes = this.implementedTypes.map((t) => t.toObject()); - } - - if (this.implementedBy) { - result.implementedBy = this.implementedBy.map((t) => t.toObject()); - } - - if (this.implementationOf) { - result.implementationOf = this.implementationOf.toObject(); - } - - return result; - } - /** * Return a string representation of this reflection. */ diff --git a/src/lib/models/reflections/index.ts b/src/lib/models/reflections/index.ts index 33cc0881b..045a3058d 100644 --- a/src/lib/models/reflections/index.ts +++ b/src/lib/models/reflections/index.ts @@ -1,4 +1,4 @@ -export { Reflection, ReflectionKind, ReflectionFlag, TypeParameterContainer, Decorator, TraverseProperty } from './abstract'; +export { Reflection, ReflectionKind, ReflectionFlag, TypeParameterContainer, Decorator, TraverseProperty, ReflectionFlags } from './abstract'; export { ContainerReflection } from './container'; export { DeclarationReflection, DeclarationHierarchy } from './declaration'; export { ParameterReflection } from './parameter'; diff --git a/src/lib/models/reflections/parameter.ts b/src/lib/models/reflections/parameter.ts index bc92c5efd..6da3b60bc 100644 --- a/src/lib/models/reflections/parameter.ts +++ b/src/lib/models/reflections/parameter.ts @@ -27,24 +27,6 @@ export class ParameterReflection extends Reflection implements DefaultValueConta super.traverse(callback); } - /** - * Return a raw object representation of this reflection. - * @deprecated Use serializers instead - */ - toObject(): any { - const result = super.toObject(); - - if (this.type) { - result.type = this.type.toObject(); - } - - if (this.defaultValue) { - result.defaultValue = this.defaultValue; - } - - return result; - } - /** * Return a string representation of this reflection. */ diff --git a/src/lib/models/reflections/reference.ts b/src/lib/models/reflections/reference.ts index 45d9708d9..9249c3b9a 100644 --- a/src/lib/models/reflections/reference.ts +++ b/src/lib/models/reflections/reference.ts @@ -91,17 +91,6 @@ export class ReferenceReflection extends DeclarationReflection { return result; } - /** - * Get a raw object representation of this reflection. - * @deprecated use serializers instead. - */ - toObject() { - return { - ...super.toObject(), - target: this.tryGetTargetReflection()?.id ?? -1 - }; - } - private _ensureResolved(throwIfFail: boolean) { if (this._state[0] === ReferenceState.Unresolved) { const target = this._project!.symbolMapping[this._state[1]]; diff --git a/src/lib/models/reflections/signature.ts b/src/lib/models/reflections/signature.ts index c1d1db399..df237a043 100644 --- a/src/lib/models/reflections/signature.ts +++ b/src/lib/models/reflections/signature.ts @@ -78,32 +78,6 @@ export class SignatureReflection extends Reflection implements TypeContainer, Ty super.traverse(callback); } - /** - * Return a raw object representation of this reflection. - * @deprecated Use serializers instead - */ - toObject(): any { - const result = super.toObject(); - - if (this.type) { - result.type = this.type.toObject(); - } - - if (this.overwrites) { - result.overwrites = this.overwrites.toObject(); - } - - if (this.inheritedFrom) { - result.inheritedFrom = this.inheritedFrom.toObject(); - } - - if (this.implementationOf) { - result.implementationOf = this.implementationOf.toObject(); - } - - return result; - } - /** * Return a string representation of this reflection. */ diff --git a/src/lib/models/reflections/type-parameter.ts b/src/lib/models/reflections/type-parameter.ts index c7e55502f..e27b22340 100644 --- a/src/lib/models/reflections/type-parameter.ts +++ b/src/lib/models/reflections/type-parameter.ts @@ -14,18 +14,4 @@ export class TypeParameterReflection extends Reflection implements TypeContainer super(type.name, ReflectionKind.TypeParameter, parent); this.type = type.constraint; } - - /** - * Return a raw object representation of this reflection. - * @deprecated Use serializers instead - */ - toObject(): any { - const result = super.toObject(); - - if (this.type) { - result.type = this.type.toObject(); - } - - return result; - } } diff --git a/src/lib/models/sources/index.ts b/src/lib/models/sources/index.ts index b65653d4a..189fe5ccc 100644 --- a/src/lib/models/sources/index.ts +++ b/src/lib/models/sources/index.ts @@ -1,2 +1,2 @@ export { SourceDirectory } from './directory'; -export { SourceFile } from './file'; +export { SourceFile, SourceReference } from './file'; diff --git a/src/lib/models/types/abstract.ts b/src/lib/models/types/abstract.ts index a0a27cc68..cdfb76eeb 100644 --- a/src/lib/models/types/abstract.ts +++ b/src/lib/models/types/abstract.ts @@ -27,17 +27,6 @@ export abstract class Type { return false; } - /** - * Return a raw object representation of this type. - * @deprecated Use serializers instead - */ - toObject(): any { - const result: any = {}; - result.type = this.type; - - return result; - } - /** * Return a string representation of this type. */ diff --git a/src/lib/models/types/array.ts b/src/lib/models/types/array.ts index 2bdc11ed9..0440d885b 100644 --- a/src/lib/models/types/array.ts +++ b/src/lib/models/types/array.ts @@ -17,7 +17,7 @@ export class ArrayType extends Type { /** * The type name identifier. */ - readonly type: string = 'array'; + readonly type = 'array'; /** * Create a new TupleType instance. @@ -51,17 +51,6 @@ export class ArrayType extends Type { return type.elementType.equals(this.elementType); } - /** - * Return a raw object representation of this type. - * @deprecated Use serializers instead - */ - toObject(): any { - const result: any = super.toObject(); - result.elementType = this.elementType.toObject(); - - return result; - } - /** * Return a string representation of this type. */ diff --git a/src/lib/models/types/conditional.ts b/src/lib/models/types/conditional.ts index 552a4ff7b..af752d450 100644 --- a/src/lib/models/types/conditional.ts +++ b/src/lib/models/types/conditional.ts @@ -48,21 +48,6 @@ export class ConditionalType extends Type { this.falseType.equals(type.falseType); } - /** - * Return a raw object representation of this type. - * @deprecated Use serializers instead - */ - toObject(): any { - const result: any = super.toObject(); - - result.checkType = this.checkType.toObject(); - result.extendsType = this.extendsType.toObject(); - result.trueType = this.trueType.toObject(); - result.falseType = this.falseType.toObject(); - - return result; - } - /** * Return a string representation of this type. */ diff --git a/src/lib/models/types/indexed-access.ts b/src/lib/models/types/indexed-access.ts index 2e53fa76e..655ce7717 100644 --- a/src/lib/models/types/indexed-access.ts +++ b/src/lib/models/types/indexed-access.ts @@ -40,18 +40,6 @@ export class IndexedAccessType extends Type { return type.objectType.equals(this.objectType) && type.indexType.equals(this.indexType); } - /** - * Return a raw object representation of this type. - * @deprecated Use serializers instead - */ - toObject(): any { - return { - ...super.toObject(), - objectType: this.objectType.toObject(), - indexType: this.indexType.toObject() - }; - } - /** * Return a string representation of this type. */ diff --git a/src/lib/models/types/inferred.ts b/src/lib/models/types/inferred.ts index c6e63b17b..273f31d20 100644 --- a/src/lib/models/types/inferred.ts +++ b/src/lib/models/types/inferred.ts @@ -39,17 +39,6 @@ export class InferredType extends Type { return this.name === type.name; } - /** - * Return a raw object representation of this type. - * @deprecated Use serializers instead - */ - toObject(): any { - return { - ...super.toObject(), - name: this.name - }; - } - /** * Return a string representation of this type. */ diff --git a/src/lib/models/types/intersection.ts b/src/lib/models/types/intersection.ts index da5f7962e..831954cec 100644 --- a/src/lib/models/types/intersection.ts +++ b/src/lib/models/types/intersection.ts @@ -50,20 +50,6 @@ export class IntersectionType extends Type { return Type.isTypeListSimilar(type.types, this.types); } - /** - * Return a raw object representation of this type. - * @deprecated Use serializers instead - */ - toObject(): any { - const result: any = super.toObject(); - - if (this.types && this.types.length) { - result.types = this.types.map((e) => e.toObject()); - } - - return result; - } - /** * Return a string representation of this type. */ diff --git a/src/lib/models/types/intrinsic.ts b/src/lib/models/types/intrinsic.ts index 6e030d1bb..2947f1871 100644 --- a/src/lib/models/types/intrinsic.ts +++ b/src/lib/models/types/intrinsic.ts @@ -16,7 +16,7 @@ export class IntrinsicType extends Type { /** * The type name identifier. */ - readonly type: string = 'intrinsic'; + readonly type = 'intrinsic'; /** * Create a new instance of IntrinsicType. @@ -48,16 +48,6 @@ export class IntrinsicType extends Type { type.name === this.name; } - /** - * Return a raw object representation of this type. - * @deprecated Use serializers instead - */ - toObject(): any { - const result: any = super.toObject(); - result.name = this.name; - return result; - } - /** * Return a string representation of this type. */ diff --git a/src/lib/models/types/predicate.ts b/src/lib/models/types/predicate.ts index 5ddfefcdb..e677ca8c0 100644 --- a/src/lib/models/types/predicate.ts +++ b/src/lib/models/types/predicate.ts @@ -74,19 +74,6 @@ export class PredicateType extends Type { && (this.targetType?.equals(type.targetType!) ?? true); } - /** - * Return a raw object representation of this type. - * @deprecated Use serializers instead - */ - toObject(): any { - return { - ...super.toObject(), - name: this.name, - asserts: this.asserts, - targetType: this.targetType?.toObject() - }; - } - /** * Return a string representation of this type. */ diff --git a/src/lib/models/types/reference.ts b/src/lib/models/types/reference.ts index 686fbea7e..ccc9c613d 100644 --- a/src/lib/models/types/reference.ts +++ b/src/lib/models/types/reference.ts @@ -12,7 +12,7 @@ export class ReferenceType extends Type { /** * The type name identifier. */ - readonly type: string = 'reference'; + readonly type = 'reference'; /** * The name of the referenced type. @@ -88,25 +88,6 @@ export class ReferenceType extends Type { (type.symbolID === this.symbolID || type.reflection === this.reflection); } - /** - * Return a raw object representation of this type. - * @deprecated Use serializers instead - */ - toObject(): any { - const result: any = super.toObject(); - result.name = this.name; - - if (this.reflection) { - result.id = this.reflection.id; - } - - if (this.typeArguments && this.typeArguments.length) { - result.typeArguments = this.typeArguments.map((t) => t.toObject()); - } - - return result; - } - /** * Return a string representation of this type. * @example EventEmitter diff --git a/src/lib/models/types/reflection.ts b/src/lib/models/types/reflection.ts index 536a1481e..492c03d35 100644 --- a/src/lib/models/types/reflection.ts +++ b/src/lib/models/types/reflection.ts @@ -17,7 +17,7 @@ export class ReflectionType extends Type { /** * The type name identifier. */ - readonly type: string = 'reflection'; + readonly type = 'reflection'; /** * Create a new instance of ReflectionType. @@ -48,20 +48,6 @@ export class ReflectionType extends Type { return type === this; } - /** - * Return a raw object representation of this type. - * @deprecated Use serializers instead - */ - toObject(): any { - const result: any = super.toObject(); - - if (this.declaration) { - result.declaration = this.declaration.toObject(); - } - - return result; - } - /** * Return a string representation of this type. */ diff --git a/src/lib/models/types/string-literal.ts b/src/lib/models/types/string-literal.ts index 1af96a338..6f8e29587 100644 --- a/src/lib/models/types/string-literal.ts +++ b/src/lib/models/types/string-literal.ts @@ -16,7 +16,7 @@ export class StringLiteralType extends Type { /** * The type name identifier. */ - readonly type: string = 'stringLiteral'; + readonly type = 'stringLiteral'; /** * Create a new instance of StringLiteralType. @@ -48,16 +48,6 @@ export class StringLiteralType extends Type { type.value === this.value; } - /** - * Return a raw object representation of this type. - * @deprecated Use serializers instead - */ - toObject(): any { - const result: any = super.toObject(); - result.value = this.value; - return result; - } - /** * Return a string representation of this type. */ diff --git a/src/lib/models/types/tuple.ts b/src/lib/models/types/tuple.ts index c761c8052..8778c71e7 100644 --- a/src/lib/models/types/tuple.ts +++ b/src/lib/models/types/tuple.ts @@ -16,7 +16,7 @@ export class TupleType extends Type { /** * The type name identifier. */ - readonly type: string = 'tuple'; + readonly type = 'tuple'; /** * Create a new TupleType instance. @@ -50,20 +50,6 @@ export class TupleType extends Type { return Type.isTypeListEqual(type.elements, this.elements); } - /** - * Return a raw object representation of this type. - * @deprecated Use serializers instead - */ - toObject(): any { - const result: any = super.toObject(); - - if (this.elements && this.elements.length) { - result.elements = this.elements.map((e) => e.toObject()); - } - - return result; - } - /** * Return a string representation of this type. */ diff --git a/src/lib/models/types/type-operator.ts b/src/lib/models/types/type-operator.ts index 2e280ff7c..75623f4ce 100644 --- a/src/lib/models/types/type-operator.ts +++ b/src/lib/models/types/type-operator.ts @@ -12,7 +12,7 @@ export class TypeOperatorType extends Type { /** * The type name identifier. */ - readonly type: string = 'typeOperator'; + readonly type = 'typeOperator'; target: Type; @@ -48,16 +48,6 @@ export class TypeOperatorType extends Type { return type.target.equals(this.target); } - /** - * Return a raw object representation of this type. - */ - toObject(): any { - const result: any = super.toObject(); - result.operator = this.operator; - result.target = this.target.toObject(); - return result; - } - /** * Return a string representation of this type. */ diff --git a/src/lib/models/types/type-parameter.ts b/src/lib/models/types/type-parameter.ts index f34d222ea..efc07f404 100644 --- a/src/lib/models/types/type-parameter.ts +++ b/src/lib/models/types/type-parameter.ts @@ -56,21 +56,6 @@ export class TypeParameterType extends Type { } } - /** - * Return a raw object representation of this type. - * @deprecated Use serializers instead - */ - toObject(): any { - const result: any = super.toObject(); - result.name = this.name; - - if (this.constraint) { - result.constraint = this.constraint.toObject(); - } - - return result; - } - /** * Return a string representation of this type. */ diff --git a/src/lib/models/types/union.ts b/src/lib/models/types/union.ts index bb3ce3a36..ade4bf63b 100644 --- a/src/lib/models/types/union.ts +++ b/src/lib/models/types/union.ts @@ -50,20 +50,6 @@ export class UnionType extends Type { return Type.isTypeListSimilar(type.types, this.types); } - /** - * Return a raw object representation of this type. - * @deprecated Use serializers instead - */ - toObject(): any { - const result: any = super.toObject(); - - if (this.types && this.types.length) { - result.types = this.types.map((e) => e.toObject()); - } - - return result; - } - /** * Return a string representation of this type. */ diff --git a/src/lib/models/types/unknown.ts b/src/lib/models/types/unknown.ts index fe93406c4..5818636da 100644 --- a/src/lib/models/types/unknown.ts +++ b/src/lib/models/types/unknown.ts @@ -12,7 +12,7 @@ export class UnknownType extends Type { /** * The type name identifier. */ - readonly type: string = 'unknown'; + readonly type = 'unknown'; /** * Create a new instance of UnknownType. @@ -44,16 +44,6 @@ export class UnknownType extends Type { type.name === this.name; } - /** - * Return a raw object representation of this type. - * @deprecated Use serializers instead - */ - toObject(): any { - const result: any = super.toObject(); - result.name = this.name; - return result; - } - /** * Return a string representation of this type. */ diff --git a/src/lib/serialization/browser.ts b/src/lib/serialization/browser.ts deleted file mode 100644 index 180c56599..000000000 --- a/src/lib/serialization/browser.ts +++ /dev/null @@ -1,361 +0,0 @@ -/** - * Shared serialized symbols - * The shared symbols can be used in node or in a browser web application. - * - * There are 2 types of symbols: - * - Object - * - Container - * - * ## Object - * Object symbols (XXXObject) represents the final structure of a JSON object after it was - * serialized by the native typedoc serializers. It is a type composition of Container symbols. - * - * ## Container - * Container symbols (XXXContainer) are partial symbols used to compose an Object symbol. - * - * ## Object vs Container symbols - * While Container symbols might look redundant they are not, when an external serialization plugin - * is used it will, most likely, alter the structure of the output, the plugin can then use the - * Container symbols to expose custom Object symbols with minimal effort. - */ - -export interface ReflectionContainer { - id: number; - name: string; - kind: number; - kindString: string; - flags: ReflectionFlagsObject; - originalName?: string; -} - -export interface DefaultValueContainer { - defaultValue: string; -} - -export interface TypeContainer { - type: TypeObject; -} - -export interface TypeParameterContainer { - typeParameters: TypeContainer[]; -} - -export interface DecoratesContainer { - decorates: TypeObject[]; -} - -export interface DecoratorsContainer { - decorators: T[]; -} - -export interface SourceReferenceContainer { - sources: T[]; -} - -export interface GroupsContainer { - groups: T[]; -} - -export interface CategoriesContainer { - categories: T[]; -} - -export interface ContainerReflectionContainer { - children: TChildren[]; -} - -export interface CommentContainer { - comment: TComment; -} - -export interface SignatureReflectionContainer { - /** - * A type that points to the reflection that has been overwritten by this reflection. - * - * Applies to interface and class members. - */ - overwrites?: TypeObject; - - /** - * A type that points to the reflection this reflection has been inherited from. - * - * Applies to interface and class members. - */ - inheritedFrom?: TypeObject; - - /** - * A type that points to the reflection this reflection is the implementation of. - * - * Applies to class members. - */ - implementationOf?: TypeObject; - - parameters?: TParameters[]; -} - -export interface DeclarationReflectionContainer { - /** - * A list of call signatures attached to this declaration. - * - * TypeDoc creates one declaration per function that may contain ore or more - * signature reflections. - */ - signatures?: T[]; - - /** - * The index signature of this declaration. - */ - indexSignature?: T[]; - - /** - * The get signature of this declaration. - */ - getSignature?: T[]; - - /** - * The set signature of this declaration. - */ - setSignature?: T[]; - - /** - * A list of all types this reflection extends (e.g. the parent classes). - */ - extendedTypes?: TypeObject[]; - - /** - * A list of all types that extend this reflection (e.g. the subclasses). - */ - extendedBy?: TypeObject[]; - - /** - * A list of all types this reflection implements. - */ - implementedTypes?: TypeObject[]; - - /** - * A list of all types that implement this reflection. - */ - implementedBy?: TypeObject[]; - -} - -export interface ReflectionObject extends ReflectionContainer, - Partial>, - Partial, - Partial> { } - -export interface ParameterReflectionObject extends ReflectionObject, - TypeContainer, - DefaultValueContainer {} - -export interface ContainerReflectionObject extends ReflectionObject, - Partial>, - Partial>, - Partial>, - ContainerReflectionContainer {} - -export interface DeclarationReflectionObject extends ContainerReflectionObject, - DefaultValueContainer, - Partial, - Partial, - Partial>, - DeclarationReflectionContainer {} - -export interface SignatureReflectionObject extends ReflectionObject, - Partial>, - Partial, - Partial { } - -export interface CommentObject { - shortText?: string; - text?: string; - returns?: string; - tags?: CommentTagObject[]; -} - -export interface CommentTagObject { - tag: string; - text: string; - param?: string; -} - -export interface DecoratorObject { - /** - * The name of the decorator being applied. - */ - name: string; - - /** - * The type declaring the decorator. - * Usually a ReferenceType instance pointing to the decorator function. - */ - type?: TypeObject; - - /** - * A named map of arguments the decorator is applied with. - */ - arguments?: any; -} - -export interface ProjectReflectionObject extends ContainerReflectionObject { } - -export interface SourceReferenceObject { - fileName: string; - line: number; - character: number; -} - -export interface TypeObject { - - /** - * The type name identifier. - */ - type: 'void' | 'array' | 'intersection' | 'intrinsic' | 'reference' | 'reflection' | 'stringLiteral' | 'tuple' | 'typeParameter' | 'union' | 'unknown' | string; - - // array - /** - * For Array type only, The type (T) of the array's elements. - */ - elementType?: TypeObject; - - // intersection - /** - * For intersection type only, the types the union consists of. - * For union type only, the types the union consists of. - */ - types?: TypeObject[]; - - // intrinsic, reference, typeParameter, unknown - /** - * For intrinsic type only, The name of the intrinsic type like `string` or `boolean`. - * - * For reference type only, The name of the referenced type. - * If the symbol cannot be found cause it's not part of the documentation this - * can be used to represent the type. - * - * For typeParameter type only, the name of the type. - * - * For unknown type only, the name of the type. - */ - name?: 'Object' | 'string' | 'number' | 'boolean' | 'this' | string; - - // reference - /** - * The reflection id for this type - */ - id?: number; - - /** - * For reference type only, The type arguments of this reference. - */ - typeArguments?: TypeObject[]; - - // reflection - /** - * For reflection type only, The reflection of the type. - */ - declaration?: ReflectionObject; - - // stringLiteral - /** - * For stringLiteral type only, The string literal value. - */ - value?: string; - - // tuple - /** - * For tuple type only, The ordered type elements of the tuple type. - */ - elements?: TypeObject[]; - - // typeParameter - /** - * For typeParameter type only, The constraint type for the generic type. - */ - constraint?: TypeObject; -} - -export interface ReflectionGroupObject { - /** - * The title, a string representation of the typescript kind, of this group. - */ - title: string; - - /** - * The original typescript kind of the children of this group. - */ - kind: number; - - /** - * A list of reflection id's for this group. - */ - children?: number[]; - - /** - * A list of categories for this group. - */ - categories?: ReflectionCategoryObject[]; -} - -export interface ReflectionCategoryObject { - /** - * The title, a string representation of the typescript kind, of this category. - */ - title: string; - - /** - * A list of reflection id's for this category. - */ - children?: number[]; -} - -export interface ReflectionFlagsObject { - /** - * Is this a private member? - */ - isPrivate?: boolean; - - /** - * Is this a protected member? - */ - isProtected?: boolean; - - /** - * Is this a public member? - */ - isPublic?: boolean; - - /** - * Is this a static member? - */ - isStatic?: boolean; - - /** - * Is this member exported? - */ - isExported?: boolean; - - /** - * Is this a declaration from an external document? - */ - isExternal?: boolean; - - /** - * Whether this reflection is an optional component or not. - * - * Applies to function parameters and object members. - */ - isOptional?: boolean; - - /** - * Whether it's a rest parameter, like `foo(...params);`. - */ - isRest?: boolean; - - /** - * - */ - hasExportAssignment?: boolean; - - isConstructorProperty?: boolean; -} diff --git a/src/lib/serialization/components.ts b/src/lib/serialization/components.ts index 8cf7b679b..661b25f51 100644 --- a/src/lib/serialization/components.ts +++ b/src/lib/serialization/components.ts @@ -1,7 +1,7 @@ import { Reflection, Type } from '../models'; -import { AbstractComponent } from '../utils'; import { Serializer } from './serializer'; +import { ModelToObject } from './schema'; /** * Represents Serializer plugin component. @@ -9,87 +9,76 @@ import { Serializer } from './serializer'; * Like [[Converter]] plugins each [[Serializer]] plugin defines a predicate that instructs if an * object can be serialized by it, this is done dynamically at runtime via a `supports` method. * - * Additionally, each [[Serializer]] plugin must defines a predicate that instructs the group + * Additionally, each [[Serializer]] plugin must define a predicate that instructs the group * it belongs to. * - * Grouping serializers is required due to performance, we don't need to check all the reflection - * serializers when we are looking for type (or any other) serializers. + * Serializers are grouped to improve performance when finding serializers that apply to a node, + * this makes it possible to skip the `supports` calls for `Type`s when searching for a + * `Reflection` and vise versa. */ -export abstract class SerializerComponent extends AbstractComponent { +export abstract class SerializerComponent { + /** + * The priority this serializer should be executed with. + * A higher priority means the [[Serializer]] will be applied earlier. + */ + static PRIORITY = 0; - /** - * The priority this serializer should be executed with. - * A higher priority means the [[Serializer]] will be applied earlier. - */ - static PRIORITY = 0; + constructor(owner: Serializer) { + this.owner = owner; + } - /** - * A high-level predicate filtering which group this serializer belongs to. - * This is a high-level filter before the [[SerializerComponent.supports]] predicate filter. - * - * When the filter returns true the group identifier is taken from - * [[SerializerComponentType.serializeGroupSymbol]]. - * - * For example, use the [[Reflection]] class class to group all reflection based serializers: - * ```typescript - * class ReflectionSerializer { - * serializeGroup(instance) { return instance instanceof Reflection } - * serializeGroupSymbol = Reflection; - * } - * ``` - * - * Use the [[Type]] class to group all type based serializers: - * ```typescript - * class TypeSerializer { - * serializeGroup(instance) { return instance instanceof Type } - * serializeGroupSymbol = Type; - * } - * ``` - * - * > When a serializer component extends a parent serializer component the SERIALIZE_GROUP - * and SERIALIZE_GROUP_SYMBOL are also inherited so child serializers of the same group do not - * need to declare a predicate nor a group. - */ - abstract serializeGroup(instance: unknown): boolean; - /** - * The symbol representing the group this serializer belongs to. - */ - abstract serializeGroupSymbol: any; + /** + * Set when the SerializerComponent is added to the serializer. + */ + protected owner: Serializer; - /** - * The priority this serializer should be executed with. - * A higher priority means the [[Serializer]] will be applied earlier. - */ - get priority(): number { - return this.constructor['PRIORITY']; - } + /** + * A high-level predicate filtering which group this serializer belongs to. + * This is a high-level filter before the [[SerializerComponent.supports]] predicate filter. + * + * For example, use the [[Reflection]] class class to group all reflection based serializers: + * ```typescript + * class ReflectionSerializer { + * serializeGroup(instance) { return instance instanceof Reflection } + * } + * ``` + * + * Use the [[Type]] class to group all type based serializers: + * ```typescript + * class TypeSerializer { + * serializeGroup(instance) { return instance instanceof Type } + * } + * ``` + */ + abstract serializeGroup(instance: unknown): boolean; - abstract supports(item: unknown): boolean; + /** + * The priority this serializer should be executed with. + * A higher priority means the [[Serializer]] will be applied earlier. + */ + get priority(): number { + return this.constructor['PRIORITY'] || SerializerComponent.PRIORITY; + } - abstract toObject(item: T, obj?: any): any; + abstract supports(item: unknown): boolean; + abstract toObject(item: T, obj?: object): Partial>; } export abstract class ReflectionSerializerComponent extends SerializerComponent { - - /** - * Filter for instances of [[Reflection]] - */ - serializeGroup(instance: unknown): boolean { - return instance instanceof Reflection; - } - - serializeGroupSymbol = Reflection; + /** + * Filter for instances of [[Reflection]] + */ + serializeGroup(instance: unknown): boolean { + return instance instanceof Reflection; + } } export abstract class TypeSerializerComponent extends SerializerComponent { - - /** - * Filter for instances of [[Type]] - */ - serializeGroup(instance: unknown): boolean { - return instance instanceof Type; - } - - serializeGroupSymbol = Type; + /** + * Filter for instances of [[Type]] + */ + serializeGroup(instance: unknown): boolean { + return instance instanceof Type; + } } diff --git a/src/lib/serialization/events.ts b/src/lib/serialization/events.ts index a8918eb60..804c8db9d 100644 --- a/src/lib/serialization/events.ts +++ b/src/lib/serialization/events.ts @@ -1,5 +1,14 @@ import { Event } from '../utils/events'; import { ProjectReflection } from '../models'; +import { ProjectReflection as JSONProjectReflection } from './schema'; + +/** + * Optional data associated with the [[SerializeEvent]]. + */ +export interface SerializeEventData { + outputDirectory?: string; + outputFile?: string; +} /** * An event emitted by the [[Serializer]] class at the very beginning and @@ -24,10 +33,11 @@ export class SerializeEvent extends Event { */ outputFile?: string; - output: any; + output: Partial; - constructor(name: string, project: ProjectReflection) { + constructor(name: string, project: ProjectReflection, output: Partial) { super(name); this.project = project; + this.output = output; } } diff --git a/src/lib/serialization/index.ts b/src/lib/serialization/index.ts index e284a0f88..963e15449 100644 --- a/src/lib/serialization/index.ts +++ b/src/lib/serialization/index.ts @@ -1,8 +1,4 @@ -export { - ReflectionSerializerComponent, - SerializerComponent, - TypeSerializerComponent -} from './components'; +export { ReflectionSerializerComponent, SerializerComponent, TypeSerializerComponent } from './components'; export { Serializer } from './serializer'; @@ -17,7 +13,6 @@ export { ArrayTypeSerializer, DeclarationReflectionSerializer, IntersectionTypeSerializer, - IntersectionUnion, IntrinsicTypeSerializer, ParameterReflectionSerializer, ProjectReflectionSerializer, @@ -38,4 +33,5 @@ export { export { SerializeEvent } from './events'; -export * from './browser'; +import * as JSONOutput from './schema'; +export { JSONOutput }; diff --git a/src/lib/serialization/schema.ts b/src/lib/serialization/schema.ts new file mode 100644 index 000000000..d42562c58 --- /dev/null +++ b/src/lib/serialization/schema.ts @@ -0,0 +1,230 @@ +/** + * Contains interfaces which describe the JSON output. Each interface is related to a specific type of serializer. + * + * ## Plugins + * Plugins which modify the serialization process can use declaration merging + * to add custom properties to the exported interfaces. + * For example, if your custom serializer adds a property to all [[Reflection]] objects: + * ```ts + * declare module 'typedoc/dist/lib/serialization/schema' { + * export interface AbstractReflection { + * myCustomProp: boolean + * } + * } + * ``` + * + * If a plugin defines a new Model type, [[ModelToObject]] will not pick up the serializer type and + * the resulting type will not be included in the return type of {@link Serializer.toObject}. + * To fix this, use declaration merging to augment the [[Serializer]] class. + * ```ts + * declare module 'typedoc/dist/lib/serialization/serializer' { + * export interface Serializer { + * toObject(value: CustomModel, obj?: Partial): CustomOutput + * } + * } + * ``` + * + * For documentation on the JSON output properties, view the corresponding model. + */ + +/** */ +import * as M from '../models'; +import { SourceReferenceWrapper, DecoratorWrapper } from './serializers'; + +/** + * Describes the mapping from Model types to the corresponding JSON output type. + */ +export type ModelToObject = T extends Array ? _ModelToObject[] : _ModelToObject; + +// Order matters here. Some types are subtypes of other types. +type _ModelToObject = + // Reflections + T extends M.ReflectionGroup ? ReflectionGroup : + T extends M.ReflectionCategory ? ReflectionCategory : + T extends M.SignatureReflection ? SignatureReflection : + T extends M.ParameterReflection ? ParameterReflection : + T extends M.DeclarationReflection ? DeclarationReflection | ReflectionPointer : + T extends M.TypeParameterReflection ? TypeParameterReflection : + T extends M.ProjectReflection ? ProjectReflection : + T extends M.ContainerReflection ? ContainerReflection : + T extends M.Reflection ? Reflection : + // Types + T extends M.ArrayType ? ArrayType : + T extends M.IntersectionType ? IntersectionType : + T extends M.IntrinsicType ? IntrinsicType : + T extends M.ReferenceType ? ReferenceType : + T extends M.ReflectionType ? ReflectionType : + T extends M.StringLiteralType ? StringLiteralType : + T extends M.TupleType ? TupleType : + T extends M.UnknownType ? UnknownType : + T extends M.Type ? SomeType : // Technically AbstractType, but the union is more useful + // Miscellaneous + T extends M.Comment ? Comment : + T extends M.CommentTag ? CommentTag : + T extends DecoratorWrapper ? Decorator : + T extends SourceReferenceWrapper ? SourceReference : + never; + +type Primitive = string | number | undefined | null | boolean; + +/** + * Helper to describe a set of serialized properties. Primitive types are returned + * directly, while other models are first passed through ModelToObject. + * This helper removes the readonly modifier from properties since the result of serialization + * is a plain object that consumers may modify as they choose, TypeDoc doesn't care. + */ +type S = { + -readonly [K2 in K]: T[K2] extends Primitive ? T[K2] : ModelToObject +}; + +// Reflections + +export interface ReflectionGroup extends S { + children?: M.ReflectionGroup['children'][number]['id'][]; +} + +export interface ReflectionCategory extends S { + children?: M.ReflectionCategory['children'][number]['id'][]; +} + +export interface SignatureReflection extends Reflection, S { +} + +export interface ParameterReflection extends Reflection, S { +} + +export interface DeclarationReflection extends ContainerReflection, S { +} + +export interface TypeParameterReflection extends Reflection, S { +} + +// Nothing extra yet. +export interface ProjectReflection extends ContainerReflection { } + +export interface ContainerReflection extends Reflection, S { + sources?: ModelToObject; +} + +/** + * If a 3rd party serializer creates a loop when serializing, a pointer will be created + * instead of re-serializing the [[DeclarationReflection]] + */ +export interface ReflectionPointer extends S { +} + +export interface Reflection extends S { + originalName?: M.Reflection['originalName']; + flags: ReflectionFlags; + decorators?: ModelToObject; +} + +// Types + +export type SomeType = + | ArrayType + | IntersectionType + | UnionType + | IntrinsicType + | ReferenceType + | ReflectionType + | StringLiteralType + | TupleType + | TypeOperatorType + | TypeParameterType + | UnionType + | UnknownType; + +export interface ArrayType extends Type, S { +} + +export interface IntersectionType extends Type, S { +} + +export interface UnionType extends Type, S { +} + +export interface IntrinsicType extends Type, S { +} + +export interface ReferenceType extends Type, S { + id?: number; +} + +export interface ReflectionType extends Type, S { + declaration?: ModelToObject; +} + +export interface StringLiteralType extends Type, S { +} + +export interface TupleType extends Type, S { + elements?: ModelToObject; +} + +export interface TypeOperatorType extends Type, S { +} + +export interface TypeParameterType extends Type, S { +} + +export interface UnknownType extends Type, S { +} + +/** + * Technically not correct, the `type` property will be set by the abstract serializer. + * But to allow tagged literals, the `type` property is instead defined by each child type. + */ +export interface Type { +} + +// Miscellaneous + +export interface ReflectionFlags extends Partial> { +} + +export interface Comment extends Partial> { +} + +export interface CommentTag extends S { + tag: M.CommentTag['tagName']; + param?: M.CommentTag['paramName']; +} + +export interface SourceReference extends S { +} + +export interface Decorator extends S { +} diff --git a/src/lib/serialization/serializer.ts b/src/lib/serialization/serializer.ts index c77ecdb6a..fa508eafd 100644 --- a/src/lib/serialization/serializer.ts +++ b/src/lib/serialization/serializer.ts @@ -1,124 +1,137 @@ -import { ChildableComponent } from '../utils'; -import { Component, ComponentClass } from '../utils/component'; -import { Application } from '../application'; +import { EventDispatcher } from '../utils'; import { ProjectReflection } from '../models'; import { SerializerComponent } from './components'; -import { SerializeEvent } from './events'; - -@Component({name: 'serializer', internal: true, childClass: SerializerComponent}) -export class Serializer extends ChildableComponent> { - - /** - * Triggered when the [[Serializer]] begins transforming a project. - * @event EVENT_BEGIN - */ - static EVENT_BEGIN = 'begin'; - - /** - * Triggered when the [[Serializer]] has finished transforming a project. - * @event EVENT_END - */ - static EVENT_END = 'end'; - - private router!: Map[] }>; - private routes!: any[]; - - initialize(): void { - this.router = new Map[] }>(); - this.routes = []; - } - - addComponent & Component>(name: string, componentClass: T | ComponentClass): T { - const component = super.addComponent(name, componentClass); - - if (component.serializeGroup && component.serializeGroupSymbol) { - let match = this.router.get(component.serializeGroup); - - if (!match) { - match = Array.from(this.router.values()).find( v => v.symbol === component.serializeGroupSymbol) - || { symbol: component.serializeGroupSymbol , group: [] }; - this.router.set(component.serializeGroup, match); - this.routes.push(component.serializeGroup); - } - match.group.push(component); - match.group.sort((a, b) => (b.priority || 0) - (a.priority || 0)); +import { SerializeEvent, SerializeEventData } from './events'; +import { ModelToObject } from './schema'; +import * as S from './serializers'; + +export class Serializer extends EventDispatcher { + /** + * Triggered when the [[Serializer]] begins transforming a project. + * @event EVENT_BEGIN + */ + static EVENT_BEGIN = 'begin'; + + /** + * Triggered when the [[Serializer]] has finished transforming a project. + * @event EVENT_END + */ + static EVENT_END = 'end'; + + /** + * Serializers, sorted by their `serializeGroup` function to enable higher performance. + */ + private serializers = new Map<(instance: unknown) => boolean, SerializerComponent[]>(); + + constructor() { + super(); + addSerializers(this); } - return component; - } - - /** - * Remove a child component from the registry. - * @param name The name the component registered as - */ - removeComponent(name: string): SerializerComponent | undefined { - const component = super.removeComponent(name); - const symbol = component && component.serializeGroupSymbol; - if (symbol) { - const values = Array.from(this.router.values()); - for (let i = 0, len = values.length; i < len; i++) { - const idx = values[i].group.findIndex( o => o === symbol ); - if (idx > -1) { - values[i].group.splice(idx, 1); - break; + addSerializer(serializer: SerializerComponent): void { + let group = this.serializers.get(serializer.serializeGroup); + + if (!group) { + this.serializers.set(serializer.serializeGroup, (group = [])); } - } + + group.push(serializer); + group.sort((a, b) => b.priority - a.priority); } - return component; - } - - removeAllComponents() { - super.removeAllComponents(); - - this.router = new Map[] }>(); - this.routes = []; - } - - toObject(value: any, obj?: any): any { - return this.findRoutes(value) - .reduce( (result, curr) => curr.toObject(value, result), obj); - } - - /** - * Same as toObject but emits [[ Serializer#EVENT_BEGIN ]] and [[ Serializer#EVENT_END ]] events. - * @param value - * @param eventData Partial information to set in the event - * @return {any} - */ - projectToObject(value: ProjectReflection, eventData?: { begin?: any, end?: any }): any { - const eventBegin = new SerializeEvent(Serializer.EVENT_BEGIN, value); - - if (eventData && eventData.begin) { - Object.assign(eventBegin, eventData.begin); + + toObject(value: T, init: object = {}): ModelToObject { + // Note: This type *could* potentially lie, if a serializer declares a partial type but fails to provide + // the defined property, but the benefit of being mostly typed is probably worth it. + // TypeScript errors out if init is correctly typed as `Partial>` + return this.findSerializers(value).reduce((result, curr) => curr.toObject(value, result), init); } - let project: any = eventBegin.output = {}; - this.trigger(eventBegin); - project = this.toObject(value, project); + /** + * Same as toObject but emits [[ Serializer#EVENT_BEGIN ]] and [[ Serializer#EVENT_END ]] events. + * @param value + * @param eventData Partial information to set in the event + */ + projectToObject( + value: ProjectReflection, + eventData: { begin?: SerializeEventData; end?: SerializeEventData } = {} + ): ModelToObject { + const eventBegin = new SerializeEvent(Serializer.EVENT_BEGIN, value, {}); + if (eventData.begin) { + eventBegin.outputDirectory = eventData.begin.outputDirectory; + eventBegin.outputFile = eventData.begin.outputFile; + } + this.trigger(eventBegin); + + const project = this.toObject(value, eventBegin.output); + + const eventEnd = new SerializeEvent(Serializer.EVENT_END, value, project); + if (eventData.end) { + eventBegin.outputDirectory = eventData.end.outputDirectory; + eventBegin.outputFile = eventData.end.outputFile; + } + this.trigger(eventEnd); - const eventEnd = new SerializeEvent(Serializer.EVENT_END, value); - if (eventData && eventData.end) { - Object.assign(eventEnd, eventData.end); + return project; } - eventEnd.output = project; - this.trigger(eventEnd); - - return project; - } - - private findRoutes(value: any): SerializerComponent[] { - const routes: SerializerComponent[] = []; - for (let i = 0, len = this.routes.length; i < len; i++) { - if (this.routes[i](value)) { - const serializers = this.router.get(this.routes[i])!.group; - for (let serializer of serializers) { - if (serializer.supports(value)) { - routes.push(serializer); - } + + private findSerializers(value: T): SerializerComponent[] { + const routes: SerializerComponent[] = []; + + for (const [groupSupports, components] of this.serializers.entries()) { + if (groupSupports(value)) { + for (const component of components) { + if (component.supports(value)) { + routes.push(component); + } + } + } } - } + + return routes as any; + } +} + +const serializerComponents: (new (owner: Serializer) => SerializerComponent)[] = [ + S.CommentTagSerializer, + S.CommentSerializer, + + S.ReflectionSerializer, + S.ReferenceReflectionSerializer, + S.ContainerReflectionSerializer, + S.DeclarationReflectionSerializer, + S.ParameterReflectionSerializer, + S.ProjectReflectionSerializer, + S.SignatureReflectionSerializer, + S.TypeParameterReflectionSerializer, + + S.SourceReferenceContainerSerializer, + + S.TypeSerializer, + S.ArrayTypeSerializer, + S.ConditionalTypeSerializer, + S.IndexedAccessTypeSerializer, + S.InferredTypeSerializer, + S.IntersectionTypeSerializer, + S.IntrinsicTypeSerializer, + S.PredicateTypeSerializer, + S.ReferenceTypeSerializer, + S.ReferenceTypeSerializer, + S.ReflectionTypeSerializer, + S.StringLiteralTypeSerializer, + S.TupleTypeSerializer, + S.TypeOperatorTypeSerializer, + S.TypeParameterTypeSerializer, + S.UnionTypeSerializer, + S.UnknownTypeSerializer, + + S.DecoratorContainerSerializer, + S.ReflectionCategorySerializer, + S.ReflectionGroupSerializer +]; + +function addSerializers(owner: Serializer) { + for (const component of serializerComponents) { + owner.addSerializer(new component(owner)); } - return routes; - } } diff --git a/src/lib/serialization/serializers/comments/comment-tag.ts b/src/lib/serialization/serializers/comments/comment-tag.ts index c4b101094..8df3f3439 100644 --- a/src/lib/serialization/serializers/comments/comment-tag.ts +++ b/src/lib/serialization/serializers/comments/comment-tag.ts @@ -1,36 +1,32 @@ -import { Component } from '../../../utils/component'; import { CommentTag } from '../../../models'; import { SerializerComponent } from '../../components'; +import { CommentTag as JSONCommentTag } from '../../schema'; -@Component({name: 'serializer:comment-tag'}) export class CommentTagSerializer extends SerializerComponent { + static PRIORITY = 1000; - static PRIORITY = 1000; - - /** - * Filter for instances of [[CommentTag]] - */ - serializeGroup(instance: unknown): boolean { - return instance instanceof CommentTag; - } - - serializeGroupSymbol = CommentTag; + /** + * Filter for instances of [[CommentTag]] + */ + serializeGroup(instance: unknown): boolean { + return instance instanceof CommentTag; + } - supports(t: unknown) { - return true; - } + supports(t: unknown) { + return true; + } - toObject(tag: CommentTag, obj?: any): any { - obj = obj || {}; + toObject(tag: CommentTag, obj: Partial = {}): JSONCommentTag { + const result: JSONCommentTag = { + tag: tag.tagName, + text: tag.text + }; - obj.tag = tag.tagName; - obj.text = tag.text; + if (tag.paramName) { + result.param = tag.paramName; + } - if (tag.paramName) { - obj.param = tag.paramName; + return { ...obj, ...result }; } - - return obj; - } } diff --git a/src/lib/serialization/serializers/comments/comment.ts b/src/lib/serialization/serializers/comments/comment.ts index d05dd3914..a64d26397 100644 --- a/src/lib/serialization/serializers/comments/comment.ts +++ b/src/lib/serialization/serializers/comments/comment.ts @@ -1,43 +1,36 @@ -import { Component } from '../../../utils/component'; import { Comment } from '../../../models'; import { SerializerComponent } from '../../components'; +import { Comment as JSONComment } from '../../schema'; -@Component({name: 'serializer:comment'}) export class CommentSerializer extends SerializerComponent { + static PRIORITY = 1000; - static PRIORITY = 1000; - - /** - * Filter for instances of [[Comment]] - */ - serializeGroup(instance: unknown): boolean { - return instance instanceof Comment; - } - - supports(t: unknown) { - return true; - } - - serializeGroupSymbol = Comment; - - toObject(comment: Comment, obj?: any): any { - obj = obj || {}; - - if (comment.shortText) { - obj.shortText = comment.shortText; - } - if (comment.text) { - obj.text = comment.text; + /** + * Filter for instances of [[Comment]] + */ + serializeGroup(instance: unknown): boolean { + return instance instanceof Comment; } - if (comment.returns) { - obj.returns = comment.returns; + + supports(t: unknown) { + return true; } - if (comment.tags && comment.tags.length) { - obj.tags = []; - comment.tags.forEach((tag) => obj.tags.push(this.owner.toObject(tag))); + toObject(comment: Comment, obj: Partial = {}): JSONComment { + if (comment.shortText) { + obj.shortText = comment.shortText; + } + if (comment.text) { + obj.text = comment.text; + } + if (comment.returns) { + obj.returns = comment.returns; + } + if (comment.tags && comment.tags.length) { + obj.tags = comment.tags.map(tag => this.owner.toObject(tag)); + } + + return obj; } - return obj; - } } diff --git a/src/lib/serialization/serializers/decorator.ts b/src/lib/serialization/serializers/decorator.ts index eb66505b9..4a7c0d88d 100644 --- a/src/lib/serialization/serializers/decorator.ts +++ b/src/lib/serialization/serializers/decorator.ts @@ -1,45 +1,35 @@ -import { Component } from '../../utils/component'; - import { SerializerComponent } from '../components'; import { DecoratorWrapper } from './models/decorator-wrapper'; +import { Decorator } from '../schema'; -@Component({name: 'serializer:decorator-container'}) export class DecoratorContainerSerializer extends SerializerComponent { - - static PRIORITY = 1000; - - /** - * Filter for instances of [[DecoratorWrapper]] - */ - serializeGroup(instance: any): boolean { - return instance instanceof DecoratorWrapper; - } - - serializeGroupSymbol = DecoratorWrapper; - - initialize(): void { - super.initialize(); - } - - supports(s: unknown) { - return s instanceof DecoratorWrapper; - } - - toObject(decoratorWrapper: DecoratorWrapper, obj?: any): any { - obj = obj || {}; - - const decorator = decoratorWrapper.decorator; - obj.name = decorator.name; - - if (decorator.type) { - obj.type = this.owner.toObject(decorator.type); - } - - if (decorator.arguments) { - obj.arguments = decorator.arguments; - } - - return obj; - } - + static PRIORITY = 1000; + + /** + * Filter for instances of [[DecoratorWrapper]] + */ + serializeGroup(instance: unknown): boolean { + return instance instanceof DecoratorWrapper; + } + + supports(_: unknown) { + return true; + } + + toObject({ decorator }: DecoratorWrapper, obj?: Partial): Decorator { + const result: Decorator = { + ...obj, + name: decorator.name + }; + + if (decorator.type) { + result.type = this.owner.toObject(decorator.type); + } + + if (decorator.arguments) { + result.arguments = decorator.arguments; + } + + return result; + } } diff --git a/src/lib/serialization/serializers/models/decorator-wrapper.ts b/src/lib/serialization/serializers/models/decorator-wrapper.ts index 95e116ee2..522d73bb6 100644 --- a/src/lib/serialization/serializers/models/decorator-wrapper.ts +++ b/src/lib/serialization/serializers/models/decorator-wrapper.ts @@ -5,5 +5,5 @@ import { Decorator } from '../../../models'; * so it can be identified */ export class DecoratorWrapper { - constructor(public decorator: Decorator) { } + constructor(public decorator: Decorator) {} } diff --git a/src/lib/serialization/serializers/models/source-reference-wrapper.ts b/src/lib/serialization/serializers/models/source-reference-wrapper.ts index 1970d0fb6..b62b41082 100644 --- a/src/lib/serialization/serializers/models/source-reference-wrapper.ts +++ b/src/lib/serialization/serializers/models/source-reference-wrapper.ts @@ -1,9 +1,9 @@ -import { SourceReference } from '../../../models/sources/file'; +import { SourceReference } from '../../../models'; /** * An internal concrete implementation for the [[ SourceReference ]] interface * so it can be identified */ export class SourceReferenceWrapper { - constructor(public sourceReference: SourceReference) { } + constructor(public sourceReference: SourceReference) {} } diff --git a/src/lib/serialization/serializers/reflection-category.ts b/src/lib/serialization/serializers/reflection-category.ts index 5cc9a59e3..01fabc667 100644 --- a/src/lib/serialization/serializers/reflection-category.ts +++ b/src/lib/serialization/serializers/reflection-category.ts @@ -1,42 +1,32 @@ -import { Component } from '../../utils/component'; import { ReflectionCategory } from '../../models/ReflectionCategory'; import { SerializerComponent } from '../components'; +import { ReflectionCategory as JSONReflectionCategory } from '../schema'; -@Component({name: 'serializer:reflection-category'}) export class ReflectionCategorySerializer extends SerializerComponent { + static PRIORITY = 1000; - static PRIORITY = 1000; - - /** - * Filter for instances of [[ReflectionCategory]] - */ - serializeGroup(instance: any): boolean { - return instance instanceof ReflectionCategory; - } - - serializeGroupSymbol = ReflectionCategory; - - initialize(): void { - super.initialize(); - } + /** + * Filter for instances of [[ReflectionCategory]] + */ + serializeGroup(instance: any): boolean { + return instance instanceof ReflectionCategory; + } - supports(r: unknown) { - return r instanceof ReflectionCategory; - } + supports(r: unknown) { + return r instanceof ReflectionCategory; + } - toObject(category: ReflectionCategory, obj?: any): any { - obj = obj || {}; + toObject(category: ReflectionCategory, obj?: Partial): JSONReflectionCategory { + const result: JSONReflectionCategory = { + ...obj, + title: category.title + }; - Object.assign(obj, { - title: category.title - }); + if (category.children && category.children.length > 0) { + result.children = category.children.map(child => child.id); + } - if (category.children && category.children.length > 0) { - obj.children = category.children.map( child => child.id ); + return result; } - - return obj; - } - } diff --git a/src/lib/serialization/serializers/reflection-group.ts b/src/lib/serialization/serializers/reflection-group.ts index f52701213..27dcb6265 100644 --- a/src/lib/serialization/serializers/reflection-group.ts +++ b/src/lib/serialization/serializers/reflection-group.ts @@ -1,47 +1,37 @@ -import { Component } from '../../utils/component'; import { ReflectionGroup } from '../../models/ReflectionGroup'; import { SerializerComponent } from '../components'; +import { ReflectionGroup as JSONReflectionGroup } from '../schema'; -@Component({name: 'serializer:reflection-group'}) export class ReflectionGroupSerializer extends SerializerComponent { + static PRIORITY = 1000; - static PRIORITY = 1000; - - /** - * Filter for instances of [[ReflectionGroup]] - */ - serializeGroup(instance: any): boolean { - return instance instanceof ReflectionGroup; - } - - serializeGroupSymbol = ReflectionGroup; - - initialize(): void { - super.initialize(); - } + /** + * Filter for instances of [[ReflectionGroup]] + */ + serializeGroup(instance: unknown): boolean { + return instance instanceof ReflectionGroup; + } - supports(r: unknown) { - return r instanceof ReflectionGroup; - } + supports(r: unknown) { + return true; + } - toObject(group: ReflectionGroup, obj?: any): any { - obj = obj || {}; + toObject(group: ReflectionGroup, obj?: Partial): JSONReflectionGroup { + const result: JSONReflectionGroup = { + ...obj, + title: group.title, + kind: group.kind + }; - Object.assign(obj, { - title: group.title, - kind: group.kind - }); + if (group.children && group.children.length > 0) { + result.children = group.children.map(child => child.id); + } - if (group.children && group.children.length > 0) { - obj.children = group.children.map( child => child.id ); - } + if (group.categories && group.categories.length > 0) { + result.categories = group.categories.map(category => this.owner.toObject(category)); + } - if (group.categories && group.categories.length > 0) { - obj.categories = group.categories.map( category => this.owner.toObject(category) ); + return result; } - - return obj; - } - } diff --git a/src/lib/serialization/serializers/reflections/abstract.ts b/src/lib/serialization/serializers/reflections/abstract.ts index 3ec7069a2..148b313c0 100644 --- a/src/lib/serialization/serializers/reflections/abstract.ts +++ b/src/lib/serialization/serializers/reflections/abstract.ts @@ -1,64 +1,61 @@ -import { Component } from '../../../utils/component'; import { Reflection, TraverseProperty } from '../../../models'; import { ReflectionSerializerComponent } from '../../components'; import { DecoratorWrapper } from '../models'; import { ReflectionFlags } from '../../../models/reflections/abstract'; +import { Reflection as JSONReflection } from '../../schema'; -@Component({name: 'serializer:reflection'}) export class ReflectionSerializer extends ReflectionSerializerComponent { + static PRIORITY = 1000; - static PRIORITY = 1000; - - supports(t: unknown) { - return t instanceof Reflection; - } - - toObject(reflection: Reflection, obj?: any): any { - obj = obj || {}; - - Object.assign(obj, { - id: reflection.id, - name: reflection.name, - kind: reflection.kind, - kindString: reflection.kindString, - flags: {} // TODO: remove if no flags - }); - - if (reflection.originalName !== reflection.name) { - obj.originalName = reflection.originalName; - } - - if (reflection.comment) { - obj.comment = this.owner.toObject(reflection.comment); + supports(t: unknown) { + return t instanceof Reflection; } - for (const key of Object.getOwnPropertyNames(ReflectionFlags.prototype)) { - if (reflection.flags[key] === true) { - obj.flags[key] = true; - } + toObject(reflection: Reflection, obj?: Partial): JSONReflection { + const result: JSONReflection = { + ...obj, + id: reflection.id, + name: reflection.name, + kind: reflection.kind, + kindString: reflection.kindString, + flags: {} + }; + + if (reflection.originalName !== reflection.name) { + result.originalName = reflection.originalName; + } + + if (reflection.comment) { + result.comment = this.owner.toObject(reflection.comment); + } + + for (const key of Object.getOwnPropertyNames(ReflectionFlags.prototype)) { + if (reflection.flags[key] === true) { + result.flags[key] = true; + } + } + + if (reflection.decorates && reflection.decorates.length > 0) { + result.decorates = reflection.decorates.map(t => this.owner.toObject(t)); + } + + if (reflection.decorators && reflection.decorators.length > 0) { + result.decorators = reflection.decorators.map(d => this.owner.toObject(new DecoratorWrapper(d))); + } + + reflection.traverse((child, property) => { + if (property === TraverseProperty.TypeLiteral) { + return; + } + let name = TraverseProperty[property]; + name = name[0].toLowerCase() + name.substr(1); + if (!result[name]) { + result[name] = []; + } + result[name].push(this.owner.toObject(child)); + }); + + return result; } - - if (reflection.decorates && reflection.decorates.length > 0) { - obj.decorates = reflection.decorates.map( t => this.owner.toObject(t) ); - } - - if (reflection.decorators && reflection.decorators.length > 0) { - obj.decorators = reflection.decorators.map( d => this.owner.toObject(new DecoratorWrapper(d)) ); - } - - reflection.traverse((child, property) => { - if (property === TraverseProperty.TypeLiteral) { - return; - } - let name = TraverseProperty[property]; - name = name.substr(0, 1).toLowerCase() + name.substr(1); - if (!obj[name]) { - obj[name] = []; - } - obj[name].push(this.owner.toObject(child)); - }); - - return obj; - } } diff --git a/src/lib/serialization/serializers/reflections/container.ts b/src/lib/serialization/serializers/reflections/container.ts index 9ac6b5b34..7290f5ccc 100644 --- a/src/lib/serialization/serializers/reflections/container.ts +++ b/src/lib/serialization/serializers/reflections/container.ts @@ -1,39 +1,44 @@ -import { Component } from '../../../utils/component'; import { ContainerReflection } from '../../../models'; import { ReflectionSerializerComponent } from '../../components'; import { SourceReferenceWrapper } from '../models'; +import { ContainerReflection as JSONContainerReflection, Reflection as JSONReflection } from '../../schema'; -@Component({name: 'serializer:container-reflection'}) export class ContainerReflectionSerializer extends ReflectionSerializerComponent { - - supports(t: unknown) { - return t instanceof ContainerReflection; - } - - toObject(container: ContainerReflection, obj?: any): any { - obj = obj || {}; - - if (container.groups && container.groups.length > 0) { - obj.groups = container.groups.map( group => this.owner.toObject(group) ); + supports(t: unknown) { + return t instanceof ContainerReflection; } - if (container.categories && container.categories.length > 0) { - obj.categories = container.categories.map( category => this.owner.toObject(category) ); + /** + * Will be run after [[ReflectionSerializer]] so will be passed the result of that serialization. + * @param container + * @param obj + */ + toObject(container: ContainerReflection, obj: JSONReflection): JSONContainerReflection { + const result: JSONContainerReflection = { + ...obj + }; + + if (container.groups && container.groups.length > 0) { + result.groups = container.groups.map(group => this.owner.toObject(group)); + } + + if (container.categories && container.categories.length > 0) { + result.categories = container.categories.map(category => this.owner.toObject(category)); + } + + if (container.sources && container.sources.length > 0) { + result.sources = container.sources.map(source => + this.owner.toObject( + new SourceReferenceWrapper({ + fileName: source.fileName, + line: source.line, + character: source.character + }) + ) + ); + } + + return result; } - - if (container.sources && container.sources.length > 0) { - obj.sources = container.sources - .map( source => this.owner - .toObject(new SourceReferenceWrapper({ - fileName: source.fileName, - line: source.line, - character: source.character - })) - ); - } - - return obj; - } - } diff --git a/src/lib/serialization/serializers/reflections/declaration.ts b/src/lib/serialization/serializers/reflections/declaration.ts index 439419a83..0f88d6d77 100644 --- a/src/lib/serialization/serializers/reflections/declaration.ts +++ b/src/lib/serialization/serializers/reflections/declaration.ts @@ -1,58 +1,60 @@ -import { Component } from '../../../utils/component'; import { DeclarationReflection } from '../../../models'; import { ReflectionSerializerComponent } from '../../components'; import { ContainerReflectionSerializer } from './container'; +import { + DeclarationReflection as JSONDeclarationReflection, + ContainerReflection as JSONContainerReflection +} from '../../schema'; -@Component({name: 'serializer:declaration-reflection'}) export class DeclarationReflectionSerializer extends ReflectionSerializerComponent { + static PRIORITY = ContainerReflectionSerializer.PRIORITY - 1; // mimic inheritance, run after parent - static PRIORITY = ContainerReflectionSerializer.PRIORITY - 1; // mimic inheritance, run after parent + supports(t: unknown) { + return t instanceof DeclarationReflection; + } - supports(t: unknown) { - return t instanceof DeclarationReflection; - } + toObject(declaration: DeclarationReflection, obj: JSONContainerReflection): JSONDeclarationReflection { + const result: JSONDeclarationReflection = { + ...obj + }; - toObject(declaration: DeclarationReflection, obj?: any): any { - obj = obj || {}; + if (declaration.type) { + result.type = this.owner.toObject(declaration.type); + } - if (declaration.type) { - obj.type = this.owner.toObject(declaration.type); - } + if (declaration.defaultValue) { + result.defaultValue = declaration.defaultValue; + } - if (declaration.defaultValue) { - obj.defaultValue = declaration.defaultValue; - } + if (declaration.overwrites) { + result.overwrites = this.owner.toObject(declaration.overwrites); + } - if (declaration.overwrites) { - obj.overwrites = this.owner.toObject(declaration.overwrites); - } + if (declaration.inheritedFrom) { + result.inheritedFrom = this.owner.toObject(declaration.inheritedFrom); + } - if (declaration.inheritedFrom) { - obj.inheritedFrom = this.owner.toObject(declaration.inheritedFrom); - } + if (declaration.extendedTypes) { + result.extendedTypes = declaration.extendedTypes.map(t => this.owner.toObject(t)); + } - if (declaration.extendedTypes) { - obj.extendedTypes = declaration.extendedTypes.map((t) => this.owner.toObject(t) ); - } + if (declaration.extendedBy) { + result.extendedBy = declaration.extendedBy.map(t => this.owner.toObject(t)); + } - if (declaration.extendedBy) { - obj.extendedBy = declaration.extendedBy.map((t) => this.owner.toObject(t) ); - } + if (declaration.implementedTypes) { + result.implementedTypes = declaration.implementedTypes.map(t => this.owner.toObject(t)); + } - if (declaration.implementedTypes) { - obj.implementedTypes = declaration.implementedTypes.map((t) => this.owner.toObject(t) ); - } + if (declaration.implementedBy) { + result.implementedBy = declaration.implementedBy.map(t => this.owner.toObject(t)); + } - if (declaration.implementedBy) { - obj.implementedBy = declaration.implementedBy.map((t) => this.owner.toObject(t) ); - } + if (declaration.implementationOf) { + result.implementationOf = this.owner.toObject(declaration.implementationOf); + } - if (declaration.implementationOf) { - obj.implementationOf = this.owner.toObject(declaration.implementationOf); + return result; } - - return obj; - } - } diff --git a/src/lib/serialization/serializers/reflections/parameter.ts b/src/lib/serialization/serializers/reflections/parameter.ts index 3ef5e9e6b..2be25af1b 100644 --- a/src/lib/serialization/serializers/reflections/parameter.ts +++ b/src/lib/serialization/serializers/reflections/parameter.ts @@ -1,27 +1,26 @@ -import { Component } from '../../../utils/component'; import { ParameterReflection } from '../../../models'; import { ReflectionSerializerComponent } from '../../components'; +import { ParameterReflection as JSONParameterReflection, Reflection as JSONReflection } from '../../schema'; -@Component({name: 'serializer:parameter-reflection'}) export class ParameterReflectionSerializer extends ReflectionSerializerComponent { + supports(t: unknown) { + return t instanceof ParameterReflection; + } - supports(t: unknown) { - return t instanceof ParameterReflection; - } + toObject(parameter: ParameterReflection, obj: JSONReflection): JSONParameterReflection { + const result: JSONParameterReflection = { + ...obj + }; - toObject(parameter: ParameterReflection, obj?: any): any { - obj = obj || {}; + if (parameter.type) { + result.type = this.owner.toObject(parameter.type); + } - if (parameter.type) { - obj.type = this.owner.toObject(parameter.type); - } + if (parameter.defaultValue) { + result.defaultValue = parameter.defaultValue; + } - if (parameter.defaultValue) { - obj.defaultValue = parameter.defaultValue; + return result; } - - return obj; - } - } diff --git a/src/lib/serialization/serializers/reflections/project.ts b/src/lib/serialization/serializers/reflections/project.ts index 2db643a2d..c15ca5559 100644 --- a/src/lib/serialization/serializers/reflections/project.ts +++ b/src/lib/serialization/serializers/reflections/project.ts @@ -1,20 +1,20 @@ -import { Component } from '../../../utils/component'; import { ProjectReflection } from '../../../models'; import { ReflectionSerializerComponent } from '../../components'; import { ContainerReflectionSerializer } from './container'; +import { + ProjectReflection as JSONProjectReflection, + ContainerReflection as JSONContainerReflection +} from '../../schema'; -@Component({name: 'serializer:project-reflection'}) export class ProjectReflectionSerializer extends ReflectionSerializerComponent { + static PRIORITY = ContainerReflectionSerializer.PRIORITY - 1; // mimic inheritance, run after parent - static PRIORITY = ContainerReflectionSerializer.PRIORITY - 1; // mimic inheritance, run after parent - - supports(t: unknown) { - return t instanceof ProjectReflection; - } - - toObject(container: ProjectReflection, obj?: any): any { - return obj; - } + supports(t: unknown) { + return t instanceof ProjectReflection; + } + toObject(container: ProjectReflection, obj: JSONContainerReflection): JSONProjectReflection { + return obj; + } } diff --git a/src/lib/serialization/serializers/reflections/reference.ts b/src/lib/serialization/serializers/reflections/reference.ts index 030045835..4c20fdbfd 100644 --- a/src/lib/serialization/serializers/reflections/reference.ts +++ b/src/lib/serialization/serializers/reflections/reference.ts @@ -1,9 +1,6 @@ -import { Component } from '../../../utils/component'; import { ReferenceReflection } from '../../../models'; - import { ReflectionSerializerComponent } from '../../components'; -@Component({ name: 'serializer:reference-reflection' }) export class ReferenceReflectionSerializer extends ReflectionSerializerComponent { supports(t: unknown) { return t instanceof ReferenceReflection; diff --git a/src/lib/serialization/serializers/reflections/signature.ts b/src/lib/serialization/serializers/reflections/signature.ts index 1591f3588..f1efa30fb 100644 --- a/src/lib/serialization/serializers/reflections/signature.ts +++ b/src/lib/serialization/serializers/reflections/signature.ts @@ -1,35 +1,32 @@ -import { Component } from '../../../utils/component'; import { SignatureReflection } from '../../../models'; import { ReflectionSerializerComponent } from '../../components'; +import { SignatureReflection as JSONSignatureReflection, Reflection as JSONReflection } from '../../schema'; -@Component({name: 'serializer:signature-reflection'}) export class SignatureReflectionSerializer extends ReflectionSerializerComponent { + supports(t: unknown) { + return t instanceof SignatureReflection; + } - supports(t: unknown) { - return t instanceof SignatureReflection; - } + toObject(signature: SignatureReflection, obj: JSONReflection): JSONSignatureReflection { + const result: JSONSignatureReflection = { ...obj }; - toObject(signature: SignatureReflection, obj?: any): any { - obj = obj || {}; + if (signature.type) { + result.type = this.owner.toObject(signature.type); + } - if (signature.type) { - obj.type = this.owner.toObject(signature.type); - } + if (signature.overwrites) { + result.overwrites = this.owner.toObject(signature.overwrites); + } - if (signature.overwrites) { - obj.overwrites = this.owner.toObject(signature.overwrites); - } + if (signature.inheritedFrom) { + result.inheritedFrom = this.owner.toObject(signature.inheritedFrom); + } - if (signature.inheritedFrom) { - obj.inheritedFrom = this.owner.toObject(signature.inheritedFrom); - } + if (signature.implementationOf) { + result.implementationOf = this.owner.toObject(signature.implementationOf); + } - if (signature.implementationOf) { - obj.implementationOf = this.owner.toObject(signature.implementationOf); + return result; } - - return obj; - } - } diff --git a/src/lib/serialization/serializers/reflections/type-parameter.ts b/src/lib/serialization/serializers/reflections/type-parameter.ts index e86a4aa76..39766ea69 100644 --- a/src/lib/serialization/serializers/reflections/type-parameter.ts +++ b/src/lib/serialization/serializers/reflections/type-parameter.ts @@ -1,23 +1,23 @@ -import { Component } from '../../../utils/component'; import { TypeParameterReflection } from '../../../models'; import { ReflectionSerializerComponent } from '../../components'; +import { + TypeParameterReflection as JSONTypeParameterReflection, + Reflection as JSONReflection +} from '../../schema'; -@Component({name: 'serializer:type-parameter-reflection'}) export class TypeParameterReflectionSerializer extends ReflectionSerializerComponent { + supports(t: unknown) { + return t instanceof TypeParameterReflection; + } - supports(t: unknown) { - return t instanceof TypeParameterReflection; - } + toObject(typeParameter: TypeParameterReflection, obj: JSONReflection): JSONTypeParameterReflection { + const result: JSONTypeParameterReflection = { ...obj }; - toObject(typeParameter: TypeParameterReflection, obj?: any): any { - obj = obj || {}; + if (typeParameter.type) { + result.type = this.owner.toObject(typeParameter.type); + } - if (typeParameter.type) { - obj.type = this.owner.toObject(typeParameter.type); + return result; } - - return obj; - } - } diff --git a/src/lib/serialization/serializers/sources/source-reference.ts b/src/lib/serialization/serializers/sources/source-reference.ts index 8836dc054..fb22ec693 100644 --- a/src/lib/serialization/serializers/sources/source-reference.ts +++ b/src/lib/serialization/serializers/sources/source-reference.ts @@ -1,30 +1,27 @@ -import { Component } from '../../../utils/component'; - import { SerializerComponent } from '../../components'; -import { SourceReferenceWrapper } from '../models/source-reference-wrapper'; +import { SourceReferenceWrapper } from '../models'; +import { SourceReference as JSONSourceReference } from '../../schema'; -@Component({name: 'serializer:source-reference-container'}) export class SourceReferenceContainerSerializer extends SerializerComponent { - - static PRIORITY = 1000; - - serializeGroupSymbol = SourceReferenceWrapper; - serializeGroup(instance: unknown) { - return instance instanceof SourceReferenceWrapper; - } - - supports(t: unknown) { - return t instanceof SourceReferenceWrapper; - } - - toObject(sourceReferenceContainer: SourceReferenceWrapper, obj?: any): any { - obj = obj || {}; - - const sourceReference = sourceReferenceContainer.sourceReference; - obj.fileName = sourceReference.fileName; - obj.line = sourceReference.line; - obj.character = sourceReference.character; - - return obj; - } + static PRIORITY = 1000; + + serializeGroup(instance: unknown) { + return instance instanceof SourceReferenceWrapper; + } + + supports(_: unknown) { + return true; + } + + toObject( + { sourceReference: ref }: SourceReferenceWrapper, + obj?: Partial + ): JSONSourceReference { + return { + ...obj, + fileName: ref.fileName, + line: ref.line, + character: ref.character + }; + } } diff --git a/src/lib/serialization/serializers/types/abstract.ts b/src/lib/serialization/serializers/types/abstract.ts index 03991000a..59cb2966d 100644 --- a/src/lib/serialization/serializers/types/abstract.ts +++ b/src/lib/serialization/serializers/types/abstract.ts @@ -1,23 +1,19 @@ -import { Component } from '../../../utils/component'; import { Type } from '../../../models'; import { TypeSerializerComponent } from '../../components'; +import { Type as JSONType } from '../../schema'; -@Component({name: 'serializer:type'}) export class TypeSerializer extends TypeSerializerComponent { - - static PRIORITY = 1000; - - supports(t: unknown) { - return t instanceof Type; - } - - toObject(type: Type, obj?: any): any { - obj = obj || {}; - - obj.type = type.type; - - return obj; - } - + static PRIORITY = 1000; + + supports(t: unknown) { + return t instanceof Type; + } + + toObject(type: Type, obj?: Partial): JSONType { + return { + ...obj, + type: type.type + }; + } } diff --git a/src/lib/serialization/serializers/types/array.ts b/src/lib/serialization/serializers/types/array.ts index f2ea7128d..1f534bcf7 100644 --- a/src/lib/serialization/serializers/types/array.ts +++ b/src/lib/serialization/serializers/types/array.ts @@ -1,21 +1,22 @@ -import { Component } from '../../../utils/component'; import { ArrayType } from '../../../models'; import { TypeSerializerComponent } from '../../components'; +import { ArrayType as JSONArrayType } from '../../schema'; -@Component({name: 'serializer:array-type'}) export class ArrayTypeSerializer extends TypeSerializerComponent { + supports(t: unknown) { + return t instanceof ArrayType; + } - supports(t: unknown) { - return t instanceof ArrayType; - } - - toObject(arrayType: ArrayType, obj?: any): any { - obj = obj || {}; - - obj.elementType = this.owner.toObject(arrayType.elementType); - - return obj; - } - + /** + * Will be run after [[TypeSerializer]] so `type` will already be set. + * @param type + * @param obj + */ + toObject(type: ArrayType, obj: Pick): JSONArrayType { + return { + ...obj, + elementType: this.owner.toObject(type.elementType) + }; + } } diff --git a/src/lib/serialization/serializers/types/conditional.ts b/src/lib/serialization/serializers/types/conditional.ts index 65dae95a2..33100058b 100644 --- a/src/lib/serialization/serializers/types/conditional.ts +++ b/src/lib/serialization/serializers/types/conditional.ts @@ -1,8 +1,6 @@ -import { Component } from '../../../utils/component'; import { ConditionalType } from '../../../models'; import { TypeSerializerComponent } from '../../components'; -@Component({ name: 'serializer:conditional-type' }) export class ConditionalTypeSerializer extends TypeSerializerComponent { supports(item: unknown): boolean { return item instanceof ConditionalType; diff --git a/src/lib/serialization/serializers/types/index.ts b/src/lib/serialization/serializers/types/index.ts index e1be64dd2..172451468 100644 --- a/src/lib/serialization/serializers/types/index.ts +++ b/src/lib/serialization/serializers/types/index.ts @@ -3,7 +3,7 @@ export * from './array'; export * from './conditional'; export * from './indexed-access'; export * from './inferred'; -export * from './intersection-union'; +export * from './intersection'; export * from './intrinsic'; export * from './predicate'; export * from './reference'; @@ -12,4 +12,5 @@ export * from './string-literal'; export * from './tuple'; export * from './type-operator'; export * from './type-parameter'; +export * from './union'; export * from './unknown'; diff --git a/src/lib/serialization/serializers/types/indexed-access.ts b/src/lib/serialization/serializers/types/indexed-access.ts index f779467db..04688cdf7 100644 --- a/src/lib/serialization/serializers/types/indexed-access.ts +++ b/src/lib/serialization/serializers/types/indexed-access.ts @@ -1,8 +1,6 @@ -import { Component } from '../../../utils/component'; import { IndexedAccessType } from '../../../models'; import { TypeSerializerComponent } from '../../components'; -@Component({ name: 'serializer:indexed-access-type' }) export class IndexedAccessTypeSerializer extends TypeSerializerComponent { supports(item: unknown): boolean { return item instanceof IndexedAccessType; diff --git a/src/lib/serialization/serializers/types/inferred.ts b/src/lib/serialization/serializers/types/inferred.ts index 486d07e90..0cfcb7b33 100644 --- a/src/lib/serialization/serializers/types/inferred.ts +++ b/src/lib/serialization/serializers/types/inferred.ts @@ -1,8 +1,6 @@ -import { Component } from '../../../utils/component'; import { InferredType } from '../../../models'; import { TypeSerializerComponent } from '../../components'; -@Component({ name: 'serializer:inferred-type' }) export class InferredTypeSerializer extends TypeSerializerComponent { supports(item: unknown): boolean { return item instanceof InferredType; diff --git a/src/lib/serialization/serializers/types/intersection-union.ts b/src/lib/serialization/serializers/types/intersection-union.ts deleted file mode 100644 index 65b23f5b1..000000000 --- a/src/lib/serialization/serializers/types/intersection-union.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { Component } from '../../../utils/component'; -import { IntersectionType, UnionType } from '../../../models'; - -import { TypeSerializerComponent } from '../../components'; - -export type IntersectionUnion = IntersectionType | UnionType; - -@Component({name: 'serializer:intersection-type'}) -export class IntersectionTypeSerializer extends TypeSerializerComponent { - - supports(t: unknown) { - return t instanceof IntersectionType || t instanceof UnionType; - } - - toObject(intersectionUnion: IntersectionUnion, obj?: any): any { - obj = obj || {}; - - if (intersectionUnion.types && intersectionUnion.types.length) { - obj.types = intersectionUnion.types.map( t => this.owner.toObject(t) ); - } - - return obj; - } - -} diff --git a/src/lib/serialization/serializers/types/intersection.ts b/src/lib/serialization/serializers/types/intersection.ts new file mode 100644 index 000000000..40eecd572 --- /dev/null +++ b/src/lib/serialization/serializers/types/intersection.ts @@ -0,0 +1,22 @@ +import { IntersectionType } from '../../../models'; + +import { TypeSerializerComponent } from '../../components'; +import { IntersectionType as JSONIntersectionType } from '../../schema'; + +export class IntersectionTypeSerializer extends TypeSerializerComponent { + supports(t: unknown) { + return t instanceof IntersectionType; + } + + /** + * Will be run after [[TypeSerializer]] so `type` will already be set. + * @param type + * @param obj + */ + toObject(type: IntersectionType, obj: Pick): JSONIntersectionType { + return { + ...obj, + types: type.types.map(t => this.owner.toObject(t)) + }; + } +} diff --git a/src/lib/serialization/serializers/types/intrinsic.ts b/src/lib/serialization/serializers/types/intrinsic.ts index fc4b5d8ca..676ea9318 100644 --- a/src/lib/serialization/serializers/types/intrinsic.ts +++ b/src/lib/serialization/serializers/types/intrinsic.ts @@ -1,21 +1,22 @@ -import { Component } from '../../../utils/component'; import { IntrinsicType } from '../../../models'; import { TypeSerializerComponent } from '../../components'; +import { IntrinsicType as JSONIntrinsicType } from '../../schema'; -@Component({name: 'serializer:intrinsic-type'}) export class IntrinsicTypeSerializer extends TypeSerializerComponent { + supports(t: unknown) { + return t instanceof IntrinsicType; + } - supports(t: unknown) { - return t instanceof IntrinsicType; - } - - toObject(intrinsic: IntrinsicType, obj?: any): any { - obj = obj || {}; - - obj.name = intrinsic.name; - - return obj; - } - + /** + * Will be run after [[TypeSerializer]] so `type` will already be set. + * @param type + * @param obj + */ + toObject(type: IntrinsicType, obj: Pick): JSONIntrinsicType { + return { + ...obj, + name: type.name + }; + } } diff --git a/src/lib/serialization/serializers/types/predicate.ts b/src/lib/serialization/serializers/types/predicate.ts index 614d9acd3..d0c5a7b5f 100644 --- a/src/lib/serialization/serializers/types/predicate.ts +++ b/src/lib/serialization/serializers/types/predicate.ts @@ -1,8 +1,6 @@ -import { Component } from '../../../utils/component'; import { PredicateType } from '../../../models'; import { TypeSerializerComponent } from '../../components'; -@Component({ name: 'serializer:predicate-type' }) export class PredicateTypeSerializer extends TypeSerializerComponent { supports(t: unknown) { return t instanceof PredicateType; diff --git a/src/lib/serialization/serializers/types/reference.ts b/src/lib/serialization/serializers/types/reference.ts index 559000750..34346fd1a 100644 --- a/src/lib/serialization/serializers/types/reference.ts +++ b/src/lib/serialization/serializers/types/reference.ts @@ -1,29 +1,28 @@ -import { Component } from '../../../utils/component'; import { ReferenceType } from '../../../models'; import { TypeSerializerComponent } from '../../components'; +import { ReferenceType as JSONReferenceType } from '../../schema'; -@Component({name: 'serializer:reference-type'}) export class ReferenceTypeSerializer extends TypeSerializerComponent { - - supports(t: unknown) { - return t instanceof ReferenceType; - } - - toObject(reference: ReferenceType, obj?: any): any { - obj = obj || {}; - - obj.name = reference.name; - - if (reference.reflection) { - obj.id = reference.reflection.id; + supports(t: unknown) { + return t instanceof ReferenceType; } - if (reference.typeArguments && reference.typeArguments.length > 0) { - obj.typeArguments = reference.typeArguments.map( t => this.owner.toObject(t) ); + toObject( + type: ReferenceType, + obj: Pick & Partial + ): JSONReferenceType { + if (type.reflection) { + obj.id = type.reflection.id; + } + + if (type.typeArguments && type.typeArguments.length > 0) { + obj.typeArguments = type.typeArguments.map(t => this.owner.toObject(t)); + } + + return { + ...obj, + name: type.name + }; } - - return obj; - } - } diff --git a/src/lib/serialization/serializers/types/reflection.ts b/src/lib/serialization/serializers/types/reflection.ts index feddf59ce..a4285958c 100644 --- a/src/lib/serialization/serializers/types/reflection.ts +++ b/src/lib/serialization/serializers/types/reflection.ts @@ -1,43 +1,43 @@ -import { Component } from '../../../utils/component'; import { DeclarationReflection, ReflectionType } from '../../../models'; import { TypeSerializerComponent } from '../../components'; +import { ReflectionType as JSONReflectionType } from '../../schema'; -@Component({name: 'serializer:reflection-type'}) export class ReflectionTypeSerializer extends TypeSerializerComponent { + private visited = new Set(); - private declaration?: DeclarationReflection; - - supports(t: unknown) { - return t instanceof ReflectionType; - } - - toObject(reference: ReflectionType, obj?: any): any { - obj = obj || {}; - - if (reference.declaration) { - - // Because `DeclarationReflection` has reference to multiple types objectifying a declaration - // on a type might fall into a loop trap (cyclic dependency). - // The TypeDoc code does not apply logic that can create this scenario but a 3rd party plugin - // might do that unintentionally so a protection is in place. - - if (this.declaration === reference.declaration) { - // if we're here it means that the reference type is rendered for the 2nd time - // by the declaration it is referencing, we will render a pointer-only declaration. - obj.declaration = { id: reference.declaration.id }; - } else { - // mark this declaration to trap a loop - this.declaration = reference.declaration; - - // objectify the declaration - obj.declaration = this.owner.toObject(reference.declaration); - } - - // no more declaration rendering, remove marker. - this.declaration = undefined; + supports(t: unknown) { + return t instanceof ReflectionType; } - return obj; - } + toObject(reference: ReflectionType, obj: Pick): JSONReflectionType { + const result: JSONReflectionType = { + ...obj + }; + + // Because `DeclarationReflection` has reference to multiple types objectifying a declaration + // on a type might fall into a loop trap (cyclic dependency). + // The TypeDoc code does not apply logic that can create this scenario but a 3rd party plugin + // might do that unintentionally so a protection is in place. + // TODO: Should this protection really be here? It seems like it might make more sense to + // do this check in the DeclarationReflection serializer... if it should even be checked. In the + // old `.toObject` code, it wasn't checked. + + if (this.visited.has(reference.declaration)) { + // if we're here it means that the reference type is rendered for the 2nd time + // by the declaration it is referencing, we will render a pointer-only declaration. + result.declaration = { id: reference.declaration.id }; + } else { + // mark this declaration to trap a loop + this.visited.add(reference.declaration); + + // objectify the declaration + result.declaration = this.owner.toObject(reference.declaration); + } + + // no more declaration rendering, remove marker. + this.visited.delete(reference.declaration); + + return result; + } } diff --git a/src/lib/serialization/serializers/types/string-literal.ts b/src/lib/serialization/serializers/types/string-literal.ts index 0fb4906a5..cc15a1415 100644 --- a/src/lib/serialization/serializers/types/string-literal.ts +++ b/src/lib/serialization/serializers/types/string-literal.ts @@ -1,21 +1,17 @@ -import { Component } from '../../../utils/component'; import { StringLiteralType } from '../../../models'; import { TypeSerializerComponent } from '../../components'; +import { StringLiteralType as JSONStringLiteralType } from '../../schema'; -@Component({name: 'serializer:string-literal-type'}) export class StringLiteralTypeSerializer extends TypeSerializerComponent { + supports(t: unknown) { + return t instanceof StringLiteralType; + } - supports(t: unknown) { - return t instanceof StringLiteralType; - } - - toObject(stringLiteral: StringLiteralType, obj?: any): any { - obj = obj || {}; - - obj.value = stringLiteral.value; - - return obj; - } - + toObject(type: StringLiteralType, obj: Pick): JSONStringLiteralType { + return { + ...obj, + value: type.value + }; + } } diff --git a/src/lib/serialization/serializers/types/tuple.ts b/src/lib/serialization/serializers/types/tuple.ts index 617016cf3..0aebed210 100644 --- a/src/lib/serialization/serializers/types/tuple.ts +++ b/src/lib/serialization/serializers/types/tuple.ts @@ -1,23 +1,20 @@ -import { Component } from '../../../utils/component'; import { TupleType } from '../../../models'; import { TypeSerializerComponent } from '../../components'; +import { TupleType as JSONTupleType } from '../../schema'; -@Component({name: 'serializer:tuple-type'}) export class TupleTypeSerializer extends TypeSerializerComponent { + supports(t: unknown) { + return t instanceof TupleType; + } - supports(t: unknown) { - return t instanceof TupleType; - } + toObject(tuple: TupleType, obj: Pick): JSONTupleType { + const result: JSONTupleType = { ...obj }; - toObject(tuple: TupleType, obj?: any): any { - obj = obj || {}; + if (tuple.elements && tuple.elements.length > 0) { + result.elements = tuple.elements.map(t => this.owner.toObject(t)); + } - if (tuple.elements && tuple.elements.length > 0) { - obj.elements = tuple.elements.map( t => this.owner.toObject(t) ); + return result; } - - return obj; - } - } diff --git a/src/lib/serialization/serializers/types/type-operator.ts b/src/lib/serialization/serializers/types/type-operator.ts index 5f2235913..200c024df 100644 --- a/src/lib/serialization/serializers/types/type-operator.ts +++ b/src/lib/serialization/serializers/types/type-operator.ts @@ -1,22 +1,18 @@ -import { Component } from '../../../utils/component'; import { TypeOperatorType } from '../../../models'; import { TypeSerializerComponent } from '../../components'; +import { TypeOperatorType as JSONTypeOperatorType } from '../../schema'; -@Component({name: 'serializer:type-operator-type'}) export class TypeOperatorTypeSerializer extends TypeSerializerComponent { + supports(t: unknown) { + return t instanceof TypeOperatorType; + } - supports(t: unknown) { - return t instanceof TypeOperatorType; - } - - toObject(typeOperator: TypeOperatorType, obj?: any): any { - obj = obj || {}; - - obj.operator = typeOperator.operator; - obj.target = this.owner.toObject(typeOperator.target); - - return obj; - } - + toObject(type: TypeOperatorType, obj: Pick): JSONTypeOperatorType { + return { + ...obj, + operator: type.operator, + target: this.owner.toObject(type.target) + }; + } } diff --git a/src/lib/serialization/serializers/types/type-parameter.ts b/src/lib/serialization/serializers/types/type-parameter.ts index 92027ecb8..ab2925700 100644 --- a/src/lib/serialization/serializers/types/type-parameter.ts +++ b/src/lib/serialization/serializers/types/type-parameter.ts @@ -1,25 +1,23 @@ -import { Component } from '../../../utils/component'; import { TypeParameterType } from '../../../models'; import { TypeSerializerComponent } from '../../components'; +import { TypeParameterType as JSONTypeParameterType } from '../../schema'; -@Component({name: 'serializer:type-parameter-type'}) export class TypeParameterTypeSerializer extends TypeSerializerComponent { + supports(t: unknown) { + return t instanceof TypeParameterType; + } - supports(t: unknown) { - return t instanceof TypeParameterType; - } - - toObject(typeParameter: TypeParameterType, obj?: any): any { - obj = obj || {}; + toObject(type: TypeParameterType, obj: Pick): JSONTypeParameterType { + const result: JSONTypeParameterType = { + ...obj, + name: type.name + }; - obj.name = typeParameter.name; + if (type.constraint) { + result.constraint = this.owner.toObject(type.constraint); + } - if (typeParameter.constraint) { - obj.constraint = this.owner.toObject(typeParameter.constraint); + return result; } - - return obj; - } - } diff --git a/src/lib/serialization/serializers/types/union.ts b/src/lib/serialization/serializers/types/union.ts new file mode 100644 index 000000000..75df55e34 --- /dev/null +++ b/src/lib/serialization/serializers/types/union.ts @@ -0,0 +1,22 @@ +import { UnionType } from '../../../models'; + +import { TypeSerializerComponent } from '../../components'; +import { UnionType as JSONUnionType } from '../../schema'; + +export class UnionTypeSerializer extends TypeSerializerComponent { + supports(t: unknown) { + return t instanceof UnionType; + } + + /** + * Will be run after [[TypeSerializer]] so `type` will already be set. + * @param type + * @param obj + */ + toObject(type: UnionType, obj: Pick): JSONUnionType { + return { + ...obj, + types: type.types.map(t => this.owner.toObject(t)) + }; + } +} diff --git a/src/lib/serialization/serializers/types/unknown.ts b/src/lib/serialization/serializers/types/unknown.ts index 56784473a..01caa451f 100644 --- a/src/lib/serialization/serializers/types/unknown.ts +++ b/src/lib/serialization/serializers/types/unknown.ts @@ -1,21 +1,22 @@ -import { Component } from '../../../utils/component'; import { UnknownType } from '../../../models'; import { TypeSerializerComponent } from '../../components'; +import { UnknownType as JSONUnknownType } from '../../schema'; -@Component({name: 'serializer:unknown-type'}) export class UnknownTypeSerializer extends TypeSerializerComponent { + supports(t: unknown) { + return t instanceof UnknownType; + } - supports(t: unknown) { - return t instanceof UnknownType; - } - - toObject(unknown: UnknownType, obj?: any): any { - obj = obj || {}; - - obj.name = unknown.name; - - return obj; - } - + /** + * Will be run after [[TypeSerializer]] so `type` will already be set. + * @param type + * @param obj + */ + toObject(type: UnknownType, obj: Pick): JSONUnknownType { + return { + ...obj, + name: type.name + }; + } } diff --git a/tslint.json b/tslint.json index 1718dddfd..10ad5d89b 100644 --- a/tslint.json +++ b/tslint.json @@ -1,65 +1,92 @@ { - "rules": { - "align": false, - "class-name": true, - "comment-format": [ true, "check-space" ], - "curly": true, - "eofline": true, - "forin": false, - "indent": [ true, "spaces", 4 ], - "interface-name": [ true, "never-prefix" ], - "jsdoc-format": true, - "label-position": true, - "max-line-length": [true, 170], - "member-access": false, - "member-ordering": false, - "no-any": false, - "no-arg": true, - "no-bitwise": false, - "no-consecutive-blank-lines": true, - "no-console": false, - "no-construct": false, - "no-debugger": true, - "no-duplicate-variable": true, - "no-empty": false, - "no-eval": true, - "no-for-in-array": true, - "no-inferrable-types": [ true, "ignore-params" ], - "no-shadowed-variable": false, - "no-string-literal": false, - "no-switch-case-fall-through": false, - "no-trailing-whitespace": true, - "no-unnecessary-type-assertion": true, - "no-unused-expression": false, - "no-use-before-declare": false, - "no-var-keyword": true, - "no-var-requires": false, - "strict-type-predicates": true, - "object-literal-sort-keys": false, - "one-line": [ true, "check-open-brace", "check-whitespace", "check-else", "check-catch" ], - "quotemark": [ true, "single", "avoid-escape" ], - "radix": true, - "semicolon": [ true, "always" ], - "trailing-comma": [ true, { - "multiline": "never", - "singleline": "never" - } ], - "triple-equals": [ true, "allow-null-check" ], - "typedef": false, - "typedef-whitespace": [ true, { - "call-signature": "nospace", - "index-signature": "nospace", - "parameter": "nospace", - "property-declaration": "nospace", - "variable-declaration": "nospace" - }, { - "call-signature": "onespace", - "index-signature": "onespace", - "parameter": "onespace", - "property-declaration": "onespace", - "variable-declaration": "onespace" - } ], - "variable-name": [ true, "check-format", "allow-leading-underscore", "ban-keywords" ], - "whitespace": [ true, "check-branch", "check-decl", "check-operator", "check-module", "check-separator", "check-type", "check-typecast" ] - } + "rules": { + "align": false, + "class-name": true, + "comment-format": [true, "check-space"], + "curly": true, + "eofline": true, + "forin": false, + "indent": [true, "spaces", 4], + "interface-name": [true, "never-prefix"], + "jsdoc-format": true, + "label-position": true, + "max-line-length": [true, 170], + "member-access": false, + "member-ordering": false, + "no-any": false, + "no-arg": true, + "no-bitwise": false, + "no-consecutive-blank-lines": true, + "no-console": false, + "no-construct": false, + "no-debugger": true, + "no-duplicate-variable": true, + "no-empty": false, + "no-eval": true, + "no-for-in-array": true, + "no-inferrable-types": [true, "ignore-params"], + "no-shadowed-variable": false, + "no-string-literal": false, + "no-switch-case-fall-through": false, + "no-trailing-whitespace": true, + "no-unnecessary-type-assertion": true, + "no-unused-expression": false, + "no-use-before-declare": false, + "no-var-keyword": true, + "no-var-requires": false, + "strict-type-predicates": true, + "object-literal-sort-keys": false, + "one-line": [ + true, + "check-open-brace", + "check-whitespace", + "check-else", + "check-catch" + ], + "quotemark": [true, "single", "avoid-escape"], + "radix": true, + "semicolon": [true, "always"], + "trailing-comma": [ + true, + { + "multiline": "never", + "singleline": "never" + } + ], + "triple-equals": [true, "allow-null-check"], + "typedef": false, + "typedef-whitespace": [ + true, + { + "call-signature": "nospace", + "index-signature": "nospace", + "parameter": "nospace", + "property-declaration": "nospace", + "variable-declaration": "nospace" + }, + { + "call-signature": "onespace", + "index-signature": "onespace", + "parameter": "onespace", + "property-declaration": "onespace", + "variable-declaration": "onespace" + } + ], + "variable-name": [ + true, + "check-format", + "allow-leading-underscore", + "ban-keywords" + ], + "whitespace": [ + true, + "check-branch", + "check-decl", + "check-operator", + "check-module", + "check-separator", + "check-type", + "check-typecast" + ] + } }