<!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>[196098] 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/196098">196098</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2016-02-03 16:56:22 -0800 (Wed, 03 Feb 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>Web Inspector: JS PrettyPrinting unary - and + issues
https://bugs.webkit.org/show_bug.cgi?id=134007
<rdar://problem/17351953>
Patch by Joseph Pecoraro <pecoraro@apple.com> 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.</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="#trunkLayoutTestsinspectorcodemirrorresourcesprettyprintingjavascripttestsunarybinaryoperatorsexpectedjs">trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/unary-binary-operators-expected.js</a></li>
<li><a href="#trunkLayoutTestsinspectorcodemirrorresourcesprettyprintingjavascripttestsunarybinaryoperatorsjs">trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/unary-binary-operators.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (196097 => 196098)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-02-04 00:35:33 UTC (rev 196097)
+++ trunk/LayoutTests/ChangeLog        2016-02-04 00:56:22 UTC (rev 196098)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2016-02-03 Joseph Pecoraro <pecoraro@apple.com>
+
+ 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.
+
</ins><span class="cx"> 2016-02-03 Brent Fulgham <bfulgham@apple.com>
</span><span class="cx">
</span><span class="cx"> REGRESSION: LayoutTest http/tests/plugins/visible_plugins.html failing on Yosemite WK1
</span></span></pre></div>
<a id="trunkLayoutTestsinspectorcodemirrorprettyprintingjavascriptexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/inspector/codemirror/prettyprinting-javascript-expected.txt (196097 => 196098)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -11,3 +11,6 @@
</span><span class="cx"> -- Running test case: CodeMirror.PrettyPrinting.JavaScript.switch-case-default.js
</span><span class="cx"> PASS
</span><span class="cx">
</span><ins>+-- Running test case: CodeMirror.PrettyPrinting.JavaScript.unary-binary-operators.js
+PASS
+
</ins></span></pre></div>
<a id="trunkLayoutTestsinspectorcodemirrorprettyprintingjavascripthtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/inspector/codemirror/prettyprinting-javascript.html (196097 => 196098)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -12,6 +12,7 @@
</span><span class="cx"> "resources/prettyprinting/javascript-tests/block-comment.js",
</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><ins>+ "resources/prettyprinting/javascript-tests/unary-binary-operators.js",
</ins><span class="cx"> ]);
</span><span class="cx">
</span><span class="cx"> suite.runTestCasesAndFinish();
</span></span></pre></div>
<a id="trunkLayoutTestsinspectorcodemirrorresourcesprettyprintingjavascripttestsunarybinaryoperatorsexpectedjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/unary-binary-operators-expected.js (0 => 196098)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,45 @@
</span><ins>++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.
+
</ins></span></pre></div>
<a id="trunkLayoutTestsinspectorcodemirrorresourcesprettyprintingjavascripttestsunarybinaryoperatorsjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/unary-binary-operators.js (0 => 196098)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,38 @@
</span><ins>++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.
</ins></span></pre></div>
<a id="trunkSourceWebInspectorUIChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/ChangeLog (196097 => 196098)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,3 +1,18 @@
</span><ins>+2016-02-03 Joseph Pecoraro <pecoraro@apple.com>
+
+ 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):
+
</ins><span class="cx"> 2016-02-03 Dave Hyatt <hyatt@apple.com>
</span><span class="cx">
</span><span class="cx"> Add hanging-punctuation property to Web Inspector
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceViewsCodeMirrorFormattersjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorFormatters.js (196097 => 196098)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -35,7 +35,7 @@
</span><span class="cx"> if (content === "(") // Most keywords like "if (" but not "function(" or "typeof(".
</span><span class="cx"> return lastToken && /\bkeyword\b/.test(lastToken) && (lastContent !== "function" && lastContent !== "typeof" && lastContent !== "instanceof");
</span><span class="cx"> if (content === ":") // Ternary.
</span><del>- return (state.lexical.type === "stat" || state.lexical.type === ")");
</del><ins>+ return (state.lexical.type === "stat" || state.lexical.type === ")" || state.lexical.type === "]");
</ins><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -43,9 +43,11 @@
</span><span class="cx"> return true;
</span><span class="cx">
</span><span class="cx"> if (/\boperator\b/.test(token)) {
</span><ins>+ if (!lastToken && (content === "+" || content === "-" || content === "~") && (lastContent !== ")" && lastContent !== "]")) // Possible Unary +/-.
+ return false;
</ins><span class="cx"> if (content === "!") // Unary ! should not be confused with "!=".
</span><span class="cx"> return false;
</span><del>- return "+-/*&&||!===+=-=>=<=?".indexOf(content) >= 0; // Operators.
</del><ins>+ return "+-/*%&&||!===+=-=>=<=?".indexOf(content) >= 0; // Operators.
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> if (/\bkeyword\b/.test(token)) { // Most keywords require spaces before them, unless a '}' can come before it.
</span><span class="lines">@@ -86,7 +88,11 @@
</span><span class="cx"> if (lastContent === "!") // Unary ! should not be confused with "!=".
</span><span class="cx"> return false;
</span><span class="cx">
</span><del>- return ",+-/*&&||:!===+=-=>=<=?".indexOf(lastContent) >= 0; // Operators.
</del><ins>+ // 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.
</ins><span class="cx"> },
</span><span class="cx">
</span><span class="cx"> newlinesAfterToken: function(lastToken, lastContent, token, state, content, isComment)
</span><span class="lines">@@ -120,7 +126,7 @@
</span><span class="cx"> if (content === ";") // "x = {};" or ";;".
</span><span class="cx"> return "};".indexOf(lastContent) >= 0;
</span><span class="cx"> if (content === ":") // Ternary.
</span><del>- return lastContent === "}" && (state.lexical.type === "stat" || state.lexical.type === ")");
</del><ins>+ return lastContent === "}" && (state.lexical.type === "stat" || state.lexical.type === ")" || state.lexical.type === "]");
</ins><span class="cx"> if (",().".indexOf(content) >= 0) // "})", "}.bind", "function() { ... }()", or "}, false)".
</span><span class="cx"> return lastContent === "}";
</span><span class="cx"> return false;
</span><span class="lines">@@ -194,6 +200,7 @@
</span><span class="cx"> lastIfIndentCount: 0, // Keep track of the indent the last time we saw an if without braces.
</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><ins>+ unaryOperatorHadLeadingExpr: false, // Try to detect if a unary operator had a leading expression and therefore may be binary.
</ins><span class="cx"> };
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -303,6 +310,11 @@
</span><span class="cx"> state._jsPrettyPrint.dedentSize = 0;
</span><span class="cx"> state._jsPrettyPrint.shouldDedent = false;
</span><span class="cx"> }
</span><ins>+
+ if ((content === "+" || content === "-" || content === "~") && (lastContent === ")" || lastContent === "]" || /\b(?:variable|number)\b/.test(lastToken)))
+ state._jsPrettyPrint.unaryOperatorHadLeadingExpr = true;
+ else
+ state._jsPrettyPrint.unaryOperatorHadLeadingExpr = false;
</ins><span class="cx"> }
</span><span class="cx"> });
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>