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

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 {}