This commit is contained in:
2026-01-19 19:13:27 +01:00
commit 9d0442e88f
4968 changed files with 1142016 additions and 0 deletions

2
node_modules/estree-util-scope/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,2 @@
export type {Scope, Visitors} from './lib/types.js'
export {createVisitors} from './lib/index.js'

2
node_modules/estree-util-scope/index.js generated vendored Normal file
View File

@@ -0,0 +1,2 @@
// Note: types exposed from `index.d.ts`.
export {createVisitors} from './lib/index.js'

9
node_modules/estree-util-scope/lib/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,9 @@
/**
* Create state to track whats defined.
*
* @returns {Visitors}
* State.
*/
export function createVisitors(): Visitors;
import type { Visitors } from './types.js';
//# sourceMappingURL=index.d.ts.map

1
node_modules/estree-util-scope/lib/index.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":"AAOA;;;;;GAKG;AACH,kCAHa,QAAQ,CAyLpB;8BAjMiC,YAAY"}

196
node_modules/estree-util-scope/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,196 @@
/**
* @import {Node, Pattern} from 'estree'
* @import {Scope, Visitors} from './types.js'
*/
import {ok as assert} from 'devlop'
/**
* Create state to track whats defined.
*
* @returns {Visitors}
* State.
*/
export function createVisitors() {
/** @type {[topLevel: Scope, ...rest: Array<Scope>]} */
const scopes = [{block: false, defined: []}]
return {enter, exit, scopes}
/**
* @param {Node} node
* Node.
* @returns {undefined}
* Nothing.
*/
function enter(node) {
// On arrow functions, create scope, add parameters.
if (node.type === 'ArrowFunctionExpression') {
scopes.push({block: false, defined: []})
for (const parameter of node.params) {
definePattern(parameter, false)
}
}
// On block statements, create scope.
// Not sure why `periscopic` only does `Block`/`For`/`ForIn`/`ForOf`.
// I added `DoWhile`/`While` here just to be sure.
else if (
node.type === 'BlockStatement' ||
node.type === 'DoWhileStatement' ||
node.type === 'ForInStatement' ||
node.type === 'ForOfStatement' ||
node.type === 'ForStatement' ||
node.type === 'WhileStatement'
) {
scopes.push({block: true, defined: []})
}
// On catch clauses, create scope, add param.
else if (node.type === 'CatchClause') {
scopes.push({block: true, defined: []})
if (node.param) definePattern(node.param, true)
}
// Add identifier of class declaration.
else if (node.type === 'ClassDeclaration') {
defineIdentifier(node.id.name, false)
}
// On function declarations, add name, create scope, add parameters.
else if (node.type === 'FunctionDeclaration') {
defineIdentifier(node.id.name, false)
scopes.push({block: false, defined: []})
for (const parameter of node.params) {
definePattern(parameter, false)
}
}
// On function expressions, add name, create scope, add parameters.
else if (node.type === 'FunctionExpression') {
if (node.id) defineIdentifier(node.id.name, false)
scopes.push({block: false, defined: []})
for (const parameter of node.params) {
definePattern(parameter, false)
}
}
// Add specifiers of import declarations.
else if (node.type === 'ImportDeclaration') {
for (const specifier of node.specifiers) {
defineIdentifier(specifier.local.name, false)
}
}
// Add patterns of variable declarations.
else if (node.type === 'VariableDeclaration') {
for (const declaration of node.declarations) {
definePattern(declaration.id, node.kind !== 'var')
}
}
}
/**
* @param {Node} node
* Node.
* @returns {undefined}
* Nothing.
*/
function exit(node) {
if (
node.type === 'ArrowFunctionExpression' ||
node.type === 'FunctionDeclaration' ||
node.type === 'FunctionExpression'
) {
const scope = scopes.pop()
assert(scope, 'expected scope')
assert(!scope.block, 'expected non-block')
} else if (
node.type === 'BlockStatement' ||
node.type === 'CatchClause' ||
node.type === 'DoWhileStatement' ||
node.type === 'ForInStatement' ||
node.type === 'ForOfStatement' ||
node.type === 'ForStatement' ||
node.type === 'WhileStatement'
) {
const scope = scopes.pop()
assert(scope, 'expected scope')
assert(scope.block, 'expected block')
}
}
/**
* Define an identifier in a scope.
*
* @param {string} id
* @param {boolean} block
* @returns {undefined}
*/
function defineIdentifier(id, block) {
let index = scopes.length
/** @type {Scope | undefined} */
let scope
while (index--) {
scope = scopes[index]
if (block || !scope.block) {
break
}
}
assert(scope)
scope.defined.push(id)
}
/**
* Define a pattern in a scope.
*
* @param {Pattern} pattern
* @param {boolean} block
*/
function definePattern(pattern, block) {
// `[, x]`
if (pattern.type === 'ArrayPattern') {
for (const element of pattern.elements) {
if (element) {
definePattern(element, block)
}
}
}
// `{x=y}`
else if (pattern.type === 'AssignmentPattern') {
definePattern(pattern.left, block)
}
// `x`
else if (pattern.type === 'Identifier') {
defineIdentifier(pattern.name, block)
}
// `{x}`
else if (pattern.type === 'ObjectPattern') {
for (const property of pattern.properties) {
// `{key}`, `{key = value}`, `{key: value}`
if (property.type === 'Property') {
definePattern(property.value, block)
}
// `{...x}`
else {
assert(property.type === 'RestElement')
definePattern(property, block)
}
}
}
// `...x`
else {
assert(pattern.type === 'RestElement')
definePattern(pattern.argument, block)
}
}
}

48
node_modules/estree-util-scope/lib/types.d.ts generated vendored Normal file
View File

@@ -0,0 +1,48 @@
import type {Node} from 'estree'
/**
* Scope.
*/
export interface Scope {
/**
* Whether this is a block scope or not;
* blocks are things made by `for` and `try` and `if`;
* non-blocks are functions and the top-level scope.
*/
block: boolean
/**
* Identifiers that are defined in this scope.
*/
defined: Array<string>
}
/**
* State to track whats defined;
* contains `enter`, `exit` callbacks you must call and `scopes`.
*/
export interface Visitors {
/**
* List of scopes;
* the first scope is the top-level scope;
* the last scope is the current scope.
*/
scopes: [topLevel: Scope, ...rest: Array<Scope>]
/**
* Callback you must call when entering a node.
*
* @param node
* Node.
* @returns
* Nothing.
*/
enter(node: Node): undefined
/**
* Callback you must call when exiting (leaving) a node.
*
* @param node
* Node.
* @returns
* Nothing.
*/
exit(node: Node): undefined
}

2
node_modules/estree-util-scope/lib/types.js generated vendored Normal file
View File

@@ -0,0 +1,2 @@
// Note: types only.
export {}

22
node_modules/estree-util-scope/license generated vendored Normal file
View File

@@ -0,0 +1,22 @@
(The MIT License)
Copyright (c) 2020 Titus Wormer <tituswormer@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

109
node_modules/estree-util-scope/package.json generated vendored Normal file
View File

@@ -0,0 +1,109 @@
{
"name": "estree-util-scope",
"version": "1.0.0",
"description": "Check whats defined in an estree scope",
"license": "MIT",
"keywords": [
"ast",
"ecmascript",
"estree",
"javascript",
"scope",
"tree"
],
"repository": "syntax-tree/estree-util-scope",
"bugs": "https://github.com/syntax-tree/estree-util-scope/issues",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/unified"
},
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
"contributors": [
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
],
"sideEffects": false,
"type": "module",
"exports": "./index.js",
"files": [
"lib/",
"index.d.ts",
"index.js"
],
"dependencies": {
"@types/estree": "^1.0.0",
"devlop": "^1.0.0"
},
"devDependencies": {
"@types/node": "^22.0.0",
"acorn": "^8.0.0",
"c8": "^10.0.0",
"estree-walker": "^3.0.0",
"prettier": "^3.0.0",
"remark-api": "^1.1.0",
"remark-cli": "^12.0.0",
"remark-preset-wooorm": "^10.0.0",
"type-coverage": "^2.0.0",
"typescript": "^5.0.0",
"xo": "^0.59.0"
},
"scripts": {
"prepack": "npm run build && npm run format",
"build": "tsc --build --clean && tsc --build && type-coverage",
"format": "remark . -qfo && prettier . -w --log-level warn && xo --fix",
"test-api": "node --conditions development test.js",
"test-coverage": "c8 --100 --reporter lcov npm run test-api",
"test": "npm run build && npm run format && npm run test-coverage"
},
"prettier": {
"bracketSpacing": false,
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
"useTabs": false
},
"remarkConfig": {
"plugins": [
"remark-api",
"remark-preset-wooorm"
]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"ignoreCatch": true,
"strict": true
},
"xo": {
"overrides": [
{
"files": [
"**/*.d.ts"
],
"rules": {
"@typescript-eslint/array-type": [
"error",
{
"default": "generic"
}
],
"@typescript-eslint/ban-types": [
"error",
{
"extendDefaults": true
}
],
"@typescript-eslint/consistent-type-definitions": [
"error",
"interface"
]
}
}
],
"prettier": true,
"rules": {
"complexity": "off",
"unicorn/prefer-switch": "off"
}
}
}

268
node_modules/estree-util-scope/readme.md generated vendored Normal file
View File

@@ -0,0 +1,268 @@
# estree-util-scope
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]
[![Sponsors][sponsors-badge]][collective]
[![Backers][backers-badge]][collective]
[![Chat][chat-badge]][chat]
[estree][] utility to check whats defined in a scope.
## Contents
* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`Scope`](#scope)
* [`Visitors`](#visitors)
* [`createVisitors()`](#createvisitors)
* [Examples](#examples)
* [Example: just the top scope](#example-just-the-top-scope)
* [Compatibility](#compatibility)
* [Related](#related)
* [Security](#security)
* [Contribute](#contribute)
* [License](#license)
## What is this?
This package is a utility that tracks whats defined in a scope.
## When should I use this?
If you are walking an estree already and want to find out whats defined,
use this.
If you have more complex scoping needs,
see [`eslint-scope`][github-eslint-scope].
## Install
This package is [ESM only][esm].
In Node.js (version 16+), install with [npm][]:
```sh
npm install estree-util-scope
```
In Deno with [`esm.sh`][esmsh]:
```js
import {createVisitors} from 'https://esm.sh/estree-util-scope@1'
```
In browsers with [`esm.sh`][esmsh]:
```html
<script type="module">
import {createVisitors} from 'https://esm.sh/estree-util-scope@1?bundle'
</script>
```
## Use
Say we have the following `example.js`:
```js
/**
* @import {Program} from 'estree'
*/
import {Parser} from 'acorn'
import {createVisitors} from 'estree-util-scope'
import {walk} from 'estree-walker'
const tree = /** @type {Program} */ (
Parser.parse('import {a} from "b"; const c = 1', {
ecmaVersion: 'latest',
sourceType: 'module'
})
)
const visitors = createVisitors()
walk(tree, {enter: visitors.enter, leave: visitors.exit})
console.log(visitors.scopes.at(-1))
```
…now running `node example.js` yields:
```js
{ block: false, defined: [ 'a', 'c' ] }
```
## API
### `Scope`
Scope.
###### Fields
* `block` (`boolean`)
— whether this is a block scope or not;
blocks are things made by `for` and `try` and `if`;
non-blocks are functions and the top-level scope
* `defined` (`Array<string>`)
— identifiers that are defined in this scope
### `Visitors`
State to track whats defined;
contains `enter`, `exit` callbacks you must call and `scopes`.
###### Fields
* `enter` (`(node: Node) => undefined`)
— callback you must call when entering a node
* `exit` (`(node: Node) => undefined`)
— callback you must call when exiting (leaving) a node
* `scopes` (`[topLevel: Scope, ...rest: Scope[]]`)
— list of scopes;
the first scope is the top-level scope;
the last scope is the current scope
### `createVisitors()`
Create state to track whats defined.
###### Parameters
There are no parameters.
###### Returns
State (`Visitors`).
## Examples
### Example: just the top scope
Sometimes, you only care about a top-scope.
Or otherwise want to skip a node.
How to do this depends on how you walk the tree.
With `estree-walker`,
you can skip by calling `this.skip`.
```js
/**
* @import {Program} from 'estree'
*/
import {Parser} from 'acorn'
import {createVisitors} from 'estree-util-scope'
import {walk} from 'estree-walker'
const tree = /** @type {Program} */ (
Parser.parse(
'function a(b) { var c = 1; if (d) { var e = 2 } }; if (f) { var g = 2 }',
{ecmaVersion: 'latest'}
)
)
const visitors = createVisitors()
walk(tree, {
enter(node) {
visitors.enter(node)
if (
node.type === 'ArrowFunctionExpression' ||
node.type === 'FunctionDeclaration' ||
node.type === 'FunctionExpression'
) {
this.skip()
visitors.exit(node) // Call the exit handler manually.
}
},
leave: visitors.exit
})
console.log(visitors.scopes.at(-1))
```
…yields:
```js
{ block: false, defined: [ 'a', 'g' ] }
```
## Compatibility
Projects maintained by the unified collective are compatible with maintained
versions of Node.js.
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-scope@1`,
compatible with Node.js 16.
## Related
## Security
This package is safe.
## Contribute
See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get
started.
See [`support.md`][support] for ways to get help.
This project has a [code of conduct][coc].
By interacting with this repository, organization, or community you agree to
abide by its terms.
## License
[MIT][license] © [Titus Wormer][author]
<!-- Definitions -->
[build-badge]: https://github.com/syntax-tree/estree-util-scope/workflows/main/badge.svg
[build]: https://github.com/syntax-tree/estree-util-scope/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/estree-util-scope.svg
[coverage]: https://codecov.io/github/syntax-tree/estree-util-scope
[downloads-badge]: https://img.shields.io/npm/dm/estree-util-scope.svg
[downloads]: https://www.npmjs.com/package/estree-util-scope
[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=estree-util-scope
[size]: https://bundlejs.com/?q=estree-util-scope
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[collective]: https://opencollective.com/unified
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/syntax-tree/unist/discussions
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[npm]: https://docs.npmjs.com/cli/install
[esmsh]: https://esm.sh
[license]: license
[author]: https://wooorm.com
[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md
[support]: https://github.com/syntax-tree/.github/blob/main/support.md
[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
[estree]: https://github.com/estree/estree
[github-eslint-scope]: https://github.com/eslint/eslint-scope