Skip to content

Commit

Permalink
feat(deps): support of function type parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
vogloblinsky committed Jul 30, 2017
1 parent 0fb9e93 commit e8b1c0f
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 57 deletions.
50 changes: 48 additions & 2 deletions dist/index-cli.js

Large diffs are not rendered by default.

50 changes: 48 additions & 2 deletions dist/index.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions src/app/compiler/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,13 @@ export class Dependencies {
if (arg.dotDotDotToken) {
_result.dotDotDotToken = true
}
if (arg.type) {
if (arg.type.kind) {
if (arg.type.kind === ts.SyntaxKind.FunctionType) {
_result.function = arg.type.parameters ? arg.type.parameters.map((prop) => this.visitArgument(prop)) : [];
}
}
}
return _result;
}

Expand Down
31 changes: 31 additions & 0 deletions src/app/engines/html.engine.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,37 @@ export let HtmlEngineHelpers = (function() {
}
} else if (arg.dotDotDotToken) {
return `...${arg.name}: ${arg.type}`;
} else if (arg.function) {
if (arg.function.length > 0) {
let argums = arg.function.map(function(argu) {
var _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}: <a href="../${path}s/${_result.data.name}.html">${argu.type}</a>`;
} else {
let path = `https://${angularDocPrefix}angular.io/docs/ts/latest/api/${_result.data.path}`;
return `${argu.name}: <a href="${path}" target="_blank">${argu.type}</a>`;
}
} else if (finderInBasicTypes(argu.type)) {
let path = `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/${argu.type}`;
return `${argu.name}: <a href="${path}" target="_blank">${argu.type}</a>`;
} else if (finderInTypeScriptBasicTypes(argu.type)) {
let path = `https://www.typescriptlang.org/docs/handbook/basic-types.html`;
return `${argu.name}: <a href="${path}" target="_blank">${argu.type}</a>`;
} else {
if (argu.name && argu.type) {
return `${argu.name}: ${argu.type}`;
} else {
return `${argu.name.text}`;
}
}
});
return `${arg.name}: (${argums}) => void`;
} else {
return `${arg.name}: () => void`;
}
} else if (finderInBasicTypes(arg.type)) {
let path = `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/${arg.type}`;
return `${arg.name}: <a href="${path}" target="_blank">${arg.type}</a>`;
Expand Down
113 changes: 60 additions & 53 deletions test/src/cli/cli-generation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,73 +82,80 @@ describe('CLI simple generation', () => {
* JSDOC
*/

it('it should have a link with this syntax {@link BarComponent}', () => {
expect(moduleFile).to.contain('See <a href="../components/BarComponent.html">BarComponent');
it('it should have a link with this syntax {@link BarComponent}', () => {
expect(moduleFile).to.contain('See <a href="../components/BarComponent.html">BarComponent');
});

it('it should have a link with this syntax [The BarComponent]{@link BarComponent}', () => {
const barModuleFile = read(`${tmp.name}/modules/BarModule.html`);
expect(barModuleFile).to.contain('Watch <a href="../components/BarComponent.html">The BarComponent');
});

it('it should have a link with this syntax {@link BarComponent|BarComponent3}', () => {
expect(fooComponentFile).to.contain('See <a href="../modules/AppModule.html">APP');
});

it('it should have infos about FooService open function param', () => {
expect(fooServiceFile).to.contain('td><p>The entry value');
});

it('it should have infos about FooService open function returns', () => {
expect(fooServiceFile).to.contain('<p>The string</p>');
});

it('it should have infos about FooService open function example', () => {
expect(fooServiceFile).to.contain('<b>Example :</b>');
expect(fooServiceFile).to.contain('FooService.open(');
});

it('it should have link to TypeScript doc', () => {
expect(fooServiceFile).to.contain('typescriptlang.org');
});

/**
* Coverage
*/

it('it should have coverage page', () => {
expect(coverageFile).to.contain('Documentation coverage');
expect(coverageFile).to.contain('img src="./images/coverage-badge.svg"');
});

/**
* internal/private methods
*/
it('should include by default methods marked as internal', () => {
expect(componentFile).to.contain('<code>internalMethod');
});

it('it should have a link with this syntax [The BarComponent]{@link BarComponent}', () => {
const barModuleFile = read(`${tmp.name}/modules/BarModule.html`);
expect(barModuleFile).to.contain('Watch <a href="../components/BarComponent.html">The BarComponent');
it('should exclude methods marked as hidden', () => {
expect(componentFile).not.to.contain('<code>hiddenMethod');
});

it('it should have a link with this syntax {@link BarComponent|BarComponent3}', () => {
expect(fooComponentFile).to.contain('See <a href="../modules/AppModule.html">APP');
it('should include by default methods marked as private', () => {
expect(componentFile).to.contain('<code>privateMethod');
});

/**
* No graph for empty module
*/

it('it should have infos about FooService open function param', () => {
expect(fooServiceFile).to.contain('<b>val</b>');
expect(fooServiceFile).to.contain('<p>The entry value</p>');
it('it should not generate graph for empty metadatas module', () => {
expect(emptyModuleFile).not.to.contain('module-graph-svg');
});

it('it should have infos about FooService open function returns', () => {
expect(fooServiceFile).to.contain('<p>The string</p>');
it('it should not break for empty raw metadatas module', () => {
expect(emptyModuleRawFile).not.to.contain('module-graph-svg');
});

it('it should have infos about FooService open function example', () => {
expect(fooServiceFile).to.contain('<b>Example :</b>');
expect(fooServiceFile).to.contain('FooService.open(');
});
/**
* Support of function type parameters
*/

it('it should have link to TypeScript doc', () => {
expect(fooServiceFile).to.contain('typescriptlang.org');
it('it should display function type parameters', () => {
expect(fooServiceFile).to.contain('<code>close(work: (toto: ');
});

/**
* Coverage
*/

it('it should have coverage page', () => {
expect(coverageFile).to.contain('Documentation coverage');
expect(coverageFile).to.contain('img src="./images/coverage-badge.svg"');
});

/**
* internal/private methods
*/
it('should include by default methods marked as internal', () => {
expect(componentFile).to.contain('<code>internalMethod');
});

it('should exclude methods marked as hidden', () => {
expect(componentFile).not.to.contain('<code>hiddenMethod');
});

it('should include by default methods marked as private', () => {
expect(componentFile).to.contain('<code>privateMethod');
});

/**
* No graph for empty module
*/

it('it should not generate graph for empty metadatas module', () => {
expect(emptyModuleFile).not.to.contain('module-graph-svg');
});

it('it should not break for empty raw metadatas module', () => {
expect(emptyModuleRawFile).not.to.contain('module-graph-svg');
});
});

describe('when generation with d flag without / at the end - relative folder', () => {
Expand Down
4 changes: 4 additions & 0 deletions test/src/sample-files/foo.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ export class FooService {
open(val: string): string {
return 'test';
}

close(work: (toto: string) => void): string {
return 'test';
}
}

0 comments on commit e8b1c0f

Please sign in to comment.