Skip to content

Commit 19cfa17

Browse files
authored
Merge pull request #30 from wehrstedt/template-path
Template can't be used with grunt
2 parents 16ab51d + 2683556 commit 19cfa17

10 files changed

+43
-32
lines changed

.npmignore

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
exampleProject/
33
node_modules/
44
src/
5-
src-out/core/publish-example.js
6-
src-out/test
7-
src-out/**/*.js.map
8-
src-out/**/*.d.ts
5+
src-out/
96
typings/
107
.editorconfig
118
.travis.yml
129
gruntfile.js
10+
publish-example.js
1311
tsconfig.json
1412
tslint.json

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## Changelog
22

3+
# v0.8.8
4+
Bugfixes:
5+
- You can now use the template with grunt or simply use the module path as for the template parameter for jsdoc (https://github.com/otris/jsdoc-tsd/issues/1)
6+
- The description of an jsdoc item was not added if the @description-annotation was omitted
7+
38
# v0.8.7
49
New features in this release:
510
- New annotations: @callback, @template

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"name": "@otris/jsdoc-tsd",
3-
"version": "0.8.7",
3+
"version": "0.8.8",
44
"description": "JSDoc Template for generate typescript definition files from JSDoc comments",
55
"main": "src-out/core/publish.js",
66
"repository": {
77
"type": "git",
88
"url": "git+ssh://[email protected]:otris/jsdoc-tsd.git"
99
},
1010
"scripts": {
11-
"prepublish": "rm -rf src-out && tsc -p ./",
11+
"prepublish": "rm -rf src-out && tsc -p ./ && cp src-out/core/*.js ./",
1212
"compile": "tsc -watch -p ./",
1313
"parse-example": "move /Y src-out\\core\\publish.js src-out\\core\\publish.backup.js && copy /Y src-out\\core\\publish-example.js src-out\\core\\publish.js && jsdoc -r exampleProject -t src-out\\core && move /Y src-out\\core\\publish.backup.js src-out\\core\\publish.js",
1414
"test": "mocha --compilers=ts:ts-node/register --no-timeouts src/test/**/test.*.ts",

src/core/jsdoc-tsd-parser.ts

+24-18
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export class JSDocTsdParser {
180180

181181
if (addItem) {
182182
if (addJsDocComment) {
183-
parsedItem.jsDocComment = this.cleanJSDocComment(item.comment);
183+
parsedItem.jsDocComment = this.cleanJSDocComment(item.comment, item.description);
184184
}
185185
this.handleFlags(item, parsedItem);
186186
this.handleTags(item, parsedItem);
@@ -392,13 +392,19 @@ export class JSDocTsdParser {
392392
return output;
393393
}
394394

395-
private cleanJSDocComment(comment: string | undefined, addExample = false): string {
395+
/**
396+
* Creates the comment for the jsdoc item
397+
* @param comment The complete comment text of the item
398+
* @param description The description (@description) of the item
399+
* @param addExample Indicates if examples should be omitted or not
400+
*/
401+
private cleanJSDocComment(comment: string | undefined, description:string = "", addExample = false): string {
396402
let cleanLines = [];
397403
let descriptionLines: string[] = [];
398404
let exampleLines: string[] = [];
399-
let description = false;
400-
let example = false;
401-
let classdesc = false;
405+
let isDescription = false;
406+
let isExample = false;
407+
let isClassdesc = false;
402408

403409
if (comment) {
404410
for (let line of comment.split(/\r?\n/)) {
@@ -414,24 +420,24 @@ export class JSDocTsdParser {
414420
// tslint:disable-next-line:max-line-length
415421
if (cleanedLine && (cleanedLine.startsWith("@param") || cleanedLine.startsWith("@throws") || cleanedLine.startsWith("@description") || cleanedLine.startsWith("@classdesc") || cleanedLine.startsWith("@example") || cleanedLine.startsWith("@return") || !cleanedLine.startsWith("@"))) {
416422
if (cleanedLine.startsWith("@")) {
417-
description = false;
418-
example = false;
419-
classdesc = false;
423+
isDescription = false;
424+
isExample = false;
425+
isClassdesc = false;
420426
}
421-
if (cleanedLine.startsWith("@description")) {
427+
if (cleanedLine.startsWith("@description") || cleanedLine === description) {
422428
cleanedLine = cleanedLine.replace("@description ", "");
423-
description = true;
429+
isDescription = true;
424430
} else if (cleanedLine.startsWith("@example")) {
425-
example = true;
431+
isExample = true;
426432
} else if (cleanedLine.startsWith("@classdesc")) {
427-
classdesc = true;
433+
isClassdesc = true;
428434
}
429435

430-
if (description) {
436+
if (isDescription) {
431437
descriptionLines.push(cleanedLine);
432-
} else if (example) {
438+
} else if (isExample) {
433439
exampleLines.push(cleanedLine);
434-
} else if (classdesc) {
440+
} else if (isClassdesc) {
435441
// the class-description is correctly added to the class already
436442
} else if (/^@[^\s]+\s/.test(cleanedLine)) {
437443
// add this line only if the annotation value is not empty
@@ -709,7 +715,7 @@ export class JSDocTsdParser {
709715
constructorDeclaration = dom.create.constructor([]);
710716
}
711717

712-
constructorDeclaration.jsDocComment = this.cleanJSDocComment(jsdocItem.comment);
718+
constructorDeclaration.jsDocComment = this.cleanJSDocComment(jsdocItem.comment, jsdocItem.description);
713719
domClass.members.push(constructorDeclaration);
714720

715721
return domClass;
@@ -724,7 +730,7 @@ export class JSDocTsdParser {
724730
if (jsdocItem.properties) {
725731
for (let property of jsdocItem.properties) {
726732
let domEnumMember: dom.EnumMemberDeclaration = dom.create.enumValue(property.name, property.defaultvalue);
727-
domEnumMember.jsDocComment = this.cleanJSDocComment(property.description);
733+
domEnumMember.jsDocComment = this.cleanJSDocComment(property.comment, property.description);
728734
domEnum.members.push(domEnumMember);
729735
}
730736
}
@@ -811,7 +817,7 @@ export class JSDocTsdParser {
811817
}
812818

813819
let domProperty = dom.create.property(property.name, propertyType);
814-
domProperty.jsDocComment = this.cleanJSDocComment(property.comment) || property.description; // normally the property 'comment' is for these types empty
820+
domProperty.jsDocComment = this.cleanJSDocComment(property.description, property.description);
815821
this.handleFlags(property, domProperty);
816822

817823
domInterface.members.push(domProperty);

src/test/class/test.parseClass.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe("JSDocTsdParser.parse.class", () => {
4141

4242
expect(classDeclarations.members.length).to.eq(1);
4343
let constr: dom.ConstructorDeclaration = classDeclarations.members[0] as dom.ConstructorDeclaration;
44-
expect(constr.jsDocComment).to.eq("My Class\n@param myParam My param description");
44+
expect(constr.jsDocComment).to.eq("@param myParam My param description");
4545
});
4646

4747
it("should add an constructor with no params to the class members", () => {

src/test/description/test.parseDescription.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ describe("JSDocTsdParser.cleanJSDocComment", () => {
2020
// parsedClass.members[0] is constructor
2121
let methodDeclaration: dom.MethodDeclaration = parsedClass.members[1] as dom.MethodDeclaration;
2222
// description should be at the beginning
23-
expect(methodDeclaration.jsDocComment).to.eq("My long description\nfirst line\nsecond line\nthird line\n@param myParamter My string parameter");
23+
expect(methodDeclaration.jsDocComment).to.eq("My long description\nfirst line\nsecond line\nthird line\n@param myParamter My string parameter\n@returns My return value");
2424
});
2525
});

src/test/function/test.jsdoc-tsd-parser.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ describe("JSDocTsdParser.parse.function", () => {
407407
* @static
408408
* @function
409409
*/`;
410+
functionData.description = "A function";
410411

411412
parser = new JSDocTsdParser();
412413
parser.parse([functionData]);
@@ -415,7 +416,7 @@ describe("JSDocTsdParser.parse.function", () => {
415416

416417
expect(functionDeclarations.length).to.equals(1);
417418
let functionDeclaration = functionDeclarations[0];
418-
functionDescription = `A function\n@param bla blub\n@throws {string} error`;
419+
functionDescription = `A function\n@param bla blub\n@returns bla\n@throws {string} error`;
419420
expect(functionDeclaration.jsDocComment).to.equals(functionDescription);
420421
});
421422

@@ -444,6 +445,7 @@ describe("JSDocTsdParser.parse.function", () => {
444445
* @static
445446
* @function
446447
*/`;
448+
functionData.description = "A function";
447449

448450
parser = new JSDocTsdParser();
449451
parser.parse([functionData]);
@@ -452,7 +454,7 @@ describe("JSDocTsdParser.parse.function", () => {
452454

453455
expect(functionDeclarations.length).to.equals(1);
454456
let functionDeclaration = functionDeclarations[0];
455-
functionDescription = `A function\n@param bla blub\n@throws {string} error`;
457+
functionDescription = `A function\n@param bla blub\n@returns bla\n@throws {string} error`;
456458
expect(functionDeclaration.jsDocComment).to.equals(functionDescription);
457459
});
458460

src/test/interface/test.parseInterface.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe("JSDocTsdParser.parse.interface", () => {
3333
expect(parsedInterface.members.length).to.eq(2);
3434

3535
let methodDeclaration: dom.MethodDeclaration = parsedInterface.members[1] as dom.MethodDeclaration;
36-
expect(methodDeclaration.jsDocComment).to.eq("A simple function\n@param myParamter My string parameter");
36+
expect(methodDeclaration.jsDocComment).to.eq("A simple function\n@param myParamter My string parameter\n@returns My return value");
3737
});
3838

3939
it("should create a number member of an interface", () => {

src/test/module/test.parseModule.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe("JSDocTsdParser.parse.module", () => {
3333
expect(parsedModule.members.length).to.eq(2);
3434

3535
let functionDeclaration: dom.FunctionDeclaration = parsedModule.members[1] as dom.FunctionDeclaration;
36-
expect(functionDeclaration.jsDocComment).to.eq("my module function\n@param param1 first param\n@param param2 second param");
36+
expect(functionDeclaration.jsDocComment).to.eq("my module function\n@param param1 first param\n@param param2 second param\n@returns function return value");
3737
});
3838

3939
it("should create a number member of an module", () => {

src/test/test.since.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ describe("Test for parsing the since tag", () => {
150150
expect(results).haveOwnPropertyDescriptor("MyTestClass");
151151
});
152152

153-
it("should not add the class definition if the tag is not a valid semver tag and no custom comparator is set", () => {
153+
it("should add the class definition if the tag is not a valid semver tag and no custom comparator is set", () => {
154154
let myClass: TDoclet = JSON.parse(JSON.stringify(emptyClassData));
155155
myClass.since = "abc";
156156
myClass.name = myClass.longname = "MyTestClass";
@@ -159,7 +159,7 @@ describe("Test for parsing the since tag", () => {
159159
parser.parse([myClass]);
160160

161161
let results = parser.getResultItems();
162-
expect(Object.keys(results).length).to.eq(0);
162+
expect(Object.keys(results).length).to.eq(1);
163163
});
164164

165165
it("should use the comparator function if it's passed as function", () => {

0 commit comments

Comments
 (0)