| Index: third_party/WebKit/Source/devtools/front_end/formatter_worker/ESTreeWalker.js
|
| diff --git a/third_party/WebKit/Source/devtools/front_end/formatter_worker/ESTreeWalker.js b/third_party/WebKit/Source/devtools/front_end/formatter_worker/ESTreeWalker.js
|
| index c42e7878e41ddc547dbb49b3cdfb42259e197e03..84aea297ade03517a22580621f4ecfbfb92feb66 100644
|
| --- a/third_party/WebKit/Source/devtools/front_end/formatter_worker/ESTreeWalker.js
|
| +++ b/third_party/WebKit/Source/devtools/front_end/formatter_worker/ESTreeWalker.js
|
| @@ -1,151 +1,145 @@
|
| // Copyright (c) 2014 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
| -
|
| /**
|
| - * @constructor
|
| - * @param {function(!ESTree.Node):(!Object|undefined)} beforeVisit
|
| - * @param {function(!ESTree.Node)=} afterVisit
|
| + * @unrestricted
|
| */
|
| -WebInspector.ESTreeWalker = function(beforeVisit, afterVisit)
|
| -{
|
| +WebInspector.ESTreeWalker = class {
|
| + /**
|
| + * @param {function(!ESTree.Node):(!Object|undefined)} beforeVisit
|
| + * @param {function(!ESTree.Node)=} afterVisit
|
| + */
|
| + constructor(beforeVisit, afterVisit) {
|
| this._beforeVisit = beforeVisit;
|
| this._afterVisit = afterVisit || new Function();
|
| this._walkNulls = false;
|
| -};
|
| -
|
| -/** @typedef {!Object} WebInspector.ESTreeWalker.SkipSubtree */
|
| -WebInspector.ESTreeWalker.SkipSubtree = {};
|
| + }
|
|
|
| -WebInspector.ESTreeWalker.prototype = {
|
| - /**
|
| - * @param {boolean} value
|
| - */
|
| - setWalkNulls: function(value)
|
| - {
|
| - this._walkNulls = value;
|
| - },
|
| + /**
|
| + * @param {boolean} value
|
| + */
|
| + setWalkNulls(value) {
|
| + this._walkNulls = value;
|
| + }
|
|
|
| - /**
|
| - * @param {!ESTree.Node} ast
|
| - */
|
| - walk: function(ast)
|
| - {
|
| - this._innerWalk(ast, null);
|
| - },
|
| + /**
|
| + * @param {!ESTree.Node} ast
|
| + */
|
| + walk(ast) {
|
| + this._innerWalk(ast, null);
|
| + }
|
|
|
| - /**
|
| - * @param {!ESTree.Node} node
|
| - * @param {?ESTree.Node} parent
|
| - */
|
| - _innerWalk: function(node, parent)
|
| - {
|
| - if (!node && parent && this._walkNulls) {
|
| - node = /** @type {!ESTree.Node} */ ({
|
| - type: "Literal",
|
| - raw: "null",
|
| - value: null
|
| - });
|
| - }
|
| + /**
|
| + * @param {!ESTree.Node} node
|
| + * @param {?ESTree.Node} parent
|
| + */
|
| + _innerWalk(node, parent) {
|
| + if (!node && parent && this._walkNulls) {
|
| + var result = /** @type {!Object} */ ({raw: 'null', value: null});
|
| + result.type = 'Literal';
|
| + node = /** @type {!ESTree.Node} */ (result);
|
| + }
|
|
|
| - if (!node)
|
| - return;
|
| - node.parent = parent;
|
| + if (!node)
|
| + return;
|
| + node.parent = parent;
|
|
|
| - if (this._beforeVisit.call(null, node) === WebInspector.ESTreeWalker.SkipSubtree) {
|
| - this._afterVisit.call(null, node);
|
| - return;
|
| - }
|
| + if (this._beforeVisit.call(null, node) === WebInspector.ESTreeWalker.SkipSubtree) {
|
| + this._afterVisit.call(null, node);
|
| + return;
|
| + }
|
|
|
| - var walkOrder = WebInspector.ESTreeWalker._walkOrder[node.type];
|
| - if (!walkOrder) {
|
| - console.error("Walk order not defined for " + node.type);
|
| - return;
|
| - }
|
| + var walkOrder = WebInspector.ESTreeWalker._walkOrder[node.type];
|
| + if (!walkOrder) {
|
| + console.error('Walk order not defined for ' + node.type);
|
| + return;
|
| + }
|
|
|
| - if (node.type === "TemplateLiteral") {
|
| - var templateLiteral = /** @type {!ESTree.TemplateLiteralNode} */ (node);
|
| - var expressionsLength = templateLiteral.expressions.length;
|
| - for (var i = 0; i < expressionsLength; ++i) {
|
| - this._innerWalk(templateLiteral.quasis[i], templateLiteral);
|
| - this._innerWalk(templateLiteral.expressions[i], templateLiteral);
|
| - }
|
| - this._innerWalk(templateLiteral.quasis[expressionsLength], templateLiteral);
|
| - } else {
|
| - for (var i = 0; i < walkOrder.length; ++i) {
|
| - var entity = node[walkOrder[i]];
|
| - if (Array.isArray(entity))
|
| - this._walkArray(entity, node);
|
| - else
|
| - this._innerWalk(entity, node);
|
| - }
|
| - }
|
| + if (node.type === 'TemplateLiteral') {
|
| + var templateLiteral = /** @type {!ESTree.TemplateLiteralNode} */ (node);
|
| + var expressionsLength = templateLiteral.expressions.length;
|
| + for (var i = 0; i < expressionsLength; ++i) {
|
| + this._innerWalk(templateLiteral.quasis[i], templateLiteral);
|
| + this._innerWalk(templateLiteral.expressions[i], templateLiteral);
|
| + }
|
| + this._innerWalk(templateLiteral.quasis[expressionsLength], templateLiteral);
|
| + } else {
|
| + for (var i = 0; i < walkOrder.length; ++i) {
|
| + var entity = node[walkOrder[i]];
|
| + if (Array.isArray(entity))
|
| + this._walkArray(entity, node);
|
| + else
|
| + this._innerWalk(entity, node);
|
| + }
|
| + }
|
|
|
| - this._afterVisit.call(null, node);
|
| - },
|
| + this._afterVisit.call(null, node);
|
| + }
|
|
|
| - /**
|
| - * @param {!Array.<!ESTree.Node>} nodeArray
|
| - * @param {?ESTree.Node} parentNode
|
| - */
|
| - _walkArray: function(nodeArray, parentNode)
|
| - {
|
| - for (var i = 0; i < nodeArray.length; ++i)
|
| - this._innerWalk(nodeArray[i], parentNode);
|
| - },
|
| + /**
|
| + * @param {!Array.<!ESTree.Node>} nodeArray
|
| + * @param {?ESTree.Node} parentNode
|
| + */
|
| + _walkArray(nodeArray, parentNode) {
|
| + for (var i = 0; i < nodeArray.length; ++i)
|
| + this._innerWalk(nodeArray[i], parentNode);
|
| + }
|
| };
|
|
|
| +/** @typedef {!Object} WebInspector.ESTreeWalker.SkipSubtree */
|
| +WebInspector.ESTreeWalker.SkipSubtree = {};
|
| +
|
| /** @enum {!Array.<string>} */
|
| WebInspector.ESTreeWalker._walkOrder = {
|
| - "ArrayExpression": ["elements"],
|
| - "ArrowFunctionExpression": ["params", "body"],
|
| - "AssignmentExpression": ["left", "right"],
|
| - "BinaryExpression": ["left", "right"],
|
| - "BlockStatement": ["body"],
|
| - "BreakStatement": ["label"],
|
| - "CallExpression": ["callee", "arguments"],
|
| - "CatchClause": ["param", "body"],
|
| - "ClassBody": ["body"],
|
| - "ClassDeclaration": ["id", "superClass", "body"],
|
| - "ClassExpression": ["id", "superClass", "body"],
|
| - "ConditionalExpression": ["test", "consequent", "alternate"],
|
| - "ContinueStatement": ["label"],
|
| - "DebuggerStatement": [],
|
| - "DoWhileStatement": ["body", "test"],
|
| - "EmptyStatement": [],
|
| - "ExpressionStatement": ["expression"],
|
| - "ForInStatement": ["left", "right", "body"],
|
| - "ForOfStatement": ["left", "right", "body"],
|
| - "ForStatement": ["init", "test", "update", "body"],
|
| - "FunctionDeclaration": ["id", "params", "body"],
|
| - "FunctionExpression": ["id", "params", "body"],
|
| - "Identifier": [],
|
| - "IfStatement": ["test", "consequent", "alternate"],
|
| - "LabeledStatement": ["label", "body"],
|
| - "Literal": [],
|
| - "LogicalExpression": ["left", "right"],
|
| - "MemberExpression": ["object", "property"],
|
| - "MethodDefinition": ["key", "value"],
|
| - "NewExpression": ["callee", "arguments"],
|
| - "ObjectExpression": ["properties"],
|
| - "Program": ["body"],
|
| - "Property": ["key", "value"],
|
| - "ReturnStatement": ["argument"],
|
| - "SequenceExpression": ["expressions"],
|
| - "Super": [],
|
| - "SwitchCase": ["test", "consequent"],
|
| - "SwitchStatement": ["discriminant", "cases"],
|
| - "TaggedTemplateExpression": ["tag", "quasi"],
|
| - "TemplateElement": [],
|
| - "TemplateLiteral": ["quasis", "expressions"],
|
| - "ThisExpression": [],
|
| - "ThrowStatement": ["argument"],
|
| - "TryStatement": ["block", "handler", "finalizer"],
|
| - "UnaryExpression": ["argument"],
|
| - "UpdateExpression": ["argument"],
|
| - "VariableDeclaration": ["declarations"],
|
| - "VariableDeclarator": ["id", "init"],
|
| - "WhileStatement": ["test", "body"],
|
| - "WithStatement": ["object", "body"],
|
| - "YieldExpression": ["argument"]
|
| + 'ArrayExpression': ['elements'],
|
| + 'ArrowFunctionExpression': ['params', 'body'],
|
| + 'AssignmentExpression': ['left', 'right'],
|
| + 'BinaryExpression': ['left', 'right'],
|
| + 'BlockStatement': ['body'],
|
| + 'BreakStatement': ['label'],
|
| + 'CallExpression': ['callee', 'arguments'],
|
| + 'CatchClause': ['param', 'body'],
|
| + 'ClassBody': ['body'],
|
| + 'ClassDeclaration': ['id', 'superClass', 'body'],
|
| + 'ClassExpression': ['id', 'superClass', 'body'],
|
| + 'ConditionalExpression': ['test', 'consequent', 'alternate'],
|
| + 'ContinueStatement': ['label'],
|
| + 'DebuggerStatement': [],
|
| + 'DoWhileStatement': ['body', 'test'],
|
| + 'EmptyStatement': [],
|
| + 'ExpressionStatement': ['expression'],
|
| + 'ForInStatement': ['left', 'right', 'body'],
|
| + 'ForOfStatement': ['left', 'right', 'body'],
|
| + 'ForStatement': ['init', 'test', 'update', 'body'],
|
| + 'FunctionDeclaration': ['id', 'params', 'body'],
|
| + 'FunctionExpression': ['id', 'params', 'body'],
|
| + 'Identifier': [],
|
| + 'IfStatement': ['test', 'consequent', 'alternate'],
|
| + 'LabeledStatement': ['label', 'body'],
|
| + 'Literal': [],
|
| + 'LogicalExpression': ['left', 'right'],
|
| + 'MemberExpression': ['object', 'property'],
|
| + 'MethodDefinition': ['key', 'value'],
|
| + 'NewExpression': ['callee', 'arguments'],
|
| + 'ObjectExpression': ['properties'],
|
| + 'Program': ['body'],
|
| + 'Property': ['key', 'value'],
|
| + 'ReturnStatement': ['argument'],
|
| + 'SequenceExpression': ['expressions'],
|
| + 'Super': [],
|
| + 'SwitchCase': ['test', 'consequent'],
|
| + 'SwitchStatement': ['discriminant', 'cases'],
|
| + 'TaggedTemplateExpression': ['tag', 'quasi'],
|
| + 'TemplateElement': [],
|
| + 'TemplateLiteral': ['quasis', 'expressions'],
|
| + 'ThisExpression': [],
|
| + 'ThrowStatement': ['argument'],
|
| + 'TryStatement': ['block', 'handler', 'finalizer'],
|
| + 'UnaryExpression': ['argument'],
|
| + 'UpdateExpression': ['argument'],
|
| + 'VariableDeclaration': ['declarations'],
|
| + 'VariableDeclarator': ['id', 'init'],
|
| + 'WhileStatement': ['test', 'body'],
|
| + 'WithStatement': ['object', 'body'],
|
| + 'YieldExpression': ['argument']
|
| };
|
|
|