File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -225,6 +225,7 @@ function tokenize(source, alternateCommentMode) {
225225 curr ,
226226 start ,
227227 isDoc ,
228+ nextLineIsComment ,
228229 isLeadingComment = offset === 0 ;
229230 do {
230231 if ( offset === length )
@@ -278,7 +279,11 @@ function tokenize(source, alternateCommentMode) {
278279 // Trailing comment cannot not be multi-line
279280 break ;
280281 }
281- } while ( isDoubleSlashCommentLine ( offset ) ) ;
282+ nextLineIsComment = isDoubleSlashCommentLine ( offset ) ;
283+ if ( nextLineIsComment ) {
284+ line ++ ;
285+ }
286+ } while ( nextLineIsComment ) ;
282287 } else {
283288 offset = Math . min ( length , findEndOfLine ( offset ) + 1 ) ;
284289 }
Original file line number Diff line number Diff line change @@ -84,3 +84,24 @@ tape.test("proto comments in alternate-parse mode with trailing comment preferre
8484 test . end ( ) ;
8585 } ) ;
8686} ) ;
87+
88+ tape . test ( "proto comments in alternate-parse mode maintain line numbers" , function ( test ) {
89+ var source = [
90+ "syntax = \"proto3\";" ,
91+ "" ,
92+ "// Multiple lines of" ,
93+ "// end-of-line comments" ,
94+ "// should keep the tokenizer" ,
95+ "// line count correct." ,
96+ "" ,
97+ "message Foo {};a"
98+ ] . join ( "\n" ) ;
99+
100+ try {
101+ protobuf . parse ( source , { alternateCommentMode : true } ) ;
102+ test . fail ( "should throw on invalid token" ) ;
103+ } catch ( err ) {
104+ test . equal ( err . message , "illegal token 'a' (line 8)" ) ;
105+ }
106+ test . end ( ) ;
107+ } ) ;
You can’t perform that action at this time.
0 commit comments