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:

committed by
Miško Hevery

parent
81f1d42328
commit
8ddbed8f7b
12
aio/tools/transforms/angular-base-package/services/filterPipes.js
vendored
Normal file
12
aio/tools/transforms/angular-base-package/services/filterPipes.js
vendored
Normal 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() === '|');
|
||||
};
|
@ -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);
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user