File tree Expand file tree Collapse file tree 4 files changed +42
-1
lines changed
tests/baselines/reference Expand file tree Collapse file tree 4 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -661,8 +661,15 @@ namespace ts {
661
661
let pendingKind ! : CommentKind ;
662
662
let pendingHasTrailingNewLine ! : boolean ;
663
663
let hasPendingCommentRange = false ;
664
- let collecting = trailing || pos === 0 ;
664
+ let collecting = trailing ;
665
665
let accumulator = initial ;
666
+ if ( pos === 0 ) {
667
+ collecting = true ;
668
+ const shebang = getShebang ( text ) ;
669
+ if ( shebang ) {
670
+ pos = shebang . length ;
671
+ }
672
+ }
666
673
scan: while ( pos >= 0 && pos < text . length ) {
667
674
const ch = text . charCodeAt ( pos ) ;
668
675
switch ( ch ) {
Original file line number Diff line number Diff line change 43
43
" unittests/asserts.ts" ,
44
44
" unittests/base64.ts" ,
45
45
" unittests/builder.ts" ,
46
+ " unittests/comments.ts" ,
46
47
" unittests/compilerCore.ts" ,
47
48
" unittests/convertToBase64.ts" ,
48
49
" unittests/customTransforms.ts" ,
Original file line number Diff line number Diff line change
1
+ namespace ts {
2
+ describe ( "comment parsing" , ( ) => {
3
+ const withShebang = `#! node
4
+ /** comment */
5
+ // another one
6
+ ;` ;
7
+ const noShebang = `/** comment */
8
+ // another one
9
+ ;` ;
10
+ const withTrailing = `;/* comment */
11
+ // another one
12
+ ` ;
13
+ it ( "skips shebang" , ( ) => {
14
+ const result = getLeadingCommentRanges ( withShebang , 0 ) ;
15
+ assert . isDefined ( result ) ;
16
+ assert . strictEqual ( result ! . length , 2 ) ;
17
+ } ) ;
18
+
19
+ it ( "treats all comments at start of file as leading comments" , ( ) => {
20
+ const result = getLeadingCommentRanges ( noShebang , 0 ) ;
21
+ assert . isDefined ( result ) ;
22
+ assert . strictEqual ( result ! . length , 2 ) ;
23
+ } ) ;
24
+
25
+ it ( "returns leading comments if position is not 0" , ( ) => {
26
+ const result = getLeadingCommentRanges ( withTrailing , 1 ) ;
27
+ assert . isDefined ( result ) ;
28
+ assert . strictEqual ( result ! . length , 1 ) ;
29
+ assert . strictEqual ( result ! [ 0 ] . kind , SyntaxKind . SingleLineCommentTrivia ) ;
30
+ } ) ;
31
+ } ) ;
32
+ }
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ use(x);
17
17
//// [f.js]
18
18
#!/usr/bin/env node
19
19
"use strict" ;
20
+ /// <reference path="f.d.ts"/>
20
21
exports . __esModule = true ;
21
22
var test_1 = require ( "test" ) ;
22
23
use ( test_1 . x ) ;
You can’t perform that action at this time.
0 commit comments