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

Version Path
immosquare-cleaner-0.1.32 node_modules/jsonc-eslint-parser/lib/parser/token-store.js
immosquare-cleaner-0.1.31 node_modules/jsonc-eslint-parser/lib/parser/token-store.js
immosquare-cleaner-0.1.30 node_modules/jsonc-eslint-parser/lib/parser/token-store.js
immosquare-cleaner-0.1.29 node_modules/jsonc-eslint-parser/lib/parser/token-store.js
immosquare-cleaner-0.1.28 node_modules/jsonc-eslint-parser/lib/parser/token-store.js
immosquare-cleaner-0.1.27 node_modules/jsonc-eslint-parser/lib/parser/token-store.js
immosquare-cleaner-0.1.26 node_modules/jsonc-eslint-parser/lib/parser/token-store.js
immosquare-cleaner-0.1.25 node_modules/jsonc-eslint-parser/lib/parser/token-store.js
immosquare-cleaner-0.1.24 node_modules/jsonc-eslint-parser/lib/parser/token-store.js
immosquare-cleaner-0.1.23 node_modules/jsonc-eslint-parser/lib/parser/token-store.js
immosquare-cleaner-0.1.22 node_modules/jsonc-eslint-parser/lib/parser/token-store.js
immosquare-cleaner-0.1.21 node_modules/jsonc-eslint-parser/lib/parser/token-store.js
immosquare-cleaner-0.1.20 node_modules/jsonc-eslint-parser/lib/parser/token-store.js
immosquare-cleaner-0.1.19 node_modules/jsonc-eslint-parser/lib/parser/token-store.js
immosquare-cleaner-0.1.18 node_modules/jsonc-eslint-parser/lib/parser/token-store.js
immosquare-cleaner-0.1.17 node_modules/jsonc-eslint-parser/lib/parser/token-store.js
immosquare-cleaner-0.1.16 node_modules/jsonc-eslint-parser/lib/parser/token-store.js
immosquare-cleaner-0.1.14 node_modules/jsonc-eslint-parser/lib/parser/token-store.js
immosquare-cleaner-0.1.13 node_modules/jsonc-eslint-parser/lib/parser/token-store.js
immosquare-cleaner-0.1.12 node_modules/jsonc-eslint-parser/lib/parser/token-store.js