| Index: third_party/WebKit/Source/devtools/front_end/formatter_worker/FormatterWorker.js
|
| diff --git a/third_party/WebKit/Source/devtools/front_end/formatter_worker/FormatterWorker.js b/third_party/WebKit/Source/devtools/front_end/formatter_worker/FormatterWorker.js
|
| index 37014ddcfc467fcdfb9099eb1d9ffe47a2fc3e32..2c8fd460578b23d61b7e29c7f08c1b2068a97a12 100644
|
| --- a/third_party/WebKit/Source/devtools/front_end/formatter_worker/FormatterWorker.js
|
| +++ b/third_party/WebKit/Source/devtools/front_end/formatter_worker/FormatterWorker.js
|
| @@ -131,11 +131,11 @@ WebInspector.evaluatableJavaScriptSubstring = function(content)
|
| */
|
| WebInspector.javaScriptIdentifiers = function(content)
|
| {
|
| - var root = acorn.parse(content, {});
|
| + var root = acorn.parse(content, { ranges: false, ecmaVersion: 6 });
|
| +
|
| /** @type {!Array<!ESTree.Node>} */
|
| var identifiers = [];
|
| - var functionDeclarationCounter = 0;
|
| - var walker = new WebInspector.ESTreeWalker(beforeVisit, afterVisit);
|
| + var walker = new WebInspector.ESTreeWalker(beforeVisit);
|
|
|
| /**
|
| * @param {!ESTree.Node} node
|
| @@ -143,7 +143,7 @@ WebInspector.javaScriptIdentifiers = function(content)
|
| */
|
| function isFunction(node)
|
| {
|
| - return node.type === "FunctionDeclaration" || node.type === "FunctionExpression";
|
| + return node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression";
|
| }
|
|
|
| /**
|
| @@ -151,29 +151,29 @@ WebInspector.javaScriptIdentifiers = function(content)
|
| */
|
| function beforeVisit(node)
|
| {
|
| - if (isFunction(node))
|
| - functionDeclarationCounter++;
|
| + if (isFunction(node)) {
|
| + if (node.id)
|
| + identifiers.push(node.id);
|
| + return WebInspector.ESTreeWalker.SkipSubtree;
|
| + }
|
|
|
| - if (functionDeclarationCounter > 1)
|
| + if (node.type !== "Identifier")
|
| return;
|
|
|
| - if (isFunction(node) && node.params)
|
| - identifiers.pushAll(node.params);
|
| -
|
| - if (node.type === "VariableDeclarator")
|
| - identifiers.push(/** @type {!ESTree.Node} */(node.id));
|
| + if (node.parent && node.parent.type === "MemberExpression" && node.parent.property === node && !node.parent.computed)
|
| + return;
|
| + identifiers.push(node);
|
| }
|
|
|
| - /**
|
| - * @param {!ESTree.Node} node
|
| - */
|
| - function afterVisit(node)
|
| - {
|
| - if (isFunction(node))
|
| - functionDeclarationCounter--;
|
| + if (!root || root.type !== "Program" || root.body.length !== 1 || !isFunction(root.body[0])) {
|
| + postMessage([]);
|
| + return;
|
| }
|
|
|
| - walker.walk(root);
|
| + var functionNode = root.body[0];
|
| + for (var param of functionNode.params)
|
| + walker.walk(param);
|
| + walker.walk(functionNode.body);
|
| var reduced = identifiers.map(id => ({name: id.name, offset: id.start}));
|
| postMessage(reduced);
|
| }
|
|
|