build(aio): improve accuracy of code auto-linking (#22494)
The new version of `dgeni-packages/typescript` no longer strips out "namespaces" from types, which was part of the problem of not autolinking correctly to `HttpEventType.Response`. Another part of the problem was that we did not include `.` characters when matching potential code blocks for auto-linking, which precluded properties of enums from being linked. Finally, members we not being given a `path` property, which is needed to effectively autolink to them. This is now set in the `simplifyMemberAnchors` processor. Closes #21375 PR Close #22494
This commit is contained in:

committed by
Alex Eagle

parent
997b30a093
commit
0e311e3918
@ -130,6 +130,6 @@ module.exports = new Package('angular-api', [basePackage, typeScriptPackage])
|
||||
]);
|
||||
convertToJsonProcessor.docTypes = convertToJsonProcessor.docTypes.concat(DOCS_TO_CONVERT);
|
||||
postProcessHtml.docTypes = convertToJsonProcessor.docTypes.concat(DOCS_TO_CONVERT);
|
||||
autoLinkCode.docTypes = DOCS_TO_CONVERT;
|
||||
autoLinkCode.docTypes = DOCS_TO_CONVERT.concat(['member']);
|
||||
autoLinkCode.codeElements = ['code', 'code-example', 'code-pane'];
|
||||
});
|
||||
|
@ -5,15 +5,21 @@
|
||||
*/
|
||||
module.exports = function simplifyMemberAnchors() {
|
||||
return {
|
||||
$runAfter: ['extra-docs-added'],
|
||||
$runBefore: ['computing-paths'],
|
||||
$runAfter: ['paths-computed'],
|
||||
$runBefore: ['rendering-docs'],
|
||||
$process: function(docs) {
|
||||
return docs.forEach(doc => {
|
||||
if (doc.members) {
|
||||
doc.members.forEach(member => member.anchor = computeAnchor(member));
|
||||
doc.members.forEach(member => {
|
||||
member.anchor = computeAnchor(member);
|
||||
member.path = doc.path + '#' + member.anchor;
|
||||
});
|
||||
}
|
||||
if (doc.statics) {
|
||||
doc.statics.forEach(member => member.anchor = computeAnchor(member));
|
||||
doc.statics.forEach(member => {
|
||||
member.anchor = computeAnchor(member);
|
||||
member.path = doc.path + '#' + member.anchor;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -0,0 +1,72 @@
|
||||
const testPackage = require('../../helpers/test-package');
|
||||
const processorFactory = require('./simplifyMemberAnchors');
|
||||
const Dgeni = require('dgeni');
|
||||
|
||||
describe('simplifyMemberAnchors processor', () => {
|
||||
|
||||
it('should be available on the injector', () => {
|
||||
const dgeni = new Dgeni([testPackage('angular-api-package')]);
|
||||
const injector = dgeni.configureInjector();
|
||||
const processor = injector.get('simplifyMemberAnchors');
|
||||
expect(processor.$process).toBeDefined();
|
||||
expect(processor.$runAfter).toEqual(['paths-computed']);
|
||||
expect(processor.$runBefore).toEqual(['rendering-docs']);
|
||||
});
|
||||
|
||||
describe('$process', () => {
|
||||
describe('docs without members', () => {
|
||||
it('should ignore the docs', () => {
|
||||
const processor = processorFactory();
|
||||
const docs = [
|
||||
{ id: 'some-doc' },
|
||||
{ id: 'some-other' }
|
||||
];
|
||||
processor.$process(docs);
|
||||
expect(docs).toEqual([
|
||||
{ id: 'some-doc' },
|
||||
{ id: 'some-other' }
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('docs with members', () => {
|
||||
it('should compute an anchor for each instance member', () => {
|
||||
const processor = processorFactory();
|
||||
const docs = [
|
||||
{ id: 'some-doc', members: [ { name: 'foo' }, { name: 'new' }, { name: '' } ] }
|
||||
];
|
||||
processor.$process(docs);
|
||||
expect(docs[0].members.map(member => member.anchor)).toEqual(['foo', 'new', 'call']);
|
||||
});
|
||||
|
||||
it('should compute a path for each instance member', () => {
|
||||
const processor = processorFactory();
|
||||
const docs = [
|
||||
{ id: 'some-doc', path: 'a/b/c', members: [ { name: 'foo' }, { name: 'new' }, { name: '' } ] }
|
||||
];
|
||||
processor.$process(docs);
|
||||
expect(docs[0].members.map(member => member.path)).toEqual(['a/b/c#foo', 'a/b/c#new', 'a/b/c#call']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('docs with static members', () => {
|
||||
it('should compute an anchor for each static member', () => {
|
||||
const processor = processorFactory();
|
||||
const docs = [
|
||||
{ id: 'some-doc', statics: [ { name: 'foo' }, { name: 'new' }, { name: '' } ] }
|
||||
];
|
||||
processor.$process(docs);
|
||||
expect(docs[0].statics.map(member => member.anchor)).toEqual(['foo', 'new', 'call']);
|
||||
});
|
||||
|
||||
it('should compute a path for each static member', () => {
|
||||
const processor = processorFactory();
|
||||
const docs = [
|
||||
{ id: 'some-doc', path: 'a/b/c', statics: [ { name: 'foo' }, { name: 'new' }, { name: '' } ] }
|
||||
];
|
||||
processor.$process(docs);
|
||||
expect(docs[0].statics.map(member => member.path)).toEqual(['a/b/c#foo', 'a/b/c#new', 'a/b/c#call']);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user