Skip to content

Commit e1b040d

Browse files
devversionjelbourn
authored andcommitted
build(docs): fix directive metadata not showing up in docs (#13057)
* Due to the recent update to TypeScript 3.0.0, the new TS version conflicts with the internal TypeScript version from `dgeni-packages`. This causes the selector, exported-as to not show up in the docs. * Removes the selector blacklist and `md-`prefix filter. All of the blacklisted selectors have been removed (except the autosize selector; but the whole class has been deprecated now)
1 parent 05563d9 commit e1b040d

File tree

2 files changed

+11
-30
lines changed

2 files changed

+11
-30
lines changed

tools/dgeni/common/decorators.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,6 @@ import {PropertyMemberDoc} from 'dgeni-packages/typescript/api-doc-types/Propert
33
import {MemberDoc} from 'dgeni-packages/typescript/api-doc-types/MemberDoc';
44
import {CategorizedClassDoc, DeprecationDoc, HasDecoratorsDoc} from './dgeni-definitions';
55

6-
/**
7-
* We want to avoid emitting selectors that are deprecated but don't have a way to mark
8-
* them as such in the source code. Thus, we maintain a separate blacklist of selectors
9-
* that should not be emitted in the documentation.
10-
*/
11-
const SELECTOR_BLACKLIST = new Set([
12-
'[portal]',
13-
'[portalHost]',
14-
'textarea[mat-autosize]',
15-
'[overlay-origin]',
16-
'[connected-overlay]',
17-
]);
18-
196
export function isMethod(doc: MemberDoc) {
207
return doc.hasOwnProperty('parameters') && !doc.isGetAccessor && !doc.isSetAccessor;
218
}
@@ -62,9 +49,7 @@ export function getDirectiveSelectors(classDoc: CategorizedClassDoc) {
6249
const directiveSelectors: string = classDoc.directiveMetadata.get('selector');
6350

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

tools/dgeni/common/directive-metadata.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import {CategorizedClassDoc} from './dgeni-definitions';
21
import {
32
ArrayLiteralExpression,
43
CallExpression,
4+
isCallExpression,
5+
NodeArray,
56
ObjectLiteralExpression,
67
PropertyAssignment,
78
StringLiteral,
89
SyntaxKind,
9-
NodeArray,
10-
} from 'typescript';
10+
} from 'dgeni-packages/node_modules/typescript';
11+
import {CategorizedClassDoc} from './dgeni-definitions';
1112

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

34-
const directiveDecorator = declaration.decorators
35-
.filter(decorator => decorator.expression)
36-
// TODO(devversion): fix this cast
37-
.filter(decorator => (decorator.expression.kind as any) === SyntaxKind.CallExpression)
38-
.find(decorator => (decorator.expression as any).expression.getText() === 'Component' ||
39-
(decorator.expression as any).expression.getText() === 'Directive');
35+
const expression = declaration.decorators
36+
.filter(decorator => decorator.expression && isCallExpression(decorator.expression))
37+
.map(decorator => decorator.expression as CallExpression)
38+
.find(callExpression => callExpression.expression.getText() === 'Component' ||
39+
callExpression.expression.getText() === 'Directive');
4040

41-
if (!directiveDecorator) {
41+
if (!expression) {
4242
return null;
4343
}
4444

45-
// Since the actual decorator expression is by default a LeftHandSideExpression, and TypeScript
46-
// doesn't allow a casting it to a CallExpression, we have to cast it to "any" before.
47-
const expression = (directiveDecorator.expression as any) as CallExpression;
48-
4945
// The argument length of the CallExpression needs to be exactly one, because it's the single
5046
// JSON object in the @Component/@Directive decorator.
5147
if (expression.arguments.length !== 1) {

0 commit comments

Comments
 (0)