Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/es_tree/ESTreeWalker.js

Issue 1912973002: [DevTools] JSONView parsing smarter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698