react / wstein / node_modules / browserify / node_modules / syntax-error / node_modules / acorn / dist / walk.js
80552 views(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){1"use strict";23var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };45// AST walker module for Mozilla Parser API compatible trees67// A simple walk is one where you simply specify callbacks to be8// called on specific nodes. The last two arguments are optional. A9// simple use would be10//11// walk.simple(myTree, {12// Expression: function(node) { ... }13// });14//15// to do something with all expressions. All Parser API node types16// can be used to identify node types, as well as Expression,17// Statement, and ScopeBody, which denote categories of nodes.18//19// The base argument can be used to pass a custom (recursive)20// walker, and state can be used to give this walked an initial21// state.2223exports.simple = simple;2425// An ancestor walk builds up an array of ancestor nodes (including26// the current node) and passes them to the callback as the state parameter.27exports.ancestor = ancestor;2829// A recursive walk is one where your functions override the default30// walkers. They can modify and replace the state parameter that's31// threaded through the walk, and can opt how and whether to walk32// their child nodes (by calling their third argument on these33// nodes).34exports.recursive = recursive;3536// Find a node with a given start, end, and type (all are optional,37// null can be used as wildcard). Returns a {node, state} object, or38// undefined when it doesn't find a matching node.39exports.findNodeAt = findNodeAt;4041// Find the innermost node of a given type that contains the given42// position. Interface similar to findNodeAt.43exports.findNodeAround = findNodeAround;4445// Find the outermost matching node after a given position.46exports.findNodeAfter = findNodeAfter;4748// Find the outermost matching node before a given position.49exports.findNodeBefore = findNodeBefore;5051// Used to create a custom walker. Will fill in all missing node52// type properties with the defaults.53exports.make = make;54exports.__esModule = true;5556function simple(node, visitors, base, state) {57if (!base) base = exports.base;(function c(node, st, override) {58var type = override || node.type,59found = visitors[type];60base[type](node, st, c);61if (found) found(node, st);62})(node, state);63}6465function ancestor(node, visitors, base, state) {66if (!base) base = exports.base;67if (!state) state = [];(function c(node, st, override) {68var type = override || node.type,69found = visitors[type];70if (node != st[st.length - 1]) {71st = st.slice();72st.push(node);73}74base[type](node, st, c);75if (found) found(node, st);76})(node, state);77}7879function recursive(node, state, funcs, base) {80var visitor = funcs ? exports.make(funcs, base) : base;(function c(node, st, override) {81visitor[override || node.type](node, st, c);82})(node, state);83}8485function makeTest(test) {86if (typeof test == "string") {87return function (type) {88return type == test;89};90} else if (!test) {91return function () {92return true;93};94} else {95return test;96}97}9899var Found = function Found(node, state) {100_classCallCheck(this, Found);101102this.node = node;this.state = state;103};104105function findNodeAt(node, start, end, test, base, state) {106test = makeTest(test);107if (!base) base = exports.base;108try {109;(function c(node, st, override) {110var type = override || node.type;111if ((start == null || node.start <= start) && (end == null || node.end >= end)) base[type](node, st, c);112if (test(type, node) && (start == null || node.start == start) && (end == null || node.end == end)) throw new Found(node, st);113})(node, state);114} catch (e) {115if (e instanceof Found) {116return e;117}throw e;118}119}120121function findNodeAround(node, pos, test, base, state) {122test = makeTest(test);123if (!base) base = exports.base;124try {125;(function c(node, st, override) {126var type = override || node.type;127if (node.start > pos || node.end < pos) {128return;129}base[type](node, st, c);130if (test(type, node)) throw new Found(node, st);131})(node, state);132} catch (e) {133if (e instanceof Found) {134return e;135}throw e;136}137}138139function findNodeAfter(node, pos, test, base, state) {140test = makeTest(test);141if (!base) base = exports.base;142try {143;(function c(node, st, override) {144if (node.end < pos) {145return;146}var type = override || node.type;147if (node.start >= pos && test(type, node)) throw new Found(node, st);148base[type](node, st, c);149})(node, state);150} catch (e) {151if (e instanceof Found) {152return e;153}throw e;154}155}156157function findNodeBefore(node, pos, test, base, state) {158test = makeTest(test);159if (!base) base = exports.base;160var max = undefined;(function c(node, st, override) {161if (node.start > pos) {162return;163}var type = override || node.type;164if (node.end <= pos && (!max || max.node.end < node.end) && test(type, node)) max = new Found(node, st);165base[type](node, st, c);166})(node, state);167return max;168}169170function make(funcs, base) {171if (!base) base = exports.base;172var visitor = {};173for (var type in base) visitor[type] = base[type];174for (var type in funcs) visitor[type] = funcs[type];175return visitor;176}177178function skipThrough(node, st, c) {179c(node, st);180}181function ignore(_node, _st, _c) {}182183// Node walkers.184185var base = {};186187exports.base = base;188base.Program = base.BlockStatement = function (node, st, c) {189for (var i = 0; i < node.body.length; ++i) {190c(node.body[i], st, "Statement");191}192};193base.Statement = skipThrough;194base.EmptyStatement = ignore;195base.ExpressionStatement = base.ParenthesizedExpression = function (node, st, c) {196return c(node.expression, st, "Expression");197};198base.IfStatement = function (node, st, c) {199c(node.test, st, "Expression");200c(node.consequent, st, "Statement");201if (node.alternate) c(node.alternate, st, "Statement");202};203base.LabeledStatement = function (node, st, c) {204return c(node.body, st, "Statement");205};206base.BreakStatement = base.ContinueStatement = ignore;207base.WithStatement = function (node, st, c) {208c(node.object, st, "Expression");209c(node.body, st, "Statement");210};211base.SwitchStatement = function (node, st, c) {212c(node.discriminant, st, "Expression");213for (var i = 0; i < node.cases.length; ++i) {214var cs = node.cases[i];215if (cs.test) c(cs.test, st, "Expression");216for (var j = 0; j < cs.consequent.length; ++j) {217c(cs.consequent[j], st, "Statement");218}219}220};221base.ReturnStatement = base.YieldExpression = function (node, st, c) {222if (node.argument) c(node.argument, st, "Expression");223};224base.ThrowStatement = base.SpreadElement = base.RestElement = function (node, st, c) {225return c(node.argument, st, "Expression");226};227base.TryStatement = function (node, st, c) {228c(node.block, st, "Statement");229if (node.handler) c(node.handler.body, st, "ScopeBody");230if (node.finalizer) c(node.finalizer, st, "Statement");231};232base.WhileStatement = base.DoWhileStatement = function (node, st, c) {233c(node.test, st, "Expression");234c(node.body, st, "Statement");235};236base.ForStatement = function (node, st, c) {237if (node.init) c(node.init, st, "ForInit");238if (node.test) c(node.test, st, "Expression");239if (node.update) c(node.update, st, "Expression");240c(node.body, st, "Statement");241};242base.ForInStatement = base.ForOfStatement = function (node, st, c) {243c(node.left, st, "ForInit");244c(node.right, st, "Expression");245c(node.body, st, "Statement");246};247base.ForInit = function (node, st, c) {248if (node.type == "VariableDeclaration") c(node, st);else c(node, st, "Expression");249};250base.DebuggerStatement = ignore;251252base.FunctionDeclaration = function (node, st, c) {253return c(node, st, "Function");254};255base.VariableDeclaration = function (node, st, c) {256for (var i = 0; i < node.declarations.length; ++i) {257var decl = node.declarations[i];258if (decl.init) c(decl.init, st, "Expression");259}260};261262base.Function = function (node, st, c) {263return c(node.body, st, "ScopeBody");264};265base.ScopeBody = function (node, st, c) {266return c(node, st, "Statement");267};268269base.Expression = skipThrough;270base.ThisExpression = base.Super = base.MetaProperty = ignore;271base.ArrayExpression = base.ArrayPattern = function (node, st, c) {272for (var i = 0; i < node.elements.length; ++i) {273var elt = node.elements[i];274if (elt) c(elt, st, "Expression");275}276};277base.ObjectExpression = base.ObjectPattern = function (node, st, c) {278for (var i = 0; i < node.properties.length; ++i) {279c(node.properties[i], st);280}281};282base.FunctionExpression = base.ArrowFunctionExpression = base.FunctionDeclaration;283base.SequenceExpression = base.TemplateLiteral = function (node, st, c) {284for (var i = 0; i < node.expressions.length; ++i) {285c(node.expressions[i], st, "Expression");286}287};288base.UnaryExpression = base.UpdateExpression = function (node, st, c) {289c(node.argument, st, "Expression");290};291base.BinaryExpression = base.AssignmentExpression = base.AssignmentPattern = base.LogicalExpression = function (node, st, c) {292c(node.left, st, "Expression");293c(node.right, st, "Expression");294};295base.ConditionalExpression = function (node, st, c) {296c(node.test, st, "Expression");297c(node.consequent, st, "Expression");298c(node.alternate, st, "Expression");299};300base.NewExpression = base.CallExpression = function (node, st, c) {301c(node.callee, st, "Expression");302if (node.arguments) for (var i = 0; i < node.arguments.length; ++i) {303c(node.arguments[i], st, "Expression");304}305};306base.MemberExpression = function (node, st, c) {307c(node.object, st, "Expression");308if (node.computed) c(node.property, st, "Expression");309};310base.ExportNamedDeclaration = base.ExportDefaultDeclaration = function (node, st, c) {311return c(node.declaration, st);312};313base.ImportDeclaration = function (node, st, c) {314for (var i = 0; i < node.specifiers.length; i++) {315c(node.specifiers[i], st);316}317};318base.ImportSpecifier = base.ImportDefaultSpecifier = base.ImportNamespaceSpecifier = base.Identifier = base.Literal = ignore;319320base.TaggedTemplateExpression = function (node, st, c) {321c(node.tag, st, "Expression");322c(node.quasi, st);323};324base.ClassDeclaration = base.ClassExpression = function (node, st, c) {325if (node.superClass) c(node.superClass, st, "Expression");326for (var i = 0; i < node.body.body.length; i++) {327c(node.body.body[i], st);328}329};330base.MethodDefinition = base.Property = function (node, st, c) {331if (node.computed) c(node.key, st, "Expression");332c(node.value, st, "Expression");333};334base.ComprehensionExpression = function (node, st, c) {335for (var i = 0; i < node.blocks.length; i++) {336c(node.blocks[i].right, st, "Expression");337}c(node.body, st, "Expression");338};339340},{}]},{},[1])(1)341});342343