diff --git a/lib/generator.js b/lib/generator.js index bfd2f30..22b2227 100644 --- a/lib/generator.js +++ b/lib/generator.js @@ -382,12 +382,13 @@ class Visitor { return item.text.text; }); - var descriptionText = description ? _escape(description.text.text.trimEnd()) : ''; - var summaryText = summary ? _escape(summary.text.text.trimEnd()) : ''; - var returnText = _return ? _return.text.text.trimEnd() : ''; let hasNextSection = false; + const summaryText = summary ? _escape(summary.text.text).trimEnd() : ''; + const descriptionText = description ? _escape(description.text.text).trimEnd() : ''; + const returnText = _return ? _escape(_return.text.text).trimEnd() : ''; + if (deprecated) { - let deprecatedText = deprecated.text.text.trimEnd(); + const deprecatedText = _escape(deprecated.text.text).trimEnd(); deprecatedText.split('\n').forEach((line, index, array) => { if(index === 0) { this.emit(`// Deprecated: ${line}\n`, level); @@ -435,30 +436,57 @@ class Visitor { if (hasNextSection) { this.emit(`// \n`, level); } - params.forEach((item, index) => { - this.emit(`// @param ${item.name} - ${item.text}`, level); - if (index < params.length - 1) { - this.emit(`// \n`, level); - } + params.forEach((item, i) => { + this.emit(`// @param ${item.name} - `, level); + const items = item.text.trimEnd().split('\n'); + items.forEach((line, j) => { + if (j === 0) { + this.emit(`${line}\n`); + } else { + this.emit(`// ${line}\n`, level); + } + if (j < items.length - 1 || (j === items.length - 1 && i < params.length -1)) { + this.emit(`// \n`, level); + } + }); }); hasNextSection = true; } - if (returnText !== '') { + if (returnText) { if (hasNextSection) { this.emit(`// \n`, level); } - this.emit(`// @return ${returnText}\n`, level); + this.emit(`// @return `, level); + const returns = returnText.split('\n'); + returns.forEach((line, index) => { + if (index === 0) { + this.emit(`${line}\n`); + } else { + this.emit(`// ${line}\n`, level); + } + if (index < returns.length - 1) { + this.emit(`// \n`, level); + } + }); hasNextSection = true; } if (throws.length > 0) { if (hasNextSection) { this.emit(`// \n`, level); } - throws.forEach((item, index) => { - this.emit(`// @throws ${item}`, level); - if (index < throws.length - 1) { - this.emit(`// \n`, level); - } + throws.forEach((item, i) => { + this.emit(`// @throws `, level); + const items = item.trimEnd().split('\n'); + items.forEach((line, j) => { + if (j === 0) { + this.emit(`${line}\n`); + } else { + this.emit(`// ${line}\n`, level); + } + if (j < items.length - 1 || (j === items.length - 1 && i < params.length -1)) { + this.emit(`// \n`, level); + } + }); }); } } diff --git a/test/fixtures/annotation/client.go b/test/fixtures/annotation/client.go index 1ad7b89..b9a4e67 100644 --- a/test/fixtures/annotation/client.go +++ b/test/fixtures/annotation/client.go @@ -136,6 +136,7 @@ func TestFuncWithAnnotation1 (test *string, _test *string) (_err error) { // @return void // // @throws InternalError Server error. 500 服务器端出现未知异常。 +// func TestFuncWithAnnotation2 (test *string, _test *string) (_err error) { // empty comment1 // empty comment2 @@ -146,14 +147,19 @@ func TestFuncWithAnnotation2 (test *string, _test *string) (_err error) { // // @param test - string param1 // +// param test for line break. +// // @param _test - string param2 // // @return void // +// return test for line break. +// // @throws InternalError Server error. 500 服务器端出现未知异常。 -func TestFuncWithAnnotation3 (test *string, _test *string) (_err error) { - // empty comment1 - // empty comment2 +// +// throws test for line break. +// +func LineBreakAnnotation (test *string, _test *string) (_err error) { return _err } diff --git a/test/fixtures/annotation/main.dara b/test/fixtures/annotation/main.dara index dce34bf..9f07b8f 100644 --- a/test/fixtures/annotation/main.dara +++ b/test/fixtures/annotation/main.dara @@ -77,11 +77,13 @@ static async function testFuncWithAnnotation2(test: string, _test: string): void * deprecated test for line break. * * @param test string param1 + * param test for line break. * @param _test string param2 * @return void + * return test for line break. * @throws InternalError Server error. 500 服务器端出现未知异常。 + * throws test for line break. */ -static async function testFuncWithAnnotation3(test: string, _test: string): void { - // empty comment1 - // empty comment2 +static async function lineBreakAnnotation(test: string, _test: string): void { } +