Socket
Socket
Sign inDemoInstall

dgeni-packages

Package Overview
Dependencies
Maintainers
2
Versions
147
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dgeni-packages - npm Package Compare versions

Comparing version 0.16.8 to 0.16.9

typescript/mocks/readTypeScriptModules/inheritedMembers.ts

5

CHANGELOG.md
# Changelog
# 0.16.9 6 March 2017
* feat(typescript): link `class` docs to inherited class docs cf8b7444
# 0.16.8 20 February 2017

@@ -4,0 +9,0 @@

5

package.json
{
"name": "dgeni-packages",
"version": "0.16.8",
"version": "0.16.9",
"description": "A collection of dgeni packages for generating documentation from source code",

@@ -99,4 +99,5 @@ "scripts": {

"Perry Govier <perrygovier@users.noreply.github.com>",
"Rod Leviton <rod@rodleviton.com>"
"Rod Leviton <rod@rodleviton.com>",
"Paul Gschwendtner <paulgschwendtner@gmail.com>"
]
}

2

typescript/index.js

@@ -17,2 +17,3 @@ var Package = require('dgeni').Package;

.factory(require('./services/convertPrivateClassesToInterfaces'))
.factory(require('./services/typescript-symbol-map'))

@@ -39,2 +40,3 @@ .factory('EXPORT_DOC_TYPES', function() {

.processor(require('./processors/readTypeScriptModules'))
.processor(require('./processors/linkInheritedDocs'))

@@ -41,0 +43,0 @@ // Configure ids and paths

@@ -6,4 +6,5 @@ var glob = require('glob');

module.exports = function readTypeScriptModules(tsParser, modules, getFileInfo, ignoreTypeScriptNamespaces,
getExportDocType, getExportAccessibility, getContent, createDocMessage, log) {
module.exports = function readTypeScriptModules(
tsParser, modules, getFileInfo, ignoreTypeScriptNamespaces, getExportDocType,
getExportAccessibility, getContent, createDocMessage, log, typescriptSymbolMap) {

@@ -45,2 +46,3 @@ return {

var moduleSymbols = parseInfo.moduleSymbols;
var typeChecker = parseInfo.typeChecker;

@@ -72,3 +74,3 @@ // Iterate through each of the modules that were parsed and generate a module doc

var exportDoc = createExportDoc(exportSymbol.name, resolvedExport, moduleDoc, basePath, parseInfo.typeChecker);
var exportDoc = createExportDoc(exportSymbol.name, resolvedExport, moduleDoc, basePath, typeChecker);
log.debug('>>>> EXPORT: ' + exportDoc.name + ' (' + exportDoc.docType + ') from ' + moduleDoc.id);

@@ -83,2 +85,8 @@

// Store the dgeni doc of the resolved symbol in the typescriptSymbolMap.
typescriptSymbolMap.set(resolvedExport, exportDoc);
// Resolve all inherited symbols and store them inside of the exportDoc object.
exportDoc.inheritedSymbols = resolveInheritedSymbols(resolvedExport, typeChecker);
// Generate docs for each of the export's members

@@ -94,3 +102,3 @@ if (resolvedExport.flags & ts.SymbolFlags.HasMembers) {

var memberSymbol = resolvedExport.members[memberName];
var memberDoc = createMemberDoc(memberSymbol, exportDoc, basePath, parseInfo.typeChecker);
var memberDoc = createMemberDoc(memberSymbol, exportDoc, basePath, typeChecker);

@@ -151,3 +159,39 @@ // We special case the constructor and sort the other members alphabetically

/**
* Resolves all inherited class symbols of the specified symbol.
* @param {ts.Symbol} symbol ClassDeclaration symbol with members
* @param {ts.TypeChecker} typeChecker TypeScript TypeChecker for symbols
* @returns {Symbol[]} List of inherited class symbols.
**/
function resolveInheritedSymbols(symbol, typeChecker) {
var declaration = symbol.valueDeclaration || symbol.declarations[0];
var symbols = [];
if (declaration && declaration.heritageClauses) {
symbols = declaration.heritageClauses
// Filter for extends heritage clauses.
.filter(isExtendsHeritage)
// Resolve an array of the inherited symbols from the heritage clause.
.map(heritage => convertHeritageClauseToSymbols(heritage, typeChecker))
// Flatten the arrays of inherited symbols.
.reduce((symbols, cur) => symbols.concat(cur), []);
}
return symbols;
}
/**
* Converts a heritage clause into a list of symbols
* @param {ts.HeritageClause} heritage
* @param {ts.TypeChecker} typeChecker
* @returns {ts.SymbolTable} List of heritage symbols.
**/
function convertHeritageClauseToSymbols(heritage, typeChecker) {
var heritages = heritage.types.map(expression =>
typeChecker.getTypeAtLocation(expression).getSymbol()
);
return heritages.reduce((inheritances, current) => inheritances.concat(current), []);
}
function createModuleDoc(moduleSymbol, basePath) {

@@ -198,3 +242,3 @@ var id = moduleSymbol.name.replace(/^"|"$/g, '');

if (heritage.token == ts.SyntaxKind.ExtendsKeyword) {
if (isExtendsHeritage(heritage)) {
heritageString += " extends";

@@ -460,2 +504,6 @@ heritage.types.forEach(function(typ, idx) {

/** Checks if the specified heritage clause is an extends keyword. */
function isExtendsHeritage(heritageClause) {
return heritageClause.token === ts.SyntaxKind.ExtendsKeyword
}
};

@@ -462,0 +510,0 @@

@@ -60,3 +60,25 @@ var mockPackage = require('../mocks/mockPackage');

describe('inherited symbols', function() {
it('should add the list of inherited symbols to a class doc', function() {
processor.sourceFiles = [ 'inheritedMembers.ts' ];
var docs = [];
processor.$process(docs);
var childDoc = docs[3];
var firstParentDoc = docs[5];
var lastParentDoc = docs[1];
expect(childDoc.inheritedSymbols.length).toBe(1);
expect(childDoc.inheritedSymbols[0]).toBe(firstParentDoc.exportSymbol);
expect(firstParentDoc.inheritedSymbols.length).toBe(1);
expect(firstParentDoc.inheritedSymbols[0]).toBe(lastParentDoc.exportSymbol);
expect(lastParentDoc.inheritedSymbols.length).toBe(0);
});
});
describe('ignoreExportsMatching', function() {

@@ -239,2 +261,2 @@ it('should ignore exports that match items in the `ignoreExportsMatching` property', function() {

return collection.map(function(item) { return item.name; });
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc