File tree 2 files changed +35
-0
lines changed
2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -751,4 +751,24 @@ export default class TokenStore {
751
751
filter : isCommentToken ,
752
752
} )
753
753
}
754
+
755
+ /**
756
+ * Returns the location of the given node or token.
757
+ * @param nodeOrToken The node or token to get the location of.
758
+ * @returns The location of the node or token.
759
+ */
760
+ // eslint-disable-next-line class-methods-use-this
761
+ public getLoc ( nodeOrToken : HasLocation ) {
762
+ return nodeOrToken . loc
763
+ }
764
+
765
+ /**
766
+ * Returns the range of the given node or token.
767
+ * @param nodeOrToken The node or token to get the range of.
768
+ * @returns The range of the node or token.
769
+ */
770
+ // eslint-disable-next-line class-methods-use-this
771
+ public getRange ( nodeOrToken : HasLocation ) {
772
+ return nodeOrToken . range
773
+ }
754
774
}
Original file line number Diff line number Diff line change @@ -285,4 +285,19 @@ describe("services.getTemplateBodyTokenStore", () => {
285
285
assert . deepStrictEqual ( actual , [ "div" , ">" ] )
286
286
} )
287
287
} )
288
+
289
+ describe ( "TokenStore#get{Range,Loc}()" , ( ) => {
290
+ it ( "should return loc and range." , ( ) => {
291
+ const {
292
+ templateBody : {
293
+ children : [ node ] ,
294
+ tokens : [ token ] ,
295
+ } ,
296
+ } = ast
297
+ assert . equal ( typeof tokens . getRange ( node ) [ 0 ] , "number" )
298
+ assert . equal ( typeof tokens . getRange ( token ) [ 1 ] , "number" )
299
+ assert . equal ( typeof tokens . getLoc ( node ) . start . line , "number" )
300
+ assert . equal ( typeof tokens . getLoc ( node ) . end . column , "number" )
301
+ } )
302
+ } )
288
303
} )
You can’t perform that action at this time.
0 commit comments