| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @constructor | 6 * @constructor |
| 7 * @param {function(!ESTree.Node)} beforeVisit | 7 * @param {function(!ESTree.Node):(!Object|undefined)} beforeVisit |
| 8 * @param {function(!ESTree.Node)=} afterVisit | 8 * @param {function(!ESTree.Node)=} afterVisit |
| 9 */ | 9 */ |
| 10 WebInspector.ESTreeWalker = function(beforeVisit, afterVisit) | 10 WebInspector.ESTreeWalker = function(beforeVisit, afterVisit) |
| 11 { | 11 { |
| 12 this._beforeVisit = beforeVisit; | 12 this._beforeVisit = beforeVisit; |
| 13 this._afterVisit = afterVisit || new Function(); | 13 this._afterVisit = afterVisit || new Function(); |
| 14 this._walkNulls = false; |
| 14 } | 15 } |
| 15 | 16 |
| 17 /** @typedef {!Object} WebInspector.ESTreeWalker.SkipSubtree */ |
| 16 WebInspector.ESTreeWalker.SkipSubtree = {}; | 18 WebInspector.ESTreeWalker.SkipSubtree = {}; |
| 17 | 19 |
| 18 WebInspector.ESTreeWalker.prototype = { | 20 WebInspector.ESTreeWalker.prototype = { |
| 19 /** | 21 /** |
| 22 * @param {boolean} value |
| 23 */ |
| 24 setWalkNulls: function(value) |
| 25 { |
| 26 this._walkNulls = value; |
| 27 }, |
| 28 |
| 29 /** |
| 20 * @param {!ESTree.Node} ast | 30 * @param {!ESTree.Node} ast |
| 21 */ | 31 */ |
| 22 walk: function(ast) | 32 walk: function(ast) |
| 23 { | 33 { |
| 24 this._innerWalk(ast, null); | 34 this._innerWalk(ast, null); |
| 25 }, | 35 }, |
| 26 | 36 |
| 27 /** | 37 /** |
| 28 * @param {!ESTree.Node} node | 38 * @param {!ESTree.Node} node |
| 29 * @param {?ESTree.Node} parent | 39 * @param {?ESTree.Node} parent |
| 30 */ | 40 */ |
| 31 _innerWalk: function(node, parent) | 41 _innerWalk: function(node, parent) |
| 32 { | 42 { |
| 43 if (!node && parent && this._walkNulls) { |
| 44 node = /** @type {!ESTree.Node} */ ({ |
| 45 type: "Literal", |
| 46 raw: "null", |
| 47 value: null |
| 48 }); |
| 49 } |
| 50 |
| 33 if (!node) | 51 if (!node) |
| 34 return; | 52 return; |
| 35 node.parent = parent; | 53 node.parent = parent; |
| 36 | 54 |
| 37 if (this._beforeVisit.call(null, node) === WebInspector.ESTreeWalker.Ski
pSubtree) { | 55 if (this._beforeVisit.call(null, node) === WebInspector.ESTreeWalker.Ski
pSubtree) { |
| 38 this._afterVisit.call(null, node); | 56 this._afterVisit.call(null, node); |
| 39 return; | 57 return; |
| 40 } | 58 } |
| 41 | 59 |
| 42 var walkOrder = WebInspector.ESTreeWalker._walkOrder[node.type]; | 60 var walkOrder = WebInspector.ESTreeWalker._walkOrder[node.type]; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 "ThrowStatement": ["argument"], | 141 "ThrowStatement": ["argument"], |
| 124 "TryStatement": ["block", "handler", "finalizer"], | 142 "TryStatement": ["block", "handler", "finalizer"], |
| 125 "UnaryExpression": ["argument"], | 143 "UnaryExpression": ["argument"], |
| 126 "UpdateExpression": ["argument"], | 144 "UpdateExpression": ["argument"], |
| 127 "VariableDeclaration": ["declarations"], | 145 "VariableDeclaration": ["declarations"], |
| 128 "VariableDeclarator": ["id", "init"], | 146 "VariableDeclarator": ["id", "init"], |
| 129 "WhileStatement": ["test", "body"], | 147 "WhileStatement": ["test", "body"], |
| 130 "WithStatement": ["object", "body"], | 148 "WithStatement": ["object", "body"], |
| 131 "YieldExpression": ["argument"] | 149 "YieldExpression": ["argument"] |
| 132 } | 150 } |
| OLD | NEW |