Skip to content

feat: Support for @packageDocumentation #1154

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

Merged
merged 3 commits into from
Dec 26, 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
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@
"keywords": [
"typescript",
"documentation",
"generator",
"gruntplugin"
"generator"
],
"nyc": {
"extension": [
Expand Down
4 changes: 4 additions & 0 deletions src/lib/converter/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,10 @@ export class Converter extends ChildableComponent<Application, ConverterComponen
this.convertNode(context, sourceFile);
});

if (this.application.ignoreCompilerErrors) {
return [];
}

let diagnostics = program.getOptionsDiagnostics().filter(isRelevantError);
if (diagnostics.length) {
return diagnostics;
Expand Down
17 changes: 15 additions & 2 deletions src/lib/converter/factories/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,26 @@ export function getRawComment(node: ts.Node): string | undefined {
const comments = getJSDocCommentRanges(node, sourceFile.text);
if (comments.length) {
let comment: ts.CommentRange;
const explicitPackageComment = comments.find(comment =>
sourceFile.text.substring(comment.pos, comment.end).includes('@packageDocumentation'));
if (node.kind === ts.SyntaxKind.SourceFile) {
if (comments.length === 1) {
if (explicitPackageComment) {
comment = explicitPackageComment;
} else if (comments.length > 1) {
// Legacy behavior, require more than one comment and use the first comment.
// TODO: GH#1083, follow deprecation process to phase this out.
comment = comments[0];
} else {
// Single comment that may be a license comment, bail.
return;
}
comment = comments[0];
} else {
comment = comments[comments.length - 1];
// If a non-SourceFile node comment has this tag, it should not be attached to the node
// as it documents the whole file by convention.
if (sourceFile.text.substring(comment.pos, comment.end).includes('@packageDocumentation')) {
return;
}
}

return sourceFile.text.substring(comment.pos, comment.end);
Expand Down
4 changes: 4 additions & 0 deletions src/lib/converter/plugins/CommentPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ export class CommentPlugin extends ConverterComponent {
}
this.hidden.push(reflection);
}

if (reflection.kindOf(ReflectionKind.ExternalModule)) {
CommentPlugin.removeTags(comment, 'packagedocumentation');
}
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/test/converter/comment/comment.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* This is a module doc comment with legacy behavior.
*/
/** dummy comment */
import './comment2';

/**
* A Comment for a class
*
Expand Down
10 changes: 10 additions & 0 deletions src/test/converter/comment/comment2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* This is a module doc with the packageDocumentation tag to mark it as documentation
* for the whole module. It is *not* documentation for the `multiply` function.
*
* @packageDocumentation
*/

export function multiply(a: number, b: number) {
return a * b;
}
102 changes: 95 additions & 7 deletions src/test/converter/comment/specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@
"flags": {},
"children": [
{
"id": 1,
"id": 6,
"name": "\"comment\"",
"kind": 1,
"kindString": "External module",
"flags": {
"isExported": true
},
"originalName": "%BASE%/comment/comment.ts",
"comment": {
"shortText": "This is a module doc comment with legacy behavior."
},
"children": [
{
"id": 2,
"id": 7,
"name": "CommentedClass",
"kind": 128,
"kindString": "Class",
Expand All @@ -38,7 +41,7 @@
},
"children": [
{
"id": 3,
"id": 8,
"name": "prop",
"kind": 1024,
"kindString": "Property",
Expand All @@ -51,7 +54,7 @@
"sources": [
{
"fileName": "comment.ts",
"line": 28,
"line": 34,
"character": 6
}
],
Expand All @@ -66,14 +69,14 @@
"title": "Properties",
"kind": 1024,
"children": [
3
8
]
}
],
"sources": [
{
"fileName": "comment.ts",
"line": 24,
"line": 30,
"character": 27
}
]
Expand All @@ -84,7 +87,7 @@
"title": "Classes",
"kind": 128,
"children": [
2
7
]
}
],
Expand All @@ -95,13 +98,98 @@
"character": 0
}
]
},
{
"id": 1,
"name": "\"comment2\"",
"kind": 1,
"kindString": "External module",
"flags": {
"isExported": true
},
"originalName": "%BASE%/comment/comment2.ts",
"comment": {
"shortText": "This is a module doc with the packageDocumentation tag to mark it as documentation\nfor the whole module. It is *not* documentation for the `multiply` function."
},
"children": [
{
"id": 2,
"name": "multiply",
"kind": 64,
"kindString": "Function",
"flags": {
"isExported": true
},
"signatures": [
{
"id": 3,
"name": "multiply",
"kind": 4096,
"kindString": "Call signature",
"flags": {},
"parameters": [
{
"id": 4,
"name": "a",
"kind": 32768,
"kindString": "Parameter",
"flags": {},
"type": {
"type": "intrinsic",
"name": "number"
}
},
{
"id": 5,
"name": "b",
"kind": 32768,
"kindString": "Parameter",
"flags": {},
"type": {
"type": "intrinsic",
"name": "number"
}
}
],
"type": {
"type": "intrinsic",
"name": "number"
}
}
],
"sources": [
{
"fileName": "comment2.ts",
"line": 8,
"character": 24
}
]
}
],
"groups": [
{
"title": "Functions",
"kind": 64,
"children": [
2
]
}
],
"sources": [
{
"fileName": "comment2.ts",
"line": 1,
"character": 0
}
]
}
],
"groups": [
{
"title": "External modules",
"kind": 1,
"children": [
6,
1
]
}
Expand Down
56 changes: 0 additions & 56 deletions tasks/typedoc.js

This file was deleted.