File tree Expand file tree Collapse file tree 3 files changed +40
-12
lines changed Expand file tree Collapse file tree 3 files changed +40
-12
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,10 @@ function evaluate(fn) {
2525 ) ;
2626}
2727
28+ afterEach ( function ( ) {
29+ mock . restore ( ) ;
30+ } ) ;
31+
2832test ( 'github' , function ( ) {
2933 mock ( mockRepo . master ) ;
3034
@@ -42,8 +46,6 @@ test('github', function() {
4246 path : 'index.js' ,
4347 url : 'https://github.com/foo/bar/blob/this_is_the_sha/index.js#L6-L8'
4448 } ) ;
45-
46- mock . restore ( ) ;
4749} ) ;
4850
4951test ( 'malformed repository' , function ( ) {
@@ -60,8 +62,6 @@ test('malformed repository', function() {
6062 }
6163 } ) [ 0 ] . context . github
6264 ) . toBe ( undefined ) ;
63-
64- mock . restore ( ) ;
6565} ) ;
6666
6767test ( 'enterprise repository' , function ( ) {
@@ -82,6 +82,28 @@ test('enterprise repository', function() {
8282 url :
8383 'https://github.enterprise.com/foo/bar/blob/this_is_the_sha/index.js#L6-L8'
8484 } ) ;
85+ } ) ;
8586
86- mock . restore ( ) ;
87+ test ( 'typedef' , function ( ) {
88+ mock ( mockRepo . master ) ;
89+
90+ expect (
91+ evaluate ( function ( ) {
92+ /**
93+ * A number, or a string containing a number.
94+ * @typedef {(number|string) } NumberLike
95+ */
96+
97+ /**
98+ * get one
99+ * @returns {number } one
100+ */
101+ function getOne ( ) {
102+ return 1 ;
103+ }
104+ } ) [ 0 ] . context . github
105+ ) . toEqual ( {
106+ path : 'index.js' ,
107+ url : 'https://github.com/foo/bar/blob/this_is_the_sha/index.js#L2-L5'
108+ } ) ;
87109} ) ;
Original file line number Diff line number Diff line change @@ -106,6 +106,7 @@ type Comment = {
106106 type ?: DoctrineType ,
107107
108108 context : CommentContext ,
109+ loc : CommentLoc ,
109110
110111 path ?: Array < {
111112 name : string ,
Original file line number Diff line number Diff line change @@ -21,15 +21,20 @@ module.exports = function(comment: Comment) {
2121 . join ( '/' ) ;
2222
2323 if ( urlPrefix ) {
24+ let startLine ;
25+ let endLine ;
26+
27+ if ( comment . kind == 'typedef' ) {
28+ startLine = comment . loc . start . line ;
29+ endLine = comment . loc . end . line ;
30+ } else {
31+ startLine = comment . context . loc . start . line ;
32+ endLine = comment . context . loc . end . line ;
33+ }
34+
2435 comment . context . github = {
2536 url :
26- urlPrefix +
27- fileRelativePath +
28- '#L' +
29- comment . context . loc . start . line +
30- '-' +
31- 'L' +
32- comment . context . loc . end . line ,
37+ urlPrefix + fileRelativePath + '#L' + startLine + '-' + 'L' + endLine ,
3338 path : fileRelativePath
3439 } ;
3540 }
You can’t perform that action at this time.
0 commit comments