@@ -21,9 +21,12 @@ function jsDocParseComments (comments) {
2121 function getJsDocForNode ( node ) {
2222 var jsdoc = getJsDocForLine ( node . loc . start . line ) ;
2323 if ( jsdoc ) {
24- jsdoc . data = parseJsDoc ( jsdoc . value ) || { } ;
25- jsdoc . invalid = ! jsdoc . data . line ;
26- jsdoc . data . tags = jsdoc . data . tags || [ ] ;
24+ var comment = Array ( jsdoc . loc . start . column + 1 ) . join ( ' ' ) + '/*' + jsdoc . value + '*/' ;
25+ jsdoc . data = parseJsDoc ( comment ) ;
26+ jsdoc . lines = comment . split ( '\n' ) . map ( function ( v ) {
27+ return v . substr ( jsdoc . loc . start . column ) ;
28+ } ) ;
29+ jsdoc . invalid = ! jsdoc . data . hasOwnProperty ( 'line' ) ;
2730 jsdoc . forEachTag = jsDocForEachTag ;
2831 }
2932 return jsdoc ;
@@ -37,7 +40,7 @@ function jsDocParseComments (comments) {
3740 }
3841
3942 function getJsDocForLine ( line ) {
40- line -- ;
43+ line -- ; // todo: buggy behaviour, can't jump back over empty lines
4144 for ( var i = 0 , l = comments . length ; i < l ; i ++ ) {
4245 var commentNode = comments [ i ] ;
4346 if ( commentNode . loc . end . line === line && commentNode . type === 'Block' &&
@@ -49,10 +52,12 @@ function jsDocParseComments (comments) {
4952 }
5053
5154 function parseJsDoc ( comment ) {
52- return parse ( '/*' + comment + '*/' , {
55+ var parsed = parse ( comment , {
5356 lineNumbers : true ,
5457 rawValue : true
55- } ) [ 0 ] || [ ] ;
58+ } ) [ 0 ] || { } ;
59+ parsed . tags = parsed . tags || [ ] ;
60+ return parsed ;
5661 }
5762}
5863
@@ -68,12 +73,20 @@ function jsDocTagValidator (validator) {
6873 } ) ;
6974 } ;
7075
71- function fixErrLocation ( err , node , shift ) {
72- return function ( text , loc ) {
73- loc = loc || { } ;
74- loc . line = loc . hasOwnProperty ( 'line' ) ? loc . line : ( node . loc . start . line + shift ) ;
75- err ( text , loc ) ;
76+ function fixErrLocation ( err , node , tagN ) {
77+ return function ( text , line , column ) {
78+ var tag = node . jsDoc . data . tags [ tagN ] ;
79+ line = line || tag . line ;
80+ // buggy. multiline comment will resolved to 0
81+ column = column || node . jsDoc . lines [ tag . line ] . indexOf ( tag . value ) ;
82+ err ( text , line , column ) ;
7683 } ;
84+ /*function addError(text, loc) {
85+ loc = loc || {};
86+ loc.line = loc.hasOwnProperty('line') ? loc.line : (node.jsDoc.tag.loc.line);
87+ loc.column = loc.hasOwnProperty('column') ? loc.column : -1; // node.jsDoc.data.tags[i].indexOf('@');
88+ errors.add(text, loc.line, loc.column);
89+ }*/
7790 }
7891}
7992
0 commit comments