Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 10 Examples of "eslint-visitor-keys in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'eslint-visitor-keys' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

/**
 * @author Toru Nagashima 
 * @copyright 2017 Toru Nagashima. All rights reserved.
 * See LICENSE file in root directory for full license.
 */
import Evk, { VisitorKeys } from "eslint-visitor-keys"
import { Node } from "./nodes"

//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------

const KEYS = Evk.unionWith({
    VAttribute: ["key", "value"],
    VDirectiveKey: ["name", "argument", "modifiers"],
    VDocumentFragment: ["children"],
    VElement: ["startTag", "children", "endTag"],
    VEndTag: [],
    VExpressionContainer: ["expression"],
    VFilter: ["callee", "arguments"],
    VFilterSequenceExpression: ["expression", "filters"],
    VForExpression: ["left", "right"],
    VIdentifier: [],
    VLiteral: [],
    VOnExpression: ["body"],
    VSlotScopeExpression: ["params"],
    VStartTag: ["attributes"],
    VText: [],
})
import * as eslintVisitorKeys from 'eslint-visitor-keys';

export const visitorKeys = eslintVisitorKeys.unionWith({
  // Additional estree nodes.
  Import: [],
  // Additional Properties.
  ArrayPattern: ['decorators', 'elements', 'typeAnnotation'],
  ArrowFunctionExpression: ['typeParameters', 'params', 'returnType', 'body'],
  ClassDeclaration: [
    'decorators',
    'id',
    'typeParameters',
    'superClass',
    'superTypeParameters',
    'implements',
    'body',
  ],
  ClassExpression: [
    'decorators',
/**
 * @fileoverview The visitor keys for the new and updated node types
 * @author Michał Sajnóg 
 * MIT License
 */

"use strict";

const Evk = require("eslint-visitor-keys");

module.exports = Evk.unionWith({
    // Additional Properties.
    ArrayPattern: ["elements", "typeAnnotation"],
    ArrowFunctionExpression: ["typeParameters", "params", "returnType", "body"],
    ClassDeclaration: ["decorators", "id", "typeParameters", "superClass", "superTypeParameters", "implements", "body"],
    ClassExpression: ["decorators", "id", "typeParameters", "superClass", "superTypeParameters", "implements", "body"],
    FunctionDeclaration: ["id", "typeParameters", "params", "returnType", "body"],
    FunctionExpression: ["id", "typeParameters", "params", "returnType", "body"],
    Identifier: ["decorators", "typeAnnotation"],
    MethodDefinition: ["decorators", "key", "value"],
    ObjectPattern: ["properties", "typeAnnotation"],
    RestElement: ["argument", "typeAnnotation"],
    NewExpression: ["callee", "typeParameters", "arguments"],
    CallExpression: ["callee", "typeParameters", "arguments"],

    // Additional Nodes.
    BigIntLiteral: [],
$visitChildren(node, options, visitorKeys) {
            const { type } = node

            for (const key of visitorKeys[type] || evk.getKeys(node)) {
                const value = node[key]

                if (Array.isArray(value)) {
                    for (const element of value) {
                        if (
                            element &&
                            this.$visit(element, options, visitorKeys)
                        ) {
                            return true
                        }
                    }
                } else if (value && this.$visit(value, options, visitorKeys)) {
                    return true
                }
            }
function analyzeScope(ast, parserOptions, visitorKeys) {
    const ecmaFeatures = parserOptions.ecmaFeatures || {};
    const ecmaVersion = parserOptions.ecmaVersion || 5;

    return eslintScope.analyze(ast, {
        ignoreEval: true,
        nodejsScope: ecmaFeatures.globalReturn,
        impliedStrict: ecmaFeatures.impliedStrict,
        ecmaVersion,
        sourceType: parserOptions.sourceType || "script",
        childVisitorKeys: visitorKeys || evk.KEYS,
        fallback: Traverser.getKeys
    });
}
const possibleImportExportTypes = [
      'ExportAllDeclaration',
      'ExportDefaultDeclaration',
      'ExportNamedDeclaration',
      'ExportSpecifier',
      'ImportDeclaration',
      'ImportDefaultSpecifier',
      'ImportNamespaceSpecifier',
      'ImportSpecifier',
    ];

    if (possibleImportExportTypes.includes(node.type)) {
      return 'module';
    }

    const keys = vk.KEYS[node.type];

    if (keys.length >= 1) {
      for (let i = 0; i < keys.length; ++i) {
        const child = node[keys[i]];

        if (Array.isArray(child)) {
          for (let j = 0; j < child.length; ++j) {
            if (this._getSourceType(child[j]) === 'module') {
              return 'module';
            }
          }
        } else {
          return this._getSourceType(child);
        }
      }
    }
traverse(node, options) {
        this._current = null;
        this._parents = [];
        this._skipped = false;
        this._broken = false;
        this._visitorKeys = options.visitorKeys || vk.KEYS;
        this._enter = options.enter || noop;
        this._leave = options.leave || noop;
        this._traverse(node, null);
    }
filePath
    });

    /*
     * Check for parsing errors first. If there's a parsing error, nothing
     * else can happen. However, a parsing error does not throw an error
     * from this method - it's just considered a fatal error message, a
     * problem that ESLint identified just like any other.
     */
    try {
        const parseResult = (typeof parser.parseForESLint === "function")
            ? parser.parseForESLint(textToParse, parserOptions)
            : { ast: parser.parse(textToParse, parserOptions) };
        const ast = parseResult.ast;
        const parserServices = parseResult.services || {};
        const visitorKeys = parseResult.visitorKeys || evk.KEYS;
        const scopeManager = parseResult.scopeManager || analyzeScope(ast, parserOptions, visitorKeys);

        return {
            success: true,

            /*
             * Save all values that `parseForESLint()` returned.
             * If a `SourceCode` object is given as the first parameter instead of source code text,
             * linter skips the parsing process and reuses the source code object.
             * In that case, linter needs all the values that `parseForESLint()` returned.
             */
            sourceCode: new SourceCode({
                text,
                ast,
                parserServices,
                scopeManager,
function analyzeScope(ast, parserOptions, visitorKeys) {
    const ecmaFeatures = parserOptions.ecmaFeatures || {};
    const ecmaVersion = parserOptions.ecmaVersion || 5;

    return eslintScope.analyze(ast, {
        ignoreEval: true,
        nodejsScope: ecmaFeatures.globalReturn,
        impliedStrict: ecmaFeatures.impliedStrict,
        ecmaVersion,
        sourceType: parserOptions.sourceType || "script",
        childVisitorKeys: visitorKeys || evk.KEYS,
        fallback: Traverser.getKeys
    });
}

Is your System Free of Underlying Vulnerabilities?
Find Out Now