Web Inspector: JS Pretty Printing: "case" or "default" outside of switch causes unbal...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 7 Mar 2015 06:10:36 +0000 (06:10 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 7 Mar 2015 06:10:36 +0000 (06:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=142428

Patch by Joseph Pecoraro <pecoraro@apple.com> on 2015-03-06
Reviewed by Timothy Hatcher.

* Tools/PrettyPrinting/CodeMirrorFormatters.js:
* UserInterface/Views/CodeMirrorFormatters.js:
Fix "case" and "default" indentation rules to only happen inside a switch.

* Tools/PrettyPrinting/js-tests/switch-case-default-expected.js:
* Tools/PrettyPrinting/js-tests/switch-case-default.js:
Add tests for "case" and "default" nested inside and outside of switches.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@181205 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/Tools/PrettyPrinting/CodeMirrorFormatters.js
Source/WebInspectorUI/Tools/PrettyPrinting/js-tests/switch-case-default-expected.js
Source/WebInspectorUI/Tools/PrettyPrinting/js-tests/switch-case-default.js
Source/WebInspectorUI/UserInterface/Views/CodeMirrorFormatters.js

index f873035..fc60698 100644 (file)
@@ -1,5 +1,20 @@
 2015-03-06  Joseph Pecoraro  <pecoraro@apple.com>
 
+        Web Inspector: JS Pretty Printing: "case" or "default" outside of switch causes unbalanced indentation
+        https://bugs.webkit.org/show_bug.cgi?id=142428
+
+        Reviewed by Timothy Hatcher.
+
+        * Tools/PrettyPrinting/CodeMirrorFormatters.js:
+        * UserInterface/Views/CodeMirrorFormatters.js:
+        Fix "case" and "default" indentation rules to only happen inside a switch.
+
+        * Tools/PrettyPrinting/js-tests/switch-case-default-expected.js:
+        * Tools/PrettyPrinting/js-tests/switch-case-default.js:
+        Add tests for "case" and "default" nested inside and outside of switches.
+
+2015-03-06  Joseph Pecoraro  <pecoraro@apple.com>
+
         Web Inspector: ES6: Improved Support for Iterator Objects
         https://bugs.webkit.org/show_bug.cgi?id=142420
 
index fec8392..71439cd 100644 (file)
@@ -137,7 +137,13 @@ CodeMirror.extendMode("javascript", {
 
     indentAfterToken: function(lastToken, lastContent, token, state, content, isComment)
     {
-        return content === "{" || content === "case" || content === "default";
+        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)
index eb19424..6e2d95e 100644 (file)
@@ -1,8 +1,17 @@
+function Ctor1() {
+    this.case = 1;
+    this.something = 2;
+}
+function Ctor2() {
+    this.default = 1;
+    this.something = 2;
+}
+
 switch (x) {
 case "abc":
-    return 1;
+    return this.default;
 case "def":
-    return 2;
+    return this.case;
 default:
     return 3;
 }
index 49db86f..877d988 100644 (file)
@@ -1,4 +1,7 @@
-switch(x){case "abc":return 1;case "def":return 2;default:return 3;}
+function Ctor1(){this.case=1;this.something=2;}
+function Ctor2(){this.default=1;this.something=2;}
+
+switch(x){case "abc":return this.default;case "def":return this.case;default:return 3;}
 
 switch(x){
   case "abc":
index fec8392..71439cd 100644 (file)
@@ -137,7 +137,13 @@ CodeMirror.extendMode("javascript", {
 
     indentAfterToken: function(lastToken, lastContent, token, state, content, isComment)
     {
-        return content === "{" || content === "case" || content === "default";
+        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)