| 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)} beforeVisit |
| 8 * @param {function(!ESTree.Node)} afterVisit | 8 * @param {function(!ESTree.Node)} afterVisit |
| 9 */ | 9 */ |
| 10 FormatterWorker.ESTreeWalker = function(beforeVisit, afterVisit) | 10 WebInspector.ESTreeWalker = function(beforeVisit, afterVisit) |
| 11 { | 11 { |
| 12 this._beforeVisit = beforeVisit; | 12 this._beforeVisit = beforeVisit; |
| 13 this._afterVisit = afterVisit; | 13 this._afterVisit = afterVisit; |
| 14 } | 14 } |
| 15 | 15 |
| 16 FormatterWorker.ESTreeWalker.prototype = { | 16 WebInspector.ESTreeWalker.prototype = { |
| 17 /** | 17 /** |
| 18 * @param {!ESTree.Node} ast | 18 * @param {!ESTree.Node} ast |
| 19 */ | 19 */ |
| 20 walk: function(ast) | 20 walk: function(ast) |
| 21 { | 21 { |
| 22 this._innerWalk(ast, null); | 22 this._innerWalk(ast, null); |
| 23 }, | 23 }, |
| 24 | 24 |
| 25 /** | 25 /** |
| 26 * @param {!ESTree.Node} node | 26 * @param {!ESTree.Node} node |
| 27 * @param {?ESTree.Node} parent | 27 * @param {?ESTree.Node} parent |
| 28 */ | 28 */ |
| 29 _innerWalk: function(node, parent) | 29 _innerWalk: function(node, parent) |
| 30 { | 30 { |
| 31 if (!node) | 31 if (!node) |
| 32 return; | 32 return; |
| 33 node.parent = parent; | 33 node.parent = parent; |
| 34 | 34 |
| 35 this._beforeVisit.call(null, node); | 35 this._beforeVisit.call(null, node); |
| 36 | 36 |
| 37 var walkOrder = FormatterWorker.ESTreeWalker._walkOrder[node.type]; | 37 var walkOrder = WebInspector.ESTreeWalker._walkOrder[node.type]; |
| 38 if (!walkOrder) { | 38 if (!walkOrder) { |
| 39 console.error("Walk order not defined for " + node.type); | 39 console.error("Walk order not defined for " + node.type); |
| 40 return; | 40 return; |
| 41 } | 41 } |
| 42 | 42 |
| 43 if (node.type === "TemplateLiteral") { | 43 if (node.type === "TemplateLiteral") { |
| 44 var templateLiteral = /** @type {!ESTree.TemplateLiteralNode} */ (no
de); | 44 var templateLiteral = /** @type {!ESTree.TemplateLiteralNode} */ (no
de); |
| 45 var expressionsLength = templateLiteral.expressions.length; | 45 var expressionsLength = templateLiteral.expressions.length; |
| 46 for (var i = 0; i < expressionsLength; ++i) { | 46 for (var i = 0; i < expressionsLength; ++i) { |
| 47 this._innerWalk(templateLiteral.quasis[i], templateLiteral); | 47 this._innerWalk(templateLiteral.quasis[i], templateLiteral); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 66 * @param {?ESTree.Node} parentNode | 66 * @param {?ESTree.Node} parentNode |
| 67 */ | 67 */ |
| 68 _walkArray: function(nodeArray, parentNode) | 68 _walkArray: function(nodeArray, parentNode) |
| 69 { | 69 { |
| 70 for (var i = 0; i < nodeArray.length; ++i) | 70 for (var i = 0; i < nodeArray.length; ++i) |
| 71 this._innerWalk(nodeArray[i], parentNode); | 71 this._innerWalk(nodeArray[i], parentNode); |
| 72 }, | 72 }, |
| 73 } | 73 } |
| 74 | 74 |
| 75 /** @enum {!Array.<string>} */ | 75 /** @enum {!Array.<string>} */ |
| 76 FormatterWorker.ESTreeWalker._walkOrder = { | 76 WebInspector.ESTreeWalker._walkOrder = { |
| 77 "ArrayExpression": ["elements"], | 77 "ArrayExpression": ["elements"], |
| 78 "ArrowFunctionExpression": ["params", "body"], | 78 "ArrowFunctionExpression": ["params", "body"], |
| 79 "AssignmentExpression": ["left", "right"], | 79 "AssignmentExpression": ["left", "right"], |
| 80 "BinaryExpression": ["left", "right"], | 80 "BinaryExpression": ["left", "right"], |
| 81 "BlockStatement": ["body"], | 81 "BlockStatement": ["body"], |
| 82 "BreakStatement": ["label"], | 82 "BreakStatement": ["label"], |
| 83 "CallExpression": ["callee", "arguments"], | 83 "CallExpression": ["callee", "arguments"], |
| 84 "CatchClause": ["param", "body"], | 84 "CatchClause": ["param", "body"], |
| 85 "ClassBody": ["body"], | 85 "ClassBody": ["body"], |
| 86 "ClassDeclaration": ["id", "superClass", "body"], | 86 "ClassDeclaration": ["id", "superClass", "body"], |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 "ThrowStatement": ["argument"], | 118 "ThrowStatement": ["argument"], |
| 119 "TryStatement": ["block", "handler", "finalizer"], | 119 "TryStatement": ["block", "handler", "finalizer"], |
| 120 "UnaryExpression": ["argument"], | 120 "UnaryExpression": ["argument"], |
| 121 "UpdateExpression": ["argument"], | 121 "UpdateExpression": ["argument"], |
| 122 "VariableDeclaration": ["declarations"], | 122 "VariableDeclaration": ["declarations"], |
| 123 "VariableDeclarator": ["id", "init"], | 123 "VariableDeclarator": ["id", "init"], |
| 124 "WhileStatement": ["test", "body"], | 124 "WhileStatement": ["test", "body"], |
| 125 "WithStatement": ["object", "body"], | 125 "WithStatement": ["object", "body"], |
| 126 "YieldExpression": ["argument"] | 126 "YieldExpression": ["argument"] |
| 127 } | 127 } |
| OLD | NEW |