Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f0a3445

Browse filesBrowse files
committed
feat: add TokenStore#get{Loc,Range}()
1 parent 7b00625 commit f0a3445
Copy full SHA for f0a3445

File tree

2 files changed

+36
-0
lines changed
Filter options

2 files changed

+36
-0
lines changed

‎src/external/token-store/index.ts

Copy file name to clipboardExpand all lines: src/external/token-store/index.ts
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,4 +751,24 @@ export default class TokenStore {
751751
filter: isCommentToken,
752752
})
753753
}
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+
}
754774
}

‎test/tokens.js

Copy file name to clipboardExpand all lines: test/tokens.js
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//------------------------------------------------------------------------------
1111

1212
const assert = require("assert")
13+
const { describe } = require("mocha")
1314
const parse = require("../src").parseForESLint
1415

1516
//------------------------------------------------------------------------------
@@ -285,4 +286,19 @@ describe("services.getTemplateBodyTokenStore", () => {
285286
assert.deepStrictEqual(actual, ["div", ">"])
286287
})
287288
})
289+
290+
describe("TokenStore#get{Range,Loc}()", () => {
291+
it("should return loc and range.", () => {
292+
const {
293+
templateBody: {
294+
children: [node],
295+
tokens: [token],
296+
},
297+
} = ast
298+
assert.equal(typeof tokens.getRange(node)[0], "number")
299+
assert.equal(typeof tokens.getRange(token)[1], "number")
300+
assert.equal(typeof tokens.getLoc(node).start.line, "number")
301+
assert.equal(typeof tokens.getLoc(node).end.column, "number")
302+
})
303+
})
288304
})

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.