chore(doc-gen): make the module of the export's original declaration available

This commit is contained in:
Peter Bacon Darwin 2015-09-16 21:35:35 +01:00 committed by Naomi Black
parent 19274e744d
commit dad40751d4
7 changed files with 38 additions and 12 deletions

View File

@ -51,12 +51,14 @@ module.exports = function addJadeDataDocsProcessor() {
// GET DATA FOR EACH PAGE (CLASS, VARS, FUNCTIONS) // GET DATA FOR EACH PAGE (CLASS, VARS, FUNCTIONS)
var modulePageInfo = _(doc.exports) var modulePageInfo = _(doc.exports)
.map(function(exportDoc) { .map(function(exportDoc) {
return { var dataDoc = {
name: exportDoc.name + '-' + exportDoc.docType, name: exportDoc.name + '-' + exportDoc.docType,
title: exportDoc.name, title: exportDoc.name,
docType: exportDoc.docType, docType: exportDoc.docType
varType: exportDoc.symbolTypeName && titleCase(exportDoc.symbolTypeName)
}; };
if (exportDoc.symbolTypeName) dataDoc.varType = titleCase(exportDoc.symbolTypeName);
if (exportDoc.originalModule) dataDoc.originalModule = exportDoc.originalModule;
return dataDoc;
}) })
.sortBy('name') .sortBy('name')
.value(); .value();

View File

@ -15,7 +15,9 @@ describe('addJadeDataDocsProcessor', function() {
{ {
docType: 'module', docType: 'module',
id: 'someModule', id: 'someModule',
exports: [{ name: 'someObj', docType: 'var', symbolTypeName: 'MyClass'}], exports: [
{ name: 'someObj', docType: 'var', symbolTypeName: 'MyClass', originalModule: 'some/private/module' }
],
fileInfo: { baseName: 'x_y' }, fileInfo: { baseName: 'x_y' },
description: 'some description\nsecond line' description: 'some description\nsecond line'
} }
@ -28,8 +30,8 @@ describe('addJadeDataDocsProcessor', function() {
docType : 'jade-data', docType : 'jade-data',
originalDoc : docs[0], originalDoc : docs[0],
data : [ data : [
{ name : 'index', title : 'X Y', intro : 'some description second line' }, { name : 'index', title : 'X Y', intro : 'some description second line', docType : 'module' },
{ name : 'someObj-var', title : 'someObj', varType : 'MyClass', docType: 'var' } { name : 'someObj-var', title : 'someObj', varType : 'MyClass', docType: 'var', originalModule: 'some/private/module' }
] }); ] });
}); });
@ -52,12 +54,12 @@ describe('addJadeDataDocsProcessor', function() {
docs = processor.$process(docs); docs = processor.$process(docs);
expect(docs[1].data).toEqual([ expect(docs[1].data).toEqual([
{ name : 'index', title : 'X Y', intro : 'some description second line' }, { name : 'index', title : 'X Y', intro : 'some description second line', docType : 'module' },
{ name: 'Alpha-class', title: 'Alpha', varType : undefined, docType: 'class' }, { name: 'Alpha-class', title: 'Alpha', docType: 'class' },
{ name: 'Beta-class', title: 'Beta', varType : undefined, docType: 'class' }, { name: 'Beta-class', title: 'Beta', docType: 'class' },
{ name: 'Gamma-class', title: 'Gamma', varType : undefined, docType: 'class' }, { name: 'Gamma-class', title: 'Gamma', docType: 'class' },
{ name: 'Mu-class', title: 'Mu', varType : undefined, docType: 'class' }, { name: 'Mu-class', title: 'Mu', docType: 'class' },
{ name: 'Nu-class', title: 'Nu', varType : undefined, docType: 'class' } { name: 'Nu-class', title: 'Nu', docType: 'class' }
]); ]);
}); });

View File

@ -8,6 +8,9 @@
{%- if item.varType %} {%- if item.varType %}
"varType" : "{$ item.varType $}", "varType" : "{$ item.varType $}",
{%- endif %} {%- endif %}
{%- if item.originalModule %}
"originalModule" : "{$ item.originalModule $}",
{%- endif %}
"docType": "{$ item.docType $}" "docType": "{$ item.docType $}"
}{% if not loop.last %},{% endif %} }{% if not loop.last %},{% endif %}
{% endfor -%} {% endfor -%}

View File

@ -0,0 +1 @@
export var x = 10;

View File

@ -0,0 +1 @@
export { x as y} from './privateModule';

View File

@ -223,6 +223,11 @@ module.exports = function readTypeScriptModules(tsParser, modules, getFileInfo,
if (exportSymbol.flags & ts.SymbolFlags.TypeAlias) { if (exportSymbol.flags & ts.SymbolFlags.TypeAlias) {
exportDoc.typeDefinition = typeDefinition; exportDoc.typeDefinition = typeDefinition;
} }
// Compute the original module name from the relative file path
exportDoc.originalModule = exportDoc.fileInfo.relativePath
.replace(new RegExp('\.' + exportDoc.fileInfo.extension + '$'), '');
return exportDoc; return exportDoc;
} }

View File

@ -14,6 +14,18 @@ describe('readTypeScriptModules', function() {
}); });
describe('exportDocs', function() {
it('should provide the original module if the export is re-exported', function() {
processor.sourceFiles = [ 'publicModule.ts' ];
var docs = [];
processor.$process(docs);
var exportedDoc = docs[1];
expect(exportedDoc.originalModule).toEqual('privateModule');
});
});
describe('ignoreExportsMatching', function() { describe('ignoreExportsMatching', function() {
it('should ignore exports that match items in the `ignoreExportsMatching` property', function() { it('should ignore exports that match items in the `ignoreExportsMatching` property', function() {
processor.sourceFiles = [ 'ignoreExportsMatching.ts']; processor.sourceFiles = [ 'ignoreExportsMatching.ts'];