Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

estree-util-visit

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

estree-util-visit - npm Package Compare versions

Comparing version 1.2.1 to 2.0.0

lib/color.default.d.ts

12

index.d.ts

@@ -1,6 +0,6 @@

export type Action = import('./lib/index.js').Action
export type ActionTuple = import('./lib/index.js').ActionTuple
export type Index = import('./lib/index.js').Index
export type Visitor = import('./lib/index.js').Visitor
export type Visitors = import('./lib/index.js').Visitors
export {CONTINUE, EXIT, SKIP, visit} from './lib/index.js'
export type Action = import('./lib/index.js').Action;
export type ActionTuple = import('./lib/index.js').ActionTuple;
export type Index = import('./lib/index.js').Index;
export type Visitor = import('./lib/index.js').Visitor;
export type Visitors = import('./lib/index.js').Visitors;
export { CONTINUE, EXIT, SKIP, visit } from "./lib/index.js";

@@ -15,28 +15,29 @@ /**

* @param {Visitor | Visitors | null | undefined} [visitor]
* Handle each node.
* @returns {void}
* Handle each node (optional).
* @returns {undefined}
* Nothing.
*/
export function visit(
tree: Node,
visitor?: Visitor | Visitors | null | undefined
): void
export function visit(tree: Node, visitor?: Visitor | Visitors | null | undefined): undefined;
/**
* Continue traversing as normal.
*/
export const CONTINUE: unique symbol
export const CONTINUE: unique symbol;
/**
* Stop traversing immediately.
*/
export const EXIT: unique symbol
export const EXIT: unique symbol;
/**
* Do not traverse this node’s children.
*/
export const SKIP: unique symbol
export type Node = import('estree-jsx').Node
export const SKIP: unique symbol;
export type Node = import('estree-jsx').Node;
/**
* Union of the action types.
*/
export type Action = typeof CONTINUE | typeof SKIP | typeof EXIT
export type Action = typeof CONTINUE | typeof EXIT | typeof SKIP;
/**
* List with one or two values, the first an action, the second an index.
*/
export type ActionTuple = [(Action | null | undefined | void)?, (Index | null | undefined)?];
/**
* Move to the sibling at `index` next (after node itself is completely

@@ -50,11 +51,4 @@ * traversed), when moving in an array.

*/
export type Index = number
export type Index = number;
/**
* List with one or two values, the first an action, the second an index.
*/
export type ActionTuple = [
(Action | null | undefined | void)?,
(Index | null | undefined)?
]
/**
* Handle a node.

@@ -74,8 +68,3 @@ *

*/
export type Visitor = (
node: Node,
key: string | null,
index: number | null,
ancestors: Array<Node>
) => Action | Index | ActionTuple | null | undefined | void
export type Visitor = (node: Node, key: string | undefined, index: number | undefined, ancestors: Array<Node>) => Action | ActionTuple | Index | null | undefined | void;
/**

@@ -85,10 +74,10 @@ * Handle nodes when entering (preorder) and leaving (postorder).

export type Visitors = {
/**
* Handle nodes when entering (preorder).
*/
enter?: Visitor | null | undefined
/**
* Handle nodes when leaving (postorder).
*/
leave?: Visitor | null | undefined
}
/**
* Handle nodes when entering (preorder) (optional).
*/
enter?: Visitor | null | undefined;
/**
* Handle nodes when leaving (postorder) (optional).
*/
leave?: Visitor | null | undefined;
};

@@ -6,5 +6,8 @@ /**

/**
* @typedef {CONTINUE | SKIP | EXIT} Action
* @typedef {CONTINUE | EXIT | SKIP} Action
* Union of the action types.
*
* @typedef {[(Action | null | undefined | void)?, (Index | null | undefined)?]} ActionTuple
* List with one or two values, the first an action, the second an index.
*
* @typedef {number} Index

@@ -18,5 +21,2 @@ * Move to the sibling at `index` next (after node itself is completely

* traversing the parent.
*
* @typedef {[(Action | null | undefined | void)?, (Index | null | undefined)?]} ActionTuple
* List with one or two values, the first an action, the second an index.
*/

@@ -41,9 +41,9 @@

* Found node.
* @param {string | null} key
* @param {string | undefined} key
* Field at which `node` lives in its parent (or where a list of nodes lives).
* @param {number | null} index
* @param {number | undefined} index
* Index where `node` lives if `parent[key]` is an array.
* @param {Array<Node>} ancestors
* Ancestors of `node`.
* @returns {Action | Index | ActionTuple | null | undefined | void}
* @returns {Action | ActionTuple | Index | null | undefined | void}
* What to do next.

@@ -63,8 +63,8 @@ *

* @property {Visitor | null | undefined} [enter]
* Handle nodes when entering (preorder).
* Handle nodes when entering (preorder) (optional).
* @property {Visitor | null | undefined} [leave]
* Handle nodes when leaving (postorder).
* Handle nodes when leaving (postorder) (optional).
*/
import {color} from './color.js'
import {color} from 'estree-util-visit/do-not-use-color'

@@ -102,4 +102,4 @@ const own = {}.hasOwnProperty

* @param {Visitor | Visitors | null | undefined} [visitor]
* Handle each node.
* @returns {void}
* Handle each node (optional).
* @returns {undefined}
* Nothing.

@@ -120,8 +120,8 @@ */

build(tree, null, null, [])()
build(tree, undefined, undefined, [])()
/**
* @param {Node} node
* @param {string | null} key
* @param {number | null} index
* @param {string | undefined} key
* @param {number | undefined} index
* @param {Array<Node>} parents

@@ -187,3 +187,3 @@ */

} else if (nodelike(value)) {
const subresult = build(value, cKey, null, grandparents)()
const subresult = build(value, cKey, undefined, grandparents)()
if (subresult[0] === EXIT) return subresult

@@ -203,3 +203,3 @@ }

*
* @param {Action | Index | ActionTuple | null | undefined | void} value
* @param {Action | ActionTuple | Index | null | undefined | void} value
* Valid return values from visitors.

@@ -206,0 +206,0 @@ * @returns {ActionTuple}

{
"name": "estree-util-visit",
"version": "1.2.1",
"version": "2.0.0",
"description": "esast (and estree) utility to visit nodes",

@@ -34,10 +34,9 @@ "license": "MIT",

"type": "module",
"main": "index.js",
"types": "index.d.ts",
"browser": {
"./lib/color.js": "./lib/color.browser.js"
"exports": {
".": "./index.js",
"./do-not-use-color": {
"node": "./lib/color.node.js",
"default": "./lib/color.default.js"
}
},
"react-native": {
"./lib/color.js": "./lib/color.browser.js"
},
"files": [

@@ -50,14 +49,14 @@ "lib/",

"@types/estree-jsx": "^1.0.0",
"@types/unist": "^2.0.0"
"@types/unist": "^3.0.0"
},
"devDependencies": {
"@types/node": "^18.0.0",
"@types/node": "^20.0.0",
"acorn": "^8.0.0",
"c8": "^7.0.0",
"prettier": "^2.0.0",
"c8": "^8.0.0",
"prettier": "^3.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"xo": "^0.53.0"
"typescript": "^5.0.0",
"xo": "^0.55.0"
},

@@ -67,21 +66,15 @@ "scripts": {

"build": "tsc --build --clean && tsc --build && type-coverage",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"format": "remark . -qfo && prettier . -w --log-level warn && xo --fix",
"test-api": "node --conditions development test.js",
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
"test-coverage": "c8 --100 --reporter lcov npm run test-api",
"test": "npm run build && npm run format && npm run test-coverage"
},
"prettier": {
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"bracketSpacing": false,
"semi": false,
"trailingComma": "none"
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
"useTabs": false
},
"xo": {
"prettier": true,
"rules": {
"max-depth": "off"
}
},
"remarkConfig": {

@@ -95,4 +88,13 @@ "plugins": [

"detail": true,
"ignoreCatch": true,
"strict": true
},
"xo": {
"prettier": true,
"rules": {
"max-depth": "off",
"n/file-extension-in-import": "off",
"unicorn/prefer-at": "off"
}
}
}

@@ -47,3 +47,3 @@ # estree-util-visit

This package is [ESM only][esm].
In Node.js (version 14.14+ and 16.0+), install with [npm][]:
In Node.js (version 16+), install with [npm][]:

@@ -57,3 +57,3 @@ ```sh

```js
import {visit} from 'https://esm.sh/estree-util-visit@1'
import {visit} from 'https://esm.sh/estree-util-visit@2'
```

@@ -65,3 +65,3 @@

<script type="module">
import {visit} from 'https://esm.sh/estree-util-visit@1?bundle'
import {visit} from 'https://esm.sh/estree-util-visit@2?bundle'
</script>

@@ -81,3 +81,3 @@ ```

visit(tree, (node) => {
visit(tree, function (node) {
if (node.type === 'Literal' && 'value' in node) console.log(node.value)

@@ -103,4 +103,6 @@ })

This package exports the identifiers [`CONTINUE`][continue], [`EXIT`][exit],
[`SKIP`][skip], and [`visit`][visit].
This package exports the identifiers [`CONTINUE`][api-continue],
[`EXIT`][api-exit],
[`SKIP`][api-skip], and
[`visit`][api-visit].
There is no default export.

@@ -129,5 +131,5 @@

— tree to traverse
* `visitor` ([`Visitor`][visitor])
* `visitor` ([`Visitor`][api-visitor])
— same as passing `{enter: visitor}`
* `visitors` ([`Visitors`][visitors])
* `visitors` ([`Visitors`][api-visitors])
— handle each node

@@ -137,3 +139,3 @@

Nothing (`void`).
Nothing (`undefined`).

@@ -159,3 +161,3 @@ ### `CONTINUE`

```ts
type Action = typeof CONTINUE | typeof SKIP | typeof EXIT
type Action = typeof CONTINUE | typeof EXIT | typeof SKIP
```

@@ -213,6 +215,6 @@

— found node
* `key` (`string` or `null`)
* `key` (`string` or `undefined`)
— field at which `node` lives in its parent (or where a list of nodes
lives)
* `index` (`number` or `null`)
* `index` (`number` or `undefined`)
— index where `node` lives if `parent[key]` is an array

@@ -224,4 +226,4 @@ * `ancestors` ([`Array<Node>`][node])

What to do next ([`Action`][action], [`Index`][index], or
[`ActionTuple`][actiontuple], optional).
What to do next ([`Action`][api-action], [`Index`][api-index], or
[`ActionTuple`][api-action-tuple], optional).

@@ -242,5 +244,5 @@ An `Index` is treated as a tuple of `[CONTINUE, Index]`.

* `enter` ([`Visitor`][visitor], optional)
* `enter` ([`Visitor`][api-visitor], optional)
— handle nodes when entering (preorder)
* `leave` ([`Visitor`][visitor], optional)
* `leave` ([`Visitor`][api-visitor], optional)
— handle nodes when leaving (postorder)

@@ -251,13 +253,18 @@

This package is fully typed with [TypeScript][].
It exports the additional types [`Action`][action],
[`ActionTuple`][actiontuple], [`Index`][index],
[`Visitor`][visitor], and [`Visitors`][visitors].
It exports the additional types [`Action`][api-action],
[`ActionTuple`][api-action-tuple],
[`Index`][api-index],
[`Visitor`][api-visitor], and
[`Visitors`][api-visitors].
## Compatibility
Projects maintained by the unified collective are compatible with all maintained
Projects maintained by the unified collective are compatible with maintained
versions of Node.js.
As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+.
Our projects sometimes work with older versions, but this is not guaranteed.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line, `estree-util-visit@^2`,
compatible with Node.js 16.
## Related

@@ -296,5 +303,5 @@

[size-badge]: https://img.shields.io/bundlephobia/minzip/estree-util-visit.svg
[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=estree-util-visit
[size]: https://bundlephobia.com/result?p=estree-util-visit
[size]: https://bundlejs.com/?q=estree-util-visit

@@ -349,18 +356,18 @@ [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg

[continue]: #continue
[api-continue]: #continue
[exit]: #exit
[api-action]: #action
[skip]: #skip
[api-action-tuple]: #actiontuple
[visit]: #visittree-visitorvisitors
[api-exit]: #exit
[visitor]: #visitor
[api-index]: #index
[visitors]: #visitors
[api-skip]: #skip
[action]: #action
[api-visit]: #visittree-visitorvisitors
[index]: #index
[api-visitor]: #visitor
[actiontuple]: #actiontuple
[api-visitors]: #visitors
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc