Skip to content

Commit

Permalink
Merge branch 'fix/serializer-plugin'
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit0 committed Jan 11, 2020
2 parents b2782d5 + 5a2fac6 commit 7dee2c3
Show file tree
Hide file tree
Showing 74 changed files with 1,065 additions and 1,724 deletions.
13 changes: 5 additions & 8 deletions scripts/rebuild_specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ export {
ParameterType,
TypeDocOptions
} from './lib/utils/options';

export { JSONOutput } from './lib/serialization';
6 changes: 3 additions & 3 deletions src/lib/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', Converter);
this.serializer = this.addComponent<Serializer>('serializer', Serializer);
this.renderer = this.addComponent<Renderer>('renderer', Renderer);
this.plugins = this.addComponent('plugins', PluginHost);
this.renderer = this.addComponent<Renderer>('renderer', Renderer);
this.plugins = this.addComponent('plugins', PluginHost);

this.bootstrap(options);
}
Expand Down
21 changes: 0 additions & 21 deletions src/lib/models/ReflectionCategory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
31 changes: 0 additions & 31 deletions src/lib/models/ReflectionGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
24 changes: 0 additions & 24 deletions src/lib/models/comments/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
17 changes: 0 additions & 17 deletions src/lib/models/comments/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
2 changes: 2 additions & 0 deletions src/lib/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
60 changes: 0 additions & 60 deletions src/lib/models/reflections/abstract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
43 changes: 0 additions & 43 deletions src/lib/models/reflections/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
46 changes: 0 additions & 46 deletions src/lib/models/reflections/declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/lib/models/reflections/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
18 changes: 0 additions & 18 deletions src/lib/models/reflections/parameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
11 changes: 0 additions & 11 deletions src/lib/models/reflections/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]];
Expand Down
Loading

0 comments on commit 7dee2c3

Please sign in to comment.