build: fix multi-line selectors in dgeni (#4336)

* Fixes multi-line selectors not being detected properly (https://github.com/angular/material2/blob/master/src/lib/button/button.ts#L185-L185)
* Template strings not being detected properly (https://github.com/angular/material2/blob/master/src/lib/input/input-container.ts#L103-L103)
* No longer repeats RegExp logic multiple times. More generic function.
This commit is contained in:
Paul Gschwendtner
2017-05-03 01:39:23 +02:00
committed by Andrew Seguin
parent 244aece0fe
commit 3acf2a2cdd
+15 -16
View File
@@ -46,7 +46,7 @@ module.exports = function categorizer() {
// Categorize the current visited classDoc into its Angular type.
if (isDirective(classDoc)) {
classDoc.isDirective = true;
classDoc.directiveExportAs = getDirectiveExportAs(classDoc);
classDoc.directiveExportAs = getMetadataProperty(classDoc, 'exportAs');
classDoc.directiveSelectors = getDirectiveSelectors(classDoc);
} else if (isService(classDoc)) {
classDoc.isService = true;
@@ -186,26 +186,25 @@ function getDirectiveOutputAlias(doc) {
}
function getDirectiveSelectors(classDoc) {
let metadata = classDoc.decorators
.find(d => d.name === 'Component' || d.name === 'Directive').arguments[0];
const directiveSelectors = getMetadataProperty(classDoc, 'selector');
let selectorMatches = /selector\s*:\s*(?:"|')([^']*?)(?:"|')/g.exec(metadata);
selectorMatches = selectorMatches && selectorMatches[1];
return selectorMatches ? selectorMatches.split(/\s*,\s*/)
.filter(s => s !== '' && !s.includes('mat') && !SELECTOR_BLACKLIST.has(s))
: selectorMatches;
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('mat') && !SELECTOR_BLACKLIST.has(s));
}
}
function getDirectiveExportAs(doc) {
let metadata = doc.decorators
.find(d => d.name === 'Component' || d.name === 'Directive').arguments[0];
function getMetadataProperty(doc, property) {
const metadata = doc.decorators
.find(d => d.name === 'Component' || d.name === 'Directive').arguments[0];
// Use a Regex to determine the exportAs metadata because we can't parse the JSON due to
// environment variables inside of the JSON.
let exportMatches = /exportAs\s*:\s*(?:"|')(\w+)(?:"|')/g.exec(metadata);
// Use a Regex to determine the given metadata property. This is necessary, because we can't
// parse the JSON due to environment variables inside of the JSON (e.g module.id)
let matches = new RegExp(`${property}s*:\\s*(?:"|'|\`)((?:.|\\n|\\r)+?)(?:"|'|\`)`)
.exec(metadata);
return exportMatches && exportMatches[1];
return matches && matches[1].trim();
}
function hasMemberDecorator(doc, decoratorName) {