Sha256: c6d96de204c771bed36cf4ec6fb5178345853fb9df03dc813c48d1be1572bac6

Contents?: true

Size: 1.79 KB

Versions: 44

Compression:

Stored size: 1.79 KB

Contents

/**
 * @author Toru Nagashima <https://github.com/mysticatea>
 * See LICENSE file in root directory for full license.
 */
"use strict"

const {
    CALL,
    CONSTRUCT,
    PatternMatcher,
    ReferenceTracker,
    getStringIfConstant,
} = require("eslint-utils")

module.exports = {
    /**
     * Define generator to search pattern.
     * The iterator generated by the generator returns the start and end index of the match.
     * @param {RegExp} pattern Base pattern
     * @returns {function(string):IterableIterator<RegExpExecArray>} generator
     */
    definePatternSearchGenerator(pattern) {
        const matcher = new PatternMatcher(pattern)
        return matcher.execAll.bind(matcher)
    },

    /**
     * Check whether a given token is a comma token or not.
     * @param {Token} token The token to check.
     * @returns {boolean} `true` if the token is a comma token.
     */
    isCommaToken(token) {
        return (
            token != null && token.type === "Punctuator" && token.value === ","
        )
    },

    /**
     * Iterate the calls of the `RegExp` global variable.
     * @param {Scope} globalScope The global scope object.
     * @returns {IterableIterator<{node:Node,pattern:(string|null),flags:(string|null)}>} The iterator of `CallExpression` or `NewExpression` for `RegExp`.
     */
    *getRegExpCalls(globalScope) {
        const tracker = new ReferenceTracker(globalScope)
        for (const { node } of tracker.iterateGlobalReferences({
            RegExp: { [CALL]: true, [CONSTRUCT]: true },
        })) {
            const [patternNode, flagsNode] = node.arguments
            yield {
                node,
                pattern: getStringIfConstant(patternNode, globalScope),
                flags: getStringIfConstant(flagsNode, globalScope),
            }
        }
    },
}

Version data entries

44 entries across 44 versions & 2 rubygems

Version Path
decidim-0.26.8 packages/eslint-config/node_modules/eslint-plugin-es/lib/utils.js
govuk_publishing_components-18.0.0 node_modules/eslint-plugin-es/lib/utils.js
govuk_publishing_components-17.21.0 node_modules/eslint-plugin-es/lib/utils.js
govuk_publishing_components-17.20.0 node_modules/eslint-plugin-es/lib/utils.js
govuk_publishing_components-17.19.1 node_modules/eslint-plugin-es/lib/utils.js
govuk_publishing_components-17.19.0 node_modules/eslint-plugin-es/lib/utils.js
govuk_publishing_components-17.18.0 node_modules/eslint-plugin-es/lib/utils.js
govuk_publishing_components-17.17.0 node_modules/eslint-plugin-es/lib/utils.js
govuk_publishing_components-17.16.0 node_modules/eslint-plugin-es/lib/utils.js
govuk_publishing_components-17.15.0 node_modules/eslint-plugin-es/lib/utils.js
govuk_publishing_components-17.14.0 node_modules/eslint-plugin-es/lib/utils.js
govuk_publishing_components-17.13.0 node_modules/eslint-plugin-es/lib/utils.js
govuk_publishing_components-17.12.2 node_modules/eslint-plugin-es/lib/utils.js
govuk_publishing_components-17.12.1 node_modules/eslint-plugin-es/lib/utils.js
govuk_publishing_components-17.12.0 node_modules/eslint-plugin-es/lib/utils.js
govuk_publishing_components-17.11.0 node_modules/eslint-plugin-es/lib/utils.js
govuk_publishing_components-17.10.0 node_modules/eslint-plugin-es/lib/utils.js
govuk_publishing_components-17.9.0 node_modules/eslint-plugin-es/lib/utils.js
govuk_publishing_components-17.8.0 node_modules/eslint-plugin-es/lib/utils.js
govuk_publishing_components-17.7.0 node_modules/eslint-plugin-es/lib/utils.js