Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/external/token-store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -751,4 +751,24 @@ export default class TokenStore {
filter: isCommentToken,
})
}

/**
* Returns the location of the given node or token.
* @param nodeOrToken The node or token to get the location of.
* @returns The location of the node or token.
*/
// eslint-disable-next-line class-methods-use-this
public getLoc(nodeOrToken: HasLocation) {
return nodeOrToken.loc
}

/**
* Returns the range of the given node or token.
* @param nodeOrToken The node or token to get the range of.
* @returns The range of the node or token.
*/
// eslint-disable-next-line class-methods-use-this
public getRange(nodeOrToken: HasLocation) {
return nodeOrToken.range
}
}
15 changes: 15 additions & 0 deletions test/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,19 @@ describe("services.getTemplateBodyTokenStore", () => {
assert.deepStrictEqual(actual, ["div", ">"])
})
})

describe("TokenStore#get{Range,Loc}()", () => {
it("should return loc and range.", () => {
const {
templateBody: {
children: [node],
tokens: [token],
},
} = ast
assert.equal(typeof tokens.getRange(node)[0], "number")
assert.equal(typeof tokens.getRange(token)[1], "number")
assert.equal(typeof tokens.getLoc(node).start.line, "number")
assert.equal(typeof tokens.getLoc(node).end.column, "number")
})
})
})
Loading