Sha256: 874d310d2df303fe26fee20f3c9f1b5659f892c69228c81555521fcbeb6b751c
Contents?: true
Size: 1.53 KB
Versions: 26
Compression:
Stored size: 1.53 KB
Contents
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isComma = exports.TokenStore = void 0; class TokenStore { constructor(tokens) { this.tokens = tokens; } add(token) { this.tokens.push(token); } findIndexByOffset(offset) { return this.tokens.findIndex((token) => token.range[0] <= offset && offset < token.range[1]); } findTokenByOffset(offset) { return this.tokens[this.findIndexByOffset(offset)]; } getFirstToken(nodeOrToken) { return this.findTokenByOffset(nodeOrToken.range[0]); } getLastToken(nodeOrToken) { return this.findTokenByOffset(nodeOrToken.range[1] - 1); } getTokenBefore(nodeOrToken, filter) { const tokenIndex = this.findIndexByOffset(nodeOrToken.range[0]); for (let index = tokenIndex - 1; index >= 0; index--) { const token = this.tokens[index]; if (!filter || filter(token)) { return token; } } return null; } getTokenAfter(nodeOrToken, filter) { const tokenIndex = this.findIndexByOffset(nodeOrToken.range[0]); for (let index = tokenIndex + 1; index < this.tokens.length; index++) { const token = this.tokens[index]; if (!filter || filter(token)) { return token; } } return null; } } exports.TokenStore = TokenStore; function isComma(token) { return token.type === "Punctuator" && token.value === ","; } exports.isComma = isComma;
Version data entries
26 entries across 26 versions & 1 rubygems