Title: [196098] trunk
Revision
196098
Author
[email protected]
Date
2016-02-03 16:56:22 -0800 (Wed, 03 Feb 2016)

Log Message

Web Inspector: JS PrettyPrinting unary - and + issues
https://bugs.webkit.org/show_bug.cgi?id=134007
<rdar://problem/17351953>

Patch by Joseph Pecoraro <[email protected]> on 2016-02-03
Reviewed by Timothy Hatcher.

Source/WebInspectorUI:

* UserInterface/Views/CodeMirrorFormatters.js:
(shouldHaveSpaceBeforeToken):
(shouldHaveSpaceAfterLastToken):
(removeLastNewline):
(modifyStateForTokenPre):
(modifyStateForTokenPost):

LayoutTests:

* inspector/codemirror/prettyprinting-_javascript_-expected.txt:
* inspector/codemirror/prettyprinting-_javascript_.html:
* inspector/codemirror/resources/prettyprinting/_javascript_-tests/unary-binary-operators-expected.js: Added.
* inspector/codemirror/resources/prettyprinting/_javascript_-tests/unary-binary-operators.js: Added.
New tests for unary and some binary operators in _javascript_ pretty printing.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (196097 => 196098)


--- trunk/LayoutTests/ChangeLog	2016-02-04 00:35:33 UTC (rev 196097)
+++ trunk/LayoutTests/ChangeLog	2016-02-04 00:56:22 UTC (rev 196098)
@@ -1,3 +1,17 @@
+2016-02-03  Joseph Pecoraro  <[email protected]>
+
+        Web Inspector: JS PrettyPrinting unary - and + issues
+        https://bugs.webkit.org/show_bug.cgi?id=134007
+        <rdar://problem/17351953>
+
+        Reviewed by Timothy Hatcher.
+
+        * inspector/codemirror/prettyprinting-_javascript_-expected.txt:
+        * inspector/codemirror/prettyprinting-_javascript_.html:
+        * inspector/codemirror/resources/prettyprinting/_javascript_-tests/unary-binary-operators-expected.js: Added.
+        * inspector/codemirror/resources/prettyprinting/_javascript_-tests/unary-binary-operators.js: Added.
+        New tests for unary and some binary operators in _javascript_ pretty printing.
+
 2016-02-03  Brent Fulgham  <[email protected]>
 
         REGRESSION: LayoutTest http/tests/plugins/visible_plugins.html failing on Yosemite WK1

Modified: trunk/LayoutTests/inspector/codemirror/prettyprinting-_javascript_-expected.txt (196097 => 196098)


--- trunk/LayoutTests/inspector/codemirror/prettyprinting-_javascript_-expected.txt	2016-02-04 00:35:33 UTC (rev 196097)
+++ trunk/LayoutTests/inspector/codemirror/prettyprinting-_javascript_-expected.txt	2016-02-04 00:56:22 UTC (rev 196098)
@@ -11,3 +11,6 @@
 -- Running test case: CodeMirror.PrettyPrinting._javascript_.switch-case-default.js
 PASS
 
+-- Running test case: CodeMirror.PrettyPrinting._javascript_.unary-binary-operators.js
+PASS
+

Modified: trunk/LayoutTests/inspector/codemirror/prettyprinting-_javascript_.html (196097 => 196098)


--- trunk/LayoutTests/inspector/codemirror/prettyprinting-_javascript_.html	2016-02-04 00:35:33 UTC (rev 196097)
+++ trunk/LayoutTests/inspector/codemirror/prettyprinting-_javascript_.html	2016-02-04 00:56:22 UTC (rev 196098)
@@ -12,6 +12,7 @@
         "resources/prettyprinting/_javascript_-tests/block-comment.js",
         "resources/prettyprinting/_javascript_-tests/single-statement-blocks.js",
         "resources/prettyprinting/_javascript_-tests/switch-case-default.js",
+        "resources/prettyprinting/_javascript_-tests/unary-binary-operators.js",
     ]);
 
     suite.runTestCasesAndFinish();

Added: trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/_javascript_-tests/unary-binary-operators-expected.js (0 => 196098)


--- trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/_javascript_-tests/unary-binary-operators-expected.js	                        (rev 0)
+++ trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/_javascript_-tests/unary-binary-operators-expected.js	2016-02-04 00:56:22 UTC (rev 196098)
@@ -0,0 +1,45 @@
++1;
+-1;
+~1;
+!1;
+!!1;
+1 + 1 - 1 * 1 / 1 % 1;
+1.2 + 1.2 - 1.2 * 1.2 / 1.2 % 1.2;
+(1 + 1 - 1 * 1 / 1 % 1);
+(1) + (1) - (1) * (1) / (1) % (1);
++(1);
++s;
+-s;
+~s;
+x = 1;
+x = 1e2;
+x = 1 + 1;
+x = 1e2 + 1e2;
+x = x + 1;
+x = x = x;
+x = x[1] + 1;
+x = [1];
+x = (1);
+x = (s);
+x = [1, 1, s];
+foo(1, 1, s);
+x = [1 + 1 - 1 * 1 / 1 % 1, +1, 1 - 1, -1, ~1, -s, s + 1, s - 1, a[1] + 1, a[1] - 1];
+foo(1 + 1 - 1 * 1 / 1 % 1, +1, 1 - 1, -1, ~1, -s, s + 1, s - 1, a[1] + 1, a[1] - 1);
+x = [-1 + 1 * 1 / 1 % 1];
+x = (-1 + 1 * 1 / 1 % 1);
+x = 1 ? +1 : -s;
+x = (1 ? +1 : -s);
+x = [1 ? -1 : +s];
+x = {
+    a: -1,
+    b: +1,
+    c: 1 - 1,
+    d: 1,
+    s: s
+};
+// FIXME: Still broken cases. Codemirror treats adjacent operator characters as one operator. For example:
+// x=+1 // Codemirror treats "=+" as a single operator.
+// x=1?+1:1 // Codemirror treats "?+" as a single operator.
+// x=1+-2+1 // Codemirror treats "+-" as a single operator.
+// x=1-+2+1 // Codemirror treats "-+" as a single operator.
+

Added: trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/_javascript_-tests/unary-binary-operators.js (0 => 196098)


--- trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/_javascript_-tests/unary-binary-operators.js	                        (rev 0)
+++ trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/_javascript_-tests/unary-binary-operators.js	2016-02-04 00:56:22 UTC (rev 196098)
@@ -0,0 +1,38 @@
++1;
+-1;
+~1;
+!1;
+!!1;
+1+1-1*1/1%1;
+1.2+1.2-1.2*1.2/1.2%1.2;
+(1+1-1*1/1%1);
+(1)+(1)-(1)*(1)/(1)%(1);
++(1);
++s;
+-s;
+~s;
+x=1;
+x=1e2;
+x=1+1;
+x=1e2+1e2;
+x=x+1;
+x=x=x;
+x=x[1]+1;
+x=[1];
+x=(1);
+x=(s);
+x=[1,1,s];
+foo(1,1,s);
+x=[1+1-1*1/1%1,+1,1-1,-1,~1,-s,s+1,s-1,a[1]+1,a[1]-1];
+foo(1+1-1*1/1%1,+1,1-1,-1,~1,-s,s+1,s-1,a[1]+1,a[1]-1);
+x=[-1+1*1/1%1];
+x=(-1+1*1/1%1);
+x=1? +1:-s;
+x=(1? +1:-s);
+x=[1? -1:+s];
+x={a:-1,b:+1,c:1-1,d:1,s:s};
+// FIXME: Still broken cases. Codemirror treats adjacent operator characters as one operator. For example:
+// x=+1 // Codemirror treats "=+" as a single operator.
+// x=1?+1:1 // Codemirror treats "?+" as a single operator.
+// x=1+-2+1 // Codemirror treats "+-" as a single operator.
+// x=1-+2+1 // Codemirror treats "-+" as a single operator.

Modified: trunk/Source/WebInspectorUI/ChangeLog (196097 => 196098)


--- trunk/Source/WebInspectorUI/ChangeLog	2016-02-04 00:35:33 UTC (rev 196097)
+++ trunk/Source/WebInspectorUI/ChangeLog	2016-02-04 00:56:22 UTC (rev 196098)
@@ -1,3 +1,18 @@
+2016-02-03  Joseph Pecoraro  <[email protected]>
+
+        Web Inspector: JS PrettyPrinting unary - and + issues
+        https://bugs.webkit.org/show_bug.cgi?id=134007
+        <rdar://problem/17351953>
+
+        Reviewed by Timothy Hatcher.
+
+        * UserInterface/Views/CodeMirrorFormatters.js:
+        (shouldHaveSpaceBeforeToken):
+        (shouldHaveSpaceAfterLastToken):
+        (removeLastNewline):
+        (modifyStateForTokenPre):
+        (modifyStateForTokenPost):
+
 2016-02-03  Dave Hyatt  <[email protected]>
 
         Add hanging-punctuation property to Web Inspector

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorFormatters.js (196097 => 196098)


--- trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorFormatters.js	2016-02-04 00:35:33 UTC (rev 196097)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorFormatters.js	2016-02-04 00:56:22 UTC (rev 196098)
@@ -35,7 +35,7 @@
             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 === ")");
+                return (state.lexical.type === "stat" || state.lexical.type === ")" || state.lexical.type === "]");
             return false;
         }
 
@@ -43,9 +43,11 @@
             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.
+            return "+-/*%&&||!===+=-=>=<=?".indexOf(content) >= 0; // Operators.
         }
 
         if (/\bkeyword\b/.test(token)) { // Most keywords require spaces before them, unless a '}' can come before it.
@@ -86,7 +88,11 @@
         if (lastContent === "!") // Unary ! should not be confused with "!=".
             return false;
 
-        return ",+-/*&&||:!===+=-=>=<=?".indexOf(lastContent) >= 0; // Operators.
+        // 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)
@@ -120,7 +126,7 @@
             if (content === ";") // "x = {};" or ";;".
                 return "};".indexOf(lastContent) >= 0;
             if (content === ":") // Ternary.
-                return lastContent === "}" && (state.lexical.type === "stat" || state.lexical.type === ")");
+                return lastContent === "}" && (state.lexical.type === "stat" || state.lexical.type === ")" || state.lexical.type === "]");
             if (",().".indexOf(content) >= 0) // "})", "}.bind", "function() { ... }()", or "}, false)".
                 return lastContent === "}";
             return false;
@@ -194,6 +200,7 @@
                 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.
             };
         }
 
@@ -303,6 +310,11 @@
             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;
     }
 });
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to