Skip to content

build(docs): fix directive metadata not showing up in docs #13057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 1 addition & 16 deletions tools/dgeni/common/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,6 @@ import {PropertyMemberDoc} from 'dgeni-packages/typescript/api-doc-types/Propert
import {MemberDoc} from 'dgeni-packages/typescript/api-doc-types/MemberDoc';
import {CategorizedClassDoc, DeprecationDoc, HasDecoratorsDoc} from './dgeni-definitions';

/**
* We want to avoid emitting selectors that are deprecated but don't have a way to mark
* them as such in the source code. Thus, we maintain a separate blacklist of selectors
* that should not be emitted in the documentation.
*/
const SELECTOR_BLACKLIST = new Set([
'[portal]',
'[portalHost]',
'textarea[mat-autosize]',
'[overlay-origin]',
'[connected-overlay]',
]);

export function isMethod(doc: MemberDoc) {
return doc.hasOwnProperty('parameters') && !doc.isGetAccessor && !doc.isSetAccessor;
}
Expand Down Expand Up @@ -62,9 +49,7 @@ export function getDirectiveSelectors(classDoc: CategorizedClassDoc) {
const directiveSelectors: string = classDoc.directiveMetadata.get('selector');

if (directiveSelectors) {
// Filter blacklisted selectors and remove line-breaks in resolved selectors.
return directiveSelectors.replace(/[\r\n]/g, '').split(/\s*,\s*/)
.filter(s => s !== '' && !s.includes('md') && !SELECTOR_BLACKLIST.has(s));
return directiveSelectors.replace(/[\r\n]/g, '').split(/\s*,\s*/).filter(s => s !== '');
}
}

Expand Down
24 changes: 10 additions & 14 deletions tools/dgeni/common/directive-metadata.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import {CategorizedClassDoc} from './dgeni-definitions';
import {
ArrayLiteralExpression,
CallExpression,
isCallExpression,
NodeArray,
ObjectLiteralExpression,
PropertyAssignment,
StringLiteral,
SyntaxKind,
NodeArray,
} from 'typescript';
} from 'dgeni-packages/node_modules/typescript';
import {CategorizedClassDoc} from './dgeni-definitions';

/**
* Determines the component or directive metadata from the specified Dgeni class doc. The resolved
Expand All @@ -31,21 +32,16 @@ export function getDirectiveMetadata(classDoc: CategorizedClassDoc): Map<string,
return null;
}

const directiveDecorator = declaration.decorators
.filter(decorator => decorator.expression)
// TODO(devversion): fix this cast
.filter(decorator => (decorator.expression.kind as any) === SyntaxKind.CallExpression)
.find(decorator => (decorator.expression as any).expression.getText() === 'Component' ||
(decorator.expression as any).expression.getText() === 'Directive');
const expression = declaration.decorators
.filter(decorator => decorator.expression && isCallExpression(decorator.expression))
.map(decorator => decorator.expression as CallExpression)
.find(callExpression => callExpression.expression.getText() === 'Component' ||
callExpression.expression.getText() === 'Directive');

if (!directiveDecorator) {
if (!expression) {
return null;
}

// Since the actual decorator expression is by default a LeftHandSideExpression, and TypeScript
// doesn't allow a casting it to a CallExpression, we have to cast it to "any" before.
const expression = (directiveDecorator.expression as any) as CallExpression;

// The argument length of the CallExpression needs to be exactly one, because it's the single
// JSON object in the @Component/@Directive decorator.
if (expression.arguments.length !== 1) {
Expand Down