<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[198815] trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/198815">198815</a></dd>
<dt>Author</dt> <dd>dburkart@apple.com</dd>
<dt>Date</dt> <dd>2016-03-29 17:31:01 -0700 (Tue, 29 Mar 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>Web Inspector: JS PrettyPrinting in do/while loops, "while" should be on the same line as "}" if there was a closing brace
https://bugs.webkit.org/show_bug.cgi?id=117616
<rdar://problem/15796884>
Reviewed by Joseph Pecoraro.
Source/WebInspectorUI:
This patch fixes the formatting of do / while loops in the WebInspector CodeFormatter.
Before:
do {
"x"
}
while (0);
After:
do {
"x"
} while (0);
* UserInterface/Views/CodeMirrorFormatters.js:
(shouldHaveSpaceBeforeToken):
If we encounter a while token and the last token was a closing brace, we *should* add a space if that closing
brace was closing a do block.
(removeLastNewline):
If we encounter a while token and the last token was a closing brace, we *should not* add a newline if that closing
brace closes a do block.
(modifyStateForTokenPre):
We should keep track of the last token that we encountered before entering into a block. We do this by setting
a lastContentBeforeBlock property on openBraceStartMarker / state objects.
In addition, this fixes a bug where we do not pop a state object off of openBraceStartMarkers if our indentCount
is 0. Without doing this, we cannot reliably determine whether or not our while token needs to be inline or not.
LayoutTests:
* inspector/codemirror/prettyprinting-javascript-expected.txt:
* inspector/codemirror/prettyprinting-javascript.html:
* inspector/codemirror/resources/prettyprinting/javascript-tests/do-while-loop-expected.js: Added.
* inspector/codemirror/resources/prettyprinting/javascript-tests/do-while-loop.js: Added.
* inspector/codemirror/resources/prettyprinting/javascript-tests/do-while-within-if-expected.js: Added.
* inspector/codemirror/resources/prettyprinting/javascript-tests/do-while-within-if.js: Added.
* inspector/codemirror/resources/prettyprinting/javascript-tests/if-followed-by-while-expected.js: Added.
* inspector/codemirror/resources/prettyprinting/javascript-tests/if-followed-by-while.js: Added.
* inspector/codemirror/resources/prettyprinting/javascript-tests/if-while-within-do-while-expected.js: Added.
* inspector/codemirror/resources/prettyprinting/javascript-tests/if-while-within-do-while.js: Added.
* inspector/codemirror/resources/prettyprinting/javascript-tests/while-within-do-while-expected.js: Added.
* inspector/codemirror/resources/prettyprinting/javascript-tests/while-within-do-while.js: Added.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsinspectorcodemirrorprettyprintingjavascriptexpectedtxt">trunk/LayoutTests/inspector/codemirror/prettyprinting-javascript-expected.txt</a></li>
<li><a href="#trunkLayoutTestsinspectorcodemirrorprettyprintingjavascripthtml">trunk/LayoutTests/inspector/codemirror/prettyprinting-javascript.html</a></li>
<li><a href="#trunkSourceWebInspectorUIChangeLog">trunk/Source/WebInspectorUI/ChangeLog</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceViewsCodeMirrorFormattersjs">trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorFormatters.js</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsinspectorcodemirrorresourcesprettyprintingjavascripttestsdowhileloopexpectedjs">trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/do-while-loop-expected.js</a></li>
<li><a href="#trunkLayoutTestsinspectorcodemirrorresourcesprettyprintingjavascripttestsdowhileloopjs">trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/do-while-loop.js</a></li>
<li><a href="#trunkLayoutTestsinspectorcodemirrorresourcesprettyprintingjavascripttestsdowhilewithinifexpectedjs">trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/do-while-within-if-expected.js</a></li>
<li><a href="#trunkLayoutTestsinspectorcodemirrorresourcesprettyprintingjavascripttestsdowhilewithinifjs">trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/do-while-within-if.js</a></li>
<li><a href="#trunkLayoutTestsinspectorcodemirrorresourcesprettyprintingjavascripttestsiffollowedbywhileexpectedjs">trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/if-followed-by-while-expected.js</a></li>
<li><a href="#trunkLayoutTestsinspectorcodemirrorresourcesprettyprintingjavascripttestsiffollowedbywhilejs">trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/if-followed-by-while.js</a></li>
<li><a href="#trunkLayoutTestsinspectorcodemirrorresourcesprettyprintingjavascripttestsifwhilewithindowhileexpectedjs">trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/if-while-within-do-while-expected.js</a></li>
<li><a href="#trunkLayoutTestsinspectorcodemirrorresourcesprettyprintingjavascripttestsifwhilewithindowhilejs">trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/if-while-within-do-while.js</a></li>
<li><a href="#trunkLayoutTestsinspectorcodemirrorresourcesprettyprintingjavascripttestswhilewithindowhileexpectedjs">trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/while-within-do-while-expected.js</a></li>
<li><a href="#trunkLayoutTestsinspectorcodemirrorresourcesprettyprintingjavascripttestswhilewithindowhilejs">trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/while-within-do-while.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (198814 => 198815)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-03-30 00:26:00 UTC (rev 198814)
+++ trunk/LayoutTests/ChangeLog        2016-03-30 00:31:01 UTC (rev 198815)
</span><span class="lines">@@ -1,3 +1,24 @@
</span><ins>+2016-03-29 Dana Burkart and Matthew Hanson <dburkart@apple.com>
+
+ Web Inspector: JS PrettyPrinting in do/while loops, "while" should be on the same line as "}" if there was a closing brace
+ https://bugs.webkit.org/show_bug.cgi?id=117616
+ <rdar://problem/15796884>
+
+ Reviewed by Joseph Pecoraro.
+
+ * inspector/codemirror/prettyprinting-javascript-expected.txt:
+ * inspector/codemirror/prettyprinting-javascript.html:
+ * inspector/codemirror/resources/prettyprinting/javascript-tests/do-while-loop-expected.js: Added.
+ * inspector/codemirror/resources/prettyprinting/javascript-tests/do-while-loop.js: Added.
+ * inspector/codemirror/resources/prettyprinting/javascript-tests/do-while-within-if-expected.js: Added.
+ * inspector/codemirror/resources/prettyprinting/javascript-tests/do-while-within-if.js: Added.
+ * inspector/codemirror/resources/prettyprinting/javascript-tests/if-followed-by-while-expected.js: Added.
+ * inspector/codemirror/resources/prettyprinting/javascript-tests/if-followed-by-while.js: Added.
+ * inspector/codemirror/resources/prettyprinting/javascript-tests/if-while-within-do-while-expected.js: Added.
+ * inspector/codemirror/resources/prettyprinting/javascript-tests/if-while-within-do-while.js: Added.
+ * inspector/codemirror/resources/prettyprinting/javascript-tests/while-within-do-while-expected.js: Added.
+ * inspector/codemirror/resources/prettyprinting/javascript-tests/while-within-do-while.js: Added.
+
</ins><span class="cx"> 2016-03-29 Saam barati <sbarati@apple.com>
</span><span class="cx">
</span><span class="cx"> Fix typos in our error messages and remove some trailing periods
</span></span></pre></div>
<a id="trunkLayoutTestsinspectorcodemirrorprettyprintingjavascriptexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/inspector/codemirror/prettyprinting-javascript-expected.txt (198814 => 198815)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/codemirror/prettyprinting-javascript-expected.txt        2016-03-30 00:26:00 UTC (rev 198814)
+++ trunk/LayoutTests/inspector/codemirror/prettyprinting-javascript-expected.txt        2016-03-30 00:31:01 UTC (rev 198815)
</span><span class="lines">@@ -14,3 +14,18 @@
</span><span class="cx"> -- Running test case: CodeMirror.PrettyPrinting.JavaScript.unary-binary-operators.js
</span><span class="cx"> PASS
</span><span class="cx">
</span><ins>+-- Running test case: CodeMirror.PrettyPrinting.JavaScript.do-while-loop.js
+PASS
+
+-- Running test case: CodeMirror.PrettyPrinting.JavaScript.if-followed-by-while.js
+PASS
+
+-- Running test case: CodeMirror.PrettyPrinting.JavaScript.while-within-do-while.js
+PASS
+
+-- Running test case: CodeMirror.PrettyPrinting.JavaScript.if-while-within-do-while.js
+PASS
+
+-- Running test case: CodeMirror.PrettyPrinting.JavaScript.do-while-within-if.js
+PASS
+
</ins></span></pre></div>
<a id="trunkLayoutTestsinspectorcodemirrorprettyprintingjavascripthtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/inspector/codemirror/prettyprinting-javascript.html (198814 => 198815)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/codemirror/prettyprinting-javascript.html        2016-03-30 00:26:00 UTC (rev 198814)
+++ trunk/LayoutTests/inspector/codemirror/prettyprinting-javascript.html        2016-03-30 00:31:01 UTC (rev 198815)
</span><span class="lines">@@ -13,6 +13,11 @@
</span><span class="cx"> "resources/prettyprinting/javascript-tests/single-statement-blocks.js",
</span><span class="cx"> "resources/prettyprinting/javascript-tests/switch-case-default.js",
</span><span class="cx"> "resources/prettyprinting/javascript-tests/unary-binary-operators.js",
</span><ins>+ "resources/prettyprinting/javascript-tests/do-while-loop.js",
+ "resources/prettyprinting/javascript-tests/if-followed-by-while.js",
+ "resources/prettyprinting/javascript-tests/while-within-do-while.js",
+ "resources/prettyprinting/javascript-tests/if-while-within-do-while.js",
+ "resources/prettyprinting/javascript-tests/do-while-within-if.js",
</ins><span class="cx"> ]);
</span><span class="cx">
</span><span class="cx"> suite.runTestCasesAndFinish();
</span></span></pre></div>
<a id="trunkLayoutTestsinspectorcodemirrorresourcesprettyprintingjavascripttestsdowhileloopexpectedjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/do-while-loop-expected.js (0 => 198815)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/do-while-loop-expected.js         (rev 0)
+++ trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/do-while-loop-expected.js        2016-03-30 00:31:01 UTC (rev 198815)
</span><span class="lines">@@ -0,0 +1,4 @@
</span><ins>+do {
+ "x"
+} while (0);
+
</ins></span></pre></div>
<a id="trunkLayoutTestsinspectorcodemirrorresourcesprettyprintingjavascripttestsdowhileloopjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/do-while-loop.js (0 => 198815)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/do-while-loop.js         (rev 0)
+++ trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/do-while-loop.js        2016-03-30 00:31:01 UTC (rev 198815)
</span><span class="lines">@@ -0,0 +1 @@
</span><ins>+do{"x"}while(0);
</ins></span></pre></div>
<a id="trunkLayoutTestsinspectorcodemirrorresourcesprettyprintingjavascripttestsdowhilewithinifexpectedjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/do-while-within-if-expected.js (0 => 198815)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/do-while-within-if-expected.js         (rev 0)
+++ trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/do-while-within-if-expected.js        2016-03-30 00:31:01 UTC (rev 198815)
</span><span class="lines">@@ -0,0 +1,6 @@
</span><ins>+if (true) {
+ do {
+ var x;
+ } while (0);
+}
+
</ins></span></pre></div>
<a id="trunkLayoutTestsinspectorcodemirrorresourcesprettyprintingjavascripttestsdowhilewithinifjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/do-while-within-if.js (0 => 198815)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/do-while-within-if.js         (rev 0)
+++ trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/do-while-within-if.js        2016-03-30 00:31:01 UTC (rev 198815)
</span><span class="lines">@@ -0,0 +1 @@
</span><ins>+if (true) { do {var x;} while (0);}
</ins></span></pre></div>
<a id="trunkLayoutTestsinspectorcodemirrorresourcesprettyprintingjavascripttestsiffollowedbywhileexpectedjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/if-followed-by-while-expected.js (0 => 198815)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/if-followed-by-while-expected.js         (rev 0)
+++ trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/if-followed-by-while-expected.js        2016-03-30 00:31:01 UTC (rev 198815)
</span><span class="lines">@@ -0,0 +1,7 @@
</span><ins>+if (x == 2) {
+ var y
+}
+while (0) {
+ y = 3
+}
+
</ins></span></pre></div>
<a id="trunkLayoutTestsinspectorcodemirrorresourcesprettyprintingjavascripttestsiffollowedbywhilejs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/if-followed-by-while.js (0 => 198815)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/if-followed-by-while.js         (rev 0)
+++ trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/if-followed-by-while.js        2016-03-30 00:31:01 UTC (rev 198815)
</span><span class="lines">@@ -0,0 +1 @@
</span><ins>+if(x==2){var y}while(0){y=3}
</ins></span></pre></div>
<a id="trunkLayoutTestsinspectorcodemirrorresourcesprettyprintingjavascripttestsifwhilewithindowhileexpectedjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/if-while-within-do-while-expected.js (0 => 198815)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/if-while-within-do-while-expected.js         (rev 0)
+++ trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/if-while-within-do-while-expected.js        2016-03-30 00:31:01 UTC (rev 198815)
</span><span class="lines">@@ -0,0 +1,13 @@
</span><ins>+do {
+ if (true) {
+ var x;
+ }
+ while (0) {
+ x = 1;
+ }
+ if (true)
+ var y;
+ while (0)
+ y = 1;
+} while (0);
+
</ins></span></pre></div>
<a id="trunkLayoutTestsinspectorcodemirrorresourcesprettyprintingjavascripttestsifwhilewithindowhilejs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/if-while-within-do-while.js (0 => 198815)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/if-while-within-do-while.js         (rev 0)
+++ trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/if-while-within-do-while.js        2016-03-30 00:31:01 UTC (rev 198815)
</span><span class="lines">@@ -0,0 +1 @@
</span><ins>+do {if (true) {var x;}while (0) {x = 1;}if (true)var y;while (0)y = 1;}while (0);
</ins></span></pre></div>
<a id="trunkLayoutTestsinspectorcodemirrorresourcesprettyprintingjavascripttestswhilewithindowhileexpectedjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/while-within-do-while-expected.js (0 => 198815)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/while-within-do-while-expected.js         (rev 0)
+++ trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/while-within-do-while-expected.js        2016-03-30 00:31:01 UTC (rev 198815)
</span><span class="lines">@@ -0,0 +1,7 @@
</span><ins>+do {
+ var counter = 0;
+ while (counter < 3) {
+ counter += 1;
+ }
+} while (0);
+
</ins></span></pre></div>
<a id="trunkLayoutTestsinspectorcodemirrorresourcesprettyprintingjavascripttestswhilewithindowhilejs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/while-within-do-while.js (0 => 198815)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/while-within-do-while.js         (rev 0)
+++ trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/while-within-do-while.js        2016-03-30 00:31:01 UTC (rev 198815)
</span><span class="lines">@@ -0,0 +1 @@
</span><ins>+do{var counter=0;while(counter<3){counter+=1;}}while(0);
</ins></span></pre></div>
<a id="trunkSourceWebInspectorUIChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/ChangeLog (198814 => 198815)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/ChangeLog        2016-03-30 00:26:00 UTC (rev 198814)
+++ trunk/Source/WebInspectorUI/ChangeLog        2016-03-30 00:31:01 UTC (rev 198815)
</span><span class="lines">@@ -1,3 +1,40 @@
</span><ins>+2016-03-29 Dana Burkart and Matthew Hanson <dburkart@apple.com>
+
+ Web Inspector: JS PrettyPrinting in do/while loops, "while" should be on the same line as "}" if there was a closing brace
+ https://bugs.webkit.org/show_bug.cgi?id=117616
+ <rdar://problem/15796884>
+
+ Reviewed by Joseph Pecoraro.
+
+ This patch fixes the formatting of do / while loops in the WebInspector CodeFormatter.
+
+ Before:
+ do {
+ "x"
+ }
+ while (0);
+
+ After:
+ do {
+ "x"
+ } while (0);
+
+ * UserInterface/Views/CodeMirrorFormatters.js:
+ (shouldHaveSpaceBeforeToken):
+ If we encounter a while token and the last token was a closing brace, we *should* add a space if that closing
+ brace was closing a do block.
+
+ (removeLastNewline):
+ If we encounter a while token and the last token was a closing brace, we *should not* add a newline if that closing
+ brace closes a do block.
+
+ (modifyStateForTokenPre):
+ We should keep track of the last token that we encountered before entering into a block. We do this by setting
+ a lastContentBeforeBlock property on openBraceStartMarker / state objects.
+
+ In addition, this fixes a bug where we do not pop a state object off of openBraceStartMarkers if our indentCount
+ is 0. Without doing this, we cannot reliably determine whether or not our while token needs to be inline or not.
+
</ins><span class="cx"> 2016-03-29 Joseph Pecoraro <pecoraro@apple.com>
</span><span class="cx">
</span><span class="cx"> Web Inspector: REGRESSION: ⌘E and ⌘G text searching does not work
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceViewsCodeMirrorFormattersjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorFormatters.js (198814 => 198815)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorFormatters.js        2016-03-30 00:26:00 UTC (rev 198814)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorFormatters.js        2016-03-30 00:31:01 UTC (rev 198815)
</span><span class="lines">@@ -53,6 +53,8 @@
</span><span class="cx"> if (/\bkeyword\b/.test(token)) { // Most keywords require spaces before them, unless a '}' can come before it.
</span><span class="cx"> if (content === "else" || content === "catch" || content === "finally")
</span><span class="cx"> return lastContent === "}";
</span><ins>+ if (content === "while" && lastContent === "}")
+ return state._jsPrettyPrint.lastContentBeforeBlock === "do";
</ins><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -141,6 +143,8 @@
</span><span class="cx"> if (/\bkeyword\b/.test(token)) {
</span><span class="cx"> if (content === "else" || content === "catch" || content === "finally") // "} else", "} catch", "} finally"
</span><span class="cx"> return lastContent === "}";
</span><ins>+ if (content === "while" && lastContent === "}")
+ return state._jsPrettyPrint.lastContentBeforeBlock === "do";
</ins><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -201,6 +205,7 @@
</span><span class="cx"> openBraceStartMarkers: [], // Keep track of non-single statement blocks.
</span><span class="cx"> openBraceTrackingCount: -1, // Keep track of "{" and "}" in non-single statement blocks.
</span><span class="cx"> unaryOperatorHadLeadingExpr: false, // Try to detect if a unary operator had a leading expression and therefore may be binary.
</span><ins>+ lastContentBeforeBlock: undefined, // Used to detect if this was a do/while.
</ins><span class="cx"> };
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -224,7 +229,7 @@
</span><span class="cx"> if (!isComment && state.lexical.prev && state.lexical.prev.type === "form" && !state.lexical.prev._jsPrettyPrintMarker && (lastContent === ")" || lastContent === "else" || lastContent === "do") && (state.lexical.type !== ")")) {
</span><span class="cx"> if (content === "{") {
</span><span class="cx"> // Save the state at the opening brace so we can return to it when we see "}".
</span><del>- var savedState = {indentCount: state._jsPrettyPrint.indentCount, openBraceTrackingCount: state._jsPrettyPrint.openBraceTrackingCount};
</del><ins>+ var savedState = {indentCount: state._jsPrettyPrint.indentCount, openBraceTrackingCount: state._jsPrettyPrint.openBraceTrackingCount, lastContentBeforeBlock: lastContent};
</ins><span class="cx"> state._jsPrettyPrint.openBraceStartMarkers.push(savedState);
</span><span class="cx"> state._jsPrettyPrint.openBraceTrackingCount = 1;
</span><span class="cx"> } else if (state.lexical.type !== "}") {
</span><span class="lines">@@ -241,7 +246,6 @@
</span><span class="cx">
</span><span class="cx"> // - Leaving:
</span><span class="cx"> // - Preconditions:
</span><del>- // - we must be indented
</del><span class="cx"> // - ignore ";", wait for the next token instead.
</span><span class="cx"> // - Cases:
</span><span class="cx"> // 1. "else"
</span><span class="lines">@@ -250,7 +254,7 @@
</span><span class="cx"> // - dedent to the last "{"
</span><span class="cx"> // 3. Token without a marker on the stack
</span><span class="cx"> // - dedent all the way
</span><del>- else if (state._jsPrettyPrint.indentCount) {
</del><ins>+ else {
</ins><span class="cx"> console.assert(!state._jsPrettyPrint.shouldDedent);
</span><span class="cx"> console.assert(!state._jsPrettyPrint.dedentSize);
</span><span class="cx">
</span><span class="lines">@@ -277,6 +281,7 @@
</span><span class="cx"> state._jsPrettyPrint.shouldDedent = true;
</span><span class="cx"> state._jsPrettyPrint.dedentSize = state._jsPrettyPrint.indentCount - savedState.indentCount;
</span><span class="cx"> state._jsPrettyPrint.openBraceTrackingCount = savedState.openBraceTrackingCount;
</span><ins>+ state._jsPrettyPrint.lastContentBeforeBlock = savedState.lastContentBeforeBlock;
</ins><span class="cx"> } else {
</span><span class="cx"> // Dedent all the way.
</span><span class="cx"> var shouldDedent = true;
</span></span></pre>
</div>
</div>
</body>
</html>