@@ -654,6 +654,16 @@ describe("TokenStore", () => {
654654 assert . strictEqual ( token . value , "c" ) ;
655655 } ) ;
656656
657+ it ( "should retrieve the first token if the root node contains a trailing comment" , ( ) => {
658+ const parser = require ( "../../fixtures/parsers/all-comments-parser" ) ;
659+ const code = "foo // comment" ;
660+ const ast = parser . parse ( code , { loc : true , range : true , tokens : true , comment : true } ) ;
661+ const tokenStore = new TokenStore ( ast . tokens , ast . comments ) ;
662+ const token = tokenStore . getFirstToken ( ast ) ;
663+
664+ assert . strictEqual ( token , ast . tokens [ 0 ] ) ;
665+ } ) ;
666+
657667 it ( "should return null if the source contains only comments" , ( ) => {
658668 const code = "// comment" ;
659669 const ast = espree . parse ( code , { loc : true , range : true , tokens : true , comment : true } ) ;
@@ -863,6 +873,16 @@ describe("TokenStore", () => {
863873 assert . strictEqual ( token . value , "b" ) ;
864874 } ) ;
865875
876+ it ( "should retrieve the last token if the root node contains a trailing comment" , ( ) => {
877+ const parser = require ( "../../fixtures/parsers/all-comments-parser" ) ;
878+ const code = "foo // comment" ;
879+ const ast = parser . parse ( code , { loc : true , range : true , tokens : true , comment : true } ) ;
880+ const tokenStore = new TokenStore ( ast . tokens , ast . comments ) ;
881+ const token = tokenStore . getLastToken ( ast ) ;
882+
883+ assert . strictEqual ( token , ast . tokens [ 0 ] ) ;
884+ } ) ;
885+
866886 it ( "should return null if the source contains only comments" , ( ) => {
867887 const code = "// comment" ;
868888 const ast = espree . parse ( code , { loc : true , range : true , tokens : true , comment : true } ) ;
0 commit comments