|
| 1 | +/** |
| 2 | + * We want to avoid emitting selectors that are deprecated but don't have a way to mark |
| 3 | + * them as such in the source code. Thus, we maintain a separate blacklist of selectors |
| 4 | + * that should not be emitted in the documentation. |
| 5 | + */ |
| 6 | +const SELECTOR_BLACKLIST = new Set([ |
| 7 | + '[portal]', |
| 8 | + '[portalHost]', |
| 9 | + 'textarea[md-autosize]', |
| 10 | + '[overlay-origin]', |
| 11 | + '[connected-overlay]', |
| 12 | +]); |
| 13 | + |
1 | 14 | /**
|
2 | 15 | * Processor to add properties to docs objects.
|
3 | 16 | *
|
@@ -29,11 +42,12 @@ module.exports = function categorizer() {
|
29 | 42 | classDoc.properties.forEach(doc => decoratePropertyDoc(doc));
|
30 | 43 |
|
31 | 44 | decoratePublicDoc(classDoc);
|
32 |
| - |
| 45 | + |
33 | 46 | // Categorize the current visited classDoc into its Angular type.
|
34 | 47 | if (isDirective(classDoc)) {
|
35 | 48 | classDoc.isDirective = true;
|
36 | 49 | classDoc.directiveExportAs = getDirectiveExportAs(classDoc);
|
| 50 | + classDoc.directiveSelectors = getDirectiveSelectors(classDoc); |
37 | 51 | } else if (isService(classDoc)) {
|
38 | 52 | classDoc.isService = true;
|
39 | 53 | } else if (isNgModule(classDoc)) {
|
@@ -171,6 +185,18 @@ function getDirectiveOutputAlias(doc) {
|
171 | 185 | return isDirectiveOutput(doc) ? doc.decorators.find(d => d.name == 'Output').arguments[0] : '';
|
172 | 186 | }
|
173 | 187 |
|
| 188 | +function getDirectiveSelectors(classDoc) { |
| 189 | + let metadata = classDoc.decorators |
| 190 | + .find(d => d.name === 'Component' || d.name === 'Directive').arguments[0]; |
| 191 | + |
| 192 | + let selectorMatches = /selector\s*:\s*(?:"|')([^']*?)(?:"|')/g.exec(metadata); |
| 193 | + selectorMatches = selectorMatches && selectorMatches[1]; |
| 194 | + |
| 195 | + return selectorMatches ? selectorMatches.split(/\s*,\s*/) |
| 196 | + .filter(s => s !== '' && !s.includes('mat') && !SELECTOR_BLACKLIST.has(s)) |
| 197 | + : selectorMatches; |
| 198 | +} |
| 199 | + |
174 | 200 | function getDirectiveExportAs(doc) {
|
175 | 201 | let metadata = doc.decorators
|
176 | 202 | .find(d => d.name === 'Component' || d.name === 'Directive').arguments[0];
|
|
0 commit comments