build(aio): do not store duplicate metadata aliases (#20512)

Having duplicates was causing the code auto-linking
to ignore `ngForm` directives.

PR Close #20512
This commit is contained in:
Peter Bacon Darwin 2017-11-20 14:46:05 +00:00 committed by Miško Hevery
parent ecce90718b
commit ae0275e2dd
2 changed files with 12 additions and 7 deletions

View File

@ -1,4 +1,4 @@
const CssSelectorParser = require('css-selector-parser').CssSelectorParser; const CssSelectorParser = require('css-selector-parser').CssSelectorParser;
const cssParser = new CssSelectorParser(); const cssParser = new CssSelectorParser();
/** /**
* @dgProcessor addMetadataAliases * @dgProcessor addMetadataAliases
@ -32,11 +32,16 @@ module.exports = function addMetadataAliasesProcessor() {
function extractSelectors(selectors) { function extractSelectors(selectors) {
const selectorAST = cssParser.parse(stripQuotes(selectors)); const selectorAST = cssParser.parse(stripQuotes(selectors));
const rules = selectorAST.selectors ? selectorAST.selectors.map(ruleSet => ruleSet.rule) : [selectorAST.rule]; const rules = selectorAST.selectors ? selectorAST.selectors.map(ruleSet => ruleSet.rule) : [selectorAST.rule];
return rules.reduce((aliases, rule) => { const aliases = {};
const tagAliases = rule.tagName? [rule.tagName] : []; rules.forEach(rule => {
const attrRulesAliases = (rule.attrs || []).map(attr => attr.name); if (rule.tagName) {
return aliases.concat(tagAliases, attrRulesAliases); aliases[rule.tagName] = true;
}, []); }
if (rule.attrs) {
rule.attrs.forEach(attr => aliases[attr.name] = true);
}
});
return Object.keys(aliases);
} }
function stripQuotes(value) { function stripQuotes(value) {

View File

@ -45,7 +45,7 @@ describe('addSelectorsAsAliases processor', () => {
expect(docs[2].aliases).toEqual([docs[2].name]); expect(docs[2].aliases).toEqual([docs[2].name]);
expect(docs[3].aliases).toEqual([docs[3].name]); expect(docs[3].aliases).toEqual([docs[3].name]);
expect(docs[4].aliases).toEqual([docs[4].name, 'myPipe']); expect(docs[4].aliases).toEqual([docs[4].name, 'myPipe']);
expect(docs[5].aliases).toEqual([docs[5].name, 'my-directive', 'myDirective', 'my-directive']); expect(docs[5].aliases).toEqual([docs[5].name, 'my-directive', 'myDirective']);
expect(docs[6].aliases).toEqual([docs[6].name, 'ngModel']); expect(docs[6].aliases).toEqual([docs[6].name, 'ngModel']);
expect(docs[7].aliases).toEqual([docs[7].name, 'my-component']); expect(docs[7].aliases).toEqual([docs[7].name, 'my-component']);
expect(docs[8].aliases).toEqual([docs[8].name]); expect(docs[8].aliases).toEqual([docs[8].name]);