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:
parent
ecce90718b
commit
ae0275e2dd
|
@ -1,4 +1,4 @@
|
|||
const CssSelectorParser = require('css-selector-parser').CssSelectorParser;
|
||||
const CssSelectorParser = require('css-selector-parser').CssSelectorParser;
|
||||
const cssParser = new CssSelectorParser();
|
||||
/**
|
||||
* @dgProcessor addMetadataAliases
|
||||
|
@ -32,11 +32,16 @@ module.exports = function addMetadataAliasesProcessor() {
|
|||
function extractSelectors(selectors) {
|
||||
const selectorAST = cssParser.parse(stripQuotes(selectors));
|
||||
const rules = selectorAST.selectors ? selectorAST.selectors.map(ruleSet => ruleSet.rule) : [selectorAST.rule];
|
||||
return rules.reduce((aliases, rule) => {
|
||||
const tagAliases = rule.tagName? [rule.tagName] : [];
|
||||
const attrRulesAliases = (rule.attrs || []).map(attr => attr.name);
|
||||
return aliases.concat(tagAliases, attrRulesAliases);
|
||||
}, []);
|
||||
const aliases = {};
|
||||
rules.forEach(rule => {
|
||||
if (rule.tagName) {
|
||||
aliases[rule.tagName] = true;
|
||||
}
|
||||
if (rule.attrs) {
|
||||
rule.attrs.forEach(attr => aliases[attr.name] = true);
|
||||
}
|
||||
});
|
||||
return Object.keys(aliases);
|
||||
}
|
||||
|
||||
function stripQuotes(value) {
|
||||
|
|
|
@ -45,7 +45,7 @@ describe('addSelectorsAsAliases processor', () => {
|
|||
expect(docs[2].aliases).toEqual([docs[2].name]);
|
||||
expect(docs[3].aliases).toEqual([docs[3].name]);
|
||||
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[7].aliases).toEqual([docs[7].name, 'my-component']);
|
||||
expect(docs[8].aliases).toEqual([docs[8].name]);
|
||||
|
|
Loading…
Reference in New Issue