@@ -46,7 +46,7 @@ module.exports = function categorizer() {
4646 // Categorize the current visited classDoc into its Angular type.
4747 if ( isDirective ( classDoc ) ) {
4848 classDoc . isDirective = true ;
49- classDoc . directiveExportAs = getDirectiveExportAs ( classDoc ) ;
49+ classDoc . directiveExportAs = getMetadataProperty ( classDoc , 'exportAs' ) ;
5050 classDoc . directiveSelectors = getDirectiveSelectors ( classDoc ) ;
5151 } else if ( isService ( classDoc ) ) {
5252 classDoc . isService = true ;
@@ -186,26 +186,25 @@ function getDirectiveOutputAlias(doc) {
186186}
187187
188188function 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' ) ;
194190
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+ }
198196}
199197
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 ] ;
203201
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 ) ;
207206
208- return exportMatches && exportMatches [ 1 ] ;
207+ return matches && matches [ 1 ] . trim ( ) ;
209208}
210209
211210function hasMemberDecorator ( doc , decoratorName ) {
0 commit comments