feat: docker compose maybe
This commit is contained in:
7
node_modules/periscopic/LICENSE
generated
vendored
Normal file
7
node_modules/periscopic/LICENSE
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
Copyright (c) 2019 Rich Harris
|
||||
|
||||
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.
|
71
node_modules/periscopic/README.md
generated
vendored
Normal file
71
node_modules/periscopic/README.md
generated
vendored
Normal file
@ -0,0 +1,71 @@
|
||||
# periscopic
|
||||
|
||||
Utility for analyzing scopes belonging to an ESTree-compliant AST.
|
||||
|
||||
|
||||
## API
|
||||
|
||||
```js
|
||||
import { analyze } from 'periscopic';
|
||||
|
||||
const ast = acorn.parse(`
|
||||
const a = b;
|
||||
console.log(a);
|
||||
`);
|
||||
|
||||
const { map, globals, scope } = analyze(ast);
|
||||
```
|
||||
|
||||
* `map` is a `WeakMap<Node, Scope>`, where the keys are the nodes of your AST that create a scope
|
||||
* `globals` is a `Map<string, Node>` of all the identifiers that are referenced without being declared anywhere in the program (in this case, `b` and `console`)
|
||||
* `scope` is the top-level `Scope` belonging to the program
|
||||
|
||||
|
||||
### Scope
|
||||
|
||||
Each `Scope` instance has the following properties:
|
||||
|
||||
* `scope.block` — true if the scope is created by a block statement (i.e. `let`, `const` and `class` are contained to it), false otherwise
|
||||
* `scope.parent` — the parent scope object
|
||||
* `scope.declarations` — a `Map<string, Node>` of all the variables declared in this scope, the node value referes to the declaration statement
|
||||
* `scope.initialised_declarations` — a `Set<string>` of all the variables declared and initialised in this scope
|
||||
* `scope.references` — a `Set<string>` of all the names referenced in this scope (or child scopes)
|
||||
|
||||
It also has two methods:
|
||||
|
||||
* `scope.has(name)` — returns `true` if `name` is declared in this scope or an ancestor scope
|
||||
* `scope.find_owner(name)` — returns the scope object in which `name` is declared (or `null` if it is not declared)
|
||||
|
||||
|
||||
### `extract_identifiers` and `extract_names`
|
||||
|
||||
This package also exposes utilities for extracting the identifiers contained in a declaration or a function parameter:
|
||||
|
||||
```js
|
||||
import { extract_identifiers, extract_names } from 'periscopic';
|
||||
|
||||
const ast = acorn.parse(`
|
||||
const { a, b: [c, d] = e } = opts;
|
||||
`);
|
||||
|
||||
const lhs = ast.body[0].declarations[0].id;
|
||||
|
||||
extract_identifiers(lhs);
|
||||
/*
|
||||
[
|
||||
{ type: 'Identifier', name: 'a', start: 9, end: 10 },
|
||||
{ type: 'Identifier', name: 'c', start: 16, end: 17 },
|
||||
{ type: 'Identifier', name: 'd', start: 19, end: 20 }
|
||||
]
|
||||
*/
|
||||
|
||||
extract_names(lhs);
|
||||
/*
|
||||
['a', 'c', 'd']
|
||||
*/
|
||||
```
|
||||
|
||||
|
||||
## License
|
||||
|
||||
[MIT](LICENSE)
|
33
node_modules/periscopic/package.json
generated
vendored
Normal file
33
node_modules/periscopic/package.json
generated
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "periscopic",
|
||||
"description": "periscopic",
|
||||
"version": "3.1.0",
|
||||
"repository": "Rich-Harris/periscopic",
|
||||
"main": "src/index.js",
|
||||
"module": "src/index.js",
|
||||
"type": "module",
|
||||
"exports": {
|
||||
"types": "./types/index.js",
|
||||
"import": "./src/index.js"
|
||||
},
|
||||
"types": "types/index.d.ts",
|
||||
"files": [
|
||||
"src",
|
||||
"types"
|
||||
],
|
||||
"devDependencies": {
|
||||
"acorn": "^8.0.0",
|
||||
"typescript": "^4.9.0",
|
||||
"uvu": "^0.5.1"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "uvu test",
|
||||
"prepublishOnly": "npm test && tsc"
|
||||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/estree": "^1.0.0",
|
||||
"estree-walker": "^3.0.0",
|
||||
"is-reference": "^3.0.0"
|
||||
}
|
||||
}
|
247
node_modules/periscopic/src/index.js
generated
vendored
Normal file
247
node_modules/periscopic/src/index.js
generated
vendored
Normal file
@ -0,0 +1,247 @@
|
||||
import { walk } from 'estree-walker';
|
||||
import is_reference from 'is-reference';
|
||||
|
||||
/** @param {import('estree').Node} expression */
|
||||
export function analyze(expression) {
|
||||
/** @typedef {import('estree').Node} Node */
|
||||
|
||||
/** @type {WeakMap<Node, Scope>} */
|
||||
const map = new WeakMap();
|
||||
|
||||
/** @type {Map<string, Node>} */
|
||||
const globals = new Map();
|
||||
|
||||
const scope = new Scope(null, false);
|
||||
|
||||
/** @type {[Scope, import('estree').Identifier][]} */
|
||||
const references = [];
|
||||
/** @type {Scope} */
|
||||
let current_scope = scope;
|
||||
|
||||
walk(expression, {
|
||||
enter(node, parent) {
|
||||
switch (node.type) {
|
||||
case 'Identifier':
|
||||
if (parent && is_reference(node, parent)) {
|
||||
references.push([current_scope, node]);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'ImportDeclaration':
|
||||
node.specifiers.forEach((specifier) => {
|
||||
current_scope.declarations.set(specifier.local.name, specifier);
|
||||
});
|
||||
break;
|
||||
|
||||
case 'FunctionExpression':
|
||||
case 'FunctionDeclaration':
|
||||
case 'ArrowFunctionExpression':
|
||||
if (node.type === 'FunctionDeclaration') {
|
||||
if (node.id) {
|
||||
current_scope.declarations.set(node.id.name, node);
|
||||
}
|
||||
|
||||
map.set(node, current_scope = new Scope(current_scope, false));
|
||||
} else {
|
||||
map.set(node, current_scope = new Scope(current_scope, false));
|
||||
|
||||
if (node.type === 'FunctionExpression' && node.id) {
|
||||
current_scope.declarations.set(node.id.name, node);
|
||||
}
|
||||
}
|
||||
|
||||
node.params.forEach(param => {
|
||||
extract_names(param).forEach(name => {
|
||||
current_scope.declarations.set(name, node);
|
||||
});
|
||||
});
|
||||
break;
|
||||
|
||||
case 'ForStatement':
|
||||
case 'ForInStatement':
|
||||
case 'ForOfStatement':
|
||||
map.set(node, current_scope = new Scope(current_scope, true));
|
||||
break;
|
||||
|
||||
case 'BlockStatement':
|
||||
map.set(node, current_scope = new Scope(current_scope, true));
|
||||
break;
|
||||
|
||||
case 'ClassDeclaration':
|
||||
case 'VariableDeclaration':
|
||||
current_scope.add_declaration(node);
|
||||
break;
|
||||
|
||||
case 'CatchClause':
|
||||
map.set(node, current_scope = new Scope(current_scope, true));
|
||||
|
||||
if (node.param) {
|
||||
extract_names(node.param).forEach(name => {
|
||||
if (node.param) {
|
||||
current_scope.declarations.set(name, node.param);
|
||||
}
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
leave(node) {
|
||||
if (map.has(node) && current_scope !== null && current_scope.parent) {
|
||||
current_scope = current_scope.parent;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
for (let i = references.length - 1; i >= 0; --i) {
|
||||
const [scope, reference] = references[i];
|
||||
|
||||
if (!scope.references.has(reference.name)) {
|
||||
add_reference(scope, reference.name);
|
||||
}
|
||||
if (!scope.find_owner(reference.name)) {
|
||||
globals.set(reference.name, reference);
|
||||
}
|
||||
}
|
||||
|
||||
return { map, scope, globals };
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Scope} scope
|
||||
* @param {string} name
|
||||
*/
|
||||
function add_reference(scope, name) {
|
||||
scope.references.add(name);
|
||||
if (scope.parent) add_reference(scope.parent, name);
|
||||
}
|
||||
|
||||
export class Scope {
|
||||
/**
|
||||
* @param {Scope | null} parent
|
||||
* @param {boolean} block
|
||||
*/
|
||||
constructor(parent, block) {
|
||||
/** @type {Scope | null} */
|
||||
this.parent = parent;
|
||||
|
||||
/** @type {boolean} */
|
||||
this.block = block;
|
||||
|
||||
/** @type {Map<string, import('estree').Node>} */
|
||||
this.declarations = new Map();
|
||||
|
||||
/** @type {Set<string>} */
|
||||
this.initialised_declarations = new Set();
|
||||
|
||||
/** @type {Set<string>} */
|
||||
this.references = new Set();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import('estree').VariableDeclaration | import('estree').ClassDeclaration} node
|
||||
*/
|
||||
add_declaration(node) {
|
||||
if (node.type === 'VariableDeclaration') {
|
||||
if (node.kind === 'var' && this.block && this.parent) {
|
||||
this.parent.add_declaration(node);
|
||||
} else {
|
||||
/** @param {import('estree').VariableDeclarator} declarator */
|
||||
const handle_declarator = (declarator) => {
|
||||
extract_names(declarator.id).forEach(name => {
|
||||
this.declarations.set(name, node);
|
||||
if (declarator.init) this.initialised_declarations.add(name);
|
||||
});;
|
||||
}
|
||||
|
||||
node.declarations.forEach(handle_declarator);
|
||||
}
|
||||
} else if (node.id) {
|
||||
this.declarations.set(node.id.name, node);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} name
|
||||
* @returns {Scope | null}
|
||||
*/
|
||||
find_owner(name) {
|
||||
if (this.declarations.has(name)) return this;
|
||||
return this.parent && this.parent.find_owner(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} name
|
||||
* @returns {boolean}
|
||||
*/
|
||||
has(name) {
|
||||
return (
|
||||
this.declarations.has(name) || (!!this.parent && this.parent.has(name))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import('estree').Node} param
|
||||
* @returns {string[]}
|
||||
*/
|
||||
export function extract_names(param) {
|
||||
return extract_identifiers(param).map(node => node.name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import('estree').Node} param
|
||||
* @param {import('estree').Identifier[]} nodes
|
||||
* @returns {import('estree').Identifier[]}
|
||||
*/
|
||||
export function extract_identifiers(param, nodes = []) {
|
||||
switch (param.type) {
|
||||
case 'Identifier':
|
||||
nodes.push(param);
|
||||
break;
|
||||
|
||||
case 'MemberExpression':
|
||||
let object = param;
|
||||
while (object.type === 'MemberExpression') {
|
||||
object = /** @type {any} */ (object.object);
|
||||
}
|
||||
nodes.push(/** @type {any} */ (object));
|
||||
break;
|
||||
|
||||
case 'ObjectPattern':
|
||||
/** @param {import('estree').Property | import('estree').RestElement} prop */
|
||||
const handle_prop = (prop) => {
|
||||
if (prop.type === 'RestElement') {
|
||||
extract_identifiers(prop.argument, nodes);
|
||||
} else {
|
||||
extract_identifiers(prop.value, nodes);
|
||||
}
|
||||
};
|
||||
|
||||
param.properties.forEach(handle_prop);
|
||||
break;
|
||||
|
||||
case 'ArrayPattern':
|
||||
/** @param {import('estree').Node} element */
|
||||
const handle_element = (element) => {
|
||||
if (element) extract_identifiers(element, nodes);
|
||||
};
|
||||
|
||||
param.elements.forEach((element) => {
|
||||
if (element) {
|
||||
handle_element(element)
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
||||
case 'RestElement':
|
||||
extract_identifiers(param.argument, nodes);
|
||||
break;
|
||||
|
||||
case 'AssignmentPattern':
|
||||
extract_identifiers(param.left, nodes);
|
||||
break;
|
||||
}
|
||||
|
||||
return nodes;
|
||||
}
|
48
node_modules/periscopic/types/index.d.ts
generated
vendored
Normal file
48
node_modules/periscopic/types/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
/** @param {import('estree').Node} expression */
|
||||
export function analyze(expression: import('estree').Node): {
|
||||
map: WeakMap<import("estree").Node, Scope>;
|
||||
scope: Scope;
|
||||
globals: Map<string, import("estree").Node>;
|
||||
};
|
||||
/**
|
||||
* @param {import('estree').Node} param
|
||||
* @returns {string[]}
|
||||
*/
|
||||
export function extract_names(param: import('estree').Node): string[];
|
||||
/**
|
||||
* @param {import('estree').Node} param
|
||||
* @param {import('estree').Identifier[]} nodes
|
||||
* @returns {import('estree').Identifier[]}
|
||||
*/
|
||||
export function extract_identifiers(param: import('estree').Node, nodes?: import('estree').Identifier[]): import('estree').Identifier[];
|
||||
export class Scope {
|
||||
/**
|
||||
* @param {Scope | null} parent
|
||||
* @param {boolean} block
|
||||
*/
|
||||
constructor(parent: Scope | null, block: boolean);
|
||||
/** @type {Scope | null} */
|
||||
parent: Scope | null;
|
||||
/** @type {boolean} */
|
||||
block: boolean;
|
||||
/** @type {Map<string, import('estree').Node>} */
|
||||
declarations: Map<string, import('estree').Node>;
|
||||
/** @type {Set<string>} */
|
||||
initialised_declarations: Set<string>;
|
||||
/** @type {Set<string>} */
|
||||
references: Set<string>;
|
||||
/**
|
||||
* @param {import('estree').VariableDeclaration | import('estree').ClassDeclaration} node
|
||||
*/
|
||||
add_declaration(node: import('estree').VariableDeclaration | import('estree').ClassDeclaration): void;
|
||||
/**
|
||||
* @param {string} name
|
||||
* @returns {Scope | null}
|
||||
*/
|
||||
find_owner(name: string): Scope | null;
|
||||
/**
|
||||
* @param {string} name
|
||||
* @returns {boolean}
|
||||
*/
|
||||
has(name: string): boolean;
|
||||
}
|
Reference in New Issue
Block a user