Initial commit
This commit is contained in:
7
node_modules/babel-walk/LICENSE.md
generated
vendored
Normal file
7
node_modules/babel-walk/LICENSE.md
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
Copyright (c) 2016 Tiancheng "Timothy" Gu
|
||||
|
||||
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.
|
127
node_modules/babel-walk/README.md
generated
vendored
Normal file
127
node_modules/babel-walk/README.md
generated
vendored
Normal file
@ -0,0 +1,127 @@
|
||||
# babel-walk
|
||||
|
||||
Lightweight AST traversal tools for [Babel] ASTs.
|
||||
|
||||
[Babel] supplies the wonderful [babel-traverse] module for walking Babel ASTs. Problem is, babel-traverse is very heavyweight, as it is designed to supply utilities to make all sorts of AST transformations possible. For simple AST walking without transformation, babel-traverse brings a lot of overhead.
|
||||
|
||||
This module loosely implements the API of Acorn parser's [walk module], which is a lightweight AST walker for the ESTree AST format.
|
||||
|
||||
In my tests, babel-walk's ancestor walker (the most complex walker provided by this module) is about 8 times faster than babel-traverse, if the visitors are cached and the same AST is used for all runs. It is about 16 times faster if a fresh AST is used every run.
|
||||
|
||||
[](https://github.com/pugjs/babel-walk/actions?query=workflow%3A%22Publish+Canary%22)
|
||||
[](https://rollingversions.com/pugjs/babel-walk)
|
||||
[](https://www.npmjs.com/package/babel-walk)
|
||||
|
||||
[babel]: https://babeljs.io/
|
||||
[babel-traverse]: https://github.com/thejameskyle/babel-handbook/blob/master/translations/en/plugin-handbook.md#toc-babel-traverse
|
||||
[walk module]: https://github.com/ternjs/acorn#distwalkjs
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
$ npm install babel-walk
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
```js
|
||||
var walk = require('babel-walk');
|
||||
```
|
||||
|
||||
### walk.simple(visitors)(node, state)
|
||||
|
||||
Do a simple walk over the AST. `node` should be the AST node to walk, and `visitors` an object containing Babel [visitors]. Each visitor function will be called as `(node, state)`, where `node` is the AST node, and `state` is the same `state` passed to `walk.simple`.
|
||||
|
||||
When `walk.simple` is called with a fresh set of visitors, it will first "explode" the visitors (e.g. expanding `Visitor(node, state) {}` to `Visitor() { enter(node, state) {} }`). This exploding process can take some time, so it is recommended to cache the result of calling `walk.simple(visitors)` and communicate state leveraging the `state` parameter.
|
||||
|
||||
All [babel-types] aliases (e.g. `Expression`) work, but the union syntax (e.g. `'Identifier|AssignmentPattern'(node, state) {}`) does not.
|
||||
|
||||
### walk.ancestor(visitors)(node, state)
|
||||
|
||||
Do a simple walk over the AST, but memoizing the ancestors of the node and making them available to the visitors. `node` should be the AST node to walk, and `visitors` an object containing Babel [visitors]. Each visitor function will be called as `(node, state, ancestors)`, where `node` is the AST node, `state` is the same `state` passed to `walk.ancestor`, and `ancestors` is an array of ancestors to the node (with the outermost node being `[0]` and the current node being `[ancestors.length - 1]`). If `state` is not specified in the call to `walk.ancestor`, the `state` parameter will be set to `ancestors`.
|
||||
|
||||
When `walk.ancestor` is called with a fresh set of visitors, it will first "explode" the visitors (e.g. expanding `Visitor(node, state) {}` to `Visitor() { enter(node, state) {} }`). This exploding process can take some time, so it is recommended to cache the result of calling `walk.ancestor(visitors)` and communicate state leveraging the `state` parameter.
|
||||
|
||||
All [babel-types] aliases (e.g. `Expression`) work, but the union syntax (e.g. `'Identifier|AssignmentPattern'(node, state) {}`) does not.
|
||||
|
||||
### walk.recursive(visitors)(node, state)
|
||||
|
||||
Do a recursive walk over the AST, where the visitors are responsible for continuing the walk on the child nodes of their target node. `node` should be the AST node to walk, and `visitors` an object containing Babel [visitors]. Each visitor function will be called as `(node, state, c)`, where `node` is the AST node, `state` is the same `state` passed to `walk.recursive`, and `c` is a function that takes a single node as argument and continues walking _that_ node. If no visitor for a node is provided, the default walker algorithm will still be used.
|
||||
|
||||
When `walk.recursive` is called with a fresh set of visitors, it will first "explode" the visitors (e.g. expanding `Visitor(node, state) {}` to `Visitor() { enter(node, state) {} }`). This exploding process can take some time, so it is recommended to cache the result of calling `walk.recursive(visitors)` and communicate state leveraging the `state` parameter.
|
||||
|
||||
Unlike other babel-walk walkers, `walk.recursive` does not call the `exit` visitor, only the `enter` (the default) visitor, of a specific node type.
|
||||
|
||||
All [babel-types] aliases (e.g. `Expression`) work, but the union syntax (e.g. `'Identifier|AssignmentPattern'(node, state) {}`) does not.
|
||||
|
||||
In the following example, we are trying to count the number of functions in the outermost scope. This means, that we can simply walk all the statements and increment a counter if it is a function declaration or expression, and then stop walking. Note that we do not specify a visitor for the `Program` node, and the default algorithm for walking `Program` nodes is used (which is what we want). Also of note is how I bring the `visitors` object outside of `countFunctions` so that the object can be cached to improve performance.
|
||||
|
||||
```js
|
||||
import * as t from 'babel-types';
|
||||
import {parse} from 'babel';
|
||||
import * as walk from 'babel-walk';
|
||||
|
||||
const visitors = walk.recursive({
|
||||
Statement(node, state, c) {
|
||||
if (t.isVariableDeclaration(node)) {
|
||||
for (let declarator of node.declarations) {
|
||||
// Continue walking the declarator
|
||||
c(declarator);
|
||||
}
|
||||
} else if (t.isFunctionDeclaration(node)) {
|
||||
state.counter++;
|
||||
}
|
||||
},
|
||||
|
||||
VariableDeclarator(node, state) {
|
||||
if (t.isFunction(node.init)) {
|
||||
state.counter++;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
function countFunctions(node) {
|
||||
const state = {
|
||||
counter: 0,
|
||||
};
|
||||
visitors(node, state);
|
||||
return state.counter;
|
||||
}
|
||||
|
||||
const ast = parse(`
|
||||
// Counts
|
||||
var a = () => {};
|
||||
|
||||
// Counts
|
||||
function b() {
|
||||
// Doesn't count
|
||||
function c() {
|
||||
}
|
||||
}
|
||||
|
||||
// Counts
|
||||
const c = function d() {};
|
||||
`);
|
||||
|
||||
countFunctions(ast);
|
||||
// = 3
|
||||
```
|
||||
|
||||
[babel-types]: https://github.com/babel/babel/tree/master/packages/babel-types
|
||||
[cache your visitors]: https://github.com/thejameskyle/babel-handbook/blob/master/translations/en/plugin-handbook.md#toc-optimizing-nested-visitors
|
||||
[visitors]: https://github.com/thejameskyle/babel-handbook/blob/master/translations/en/plugin-handbook.md#toc-visitors
|
||||
|
||||
## Caveat
|
||||
|
||||
For those of you migrating from Acorn to Babel, there are a few things to be aware of.
|
||||
|
||||
1. The visitor caching suggestions do not apply to Acorn's walk module, but do for babel-walk.
|
||||
|
||||
2. babel-walk does not provide any of the other functions Acorn's walk module provides (e.g. `make`, `findNode*`).
|
||||
|
||||
3. babel-walk does not use a `base` variable. The walker algorithm is the same as what babel-traverse uses.
|
||||
- That means certain nodes that are not walked by Acorn, such as the `property` property of a non-computed `MemberExpression`, are walked by babel-walk.
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
1704
node_modules/babel-walk/lib/.tsbuildinfo
generated
vendored
Normal file
1704
node_modules/babel-walk/lib/.tsbuildinfo
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
8
node_modules/babel-walk/lib/explode.d.ts
generated
vendored
Normal file
8
node_modules/babel-walk/lib/explode.d.ts
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* This serves thre functions:
|
||||
*
|
||||
* 1. Take any "aliases" and explode them to refecence the concrete types
|
||||
* 2. Normalize all handlers to have an `{enter, exit}` pair, rather than raw functions
|
||||
* 3. make the enter and exit handlers arrays, so that multiple handlers can be merged
|
||||
*/
|
||||
export default function explode(input: any): any;
|
109
node_modules/babel-walk/lib/explode.js
generated
vendored
Normal file
109
node_modules/babel-walk/lib/explode.js
generated
vendored
Normal file
@ -0,0 +1,109 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const t = __importStar(require("@babel/types"));
|
||||
if (!(Array.isArray(t.TYPES) &&
|
||||
t.TYPES.every((t) => typeof t === 'string'))) {
|
||||
throw new Error('@babel/types TYPES does not match the expected type.');
|
||||
}
|
||||
const FLIPPED_ALIAS_KEYS = t
|
||||
.FLIPPED_ALIAS_KEYS;
|
||||
const TYPES = new Set(t.TYPES);
|
||||
if (!(FLIPPED_ALIAS_KEYS &&
|
||||
// tslint:disable-next-line: strict-type-predicates
|
||||
typeof FLIPPED_ALIAS_KEYS === 'object' &&
|
||||
Object.keys(FLIPPED_ALIAS_KEYS).every((key) => Array.isArray(FLIPPED_ALIAS_KEYS[key]) &&
|
||||
// tslint:disable-next-line: strict-type-predicates
|
||||
FLIPPED_ALIAS_KEYS[key].every((v) => typeof v === 'string')))) {
|
||||
throw new Error('@babel/types FLIPPED_ALIAS_KEYS does not match the expected type.');
|
||||
}
|
||||
/**
|
||||
* This serves thre functions:
|
||||
*
|
||||
* 1. Take any "aliases" and explode them to refecence the concrete types
|
||||
* 2. Normalize all handlers to have an `{enter, exit}` pair, rather than raw functions
|
||||
* 3. make the enter and exit handlers arrays, so that multiple handlers can be merged
|
||||
*/
|
||||
function explode(input) {
|
||||
const results = {};
|
||||
for (const key in input) {
|
||||
const aliases = FLIPPED_ALIAS_KEYS[key];
|
||||
if (aliases) {
|
||||
for (const concreteKey of aliases) {
|
||||
if (concreteKey in results) {
|
||||
if (typeof input[key] === 'function') {
|
||||
results[concreteKey].enter.push(input[key]);
|
||||
}
|
||||
else {
|
||||
if (input[key].enter)
|
||||
results[concreteKey].enter.push(input[key].enter);
|
||||
if (input[key].exit)
|
||||
results[concreteKey].exit.push(input[key].exit);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (typeof input[key] === 'function') {
|
||||
results[concreteKey] = {
|
||||
enter: [input[key]],
|
||||
exit: [],
|
||||
};
|
||||
}
|
||||
else {
|
||||
results[concreteKey] = {
|
||||
enter: input[key].enter ? [input[key].enter] : [],
|
||||
exit: input[key].exit ? [input[key].exit] : [],
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (TYPES.has(key)) {
|
||||
if (key in results) {
|
||||
if (typeof input[key] === 'function') {
|
||||
results[key].enter.push(input[key]);
|
||||
}
|
||||
else {
|
||||
if (input[key].enter)
|
||||
results[key].enter.push(input[key].enter);
|
||||
if (input[key].exit)
|
||||
results[key].exit.push(input[key].exit);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (typeof input[key] === 'function') {
|
||||
results[key] = {
|
||||
enter: [input[key]],
|
||||
exit: [],
|
||||
};
|
||||
}
|
||||
else {
|
||||
results[key] = {
|
||||
enter: input[key].enter ? [input[key].enter] : [],
|
||||
exit: input[key].exit ? [input[key].exit] : [],
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
exports.default = explode;
|
||||
//# sourceMappingURL=explode.js.map
|
1
node_modules/babel-walk/lib/explode.js.map
generated
vendored
Normal file
1
node_modules/babel-walk/lib/explode.js.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"explode.js","sourceRoot":"","sources":["../src/explode.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,gDAAkC;AAElC,IACE,CAAC,CACC,KAAK,CAAC,OAAO,CAAE,CAAS,CAAC,KAAK,CAAC;IAC9B,CAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAC1D,EACD;IACA,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;CACzE;AAED,MAAM,kBAAkB,GAA+B,CAAS;KAC7D,kBAAkB,CAAC;AACtB,MAAM,KAAK,GAAG,IAAI,GAAG,CAAU,CAAS,CAAC,KAAK,CAAC,CAAC;AAEhD,IACE,CAAC,CACC,kBAAkB;IAClB,mDAAmD;IACnD,OAAO,kBAAkB,KAAK,QAAQ;IACtC,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,KAAK,CACnC,CAAC,GAAG,EAAE,EAAE,CACN,KAAK,CAAC,OAAO,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC;QACtC,mDAAmD;QACnD,kBAAkB,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAC9D,CACF,EACD;IACA,MAAM,IAAI,KAAK,CACb,mEAAmE,CACpE,CAAC;CACH;AAED;;;;;;GAMG;AACH,SAAwB,OAAO,CAAC,KAAU;IACxC,MAAM,OAAO,GAAQ,EAAE,CA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CAAC;AACjB,CAAC;AArDD,0BAqDC"}
|
24
node_modules/babel-walk/lib/index.d.ts
generated
vendored
Normal file
24
node_modules/babel-walk/lib/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
import * as t from '@babel/types';
|
||||
export declare type NodeType<type extends string> = type extends keyof t.Aliases ? t.Aliases[type] : Extract<t.Node, {
|
||||
type: type;
|
||||
}>;
|
||||
export declare type SimpleFunction<TKey extends string, TState> = (node: NodeType<TKey>, state: TState) => void;
|
||||
export declare type SimpleVisitors<TState = void> = {
|
||||
[key in keyof t.Aliases | t.Node['type']]?: SimpleFunction<key, TState> | {
|
||||
enter?: SimpleFunction<key, TState>;
|
||||
exit?: SimpleFunction<key, TState>;
|
||||
};
|
||||
};
|
||||
export declare function simple<TState = void>(visitors: SimpleVisitors<TState>): (node: t.Node, state: TState) => void;
|
||||
export declare type AncestorFunction<TKey extends string, TState> = (node: NodeType<TKey>, state: TState, ancestors: t.Node[]) => void;
|
||||
export declare type AncestorVisitor<TState = void> = {
|
||||
[key in keyof t.Aliases | t.Node['type']]?: AncestorFunction<key, TState> | {
|
||||
enter?: AncestorFunction<key, TState>;
|
||||
exit?: AncestorFunction<key, TState>;
|
||||
};
|
||||
};
|
||||
export declare function ancestor<TState = void>(visitors: AncestorVisitor<TState>): (node: t.Node, state: TState) => void;
|
||||
export declare type RecursiveVisitors<TState = void> = {
|
||||
[key in keyof t.Aliases | t.Node['type']]?: (node: NodeType<key>, state: TState, recurse: (node: t.Node) => void) => void;
|
||||
};
|
||||
export declare function recursive<TState = void>(visitors: RecursiveVisitors<TState>): (node: t.Node, state: TState) => void;
|
136
node_modules/babel-walk/lib/index.js
generated
vendored
Normal file
136
node_modules/babel-walk/lib/index.js
generated
vendored
Normal file
@ -0,0 +1,136 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.recursive = exports.ancestor = exports.simple = void 0;
|
||||
const t = __importStar(require("@babel/types"));
|
||||
const explode_1 = __importDefault(require("./explode"));
|
||||
const VISITOR_KEYS = t.VISITOR_KEYS;
|
||||
if (!(VISITOR_KEYS &&
|
||||
// tslint:disable-next-line: strict-type-predicates
|
||||
typeof VISITOR_KEYS === 'object' &&
|
||||
Object.keys(VISITOR_KEYS).every((key) => Array.isArray(VISITOR_KEYS[key]) &&
|
||||
// tslint:disable-next-line: strict-type-predicates
|
||||
VISITOR_KEYS[key].every((v) => typeof v === 'string')))) {
|
||||
throw new Error('@babel/types VISITOR_KEYS does not match the expected type.');
|
||||
}
|
||||
function simple(visitors) {
|
||||
const vis = explode_1.default(visitors);
|
||||
return (node, state) => {
|
||||
(function recurse(node) {
|
||||
if (!node)
|
||||
return;
|
||||
const visitor = vis[node.type];
|
||||
if (visitor === null || visitor === void 0 ? void 0 : visitor.enter) {
|
||||
for (const v of visitor.enter) {
|
||||
v(node, state);
|
||||
}
|
||||
}
|
||||
for (const key of VISITOR_KEYS[node.type] || []) {
|
||||
const subNode = node[key];
|
||||
if (Array.isArray(subNode)) {
|
||||
for (const subSubNode of subNode) {
|
||||
recurse(subSubNode);
|
||||
}
|
||||
}
|
||||
else {
|
||||
recurse(subNode);
|
||||
}
|
||||
}
|
||||
if (visitor === null || visitor === void 0 ? void 0 : visitor.exit) {
|
||||
for (const v of visitor.exit) {
|
||||
v(node, state);
|
||||
}
|
||||
}
|
||||
})(node);
|
||||
};
|
||||
}
|
||||
exports.simple = simple;
|
||||
function ancestor(visitors) {
|
||||
const vis = explode_1.default(visitors);
|
||||
return (node, state) => {
|
||||
const ancestors = [];
|
||||
(function recurse(node) {
|
||||
if (!node)
|
||||
return;
|
||||
const visitor = vis[node.type];
|
||||
const isNew = node !== ancestors[ancestors.length - 1];
|
||||
if (isNew)
|
||||
ancestors.push(node);
|
||||
if (visitor === null || visitor === void 0 ? void 0 : visitor.enter) {
|
||||
for (const v of visitor.enter) {
|
||||
v(node, state, ancestors);
|
||||
}
|
||||
}
|
||||
for (const key of VISITOR_KEYS[node.type] || []) {
|
||||
const subNode = node[key];
|
||||
if (Array.isArray(subNode)) {
|
||||
for (const subSubNode of subNode) {
|
||||
recurse(subSubNode);
|
||||
}
|
||||
}
|
||||
else {
|
||||
recurse(subNode);
|
||||
}
|
||||
}
|
||||
if (visitor === null || visitor === void 0 ? void 0 : visitor.exit) {
|
||||
for (const v of visitor.exit) {
|
||||
v(node, state, ancestors);
|
||||
}
|
||||
}
|
||||
if (isNew)
|
||||
ancestors.pop();
|
||||
})(node);
|
||||
};
|
||||
}
|
||||
exports.ancestor = ancestor;
|
||||
function recursive(visitors) {
|
||||
const vis = explode_1.default(visitors);
|
||||
return (node, state) => {
|
||||
(function recurse(node) {
|
||||
if (!node)
|
||||
return;
|
||||
const visitor = vis[node.type];
|
||||
if (visitor === null || visitor === void 0 ? void 0 : visitor.enter) {
|
||||
for (const v of visitor.enter) {
|
||||
v(node, state, recurse);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (const key of VISITOR_KEYS[node.type] || []) {
|
||||
const subNode = node[key];
|
||||
if (Array.isArray(subNode)) {
|
||||
for (const subSubNode of subNode) {
|
||||
recurse(subSubNode);
|
||||
}
|
||||
}
|
||||
else {
|
||||
recurse(subNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
})(node);
|
||||
};
|
||||
}
|
||||
exports.recursive = recursive;
|
||||
//# sourceMappingURL=index.js.map
|
1
node_modules/babel-walk/lib/index.js.map
generated
vendored
Normal file
1
node_modules/babel-walk/lib/index.js.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAkC;AAClC,wDAAgC;AAEhC,MAAM,YAAY,GAA+B,CAAS,CAAC,YAAY,CAAC;AACxE,IACE,CAAC,CACC,YAAY;IACZ,mDAAmD;IACnD,OAAO,YAAY,KAAK,QAAQ;IAChC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,KAAK,CAC7B,CAAC,GAAG,EAAE,EAAE,CACN,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;QAChC,mDAAmD;QACnD,YAAY,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CACxD,CACF,EACD;IACA,MAAM,IAAI,KAAK,CACb,6DAA6D,CAC9D,CAAC;CACH;AAoBD,SAAgB,MAAM,CAAgB,QAAgC;IACpE,MAAM,GAAG,GAAG,iBAAO,CAAC,QAAQ,CAAC,CAAC;IAC9B,OAAO,CAAC,IAAY,EAAE,KAAa,EAAE,EAAE;QACrC,CAAC,SAAS,OAAO,CAAC,IAAI;YACpB,IAAI,CAAC,IAAI;gBAAE,OAAO;YAElB,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAE/B,IAAI,OAAO,aAAP,OAAO,uBAAP,O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AAC,IAAI,OAAO,CAAC,KAAK,EAAE;oBAC7B,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;iBACzB;aACF;iBAAM;gBACL,KAAK,MAAM,GAAG,IAAI,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE;oBAC/C,MAAM,OAAO,GAAI,IAAY,CAAC,GAAG,CAAC,CAAC;oBACnC,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;wBAC1B,KAAK,MAAM,UAAU,IAAI,OAAO,EAAE;4BAChC,OAAO,CAAC,UAAU,CAAC,CAAC;yBACrB;qBACF;yBAAM;wBACL,OAAO,CAAC,OAAO,CAAC,CAAC;qBAClB;iBACF;aACF;QACH,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACX,CAAC,CAAC;AACJ,CAAC;AAzBD,8BAyBC"}
|
1
node_modules/babel-walk/lib/test.d.ts
generated
vendored
Normal file
1
node_modules/babel-walk/lib/test.d.ts
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
export {};
|
35
node_modules/babel-walk/lib/test.js
generated
vendored
Normal file
35
node_modules/babel-walk/lib/test.js
generated
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const t = __importStar(require("@babel/types"));
|
||||
const _1 = require("./");
|
||||
_1.ancestor({})(t.program([]), undefined);
|
||||
_1.ancestor({
|
||||
Function(node) {
|
||||
console.info(node);
|
||||
},
|
||||
})(t.program([]), undefined);
|
||||
_1.ancestor({
|
||||
Function(node, state) {
|
||||
console.info(node, state);
|
||||
},
|
||||
})(t.program([]), 'hello world');
|
||||
//# sourceMappingURL=test.js.map
|
1
node_modules/babel-walk/lib/test.js.map
generated
vendored
Normal file
1
node_modules/babel-walk/lib/test.js.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"test.js","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,gDAAkC;AAClC,yBAA4B;AAE5B,WAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,SAAS,CAAC,CAAC;AACvC,WAAQ,CAAC;IACP,QAAQ,CAAC,IAAI;QACX,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrB,CAAC;CACF,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,SAAS,CAAC,CAAC;AAE7B,WAAQ,CAAS;IACf,QAAQ,CAAC,IAAI,EAAE,KAAK;QAClB,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC5B,CAAC;CACF,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,aAAa,CAAC,CAAC"}
|
36
node_modules/babel-walk/package.json
generated
vendored
Normal file
36
node_modules/babel-walk/package.json
generated
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
{
|
||||
"name": "babel-walk",
|
||||
"version": "3.0.0-canary-5",
|
||||
"description": "Lightweight Babel AST traversal",
|
||||
"main": "lib/index.js",
|
||||
"files": [
|
||||
"lib"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "tsc && node lib",
|
||||
"postbuild": "rimraf lib/**/__tests__",
|
||||
"lint": "tslint './src/**/*.{ts,tsx}' -t verbose -p .",
|
||||
"prettier:write": "prettier --ignore-path .gitignore --write './**/*.{md,json,yaml,js,jsx,ts,tsx}'",
|
||||
"prettier:check": "prettier --ignore-path .gitignore --list-different './**/*.{md,json,yaml,js,jsx,ts,tsx}'"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/pugjs/babel-walk.git"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 10.0.0"
|
||||
},
|
||||
"author": "Timothy Gu <timothygu99@gmail.com>",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@babel/types": "^7.9.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@forbeslindesay/tsconfig": "^2.0.0",
|
||||
"@types/node": "^14.0.5",
|
||||
"prettier": "^2.0.5",
|
||||
"rimraf": "^3.0.2",
|
||||
"tslint": "^6.1.2",
|
||||
"typescript": "^3.9.3"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user