Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issues with generating docs. Issue #587 #598

Merged
merged 1 commit into from
Dec 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion node/buildutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ exports.getExternals = function () {
// download the same version of node used by the agent
// and add node to the PATH
var nodeUrl = 'https://nodejs.org/dist';
var nodeVersion = 'v5.10.1';
var nodeVersion = 'v6.17.1';
switch (platform) {
case 'darwin':
var nodeArchivePath = downloadArchive(nodeUrl + '/' + nodeVersion + '/node-' + nodeVersion + '-darwin-x64.tar.gz');
Expand Down
36 changes: 17 additions & 19 deletions node/docs/TypeScriptSourceToJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,25 @@ export function generate(filePaths: string[], options: ts.CompilerOptions): DocE
program = ts.createProgram(filePaths, options);
checker = program.getTypeChecker();

let files: ts.SourceFile[] = program.getSourceFiles();
for (const sourceFile of program.getSourceFiles()) {
// only document files we specified. dependency files may be in program
if (filePaths.indexOf(sourceFile.fileName) >= 0) {
let name = path.basename(sourceFile.fileName, '.ts');
let name = path.basename(sourceFile.fileName, '.ts');
console.log('Processing:', name);

let fd: DocEntry = {
name: name,
kind: 'file',
members: {} as { string: [DocEntry]}
};

doc.members[name] = fd;
push(fd);

ts.forEachChild(sourceFile, visit);
}
}

return doc;
}

Expand Down Expand Up @@ -80,7 +79,7 @@ function visit(node: ts.Node): void {
else if (node.kind == ts.SyntaxKind.InterfaceDeclaration) {
if (!isNodeExported(node)) {
return;
}
}
let id: ts.InterfaceDeclaration = <ts.InterfaceDeclaration>node;
let symbol = checker.getSymbolAtLocation(id.name);
if (symbol) {
Expand All @@ -100,7 +99,7 @@ function visit(node: ts.Node): void {
let memberDeclarations: ts.Declaration[] = s.getDeclarations();
if (memberDeclarations.length > 0) {
let memberDoc: DocEntry = {};
memberDoc.documentation = ts.displayPartsToString(s.getDocumentationComment());
memberDoc.documentation = ts.displayPartsToString(s.getDocumentationComment(checker));
memberDoc.name = memberName;
memberDoc.return = checker.typeToString(checker.getTypeAtLocation(memberDeclarations[0]))
doc.members[memberName] = memberDoc;
Expand All @@ -109,7 +108,7 @@ function visit(node: ts.Node): void {

current.members[doc.name] = doc;
push(doc);
}
}
}
if (node.kind == ts.SyntaxKind.EndOfFileToken) {
inClass = false;
Expand All @@ -118,7 +117,7 @@ function visit(node: ts.Node): void {
else if (node.kind == ts.SyntaxKind.MethodDeclaration) {
let m: ts.MethodDeclaration = <ts.MethodDeclaration>node;
let symbol = checker.getSymbolAtLocation(m.name);

if (symbol) {
let doc: DocEntry = getDocEntryFromSymbol(symbol);
doc.kind = 'method';
Expand Down Expand Up @@ -156,7 +155,7 @@ function visit(node: ts.Node): void {
}
}
// handle re-export from internal.ts
else if (node.kind === ts.SyntaxKind.VariableStatement && node.flags === ts.NodeFlags.Export) {
else if (node.kind === ts.SyntaxKind.VariableStatement && node.flags === ts.NodeFlags.ExportContext) {
let statement = <ts.VariableStatement>node;
let list: ts.VariableDeclarationList = statement.declarationList;
for (let declaration of list.declarations) {
Expand All @@ -171,29 +170,28 @@ function visit(node: ts.Node): void {
}
}

ts.forEachChild(node, visit);
ts.forEachChild(node, visit);
}

function getDocEntryFromSignature(signature: ts.Signature): DocEntry {
let paramEntries: DocEntry[] = [];
let params: ts.Symbol[] = signature.parameters;
params.forEach((ps: ts.Symbol) => {
signature.parameters.forEach((ps: ts.Symbol) => {
let de = {} as DocEntry;
de.name = ps.getName();

let decls: ts.Declaration[] = ps.declarations;
let paramType: ts.Type = checker.getTypeAtLocation(decls[0]);
de.type = checker.typeToString(paramType);
de.optional = checker.isOptionalParameter(ps.declarations[0] as ts.ParameterDeclaration);
de.documentation = ts.displayPartsToString(ps.getDocumentationComment());
de.documentation = ts.displayPartsToString(ps.getDocumentationComment(checker));
paramEntries.push(de);
});

let e: DocEntry = {
parameters: paramEntries,
members: {} as { string: [DocEntry]},
return: checker.typeToString(signature.getReturnType()),
documentation: ts.displayPartsToString(signature.getDocumentationComment())
documentation: ts.displayPartsToString(signature.getDocumentationComment(checker))
};

return e;
Expand All @@ -203,19 +201,19 @@ function getDocEntryFromSymbol(symbol: ts.Symbol): DocEntry {
return {
name: symbol.getName(),
members: {} as { string: [DocEntry]},
documentation: ts.displayPartsToString(symbol.getDocumentationComment()),
documentation: ts.displayPartsToString(symbol.getDocumentationComment(checker)),

//type: checker.typeToString(checker.getTypeOfSymbolAtLocation(symbol, symbol.valueDeclaration))
};
}

/** True if this is visible outside this file, false otherwise */
function isNodeExported(node: ts.Node): boolean {
return (node.flags & ts.NodeFlags.Export) !== 0 || (node.parent && node.parent.kind === ts.SyntaxKind.SourceFile);
}
return (node.flags & ts.NodeFlags.ExportContext) !== 0 || (node.parent && node.parent.kind === ts.SyntaxKind.SourceFile);
}

//
// convenience stack
// convenience stack
//

let push = function(entry: DocEntry) {
Expand Down
2 changes: 1 addition & 1 deletion node/docs/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ function failed()
}

../node_modules/.bin/tsc || failed 'Compilation failed.'
../_download/archive/https___nodejs.org_dist_v5.10.1_node-v5.10.1-darwin-x64.tar.gz/node-v5.10.1-darwin-x64/bin/node gendocs.js
../_download/archive/*/*/bin/node gendocs.js
4 changes: 2 additions & 2 deletions node/test/dirtests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('Dir Operation Tests', function () {
this.timeout(1000);

console.log('node version: ' + process.version);
const supportedNodeVersions = ['v5.10.1', 'v6.10.3', 'v8.9.1'];
const supportedNodeVersions = ['v5.10.1', 'v6.10.3', 'v6.17.1', 'v8.9.1', 'v10.17.0', 'v10.18.0'];
if (supportedNodeVersions.indexOf(process.version) === -1) {
assert.fail(`expected node node version to be one of ${supportedNodeVersions.map(o => o).join(', ')}. actual: ` + process.version);
}
Expand Down Expand Up @@ -292,7 +292,7 @@ describe('Dir Operation Tests', function () {

done();
});

it('which() requires rooted path to be a file', function (done) {
this.timeout(1000);

Expand Down