diff --git a/__tests__/lib/github.js b/__tests__/lib/github.js index ce15eccde..92968adcf 100644 --- a/__tests__/lib/github.js +++ b/__tests__/lib/github.js @@ -25,6 +25,10 @@ function evaluate(fn) { ); } +afterEach(function() { + mock.restore(); +}); + test('github', function() { mock(mockRepo.master); @@ -42,8 +46,6 @@ test('github', function() { path: 'index.js', url: 'https://github.com/foo/bar/blob/this_is_the_sha/index.js#L6-L8' }); - - mock.restore(); }); test('malformed repository', function() { @@ -60,8 +62,6 @@ test('malformed repository', function() { } })[0].context.github ).toBe(undefined); - - mock.restore(); }); test('enterprise repository', function() { @@ -82,6 +82,28 @@ test('enterprise repository', function() { url: 'https://github.enterprise.com/foo/bar/blob/this_is_the_sha/index.js#L6-L8' }); +}); - mock.restore(); +test('typedef', function() { + mock(mockRepo.master); + + expect( + evaluate(function() { + /** + * A number, or a string containing a number. + * @typedef {(number|string)} NumberLike + */ + + /** + * get one + * @returns {number} one + */ + function getOne() { + return 1; + } + })[0].context.github + ).toEqual({ + path: 'index.js', + url: 'https://github.com/foo/bar/blob/this_is_the_sha/index.js#L2-L5' + }); }); diff --git a/declarations/comment.js b/declarations/comment.js index 257dee204..24fb5ba64 100644 --- a/declarations/comment.js +++ b/declarations/comment.js @@ -106,6 +106,7 @@ type Comment = { type?: DoctrineType, context: CommentContext, + loc: CommentLoc, path?: Array<{ name: string, diff --git a/src/github.js b/src/github.js index 1a80cfffc..291275b13 100644 --- a/src/github.js +++ b/src/github.js @@ -21,15 +21,20 @@ module.exports = function(comment: Comment) { .join('/'); if (urlPrefix) { + let startLine; + let endLine; + + if (comment.kind == 'typedef') { + startLine = comment.loc.start.line; + endLine = comment.loc.end.line; + } else { + startLine = comment.context.loc.start.line; + endLine = comment.context.loc.end.line; + } + comment.context.github = { url: - urlPrefix + - fileRelativePath + - '#L' + - comment.context.loc.start.line + - '-' + - 'L' + - comment.context.loc.end.line, + urlPrefix + fileRelativePath + '#L' + startLine + '-' + 'L' + endLine, path: fileRelativePath }; } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy