@@ -46,7 +46,7 @@ module.exports = function categorizer() {
46
46
// Categorize the current visited classDoc into its Angular type.
47
47
if ( isDirective ( classDoc ) ) {
48
48
classDoc . isDirective = true ;
49
- classDoc . directiveExportAs = getDirectiveExportAs ( classDoc ) ;
49
+ classDoc . directiveExportAs = getMetadataProperty ( classDoc , 'exportAs' ) ;
50
50
classDoc . directiveSelectors = getDirectiveSelectors ( classDoc ) ;
51
51
} else if ( isService ( classDoc ) ) {
52
52
classDoc . isService = true ;
@@ -186,26 +186,25 @@ function getDirectiveOutputAlias(doc) {
186
186
}
187
187
188
188
function getDirectiveSelectors ( classDoc ) {
189
- let metadata = classDoc . decorators
190
- . find ( d => d . name === 'Component' || d . name === 'Directive' ) . arguments [ 0 ] ;
191
-
192
- let selectorMatches = / s e l e c t o r \s * : \s * (?: " | ' ) ( [ ^ ' ] * ?) (?: " | ' ) / g. exec ( metadata ) ;
193
- selectorMatches = selectorMatches && selectorMatches [ 1 ] ;
189
+ const directiveSelectors = getMetadataProperty ( classDoc , 'selector' ) ;
194
190
195
- return selectorMatches ? selectorMatches . split ( / \s * , \s * / )
196
- . filter ( s => s !== '' && ! s . includes ( 'mat' ) && ! SELECTOR_BLACKLIST . has ( s ) )
197
- : selectorMatches ;
191
+ if ( directiveSelectors ) {
192
+ // Filter blacklisted selectors and remove line-breaks in resolved selectors.
193
+ return directiveSelectors . replace ( / [ \r \n ] / g, '' ) . split ( / \s * , \s * / )
194
+ . filter ( s => s !== '' && ! s . includes ( 'mat' ) && ! SELECTOR_BLACKLIST . has ( s ) ) ;
195
+ }
198
196
}
199
197
200
- function getDirectiveExportAs ( doc ) {
201
- let metadata = doc . decorators
202
- . find ( d => d . name === 'Component' || d . name === 'Directive' ) . arguments [ 0 ] ;
198
+ function getMetadataProperty ( doc , property ) {
199
+ const metadata = doc . decorators
200
+ . find ( d => d . name === 'Component' || d . name === 'Directive' ) . arguments [ 0 ] ;
203
201
204
- // Use a Regex to determine the exportAs metadata because we can't parse the JSON due to
205
- // environment variables inside of the JSON.
206
- let exportMatches = / e x p o r t A s \s * : \s * (?: " | ' ) ( \w + ) (?: " | ' ) / g. exec ( metadata ) ;
202
+ // Use a Regex to determine the given metadata property. This is necessary, because we can't
203
+ // parse the JSON due to environment variables inside of the JSON (e.g module.id)
204
+ let matches = new RegExp ( `${ property } s*:\\s*(?:"|'|\`)((?:.|\\n|\\r)+?)(?:"|'|\`)` )
205
+ . exec ( metadata ) ;
207
206
208
- return exportMatches && exportMatches [ 1 ] ;
207
+ return matches && matches [ 1 ] . trim ( ) ;
209
208
}
210
209
211
210
function hasMemberDecorator ( doc , decoratorName ) {
0 commit comments