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

Unified Diff: third_party/WebKit/Source/devtools/front_end/formatter_worker/JavaScriptOutline.js

Issue 2466123002: DevTools: reformat front-end code to match chromium style. (Closed)
Patch Set: all done Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/front_end/formatter_worker/JavaScriptOutline.js
diff --git a/third_party/WebKit/Source/devtools/front_end/formatter_worker/JavaScriptOutline.js b/third_party/WebKit/Source/devtools/front_end/formatter_worker/JavaScriptOutline.js
index c9a9347ab22cd6e70ff46dfa672a3efbf7cd84a4..a11b0fa2bd5be7c43a5590d8dd6137b966c100fa 100644
--- a/third_party/WebKit/Source/devtools/front_end/formatter_worker/JavaScriptOutline.js
+++ b/third_party/WebKit/Source/devtools/front_end/formatter_worker/JavaScriptOutline.js
@@ -1,86 +1,81 @@
// Copyright 2016 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.
-
/**
* @param {string} content
*/
-WebInspector.javaScriptOutline = function(content)
-{
- var chunkSize = 100000; // characters per data chunk
- var outlineChunk = [];
- var previousIdentifier = null;
- var previousToken = null;
- var processedChunkCharacters = 0;
- var addedFunction = false;
- var isReadingArguments = false;
- var argumentsText = "";
- var currentFunction = null;
- var tokenizer = new WebInspector.AcornTokenizer(content);
- var AT = WebInspector.AcornTokenizer;
+WebInspector.javaScriptOutline = function(content) {
+ var chunkSize = 100000; // characters per data chunk
+ var outlineChunk = [];
+ var previousIdentifier = null;
+ var previousToken = null;
+ var processedChunkCharacters = 0;
+ var addedFunction = false;
+ var isReadingArguments = false;
+ var argumentsText = '';
+ var currentFunction = null;
+ var tokenizer = new WebInspector.AcornTokenizer(content);
+ var AT = WebInspector.AcornTokenizer;
- while (tokenizer.peekToken()) {
- var token = /** @type {!Acorn.TokenOrComment} */(tokenizer.nextToken());
- if (AT.lineComment(token) || AT.blockComment(token))
- continue;
+ while (tokenizer.peekToken()) {
+ var token = /** @type {!Acorn.TokenOrComment} */ (tokenizer.nextToken());
+ if (AT.lineComment(token) || AT.blockComment(token))
+ continue;
- var tokenValue = content.substring(token.start, token.end);
+ var tokenValue = content.substring(token.start, token.end);
- if (AT.identifier(token) && previousToken && (AT.identifier(previousToken, "get") || AT.identifier(previousToken, "set"))) {
- currentFunction = {
- line: tokenizer.tokenLineStart(),
- column: tokenizer.tokenColumnStart(),
- name : previousToken.value + " " + tokenValue
- };
- addedFunction = true;
- previousIdentifier = null;
- } else if (AT.identifier(token)) {
- previousIdentifier = tokenValue;
- if (tokenValue && previousToken && AT.keyword(previousToken, "function")) {
- // A named function: "function f...".
- currentFunction = {
- line: tokenizer.tokenLineStart(),
- column: tokenizer.tokenColumnStart(),
- name: tokenValue
- };
- addedFunction = true;
- previousIdentifier = null;
- }
- } else if (AT.keyword(token, "function") && previousIdentifier && previousToken && AT.punctuator(previousToken, ":=")) {
- // Anonymous function assigned to an identifier: "...f = function..."
- // or "funcName: function...".
- currentFunction = {
- line: tokenizer.tokenLineStart(),
- column: tokenizer.tokenColumnStart(),
- name: previousIdentifier
- };
- addedFunction = true;
- previousIdentifier = null;
- } else if (AT.punctuator(token, ".") && previousToken && AT.identifier(previousToken))
- previousIdentifier += ".";
- else if (AT.punctuator(token, "(") && addedFunction)
- isReadingArguments = true;
- if (isReadingArguments && tokenValue)
- argumentsText += tokenValue;
+ if (AT.identifier(token) && previousToken &&
+ (AT.identifier(previousToken, 'get') || AT.identifier(previousToken, 'set'))) {
+ currentFunction = {
+ line: tokenizer.tokenLineStart(),
+ column: tokenizer.tokenColumnStart(),
+ name: previousToken.value + ' ' + tokenValue
+ };
+ addedFunction = true;
+ previousIdentifier = null;
+ } else if (AT.identifier(token)) {
+ previousIdentifier = tokenValue;
+ if (tokenValue && previousToken && AT.keyword(previousToken, 'function')) {
+ // A named function: "function f...".
+ currentFunction = {line: tokenizer.tokenLineStart(), column: tokenizer.tokenColumnStart(), name: tokenValue};
+ addedFunction = true;
+ previousIdentifier = null;
+ }
+ } else if (
+ AT.keyword(token, 'function') && previousIdentifier && previousToken && AT.punctuator(previousToken, ':=')) {
+ // Anonymous function assigned to an identifier: "...f = function..."
+ // or "funcName: function...".
+ currentFunction = {
+ line: tokenizer.tokenLineStart(),
+ column: tokenizer.tokenColumnStart(),
+ name: previousIdentifier
+ };
+ addedFunction = true;
+ previousIdentifier = null;
+ } else if (AT.punctuator(token, '.') && previousToken && AT.identifier(previousToken))
+ previousIdentifier += '.';
+ else if (AT.punctuator(token, '(') && addedFunction)
+ isReadingArguments = true;
+ if (isReadingArguments && tokenValue)
+ argumentsText += tokenValue;
- if (AT.punctuator(token, ")") && isReadingArguments) {
- addedFunction = false;
- isReadingArguments = false;
- currentFunction.arguments = argumentsText.replace(/,[\r\n\s]*/g, ", ").replace(/([^,])[\r\n\s]+/g, "$1");
- argumentsText = "";
- outlineChunk.push(currentFunction);
- }
+ if (AT.punctuator(token, ')') && isReadingArguments) {
+ addedFunction = false;
+ isReadingArguments = false;
+ currentFunction.arguments = argumentsText.replace(/,[\r\n\s]*/g, ', ').replace(/([^,])[\r\n\s]+/g, '$1');
+ argumentsText = '';
+ outlineChunk.push(currentFunction);
+ }
- previousToken = token;
- processedChunkCharacters += token.end - token.start;
+ previousToken = token;
+ processedChunkCharacters += token.end - token.start;
- if (processedChunkCharacters >= chunkSize) {
- postMessage({ chunk: outlineChunk, isLastChunk: false });
- outlineChunk = [];
- processedChunkCharacters = 0;
- }
+ if (processedChunkCharacters >= chunkSize) {
+ postMessage({chunk: outlineChunk, isLastChunk: false});
+ outlineChunk = [];
+ processedChunkCharacters = 0;
}
+ }
- postMessage({ chunk: outlineChunk, isLastChunk: true });
+ postMessage({chunk: outlineChunk, isLastChunk: true});
};
-

Powered by Google App Engine
This is Rietveld 408576698