123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377 |
- (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}(g.acorn || (g.acorn = {})).walk = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
- // AST walker module for Mozilla Parser API compatible trees
- // A simple walk is one where you simply specify callbacks to be
- // called on specific nodes. The last two arguments are optional. A
- // simple use would be
- //
- // walk.simple(myTree, {
- // Expression: function(node) { ... }
- // });
- //
- // to do something with all expressions. All Parser API node types
- // can be used to identify node types, as well as Expression,
- // Statement, and ScopeBody, which denote categories of nodes.
- //
- // The base argument can be used to pass a custom (recursive)
- // walker, and state can be used to give this walked an initial
- // state.
- "use strict";
- exports.__esModule = true;
- exports.simple = simple;
- exports.ancestor = ancestor;
- exports.recursive = recursive;
- exports.findNodeAt = findNodeAt;
- exports.findNodeAround = findNodeAround;
- exports.findNodeAfter = findNodeAfter;
- exports.findNodeBefore = findNodeBefore;
- exports.make = make;
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- function simple(node, visitors, base, state, override) {
- if (!base) base = exports.base;(function c(node, st, override) {
- var type = override || node.type,
- found = visitors[type];
- base[type](node, st, c);
- if (found) found(node, st);
- })(node, state, override);
- }
- // An ancestor walk builds up an array of ancestor nodes (including
- // the current node) and passes them to the callback as the state parameter.
- function ancestor(node, visitors, base, state) {
- if (!base) base = exports.base;
- if (!state) state = [];(function c(node, st, override) {
- var type = override || node.type,
- found = visitors[type];
- if (node != st[st.length - 1]) {
- st = st.slice();
- st.push(node);
- }
- base[type](node, st, c);
- if (found) found(node, st);
- })(node, state);
- }
- // A recursive walk is one where your functions override the default
- // walkers. They can modify and replace the state parameter that's
- // threaded through the walk, and can opt how and whether to walk
- // their child nodes (by calling their third argument on these
- // nodes).
- function recursive(node, state, funcs, base, override) {
- var visitor = funcs ? exports.make(funcs, base) : base;(function c(node, st, override) {
- visitor[override || node.type](node, st, c);
- })(node, state, override);
- }
- function makeTest(test) {
- if (typeof test == "string") return function (type) {
- return type == test;
- };else if (!test) return function () {
- return true;
- };else return test;
- }
- var Found = function Found(node, state) {
- _classCallCheck(this, Found);
- this.node = node;this.state = state;
- }
- // Find a node with a given start, end, and type (all are optional,
- // null can be used as wildcard). Returns a {node, state} object, or
- // undefined when it doesn't find a matching node.
- ;
- function findNodeAt(node, start, end, test, base, state) {
- test = makeTest(test);
- if (!base) base = exports.base;
- try {
- ;(function c(node, st, override) {
- var type = override || node.type;
- if ((start == null || node.start <= start) && (end == null || node.end >= end)) base[type](node, st, c);
- if ((start == null || node.start == start) && (end == null || node.end == end) && test(type, node)) throw new Found(node, st);
- })(node, state);
- } catch (e) {
- if (e instanceof Found) return e;
- throw e;
- }
- }
- // Find the innermost node of a given type that contains the given
- // position. Interface similar to findNodeAt.
- function findNodeAround(node, pos, test, base, state) {
- test = makeTest(test);
- if (!base) base = exports.base;
- try {
- ;(function c(node, st, override) {
- var type = override || node.type;
- if (node.start > pos || node.end < pos) return;
- base[type](node, st, c);
- if (test(type, node)) throw new Found(node, st);
- })(node, state);
- } catch (e) {
- if (e instanceof Found) return e;
- throw e;
- }
- }
- // Find the outermost matching node after a given position.
- function findNodeAfter(node, pos, test, base, state) {
- test = makeTest(test);
- if (!base) base = exports.base;
- try {
- ;(function c(node, st, override) {
- if (node.end < pos) return;
- var type = override || node.type;
- if (node.start >= pos && test(type, node)) throw new Found(node, st);
- base[type](node, st, c);
- })(node, state);
- } catch (e) {
- if (e instanceof Found) return e;
- throw e;
- }
- }
- // Find the outermost matching node before a given position.
- function findNodeBefore(node, pos, test, base, state) {
- test = makeTest(test);
- if (!base) base = exports.base;
- var max = undefined;(function c(node, st, override) {
- if (node.start > pos) return;
- var type = override || node.type;
- if (node.end <= pos && (!max || max.node.end < node.end) && test(type, node)) max = new Found(node, st);
- base[type](node, st, c);
- })(node, state);
- return max;
- }
- // Used to create a custom walker. Will fill in all missing node
- // type properties with the defaults.
- function make(funcs, base) {
- if (!base) base = exports.base;
- var visitor = {};
- for (var type in base) visitor[type] = base[type];
- for (var type in funcs) visitor[type] = funcs[type];
- return visitor;
- }
- function skipThrough(node, st, c) {
- c(node, st);
- }
- function ignore(_node, _st, _c) {}
- // Node walkers.
- var base = {};
- exports.base = base;
- base.Program = base.BlockStatement = function (node, st, c) {
- for (var i = 0; i < node.body.length; ++i) {
- c(node.body[i], st, "Statement");
- }
- };
- base.Statement = skipThrough;
- base.EmptyStatement = ignore;
- base.ExpressionStatement = base.ParenthesizedExpression = function (node, st, c) {
- return c(node.expression, st, "Expression");
- };
- base.IfStatement = function (node, st, c) {
- c(node.test, st, "Expression");
- c(node.consequent, st, "Statement");
- if (node.alternate) c(node.alternate, st, "Statement");
- };
- base.LabeledStatement = function (node, st, c) {
- return c(node.body, st, "Statement");
- };
- base.BreakStatement = base.ContinueStatement = ignore;
- base.WithStatement = function (node, st, c) {
- c(node.object, st, "Expression");
- c(node.body, st, "Statement");
- };
- base.SwitchStatement = function (node, st, c) {
- c(node.discriminant, st, "Expression");
- for (var i = 0; i < node.cases.length; ++i) {
- var cs = node.cases[i];
- if (cs.test) c(cs.test, st, "Expression");
- for (var j = 0; j < cs.consequent.length; ++j) {
- c(cs.consequent[j], st, "Statement");
- }
- }
- };
- base.ReturnStatement = base.YieldExpression = function (node, st, c) {
- if (node.argument) c(node.argument, st, "Expression");
- };
- base.ThrowStatement = base.SpreadElement = function (node, st, c) {
- return c(node.argument, st, "Expression");
- };
- base.TryStatement = function (node, st, c) {
- c(node.block, st, "Statement");
- if (node.handler) {
- c(node.handler.param, st, "Pattern");
- c(node.handler.body, st, "ScopeBody");
- }
- if (node.finalizer) c(node.finalizer, st, "Statement");
- };
- base.WhileStatement = base.DoWhileStatement = function (node, st, c) {
- c(node.test, st, "Expression");
- c(node.body, st, "Statement");
- };
- base.ForStatement = function (node, st, c) {
- if (node.init) c(node.init, st, "ForInit");
- if (node.test) c(node.test, st, "Expression");
- if (node.update) c(node.update, st, "Expression");
- c(node.body, st, "Statement");
- };
- base.ForInStatement = base.ForOfStatement = function (node, st, c) {
- c(node.left, st, "ForInit");
- c(node.right, st, "Expression");
- c(node.body, st, "Statement");
- };
- base.ForInit = function (node, st, c) {
- if (node.type == "VariableDeclaration") c(node, st);else c(node, st, "Expression");
- };
- base.DebuggerStatement = ignore;
- base.FunctionDeclaration = function (node, st, c) {
- return c(node, st, "Function");
- };
- base.VariableDeclaration = function (node, st, c) {
- for (var i = 0; i < node.declarations.length; ++i) {
- c(node.declarations[i], st);
- }
- };
- base.VariableDeclarator = function (node, st, c) {
- c(node.id, st, "Pattern");
- if (node.init) c(node.init, st, "Expression");
- };
- base.Function = function (node, st, c) {
- if (node.id) c(node.id, st, "Pattern");
- for (var i = 0; i < node.params.length; i++) {
- c(node.params[i], st, "Pattern");
- }c(node.body, st, node.expression ? "ScopeExpression" : "ScopeBody");
- };
- // FIXME drop these node types in next major version
- // (They are awkward, and in ES6 every block can be a scope.)
- base.ScopeBody = function (node, st, c) {
- return c(node, st, "Statement");
- };
- base.ScopeExpression = function (node, st, c) {
- return c(node, st, "Expression");
- };
- base.Pattern = function (node, st, c) {
- if (node.type == "Identifier") c(node, st, "VariablePattern");else if (node.type == "MemberExpression") c(node, st, "MemberPattern");else c(node, st);
- };
- base.VariablePattern = ignore;
- base.MemberPattern = skipThrough;
- base.RestElement = function (node, st, c) {
- return c(node.argument, st, "Pattern");
- };
- base.ArrayPattern = function (node, st, c) {
- for (var i = 0; i < node.elements.length; ++i) {
- var elt = node.elements[i];
- if (elt) c(elt, st, "Pattern");
- }
- };
- base.ObjectPattern = function (node, st, c) {
- for (var i = 0; i < node.properties.length; ++i) {
- c(node.properties[i].value, st, "Pattern");
- }
- };
- base.Expression = skipThrough;
- base.ThisExpression = base.Super = base.MetaProperty = ignore;
- base.ArrayExpression = function (node, st, c) {
- for (var i = 0; i < node.elements.length; ++i) {
- var elt = node.elements[i];
- if (elt) c(elt, st, "Expression");
- }
- };
- base.ObjectExpression = function (node, st, c) {
- for (var i = 0; i < node.properties.length; ++i) {
- c(node.properties[i], st);
- }
- };
- base.FunctionExpression = base.ArrowFunctionExpression = base.FunctionDeclaration;
- base.SequenceExpression = base.TemplateLiteral = function (node, st, c) {
- for (var i = 0; i < node.expressions.length; ++i) {
- c(node.expressions[i], st, "Expression");
- }
- };
- base.UnaryExpression = base.UpdateExpression = function (node, st, c) {
- c(node.argument, st, "Expression");
- };
- base.BinaryExpression = base.LogicalExpression = function (node, st, c) {
- c(node.left, st, "Expression");
- c(node.right, st, "Expression");
- };
- base.AssignmentExpression = base.AssignmentPattern = function (node, st, c) {
- c(node.left, st, "Pattern");
- c(node.right, st, "Expression");
- };
- base.ConditionalExpression = function (node, st, c) {
- c(node.test, st, "Expression");
- c(node.consequent, st, "Expression");
- c(node.alternate, st, "Expression");
- };
- base.NewExpression = base.CallExpression = function (node, st, c) {
- c(node.callee, st, "Expression");
- if (node.arguments) for (var i = 0; i < node.arguments.length; ++i) {
- c(node.arguments[i], st, "Expression");
- }
- };
- base.MemberExpression = function (node, st, c) {
- c(node.object, st, "Expression");
- if (node.computed) c(node.property, st, "Expression");
- };
- base.ExportNamedDeclaration = base.ExportDefaultDeclaration = function (node, st, c) {
- if (node.declaration) c(node.declaration, st, node.type == "ExportNamedDeclaration" || node.declaration.id ? "Statement" : "Expression");
- if (node.source) c(node.source, st, "Expression");
- };
- base.ExportAllDeclaration = function (node, st, c) {
- c(node.source, st, "Expression");
- };
- base.ImportDeclaration = function (node, st, c) {
- for (var i = 0; i < node.specifiers.length; i++) {
- c(node.specifiers[i], st);
- }c(node.source, st, "Expression");
- };
- base.ImportSpecifier = base.ImportDefaultSpecifier = base.ImportNamespaceSpecifier = base.Identifier = base.Literal = ignore;
- base.TaggedTemplateExpression = function (node, st, c) {
- c(node.tag, st, "Expression");
- c(node.quasi, st);
- };
- base.ClassDeclaration = base.ClassExpression = function (node, st, c) {
- return c(node, st, "Class");
- };
- base.Class = function (node, st, c) {
- if (node.id) c(node.id, st, "Pattern");
- if (node.superClass) c(node.superClass, st, "Expression");
- for (var i = 0; i < node.body.body.length; i++) {
- c(node.body.body[i], st);
- }
- };
- base.MethodDefinition = base.Property = function (node, st, c) {
- if (node.computed) c(node.key, st, "Expression");
- c(node.value, st, "Expression");
- };
- base.ComprehensionExpression = function (node, st, c) {
- for (var i = 0; i < node.blocks.length; i++) {
- c(node.blocks[i].right, st, "Expression");
- }c(node.body, st, "Expression");
- };
- },{}]},{},[1])(1)
- });
|