Skip to content

Commit 53a9d43

Browse files
committed
fix(parser): use doctrine to unwrap comments
1 parent d00c7f2 commit 53a9d43

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

Diff for: package.json

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"@commitlint/cli": "^8.0.0",
2424
"@commitlint/config-conventional": "^8.0.0",
2525
"@types/babel__core": "^7.1.2",
26+
"@types/doctrine": "^0.0.3",
2627
"@types/jest": "^24.0.15",
2728
"@types/lodash": "^4.14.136",
2829
"@types/node": "^12.6.2",
@@ -41,6 +42,7 @@
4142
"@babel/plugin-syntax-class-properties": "^7.2.0",
4243
"@babel/plugin-syntax-jsx": "^7.2.0",
4344
"@babel/types": "^7.5.0",
45+
"doctrine": "^3.0.0",
4446
"lodash": "^4.17.14",
4547
"typescript": "3.5.2",
4648
"uuid": "^3.3.2"

Diff for: src/parser.ts

+2-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as ts from 'typescript';
22
import * as t from './types';
3+
import * as doctrine from 'doctrine';
34

45
/**
56
* Options that specify how the parser should act
@@ -441,19 +442,7 @@ export function parseFromProgram(
441442
if (comments && comments.length === 1) {
442443
const commentNode = comments[0];
443444
if (ts.isJSDoc(commentNode)) {
444-
let commentText = commentNode.comment ? commentNode.comment : '';
445-
if (commentNode.tags) {
446-
const tags = commentNode.tags
447-
.map(tag =>
448-
tag
449-
.getText()
450-
.replace(/\* *$/, '')
451-
.trim(),
452-
)
453-
.reduce((prev, curr) => `${prev}\n${curr}`);
454-
commentText = commentText ? `${commentText}\n${tags}` : tags;
455-
}
456-
return commentText;
445+
return doctrine.unwrapComment(commentNode.getText()).trim();
457446
}
458447
}
459448
}

Diff for: yarn.lock

+12
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,11 @@
471471
dependencies:
472472
"@babel/types" "^7.3.0"
473473

474+
"@types/doctrine@^0.0.3":
475+
version "0.0.3"
476+
resolved "https://registry.yarnpkg.com/@types/doctrine/-/doctrine-0.0.3.tgz#e892d293c92c9c1d3f9af72c15a554fbc7e0895a"
477+
integrity sha1-6JLSk8ksnB0/mvcsFaVU+8fgiVo=
478+
474479
"@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0":
475480
version "2.0.1"
476481
resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.1.tgz#42995b446db9a48a11a07ec083499a860e9138ff"
@@ -1498,6 +1503,13 @@ diff-sequences@^24.3.0:
14981503
resolved "https://registry.yarnpkg.com/diff-sequences/-/diff-sequences-24.3.0.tgz#0f20e8a1df1abddaf4d9c226680952e64118b975"
14991504
integrity sha512-xLqpez+Zj9GKSnPWS0WZw1igGocZ+uua8+y+5dDNTT934N3QuY1sp2LkHzwiaYQGz60hMq0pjAshdeXm5VUOEw==
15001505

1506+
doctrine@^3.0.0:
1507+
version "3.0.0"
1508+
resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-3.0.0.tgz#addebead72a6574db783639dc87a121773973961"
1509+
integrity sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==
1510+
dependencies:
1511+
esutils "^2.0.2"
1512+
15011513
domexception@^1.0.1:
15021514
version "1.0.1"
15031515
resolved "https://registry.yarnpkg.com/domexception/-/domexception-1.0.1.tgz#937442644ca6a31261ef36e3ec677fe805582c90"

0 commit comments

Comments
 (0)