build(aio): tighten up code autolinking (#20468)

Do not match code "words" that are part of a hyphenated
string of characters: e.g. `platform-browser-dynamic` should
not auto-link `browser`.

Do not match code "words" that correspond to pipe names
but are not preceded by a pipe `|` character. E.g. `package.json` should
not auto link `json` to the `JsonPipe`.

Closes #20187

PR Close #20468
This commit is contained in:
Peter Bacon Darwin
2017-11-15 23:30:09 +00:00
committed by Miško Hevery
parent 81f1d42328
commit 8ddbed8f7b
5 changed files with 86 additions and 7 deletions

View File

@ -0,0 +1,12 @@
/**
* This service is used by the autoLinkCode post-processors to filter out pipe docs
* where the matching word is the pipe name and is not preceded by a pipe
*/
module.exports = function filterPipes() {
return (docs, words, index) =>
docs.filter(doc =>
doc.docType !== 'pipe' ||
doc.pipeOptions.name !== '\'' + words[index] + '\'' ||
index > 0 && words[index - 1].trim() === '|');
};

View File

@ -0,0 +1,36 @@
const filterPipes = require('./filterPipes')();
describe('filterPipes', () => {
it('should ignore docs that are not pipes', () => {
const docs = [{ docType: 'class', name: 'B', pipeOptions: { name: '\'b\'' } }];
const words = ['A', 'b', 'B', 'C'];
const filteredDocs = [{ docType: 'class', name: 'B', pipeOptions: { name: '\'b\'' } }];
expect(filterPipes(docs, words, 1)).toEqual(filteredDocs);
expect(filterPipes(docs, words, 2)).toEqual(filteredDocs);
});
it('should ignore docs that are pipes but do not match the pipe name', () => {
const docs = [{ docType: 'pipe', name: 'B', pipeOptions: { name: '\'b\'' } }];
const words = ['A', 'B', 'C'];
const filteredDocs = [{ docType: 'pipe', name: 'B', pipeOptions: { name: '\'b\'' } }];
expect(filterPipes(docs, words, 1)).toEqual(filteredDocs);
});
it('should ignore docs that are pipes, match the pipe name and are preceded by a pipe character', () => {
const docs = [{ docType: 'pipe', name: 'B', pipeOptions: { name: '\'b\'' } }];
const words = ['A', '|', 'b', 'C'];
const filteredDocs = [{ docType: 'pipe', name: 'B', pipeOptions: { name: '\'b\'' } }];
expect(filterPipes(docs, words, 2)).toEqual(filteredDocs);
});
it('should filter out docs that are pipes, match the pipe name but are not preceded by a pipe character', () => {
const docs = [
{ docType: 'pipe', name: 'B', pipeOptions: { name: '\'b\'' } },
{ docType: 'class', name: 'B' }
];
const words = ['A', 'b', 'C'];
const index = 1;
const filteredDocs = [{ docType: 'class', name: 'B' }];
expect(filterPipes(docs, words, index)).toEqual(filteredDocs);
});
});