Skip to content

Commit

Permalink
feat(deps): decorators arguments listing
Browse files Browse the repository at this point in the history
fix #630
fix #640
  • Loading branch information
vogloblinsky committed Oct 17, 2018
1 parent 4e7593b commit bd23ec8
Show file tree
Hide file tree
Showing 21 changed files with 326 additions and 287 deletions.
126 changes: 61 additions & 65 deletions src/app/application.ts

Large diffs are not rendered by default.

150 changes: 118 additions & 32 deletions src/app/compiler/angular/deps/helpers/class-helper.ts
Expand Up @@ -10,14 +10,19 @@ import { ConfigurationInterface } from '../../../../interfaces/configuration.int
import { JsdocParserUtil } from '../../../../../utils/jsdoc-parser.util';
import { ImportsUtil } from '../../../../../utils/imports.util';
import { logger } from '../../../../../logger';
import { isIgnore } from '../../../../../utils';
import { isIgnore, AngularVersionUtil, BasicTypeUtil } from '../../../../../utils';
import { StringifyObjectLiteralExpression } from '../../../../../utils/object-literal-expression.util';

import DependenciesEngine from '../../../../engines/dependencies.engine';

const crypto = require('crypto');
const marked = require('marked');

export class ClassHelper {
private jsdocParserUtil = new JsdocParserUtil();
private importsUtil = new ImportsUtil();
private angularVersionUtil = new AngularVersionUtil();
private basicTypeUtil = new BasicTypeUtil();

constructor(
private typeChecker: ts.TypeChecker,
Expand Down Expand Up @@ -61,18 +66,12 @@ export class ClassHelper {
_.forEach(decorators, (decorator: any) => {
if (decorator.expression) {
if (decorator.expression.text) {
_decorators.push({
name: decorator.expression.text
});
_decorators.push({ name: decorator.expression.text });
}
if (decorator.expression.expression) {
let info: any = {
name: decorator.expression.expression.text
};
let info: any = { name: decorator.expression.expression.text };
if (decorator.expression.arguments) {
if (decorator.expression.arguments.length > 0) {
info.args = decorator.expression.arguments;
}
info.stringifiedArguments = this.stringifyArguments(decorator.expression.arguments);
}
_decorators.push(info);
}
Expand All @@ -82,6 +81,111 @@ export class ClassHelper {
return _decorators;
}

private handleFunction(arg): string {
if (arg.function.length === 0) {
return `${arg.name}${this.getOptionalString(arg)}: () => void`;
}

let argums = arg.function.map(argu => {
let _result = DependenciesEngine.find(argu.type);
if (_result) {
if (_result.source === 'internal') {
let path = _result.data.type;
if (_result.data.type === 'class') {
path = 'classe';
}
return `${argu.name}${this.getOptionalString(arg)}: <a href="../${path}s/${
_result.data.name
}.html">${argu.type}</a>`;
} else {
let path = this.angularVersionUtil.getApiLink(
_result.data,
this.configuration.mainData.angularVersion
);
return `${argu.name}${this.getOptionalString(
arg
)}: <a href="${path}" target="_blank">${argu.type}</a>`;
}
} else if (this.basicTypeUtil.isKnownType(argu.type)) {
let path = this.basicTypeUtil.getTypeUrl(argu.type);
return `${argu.name}${this.getOptionalString(
arg
)}: <a href="${path}" target="_blank">${argu.type}</a>`;
} else {
if (argu.name && argu.type) {
return `${argu.name}${this.getOptionalString(arg)}: ${argu.type}`;
} else {
if (argu.name) {
return `${argu.name.text}`;
} else {
return '';
}
}
}
});
return `${arg.name}${this.getOptionalString(arg)}: (${argums}) => void`;
}

private getOptionalString(arg): string {
return arg.optional ? '?' : '';
}

private stringifyArguments(args) {
let stringifyArgs = [];

stringifyArgs = args
.map(arg => {
let _result = DependenciesEngine.find(arg.type);
if (_result) {
if (_result.source === 'internal') {
let path = _result.data.type;
if (_result.data.type === 'class') {
path = 'classe';
}
return `${arg.name}${this.getOptionalString(arg)}: <a href="../${path}s/${
_result.data.name
}.html">${arg.type}</a>`;
} else {
let path = this.angularVersionUtil.getApiLink(
_result.data,
this.configuration.mainData.angularVersion
);
return `${arg.name}${this.getOptionalString(
arg
)}: <a href="${path}" target="_blank">${arg.type}</a>`;
}
} else if (arg.dotDotDotToken) {
return `...${arg.name}: ${arg.type}`;
} else if (arg.function) {
return this.handleFunction(arg);
} else if (arg.expression && arg.name) {
return arg.expression.text + '.' + arg.name.text;
} else if (arg.expression && arg.kind === SyntaxKind.NewExpression) {
return 'new ' + arg.expression.text + '()';
} else if (arg.kind && arg.kind === SyntaxKind.StringLiteral) {
return `'` + arg.text + `'`;
} else if (arg.kind && arg.kind === SyntaxKind.ObjectLiteralExpression) {
return StringifyObjectLiteralExpression(arg);
} else if (this.basicTypeUtil.isKnownType(arg.type)) {
let path = this.basicTypeUtil.getTypeUrl(arg.type);
return `${arg.name}${this.getOptionalString(
arg
)}: <a href="${path}" target="_blank">${arg.type}</a>`;
} else {
if (arg.type) {
return `${arg.name}${this.getOptionalString(arg)}: ${arg.type}`;
} else if (arg.text) {
return `${arg.text}`;
} else {
return `${arg.name}${this.getOptionalString(arg)}`;
}
}
})
.join(', ');

return stringifyArgs;
}

private getPosition(node: ts.Node, sourceFile: ts.SourceFile): ts.LineAndCharacter {
let position: ts.LineAndCharacter;
if (node.name && node.name.end) {
Expand Down Expand Up @@ -289,19 +393,11 @@ export class ClassHelper {
if (symbol) {
description = marked(this.jsdocParserUtil.getMainCommentOfNode(classDeclaration));
if (symbol.valueDeclaration && isIgnore(symbol.valueDeclaration)) {
return [
{
ignore: true
}
];
return [{ ignore: true }];
}
if (symbol.declarations && symbol.declarations.length > 0) {
if (isIgnore(symbol.declarations[0])) {
return [
{
ignore: true
}
];
return [{ ignore: true }];
}
}
}
Expand Down Expand Up @@ -389,14 +485,7 @@ export class ClassHelper {
}
];
} else if (this.isModuleDecorator(classDeclaration.decorators[i])) {
return [
{
fileName,
className,
description,
jsdoctags: jsdoctags
}
];
return [{ fileName, className, description, jsdoctags: jsdoctags }];
} else {
return [
{
Expand Down Expand Up @@ -1065,10 +1154,7 @@ export class ClassHelper {
}

private visitArgument(arg: ts.ParameterDeclaration) {
let _result: any = {
name: arg.name.text,
type: this.visitType(arg)
};
let _result: any = { name: arg.name.text, type: this.visitType(arg) };
if (arg.dotDotDotToken) {
_result.dotDotDotToken = true;
}
Expand Down
42 changes: 32 additions & 10 deletions src/app/engines/dependencies.engine.ts
Expand Up @@ -39,10 +39,28 @@ export class DependenciesEngine {
public routes: RouteInterface;
public pipes: Object[];
public classes: Object[];
public miscellaneous: MiscellaneousData;
public miscellaneous: MiscellaneousData = {
variables: [],
functions:[],
typealiases:[],
enumerations:[],
groupedVariables: [],
groupedFunctions: [],
groupedEnumerations: [],
groupedTypeAliases: [],
};

private angularApiUtil: AngularApiUtil = new AngularApiUtil();

private static instance: DependenciesEngine;
private constructor() { }
public static getInstance() {
if (!DependenciesEngine.instance) {
DependenciesEngine.instance = new DependenciesEngine();
}
return DependenciesEngine.instance;
}

private updateModulesDeclarationsExportsTypes() {
let _m = this.modules,
i = 0,
Expand Down Expand Up @@ -119,15 +137,17 @@ export class DependenciesEngine {
source: 'internal',
data: undefined
};
for (let i = 0; i < data.length; i++) {
if (typeof name !== 'undefined') {
if (typeof file !== 'undefined') {
if (name.indexOf(data[i].name) !== -1 && file.replace(/\\/g, '/').indexOf(data[i].file) !== -1) {
_result.data = data[i];
}
} else {
if (name.indexOf(data[i].name) !== -1) {
_result.data = data[i];
if (data && data.length > 0) {
for (let i = 0; i < data.length; i++) {
if (typeof name !== 'undefined') {
if (typeof file !== 'undefined') {
if (name.indexOf(data[i].name) !== -1 && file.replace(/\\/g, '/').indexOf(data[i].file) !== -1) {
_result.data = data[i];
}
} else {
if (name.indexOf(data[i].name) !== -1) {
_result.data = data[i];
}
}
}
}
Expand Down Expand Up @@ -386,3 +406,5 @@ export class DependenciesEngine {
return this.miscellaneous;
}
}

export default DependenciesEngine.getInstance();
5 changes: 2 additions & 3 deletions src/app/engines/export-json.engine.ts
@@ -1,7 +1,7 @@
import * as path from 'path';

import { logger } from '../../logger';
import { DependenciesEngine } from './dependencies.engine';
import DependenciesEngine from './dependencies.engine';
import { ConfigurationInterface } from '../interfaces/configuration.interface';
import { FileEngine } from './file.engine';

Expand All @@ -14,7 +14,6 @@ const traverse = require('traverse');
export class ExportJsonEngine {
constructor(
private configuration: ConfigurationInterface,
private dependenciesEngine: DependenciesEngine,
private fileEngine: FileEngine = new FileEngine()
) {}

Expand Down Expand Up @@ -51,7 +50,7 @@ export class ExportJsonEngine {
}

processModules() {
const modules: AngularNgModuleNode[] = this.dependenciesEngine.getModules();
const modules: AngularNgModuleNode[] = DependenciesEngine.getModules();

let _resultedModules = [];

Expand Down
4 changes: 1 addition & 3 deletions src/app/engines/export.engine.ts
@@ -1,4 +1,4 @@
import { DependenciesEngine } from './dependencies.engine';
import DependenciesEngine from './dependencies.engine';
import { ConfigurationInterface } from '../interfaces/configuration.interface';
import { FileEngine } from './file.engine';

Expand All @@ -9,7 +9,6 @@ export class ExportEngine {

constructor(
private configuration: ConfigurationInterface,
private dependenciesEngine: DependenciesEngine,
private fileEngine: FileEngine = new FileEngine()
) {}

Expand All @@ -18,7 +17,6 @@ export class ExportEngine {
case 'json':
this._engine = new ExportJsonEngine(
this.configuration,
this.dependenciesEngine,
this.fileEngine
);
return this._engine.export(outputFolder, data);
Expand Down
6 changes: 3 additions & 3 deletions src/app/engines/html-engine-helpers/element-alone.helper.ts
@@ -1,13 +1,13 @@
import { IHtmlEngineHelper, IHandlebarsOptions } from './html-engine-helper.interface';
import { extractLeadingText, splitLinkText } from '../../../utils/link-parser';
import { DependenciesEngine } from '../dependencies.engine';
import DependenciesEngine from '../dependencies.engine';

export class ElementAloneHelper implements IHtmlEngineHelper {
constructor(private dependenciesEngine: DependenciesEngine) {}
constructor() {}

public helperFunc(context: any, elements, elementType: string, options: IHandlebarsOptions) {
let alones = [];
let modules = this.dependenciesEngine.modules;
let modules = DependenciesEngine.modules;

elements.forEach(element => {
let foundInOneModule = false;
Expand Down

0 comments on commit bd23ec8

Please sign in to comment.