Title: [249751] trunk
Revision
249751
Author
pecor...@apple.com
Date
2019-09-10 21:01:40 -0700 (Tue, 10 Sep 2019)

Log Message

Web Inspector: Remove legacy CodeMirror based pretty printers
https://bugs.webkit.org/show_bug.cgi?id=201624

Reviewed by Devin Rousso.

Source/WebInspectorUI:

* Tools/PrettyPrinting/FormatterDebug.js: Removed.
* Tools/PrettyPrinting/Utilities.js: Removed.
* Tools/PrettyPrinting/codemirror-additions.css: Removed.
* Tools/PrettyPrinting/index.html: Removed.
* Tools/PrettyPrinting/populate/apple.css: Removed.
* UserInterface/Controllers/Formatter.js: Removed.
* UserInterface/Main.html:
* UserInterface/Test.html:
* UserInterface/Views/CodeMirrorFormatters.js: Removed.
* UserInterface/Views/TextEditor.js:
(WI.TextEditor.prototype.prettyPrint):
(WI.TextEditor.prototype._canUseFormatterWorker): Deleted.
(WI.TextEditor.prototype._startCodeMirrorPrettyPrint): Deleted.
* WebInspectorUI.vcxproj/WebInspectorUI.vcxproj:
* WebInspectorUI.vcxproj/WebInspectorUI.vcxproj.filters:

LayoutTests:

* inspector/codemirror/prettyprinting-css-expected.txt: Removed.
* inspector/codemirror/prettyprinting-css.html: Removed.
* inspector/codemirror/prettyprinting-_javascript_-expected.txt: Removed.
* inspector/codemirror/prettyprinting-_javascript_.html: Removed.
* inspector/codemirror/resources/prettyprinting/css-tests/basic-expected.css: Removed.
* inspector/codemirror/resources/prettyprinting/css-tests/basic.css: Removed.
* inspector/codemirror/resources/prettyprinting/css-tests/calc-expected.css: Removed.
* inspector/codemirror/resources/prettyprinting/css-tests/calc.css: Removed.
* inspector/codemirror/resources/prettyprinting/css-tests/gradient-expected.css: Removed.
* inspector/codemirror/resources/prettyprinting/css-tests/gradient.css: Removed.
* inspector/codemirror/resources/prettyprinting/css-tests/keyframes-expected.css: Removed.
* inspector/codemirror/resources/prettyprinting/css-tests/keyframes.css: Removed.
* inspector/codemirror/resources/prettyprinting/css-tests/media-query-expected.css: Removed.
* inspector/codemirror/resources/prettyprinting/css-tests/media-query.css: Removed.
* inspector/codemirror/resources/prettyprinting/css-tests/selectors-expected.css: Removed.
* inspector/codemirror/resources/prettyprinting/css-tests/selectors.css: Removed.
* inspector/codemirror/resources/prettyprinting/css-tests/wrapping-expected.css: Removed.
* inspector/codemirror/resources/prettyprinting/css-tests/wrapping.css: Removed.
* inspector/codemirror/resources/prettyprinting/_javascript_-tests/block-comment-expected.js: Removed.
* inspector/codemirror/resources/prettyprinting/_javascript_-tests/block-comment.js: Removed.
* inspector/codemirror/resources/prettyprinting/_javascript_-tests/do-while-loop-expected.js: Removed.
* inspector/codemirror/resources/prettyprinting/_javascript_-tests/do-while-loop.js: Removed.
* inspector/codemirror/resources/prettyprinting/_javascript_-tests/do-while-within-if-expected.js: Removed.
* inspector/codemirror/resources/prettyprinting/_javascript_-tests/do-while-within-if.js: Removed.
* inspector/codemirror/resources/prettyprinting/_javascript_-tests/if-followed-by-while-expected.js: Removed.
* inspector/codemirror/resources/prettyprinting/_javascript_-tests/if-followed-by-while.js: Removed.
* inspector/codemirror/resources/prettyprinting/_javascript_-tests/if-while-within-do-while-expected.js: Removed.
* inspector/codemirror/resources/prettyprinting/_javascript_-tests/if-while-within-do-while.js: Removed.
* inspector/codemirror/resources/prettyprinting/_javascript_-tests/single-statement-blocks-expected.js: Removed.
* inspector/codemirror/resources/prettyprinting/_javascript_-tests/single-statement-blocks.js: Removed.
* inspector/codemirror/resources/prettyprinting/_javascript_-tests/switch-case-default-expected.js: Removed.
* inspector/codemirror/resources/prettyprinting/_javascript_-tests/switch-case-default.js: Removed.
* inspector/codemirror/resources/prettyprinting/_javascript_-tests/unary-binary-operators-expected.js: Removed.
* inspector/codemirror/resources/prettyprinting/_javascript_-tests/unary-binary-operators.js: Removed.
* inspector/codemirror/resources/prettyprinting/_javascript_-tests/while-within-do-while-expected.js: Removed.
* inspector/codemirror/resources/prettyprinting/_javascript_-tests/while-within-do-while.js: Removed.
* inspector/codemirror/resources/prettyprinting/utilities.js: Removed.

Modified Paths

Removed Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (249750 => 249751)


--- trunk/LayoutTests/ChangeLog	2019-09-11 01:57:06 UTC (rev 249750)
+++ trunk/LayoutTests/ChangeLog	2019-09-11 04:01:40 UTC (rev 249751)
@@ -1,3 +1,48 @@
+2019-09-10  Joseph Pecoraro  <pecor...@apple.com>
+
+        Web Inspector: Remove legacy CodeMirror based pretty printers
+        https://bugs.webkit.org/show_bug.cgi?id=201624
+
+        Reviewed by Devin Rousso.
+
+        * inspector/codemirror/prettyprinting-css-expected.txt: Removed.
+        * inspector/codemirror/prettyprinting-css.html: Removed.
+        * inspector/codemirror/prettyprinting-_javascript_-expected.txt: Removed.
+        * inspector/codemirror/prettyprinting-_javascript_.html: Removed.
+        * inspector/codemirror/resources/prettyprinting/css-tests/basic-expected.css: Removed.
+        * inspector/codemirror/resources/prettyprinting/css-tests/basic.css: Removed.
+        * inspector/codemirror/resources/prettyprinting/css-tests/calc-expected.css: Removed.
+        * inspector/codemirror/resources/prettyprinting/css-tests/calc.css: Removed.
+        * inspector/codemirror/resources/prettyprinting/css-tests/gradient-expected.css: Removed.
+        * inspector/codemirror/resources/prettyprinting/css-tests/gradient.css: Removed.
+        * inspector/codemirror/resources/prettyprinting/css-tests/keyframes-expected.css: Removed.
+        * inspector/codemirror/resources/prettyprinting/css-tests/keyframes.css: Removed.
+        * inspector/codemirror/resources/prettyprinting/css-tests/media-query-expected.css: Removed.
+        * inspector/codemirror/resources/prettyprinting/css-tests/media-query.css: Removed.
+        * inspector/codemirror/resources/prettyprinting/css-tests/selectors-expected.css: Removed.
+        * inspector/codemirror/resources/prettyprinting/css-tests/selectors.css: Removed.
+        * inspector/codemirror/resources/prettyprinting/css-tests/wrapping-expected.css: Removed.
+        * inspector/codemirror/resources/prettyprinting/css-tests/wrapping.css: Removed.
+        * inspector/codemirror/resources/prettyprinting/_javascript_-tests/block-comment-expected.js: Removed.
+        * inspector/codemirror/resources/prettyprinting/_javascript_-tests/block-comment.js: Removed.
+        * inspector/codemirror/resources/prettyprinting/_javascript_-tests/do-while-loop-expected.js: Removed.
+        * inspector/codemirror/resources/prettyprinting/_javascript_-tests/do-while-loop.js: Removed.
+        * inspector/codemirror/resources/prettyprinting/_javascript_-tests/do-while-within-if-expected.js: Removed.
+        * inspector/codemirror/resources/prettyprinting/_javascript_-tests/do-while-within-if.js: Removed.
+        * inspector/codemirror/resources/prettyprinting/_javascript_-tests/if-followed-by-while-expected.js: Removed.
+        * inspector/codemirror/resources/prettyprinting/_javascript_-tests/if-followed-by-while.js: Removed.
+        * inspector/codemirror/resources/prettyprinting/_javascript_-tests/if-while-within-do-while-expected.js: Removed.
+        * inspector/codemirror/resources/prettyprinting/_javascript_-tests/if-while-within-do-while.js: Removed.
+        * inspector/codemirror/resources/prettyprinting/_javascript_-tests/single-statement-blocks-expected.js: Removed.
+        * inspector/codemirror/resources/prettyprinting/_javascript_-tests/single-statement-blocks.js: Removed.
+        * inspector/codemirror/resources/prettyprinting/_javascript_-tests/switch-case-default-expected.js: Removed.
+        * inspector/codemirror/resources/prettyprinting/_javascript_-tests/switch-case-default.js: Removed.
+        * inspector/codemirror/resources/prettyprinting/_javascript_-tests/unary-binary-operators-expected.js: Removed.
+        * inspector/codemirror/resources/prettyprinting/_javascript_-tests/unary-binary-operators.js: Removed.
+        * inspector/codemirror/resources/prettyprinting/_javascript_-tests/while-within-do-while-expected.js: Removed.
+        * inspector/codemirror/resources/prettyprinting/_javascript_-tests/while-within-do-while.js: Removed.
+        * inspector/codemirror/resources/prettyprinting/utilities.js: Removed.
+
 2019-09-10  Chris Dumez  <cdu...@apple.com>
 
         Stop using testRunner.setPrivateBrowsingEnabled_DEPRECATED() in http/tests/cookies/private-cookie-storage.html

Modified: trunk/Source/WebInspectorUI/ChangeLog (249750 => 249751)


--- trunk/Source/WebInspectorUI/ChangeLog	2019-09-11 01:57:06 UTC (rev 249750)
+++ trunk/Source/WebInspectorUI/ChangeLog	2019-09-11 04:01:40 UTC (rev 249751)
@@ -1,3 +1,26 @@
+2019-09-10  Joseph Pecoraro  <pecor...@apple.com>
+
+        Web Inspector: Remove legacy CodeMirror based pretty printers
+        https://bugs.webkit.org/show_bug.cgi?id=201624
+
+        Reviewed by Devin Rousso.
+
+        * Tools/PrettyPrinting/FormatterDebug.js: Removed.
+        * Tools/PrettyPrinting/Utilities.js: Removed.
+        * Tools/PrettyPrinting/codemirror-additions.css: Removed.
+        * Tools/PrettyPrinting/index.html: Removed.
+        * Tools/PrettyPrinting/populate/apple.css: Removed.
+        * UserInterface/Controllers/Formatter.js: Removed.
+        * UserInterface/Main.html:
+        * UserInterface/Test.html:
+        * UserInterface/Views/CodeMirrorFormatters.js: Removed.
+        * UserInterface/Views/TextEditor.js:
+        (WI.TextEditor.prototype.prettyPrint):
+        (WI.TextEditor.prototype._canUseFormatterWorker): Deleted.
+        (WI.TextEditor.prototype._startCodeMirrorPrettyPrint): Deleted.
+        * WebInspectorUI.vcxproj/WebInspectorUI.vcxproj:
+        * WebInspectorUI.vcxproj/WebInspectorUI.vcxproj.filters:
+
 2019-09-09  Joseph Pecoraro  <pecor...@apple.com>
 
         Web Inspector: Dark Mode: Overview Timeline View has jarring white box-shadows in dark mode

Deleted: trunk/Source/WebInspectorUI/UserInterface/Controllers/Formatter.js (249750 => 249751)


--- trunk/Source/WebInspectorUI/UserInterface/Controllers/Formatter.js	2019-09-11 01:57:06 UTC (rev 249750)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/Formatter.js	2019-09-11 04:01:40 UTC (rev 249751)
@@ -1,167 +0,0 @@
-/*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-WI.Formatter = class Formatter
-{
-    constructor(codeMirror, builder)
-    {
-        console.assert(codeMirror);
-        console.assert(builder);
-
-        this._codeMirror = codeMirror;
-        this._builder = builder;
-
-        this._lastToken = null;
-        this._lastContent = "";
-    }
-
-    // Public
-
-    format(from, to)
-    {
-        console.assert(this._builder.originalContent === null);
-        if (this._builder.originalContent !== null)
-            return;
-
-        var outerMode = this._codeMirror.getMode();
-        var content = this._codeMirror.getRange(from, to);
-        var state = CodeMirror.copyState(outerMode, this._codeMirror.getTokenAt(from).state);
-        this._builder.setOriginalContent(content);
-
-        var lineOffset = 0;
-        var lines = content.split("\n");
-        for (var i = 0; i < lines.length; ++i) {
-            var line = lines[i];
-            var startOfNewLine = true;
-            var firstTokenOnLine = true;
-            var stream = new CodeMirror.StringStream(line);
-            while (!stream.eol()) {
-                var innerMode = CodeMirror.innerMode(outerMode, state);
-                var token = outerMode.token(stream, state);
-                var isWhiteSpace = token === null && /^\s*$/.test(stream.current());
-                this._handleToken(innerMode.mode, token, state, stream, lineOffset + stream.start, isWhiteSpace, startOfNewLine, firstTokenOnLine);
-                stream.start = stream.pos;
-                startOfNewLine = false;
-                if (firstTokenOnLine && !isWhiteSpace)
-                    firstTokenOnLine = false;
-            }
-
-            if (firstTokenOnLine)
-                this._handleEmptyLine();
-
-            lineOffset += line.length + 1; // +1 for the "\n" removed in split.
-            this._handleLineEnding(lineOffset - 1); // -1 for the index of the "\n".
-        }
-
-        this._builder.finish();
-    }
-
-    // Private
-
-    _handleToken(mode, token, state, stream, originalPosition, isWhiteSpace, startOfNewLine, firstTokenOnLine)
-    {
-        // String content of the token.
-        var content = stream.current();
-
-        // Start of a new line. Insert a newline to be safe if code was not-ASI safe. These are collapsed.
-        if (startOfNewLine)
-            this._builder.appendNewline();
-
-        // Whitespace. Remove all spaces or collapse to a single space.
-        if (isWhiteSpace) {
-            this._builder.appendSpace();
-            return;
-        }
-
-        // Avoid some hooks for content in comments.
-        var isComment = token && /\bcomment\b/.test(token);
-
-        if (mode.modifyStateForTokenPre)
-            mode.modifyStateForTokenPre(this._lastToken, this._lastContent, token, state, content, isComment);
-
-        // Should we remove the last whitespace?
-        if (this._builder.lastTokenWasWhitespace && mode.removeLastWhitespace(this._lastToken, this._lastContent, token, state, content, isComment))
-            this._builder.removeLastWhitespace();
-
-        // Should we remove the last newline?
-        if (this._builder.lastTokenWasNewline && mode.removeLastNewline(this._lastToken, this._lastContent, token, state, content, isComment, firstTokenOnLine))
-            this._builder.removeLastNewline();
-
-        // Add whitespace after the last token?
-        if (!this._builder.lastTokenWasWhitespace && mode.shouldHaveSpaceAfterLastToken(this._lastToken, this._lastContent, token, state, content, isComment))
-            this._builder.appendSpace();
-
-        // Add whitespace before this token?
-        if (!this._builder.lastTokenWasWhitespace && mode.shouldHaveSpaceBeforeToken(this._lastToken, this._lastContent, token, state, content, isComment))
-            this._builder.appendSpace();
-
-        // Should we dedent before this token?
-        var dedents = mode.dedentsBeforeToken(this._lastToken, this._lastContent, token, state, content, isComment);
-        while (dedents-- > 0)
-            this._builder.dedent();
-
-        // Should we add a newline before this token?
-        if (mode.newlineBeforeToken(this._lastToken, this._lastContent, token, state, content, isComment))
-            this._builder.appendNewline();
-
-        // Should we indent before this token?
-        if (mode.indentBeforeToken(this._lastToken, this._lastContent, token, state, content, isComment))
-            this._builder.indent();
-
-        // Append token.
-        this._builder.appendToken(content, originalPosition);
-
-        // Let the pretty printer update any state it keeps track of.
-        if (mode.modifyStateForTokenPost)
-            mode.modifyStateForTokenPost(this._lastToken, this._lastContent, token, state, content, isComment);
-
-        // Should we indent or dedent after this token?
-        if (!isComment && mode.indentAfterToken(this._lastToken, this._lastContent, token, state, content, isComment))
-            this._builder.indent();
-
-        // Should we add newlines after this token?
-        var newlines = mode.newlinesAfterToken(this._lastToken, this._lastContent, token, state, content, isComment);
-        if (newlines)
-            this._builder.appendMultipleNewlines(newlines);
-
-        // Record this token as the last token.
-        this._lastToken = token;
-        this._lastContent = content;
-    }
-
-    _handleEmptyLine()
-    {
-        // Preserve original whitespace only lines by adding a newline.
-        // However, don't do this if the builder just added multiple newlines.
-        if (!(this._builder.lastTokenWasNewline && this._builder.lastNewlineAppendWasMultiple))
-            this._builder.appendNewline(true);
-    }
-
-    _handleLineEnding(originalNewLinePosition)
-    {
-        // Record the original line ending.
-        this._builder.addOriginalLineEnding(originalNewLinePosition);
-    }
-};

Modified: trunk/Source/WebInspectorUI/UserInterface/Main.html (249750 => 249751)


--- trunk/Source/WebInspectorUI/UserInterface/Main.html	2019-09-11 01:57:06 UTC (rev 249750)
+++ trunk/Source/WebInspectorUI/UserInterface/Main.html	2019-09-11 04:01:40 UTC (rev 249751)
@@ -625,7 +625,6 @@
     <script src=""
     <script src=""
     <script src=""
-    <script src=""
     <script src=""
     <script src=""
     <script src=""
@@ -879,7 +878,6 @@
     <script src=""
     <script src=""
     <script src=""
-    <script src=""
     <script src=""
     <script src=""
     <script src=""

Modified: trunk/Source/WebInspectorUI/UserInterface/Test.html (249750 => 249751)


--- trunk/Source/WebInspectorUI/UserInterface/Test.html	2019-09-11 01:57:06 UTC (rev 249750)
+++ trunk/Source/WebInspectorUI/UserInterface/Test.html	2019-09-11 04:01:40 UTC (rev 249751)
@@ -257,12 +257,10 @@
     <script src=""
     <script src=""
 
-    <script src=""
     <script src=""
     <script src=""
     <script src=""
     <script src=""
-    <script src=""
     <script src=""
     <script src=""
 

Deleted: trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorFormatters.js (249750 => 249751)


--- trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorFormatters.js	2019-09-11 01:57:06 UTC (rev 249750)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorFormatters.js	2019-09-11 04:01:40 UTC (rev 249751)
@@ -1,449 +0,0 @@
-/*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
- * Copyright (C) 2015 Tobias Reiss <tobi+web...@basecode.de>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-// In the inspector token types have been modified to include extra mode information
-// after the actual token type. So we can't do token === "foo". So instead we do
-// /\bfoo\b/.test(token).
-
-CodeMirror.extendMode("_javascript_", {
-    shouldHaveSpaceBeforeToken: function(lastToken, lastContent, token, state, content, isComment)
-    {
-        if (!token) {
-            if (content === "(") // Most keywords like "if (" but not "function(" or "typeof(".
-                return lastToken && /\bkeyword\b/.test(lastToken) && (lastContent !== "function" && lastContent !== "typeof" && lastContent !== "instanceof");
-            if (content === ":") // Ternary.
-                return state.lexical.type === "stat" || state.lexical.type === ")" || state.lexical.type === "]";
-            return false;
-        }
-
-        if (isComment)
-            return true;
-
-        if (/\boperator\b/.test(token)) {
-            if (!lastToken && (content === "+" || content === "-" || content === "~") && (lastContent !== ")" && lastContent !== "]")) // Possible Unary +/-.
-                return false;
-            if (content === "!") // Unary ! should not be confused with "!=".
-                return false;
-            return "+-/*%&&||!===+=-=>=<=?".indexOf(content) >= 0; // Operators.
-        }
-
-        if (/\bkeyword\b/.test(token)) { // Most keywords require spaces before them, unless a '}' can come before it.
-            if (content === "else" || content === "catch" || content === "finally")
-                return lastContent === "}";
-            if (content === "while" && lastContent === "}")
-                return state._jsPrettyPrint.lastContentBeforeBlock === "do";
-            return false;
-        }
-
-        return false;
-    },
-
-    shouldHaveSpaceAfterLastToken: function(lastToken, lastContent, token, state, content, isComment)
-    {
-        if (lastToken && /\bkeyword\b/.test(lastToken)) { // Most keywords require spaces after them, unless a '{' or ';' can come after it.
-            if (lastContent === "else")
-                return true;
-            if (lastContent === "catch")
-                return true;
-            if (lastContent === "return")
-                return content !== ";";
-            if (lastContent === "throw")
-                return true;
-            if (lastContent === "try")
-                return true;
-            if (lastContent === "finally")
-                return true;
-            if (lastContent === "do")
-                return true;
-            return false;
-        }
-
-        if (lastToken && /\bcomment\b/.test(lastToken)) // Embedded /* comment */.
-            return true;
-        if (lastContent === ")") // "){".
-            return content === "{";
-        if (lastContent === ";") // In for loop.
-            return state.lexical.type === ")";
-        if (lastContent === "!") // Unary ! should not be confused with "!=".
-            return false;
-
-        // If this unary operator did not have a leading _expression_ it is probably unary.
-        if ((lastContent === "+" || lastContent === "-" || lastContent === "~") && !state._jsPrettyPrint.unaryOperatorHadLeadingExpr)
-            return false;
-
-        return ",+-/*%&&||:!===+=-=>=<=?".indexOf(lastContent) >= 0; // Operators.
-    },
-
-    newlinesAfterToken: function(lastToken, lastContent, token, state, content, isComment)
-    {
-        if (!token) {
-            if (content === ",") // In object literals, like in {a:1,b:2}, but not in param lists or vardef lists.
-                return state.lexical.type === "}" ? 1 : 0;
-            if (content === ";") // Everywhere except in for loop conditions.
-                return state.lexical.type !== ")" ? 1 : 0;
-            if (content === ":" && state.lexical.type === "}" && state.lexical.prev && state.lexical.prev.type === "form") // Switch case/default.
-                return 1;
-            return content.length === 1 && "{}".indexOf(content) >= 0 ? 1 : 0; // After braces.
-        }
-
-        if (isComment)
-            return 1;
-
-        return 0;
-    },
-
-    removeLastWhitespace: function(lastToken, lastContent, token, state, content, isComment)
-    {
-        return false;
-    },
-
-    removeLastNewline: function(lastToken, lastContent, token, state, content, isComment, firstTokenOnLine)
-    {
-        if (!token) {
-            if (content === "}") // "{}".
-                return lastContent === "{";
-            if (content === ";") // "x = {};" or ";;".
-                return "};".indexOf(lastContent) >= 0;
-            if (content === ":") // Ternary.
-                return lastContent === "}" && (state.lexical.type === "stat" || state.lexical.type === ")" || state.lexical.type === "]");
-            if (",().".indexOf(content) >= 0) // "})", "}.bind", "function() { ... }()", or "}, false)".
-                return lastContent === "}";
-            return false;
-        }
-
-        if (isComment) { // Comment after semicolon.
-            if (!firstTokenOnLine && lastContent === ";")
-                return true;
-            return false;
-        }
-
-        if (/\bkeyword\b/.test(token)) {
-            if (content === "else" || content === "catch" || content === "finally") // "} else", "} catch", "} finally"
-                return lastContent === "}";
-            if (content === "while" && lastContent === "}")
-                return state._jsPrettyPrint.lastContentBeforeBlock === "do";
-            return false;
-        }
-
-        return false;
-    },
-
-    indentAfterToken: function(lastToken, lastContent, token, state, content, isComment)
-    {
-        if (content === "{")
-            return true;
-
-        if (content === "case" || content === "default")
-            return state.lexical.type === "}" && state.lexical.prev && state.lexical.prev.type === "form"; // Switch case/default.
-
-        return false;
-    },
-
-    newlineBeforeToken: function(lastToken, lastContent, token, state, content, isComment)
-    {
-        if (state._jsPrettyPrint.shouldIndent)
-            return true;
-
-        return content === "}" && lastContent !== "{"; // "{}"
-    },
-
-    indentBeforeToken: function(lastToken, lastContent, token, state, content, isComment)
-    {
-        if (state._jsPrettyPrint.shouldIndent)
-            return true;
-
-        return false;
-    },
-
-    dedentsBeforeToken: function(lastToken, lastContent, token, state, content, isComment)
-    {
-        var dedent = 0;
-
-        if (state._jsPrettyPrint.shouldDedent)
-            dedent += state._jsPrettyPrint.dedentSize;
-
-        if (!token && content === "}")
-            dedent += 1;
-        else if (token && /\bkeyword\b/.test(token) && (content === "case" || content === "default"))
-            dedent += 1;
-
-        return dedent;
-    },
-
-    modifyStateForTokenPre: function(lastToken, lastContent, token, state, content, isComment)
-    {
-        if (!state._jsPrettyPrint) {
-            state._jsPrettyPrint = {
-                indentCount: 0,       // How far have we indented because of single statement blocks.
-                shouldIndent: false,  // Signal we should indent on entering a single statement block.
-                shouldDedent: false,  // Signal we should dedent on leaving a single statement block.
-                dedentSize: 0,        // How far we should dedent when leaving a single statement block.
-                lastIfIndentCount: 0, // Keep track of the indent the last time we saw an if without braces.
-                openBraceStartMarkers: [],  // Keep track of non-single statement blocks.
-                openBraceTrackingCount: -1, // Keep track of "{" and "}" in non-single statement blocks.
-                unaryOperatorHadLeadingExpr: false, // Try to detect if a unary operator had a leading _expression_ and therefore may be binary.
-                lastContentBeforeBlock: undefined, // Used to detect if this was a do/while.
-            };
-        }
-
-        // - Entering:
-        //   - Preconditions:
-        //     - last lexical was a "form" we haven't encountered before
-        //     - last content was ")", "else", or "do"
-        //     - current lexical is not ")" (in an _expression_ or condition)
-        //   - Cases:
-        //     1. "{"
-        //       - indent +0
-        //       - save this indent size so when we encounter the "}" we know how far to dedent
-        //     2. "else if"
-        //       - indent +0 and do not signal to add a newline and indent
-        //       - mark the last if location so when we encounter an "else" we know how far to dedent
-        //       - mark the lexical state so we know we are inside a single statement block
-        //     3. Token without brace.
-        //       - indent +1 and signal to add a newline and indent
-        //       - mark the last if location so when we encounter an "else" we know how far to dedent
-        //       - mark the lexical state so we know we are inside a single statement block
-        if (!isComment && state.lexical.prev && state.lexical.prev.type === "form" && !state.lexical.prev._jsPrettyPrintMarker && (lastContent === ")" || lastContent === "else" || lastContent === "do") && (state.lexical.type !== ")")) {
-            if (content === "{") {
-                // Save the state at the opening brace so we can return to it when we see "}".
-                var savedState = {indentCount: state._jsPrettyPrint.indentCount, openBraceTrackingCount: state._jsPrettyPrint.openBraceTrackingCount, lastContentBeforeBlock: lastContent};
-                state._jsPrettyPrint.openBraceStartMarkers.push(savedState);
-                state._jsPrettyPrint.openBraceTrackingCount = 1;
-            } else if (state.lexical.type !== "}") {
-                // Increase the indent count. Signal for a newline and indent if needed.
-                if (!(lastContent === "else" && content === "if")) {
-                    state._jsPrettyPrint.indentCount++;
-                    state._jsPrettyPrint.shouldIndent = true;
-                }
-                state.lexical.prev._jsPrettyPrintMarker = true;
-                if (state._jsPrettyPrint.enteringIf)
-                    state._jsPrettyPrint.lastIfIndentCount = state._jsPrettyPrint.indentCount - 1;
-            }
-        }
-
-        // - Leaving:
-        //   - Preconditions:
-        //     - ignore ";", wait for the next token instead.
-        //   - Cases:
-        //     1. "else"
-        //       - dedent to the last "if"
-        //     2. "}" and all braces we saw are balanced
-        //       - dedent to the last "{"
-        //     3. Token without a marker on the stack
-        //       - dedent all the way
-        else {
-            console.assert(!state._jsPrettyPrint.shouldDedent);
-            console.assert(!state._jsPrettyPrint.dedentSize);
-
-            // Track "{" and "}" to know when the "}" is really closing a block.
-            if (!isComment) {
-                if (content === "{")
-                    state._jsPrettyPrint.openBraceTrackingCount++;
-                else if (content === "}")
-                    state._jsPrettyPrint.openBraceTrackingCount--;
-            }
-
-            if (content === ";") {
-                // Ignore.
-            } else if (content === "else") {
-                // Dedent to the last "if".
-                if (lastContent !== "}") {
-                    state._jsPrettyPrint.shouldDedent = true;
-                    state._jsPrettyPrint.dedentSize = state._jsPrettyPrint.indentCount - state._jsPrettyPrint.lastIfIndentCount;
-                    state._jsPrettyPrint.lastIfIndentCount = 0;
-                }
-            } else if (content === "}" && !state._jsPrettyPrint.openBraceTrackingCount && state._jsPrettyPrint.openBraceStartMarkers.length) {
-                // Dedent to the last "{".
-                var savedState = state._jsPrettyPrint.openBraceStartMarkers.pop();
-                state._jsPrettyPrint.shouldDedent = true;
-                state._jsPrettyPrint.dedentSize = state._jsPrettyPrint.indentCount - savedState.indentCount;
-                state._jsPrettyPrint.openBraceTrackingCount = savedState.openBraceTrackingCount;
-                state._jsPrettyPrint.lastContentBeforeBlock = savedState.lastContentBeforeBlock;
-            } else {
-                // Dedent all the way.
-                var shouldDedent = true;
-                var lexical = state.lexical.prev;
-                while (lexical) {
-                    if (lexical._jsPrettyPrintMarker) {
-                        shouldDedent = false;
-                        break;
-                    }
-                    lexical = lexical.prev;
-                }
-                if (shouldDedent) {
-                    state._jsPrettyPrint.shouldDedent = true;
-                    state._jsPrettyPrint.dedentSize = state._jsPrettyPrint.indentCount;
-                }
-            }
-        }
-
-        // Signal for when we will be entering an if.
-        if (token && state.lexical.type === "form" && state.lexical.prev && state.lexical.prev !== "form" && /\bkeyword\b/.test(token))
-            state._jsPrettyPrint.enteringIf = content === "if";
-    },
-
-    modifyStateForTokenPost: function(lastToken, lastContent, token, state, content, isComment)
-    {
-        if (state._jsPrettyPrint.shouldIndent)
-            state._jsPrettyPrint.shouldIndent = false;
-
-        if (state._jsPrettyPrint.shouldDedent) {
-            state._jsPrettyPrint.indentCount -= state._jsPrettyPrint.dedentSize;
-            state._jsPrettyPrint.dedentSize = 0;
-            state._jsPrettyPrint.shouldDedent = false;
-        }
-
-        if ((content === "+" || content === "-" || content === "~") && (lastContent === ")" || lastContent === "]" || /\b(?:variable|number)\b/.test(lastToken)))
-            state._jsPrettyPrint.unaryOperatorHadLeadingExpr = true;
-        else
-            state._jsPrettyPrint.unaryOperatorHadLeadingExpr = false;
-    }
-});
-
-CodeMirror.extendMode("css", {
-    shouldHaveSpaceBeforeToken: function(lastToken, lastContent, token, state, content, isComment)
-    {
-        if (!token) {
-            if (content === "{")
-                return true;
-            return ">+~-*/".indexOf(content) >= 0; // calc() _expression_ or child/sibling selectors
-        }
-
-        if (isComment)
-            return true;
-
-        if (/\bkeyword\b/.test(token)) {
-            if (content.charAt(0) === "!") // "!important".
-                return true;
-            return false;
-        }
-
-        return false;
-    },
-
-    shouldHaveSpaceAfterLastToken: function(lastToken, lastContent, token, state, content, isComment)
-    {
-        if (!lastToken) {
-            if (lastContent === ",")
-                return true;
-            if (lastContent === ":") // Space in "prop: value" but not in a selectors "a:link" or "div::after" or media queries "(max-device-width:480px)".
-                return state.state === "prop";
-            if (lastContent === ")" && (content !== ")" && content !== ",")) {
-                if (/\bnumber\b/.test(token)) // linear-gradient(rgb(...)0%,rgb(...)100%)
-                    return true;
-                if (state.state === "prop") // -webkit-transform:rotate(...)translate(...);
-                    return true;
-                if (state.state === "media" || state.state === "atBlock_parens") // Space in "not(foo)and" but not at the end of "not(not(foo))"
-                    return true;
-                return false; // color: rgb(...);
-            }
-            return ">+~-*/".indexOf(lastContent) >= 0; // calc() _expression_ or child/sibling selectors
-        }
-
-        if (/\bcomment\b/.test(lastToken))
-            return true;
-
-        if (/\bkeyword\b/.test(lastToken)) // media-query keywords
-            return state.state === "media" || (state.state === "atBlock_parens" && content !== ")");
-
-        return false;
-    },
-
-    newlinesAfterToken: function(lastToken, lastContent, token, state, content, isComment)
-    {
-        if (!token) {
-            if (content === ";")
-                return 1;
-            if (content === ",") { // "a,b,c,...,z{}" rule list at top level or in @media top level and only if the line length will be large.
-                if ((state.state === "top" || state.state === "media") && state._cssPrettyPrint.lineLength > 60) {
-                    state._cssPrettyPrint.lineLength = 0;
-                    return 1;
-                }
-                return 0;
-            }
-            if (content === "{")
-                return 1;
-            if (content === "}") // 2 newlines between rule declarations.
-                return 2;
-            return 0;
-        }
-
-        if (isComment)
-            return 1;
-
-        return 0;
-    },
-
-    removeLastWhitespace: function(lastToken, lastContent, token, state, content, isComment)
-    {
-        return false;
-    },
-
-    removeLastNewline: function(lastToken, lastContent, token, state, content, isComment, firstTokenOnLine)
-    {
-        if (isComment) { // Comment after semicolon.
-            if (!firstTokenOnLine && lastContent === ";")
-                return true;
-            return false;
-        }
-
-        return content === "}" && (lastContent === "{" || lastContent === "}"); // "{}" and "}\n}" when closing @media.
-    },
-
-    indentAfterToken: function(lastToken, lastContent, token, state, content, isComment)
-    {
-        return content === "{";
-    },
-
-    newlineBeforeToken: function(lastToken, lastContent, token, state, content, isComment)
-    {
-        return content === "}" && (lastContent !== "{" && lastContent !== "}"); // "{}" and "}\n}" when closing @media.
-    },
-
-    indentBeforeToken: function(lastToken, lastContent, token, state, content, isComment)
-    {
-        return false;
-    },
-
-    dedentsBeforeToken: function(lastToken, lastContent, token, state, content, isComment)
-    {
-        return content === "}" ? 1 : 0;
-    },
-
-    modifyStateForTokenPost: function(lastToken, lastContent, token, state, content, isComment)
-    {
-        if (!state._cssPrettyPrint)
-            state._cssPrettyPrint = {lineLength: 0};
-
-        // In order insert newlines in selector lists we need keep track of the length of the current line.
-        // This isn't exact line length, only the builder knows that, but it is good enough to get an idea.
-        // If we are at a top level, keep track of the current line length, otherwise we reset to 0.
-        if (!isComment && (state.state === "top" || state.state === "media" || state.state === "pseudo"))
-            state._cssPrettyPrint.lineLength += content.length;
-        else
-            state._cssPrettyPrint.lineLength = 0;
-    }
-});

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/TextEditor.js (249750 => 249751)


--- trunk/Source/WebInspectorUI/UserInterface/Views/TextEditor.js	2019-09-11 01:57:06 UTC (rev 249750)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/TextEditor.js	2019-09-11 04:01:40 UTC (rev 249751)
@@ -853,19 +853,11 @@
 
             if (!pretty)
                 this._undoFormatting(beforePrettyPrintState, resolve);
-            else if (this._canUseFormatterWorker())
+            else
                 this._startWorkerPrettyPrint(beforePrettyPrintState, resolve);
-            else
-                this._startCodeMirrorPrettyPrint(beforePrettyPrintState, resolve);
         });
     }
 
-    _canUseFormatterWorker()
-    {
-        let mode = this._codeMirror.getMode().name;
-        return mode === "_javascript_" || mode === "css";
-    }
-
     _attemptToDetermineMIMEType()
     {
         let startTime = Date.now();
@@ -909,20 +901,6 @@
             workerProxy.formatCSS(sourceText, indentString, includeSourceMapData, formatCallback);
     }
 
-    _startCodeMirrorPrettyPrint(beforePrettyPrintState, callback)
-    {
-        let indentString = WI.indentString();
-        let start = {line: 0, ch: 0};
-        let end = {line: this._codeMirror.lineCount() - 1};
-        let builder = new FormatterContentBuilder(indentString);
-        let formatter = new WI.Formatter(this._codeMirror, builder);
-        formatter.format(start, end);
-
-        let formattedText = builder.formattedContent;
-        let sourceMapData = builder.sourceMapData;
-        this._finishPrettyPrint(beforePrettyPrintState, formattedText, sourceMapData, callback);
-    }
-
     _finishPrettyPrint(beforePrettyPrintState, formattedText, sourceMapData, callback)
     {
         this._codeMirror.operation(() => {

Modified: trunk/Source/WebInspectorUI/WebInspectorUI.vcxproj/WebInspectorUI.vcxproj (249750 => 249751)


--- trunk/Source/WebInspectorUI/WebInspectorUI.vcxproj/WebInspectorUI.vcxproj	2019-09-11 01:57:06 UTC (rev 249750)
+++ trunk/Source/WebInspectorUI/WebInspectorUI.vcxproj/WebInspectorUI.vcxproj	2019-09-11 04:01:40 UTC (rev 249751)
@@ -306,7 +306,6 @@
     <None Include="..\UserInterface\CodeMirrorCompletionController.js" />
     <None Include="..\UserInterface\CodeMirrorDragToAlterNumberController.css" />
     <None Include="..\UserInterface\CodeMirrorDragToAlterNumberController.js" />
-    <None Include="..\UserInterface\CodeMirrorFormatters.js" />
     <None Include="..\UserInterface\CodeMirrorOverrides.css" />
     <None Include="..\UserInterface\CodeMirrorTokenTrackingController.css" />
     <None Include="..\UserInterface\CodeMirrorTokenTrackingController.js" />
@@ -441,7 +440,6 @@
     <None Include="..\UserInterface\FolderizedTreeElement.js" />
     <None Include="..\UserInterface\FontResourceContentView.css" />
     <None Include="..\UserInterface\FontResourceContentView.js" />
-    <None Include="..\UserInterface\Formatter.js" />
     <None Include="..\UserInterface\FormatterContentBuilder.js" />
     <None Include="..\UserInterface\FormatterSourceMap.js" />
     <None Include="..\UserInterface\Frame.js" />

Modified: trunk/Source/WebInspectorUI/WebInspectorUI.vcxproj/WebInspectorUI.vcxproj.filters (249750 => 249751)


--- trunk/Source/WebInspectorUI/WebInspectorUI.vcxproj/WebInspectorUI.vcxproj.filters	2019-09-11 01:57:06 UTC (rev 249750)
+++ trunk/Source/WebInspectorUI/WebInspectorUI.vcxproj/WebInspectorUI.vcxproj.filters	2019-09-11 04:01:40 UTC (rev 249751)
@@ -168,9 +168,6 @@
     <None Include="..\UserInterface\CodeMirrorDragToAlterNumberController.js">
       <Filter>UserInterface</Filter>
     </None>
-    <None Include="..\UserInterface\CodeMirrorFormatters.js">
-      <Filter>UserInterface</Filter>
-    </None>
     <None Include="..\UserInterface\CodeMirrorOverrides.css">
       <Filter>UserInterface</Filter>
     </None>
@@ -510,9 +507,6 @@
     <None Include="..\UserInterface\FontResourceContentView.js">
       <Filter>UserInterface</Filter>
     </None>
-    <None Include="..\UserInterface\Formatter.js">
-      <Filter>UserInterface</Filter>
-    </None>
     <None Include="..\UserInterface\FormatterContentBuilder.js">
       <Filter>UserInterface</Filter>
     </None>
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to