GithubHelp home page GithubHelp logo

isabella232 / eslint-visitor-keys Goto Github PK

View Code? Open in Web Editor NEW

This project forked from eslint/eslint-visitor-keys

0.0 0.0 0.0 33 KB

Constants and utilities about visitor keys to traverse AST.

License: Apache License 2.0

JavaScript 100.00%

eslint-visitor-keys's Introduction

eslint-visitor-keys

npm version Downloads/month Build Status Dependency Status

Constants and utilities about visitor keys to traverse AST.

๐Ÿ’ฟ Installation

Use npm to install.

$ npm install eslint-visitor-keys

Requirements

๐Ÿ“– Usage

const evk = require("eslint-visitor-keys")

evk.KEYS

type: { [type: string]: string[] | undefined }

Visitor keys. This keys are frozen.

This is an object. Keys are the type of ESTree nodes. Their values are an array of property names which have child nodes.

For example:

console.log(evk.KEYS.AssignmentExpression) // โ†’ ["left", "right"]

evk.getKeys(node)

type: (node: object) => string[]

Get the visitor keys of a given AST node.

This is similar to Object.keys(node) of ES Standard, but some keys are excluded: parent, leadingComments, trailingComments, and names which start with _.

This will be used to traverse unknown nodes.

For example:

const node = {
    type: "AssignmentExpression",
    left: { type: "Identifier", name: "foo" },
    right: { type: "Literal", value: 0 }
}
console.log(evk.getKeys(node)) // โ†’ ["type", "left", "right"]

evk.unionWith(additionalKeys)

type: (additionalKeys: object) => { [type: string]: string[] | undefined }

Make the union set with evk.KEYS and the given keys.

  • The order of keys is, additionalKeys is at first, then evk.KEYS is concatenated after that.
  • It removes duplicated keys as keeping the first one.

For example:

console.log(evk.unionWith({
    MethodDefinition: ["decorators"]
})) // โ†’ { ..., MethodDefinition: ["decorators", "key", "value"], ... }

๐Ÿ“ฐ Change log

See GitHub releases.

๐Ÿป Contributing

Welcome. See ESLint contribution guidelines.

Development commands

  • npm test runs tests and measures code coverage.
  • npm run lint checks source codes with ESLint.
  • npm run coverage opens the code coverage report of the previous test with your default browser.
  • npm run release publishes this package to npm registory.

eslint-visitor-keys's People

Contributors

mysticatea avatar kaicataldo avatar michaeldeboey avatar anikethsaha avatar ilyavolodin avatar not-an-aardvark avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.