diff options
Diffstat (limited to 'deps/acorn/dist/walk.es.js')
-rw-r--r-- | deps/acorn/dist/walk.es.js | 112 |
1 files changed, 64 insertions, 48 deletions
diff --git a/deps/acorn/dist/walk.es.js b/deps/acorn/dist/walk.es.js index 40356507d9..faa2f0012d 100644 --- a/deps/acorn/dist/walk.es.js +++ b/deps/acorn/dist/walk.es.js @@ -16,11 +16,11 @@ // walker, and state can be used to give this walked an initial // state. -function simple(node, visitors, base, state, override) { - if (!base) { base = exports.base +function simple(node, visitors, baseVisitor, state, override) { + if (!baseVisitor) { baseVisitor = base ; }(function c(node, st, override) { var type = override || node.type, found = visitors[type]; - base[type](node, st, c); + baseVisitor[type](node, st, c); if (found) { found(node, st); } })(node, state, override); } @@ -28,13 +28,14 @@ function simple(node, visitors, base, state, override) { // An ancestor walk keeps an array of ancestor nodes (including the // current node) and passes them to the callback as third parameter // (and also as state parameter when no other state is present). -function ancestor(node, visitors, base, state) { - if (!base) { base = exports.base; } - var ancestors = [];(function c(node, st, override) { +function ancestor(node, visitors, baseVisitor, state) { + var ancestors = []; + if (!baseVisitor) { baseVisitor = base + ; }(function c(node, st, override) { var type = override || node.type, found = visitors[type]; - var isNew = node != ancestors[ancestors.length - 1]; + var isNew = node !== ancestors[ancestors.length - 1]; if (isNew) { ancestors.push(node); } - base[type](node, st, c); + baseVisitor[type](node, st, c); if (found) { found(node, st || ancestors, ancestors); } if (isNew) { ancestors.pop(); } })(node, state); @@ -45,15 +46,15 @@ function ancestor(node, visitors, base, state) { // 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) { +function recursive(node, state, funcs, baseVisitor, override) { + var visitor = funcs ? make(funcs, baseVisitor || undefined) : baseVisitor;(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; } } + if (typeof test === "string") + { return function (type) { return type === test; } } else if (!test) { return function () { return true; } } else @@ -63,24 +64,24 @@ function makeTest(test) { var Found = function Found(node, state) { this.node = node; this.state = state; }; // A full walk triggers the callback on each node -function full(node, callback, base, state, override) { - if (!base) { base = exports.base +function full(node, callback, baseVisitor, state, override) { + if (!baseVisitor) { baseVisitor = base ; }(function c(node, st, override) { var type = override || node.type; - base[type](node, st, c); + baseVisitor[type](node, st, c); if (!override) { callback(node, st, type); } })(node, state, override); } // An fullAncestor walk is like an ancestor walk, but triggers // the callback on each node -function fullAncestor(node, callback, base, state) { - if (!base) { base = exports.base; } +function fullAncestor(node, callback, baseVisitor, state) { + if (!baseVisitor) { baseVisitor = base; } var ancestors = [];(function c(node, st, override) { var type = override || node.type; - var isNew = node != ancestors[ancestors.length - 1]; + var isNew = node !== ancestors[ancestors.length - 1]; if (isNew) { ancestors.push(node); } - base[type](node, st, c); + baseVisitor[type](node, st, c); if (!override) { callback(node, st || ancestors, ancestors, type); } if (isNew) { ancestors.pop(); } })(node, state); @@ -89,17 +90,17 @@ function fullAncestor(node, callback, base, 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) { +function findNodeAt(node, start, end, test, baseVisitor, state) { + if (!baseVisitor) { baseVisitor = base; } 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) && + { baseVisitor[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); @@ -111,14 +112,14 @@ function findNodeAt(node, start, end, test, base, state) { // Find the innermost node of a given type that contains the given // position. Interface similar to findNodeAt. -function findNodeAround(node, pos, test, base, state) { +function findNodeAround(node, pos, test, baseVisitor, state) { test = makeTest(test); - if (!base) { base = exports.base; } + if (!baseVisitor) { baseVisitor = 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); + baseVisitor[type](node, st, c); if (test(type, node)) { throw new Found(node, st) } })(node, state); } catch (e) { @@ -128,15 +129,15 @@ function findNodeAround(node, pos, test, base, state) { } // Find the outermost matching node after a given position. -function findNodeAfter(node, pos, test, base, state) { +function findNodeAfter(node, pos, test, baseVisitor, state) { test = makeTest(test); - if (!base) { base = exports.base; } + if (!baseVisitor) { baseVisitor = 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); + baseVisitor[type](node, st, c); })(node, state); } catch (e) { if (e instanceof Found) { return e } @@ -145,15 +146,15 @@ function findNodeAfter(node, pos, test, base, state) { } // Find the outermost matching node before a given position. -function findNodeBefore(node, pos, test, base, state) { +function findNodeBefore(node, pos, test, baseVisitor, state) { test = makeTest(test); - if (!base) { base = exports.base; } + if (!baseVisitor) { baseVisitor = base; } var max;(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); + baseVisitor[type](node, st, c); })(node, state); return max } @@ -167,9 +168,8 @@ var create = Object.create || function(proto) { // 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 = create(base); +function make(funcs, baseVisitor) { + var visitor = create(baseVisitor || base); for (var type in funcs) { visitor[type] = funcs[type]; } return visitor } @@ -218,6 +218,15 @@ base.SwitchStatement = function (node, st, c) { } } }; +base.SwitchCase = function (node, st, c) { + if (node.test) { c(node.test, st, "Expression"); } + for (var i = 0, list = node.consequent; i < list.length; i += 1) + { + var cons = list[i]; + + c(cons, st, "Statement"); + } +}; base.ReturnStatement = base.YieldExpression = base.AwaitExpression = function (node, st, c) { if (node.argument) { c(node.argument, st, "Expression"); } }; @@ -229,7 +238,7 @@ base.TryStatement = function (node, st, c) { if (node.finalizer) { c(node.finalizer, st, "Statement"); } }; base.CatchClause = function (node, st, c) { - c(node.param, st, "Pattern"); + if (node.param) { c(node.param, st, "Pattern"); } c(node.body, st, "ScopeBody"); }; base.WhileStatement = base.DoWhileStatement = function (node, st, c) { @@ -248,7 +257,7 @@ base.ForInStatement = base.ForOfStatement = function (node, st, c) { c(node.body, st, "Statement"); }; base.ForInit = function (node, st, c) { - if (node.type == "VariableDeclaration") { c(node, st); } + if (node.type === "VariableDeclaration") { c(node, st); } else { c(node, st, "Expression"); } }; base.DebuggerStatement = ignore; @@ -283,9 +292,9 @@ 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") + if (node.type === "Identifier") { c(node, st, "VariablePattern"); } - else if (node.type == "MemberExpression") + else if (node.type === "MemberExpression") { c(node, st, "MemberPattern"); } else { c(node, st); } @@ -301,11 +310,15 @@ base.ArrayPattern = function (node, st, c) { } }; base.ObjectPattern = function (node, st, c) { - for (var i = 0, list = node.properties; i < list.length; i += 1) - { + for (var i = 0, list = node.properties; i < list.length; i += 1) { var prop = list[i]; - c(prop.value, st, "Pattern"); + if (prop.type === "Property") { + if (prop.computed) { c(prop.key, st, "Expression"); } + c(prop.value, st, "Pattern"); + } else if (prop.type === "RestElement") { + c(prop.argument, st, "Pattern"); + } } }; @@ -367,7 +380,7 @@ base.MemberExpression = function (node, st, c) { }; base.ExportNamedDeclaration = base.ExportDefaultDeclaration = function (node, st, c) { if (node.declaration) - { c(node.declaration, st, node.type == "ExportNamedDeclaration" || node.declaration.id ? "Statement" : "Expression"); } + { 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) { @@ -386,17 +399,20 @@ base.ImportSpecifier = base.ImportDefaultSpecifier = base.ImportNamespaceSpecifi base.TaggedTemplateExpression = function (node, st, c) { c(node.tag, st, "Expression"); - c(node.quasi, st); + c(node.quasi, st, "Expression"); }; 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, list = node.body.body; i < list.length; i += 1) + c(node.body, st); +}; +base.ClassBody = function (node, st, c) { + for (var i = 0, list = node.body; i < list.length; i += 1) { - var item = list[i]; + var elt = list[i]; - c(item, st); + c(elt, st); } }; base.MethodDefinition = base.Property = function (node, st, c) { |