Web Inspector: JS PrettyPrinting in do/while loops, "while" should be on the same...
authordburkart@apple.com <dburkart@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Mar 2016 00:31:01 +0000 (00:31 +0000)
committerdburkart@apple.com <dburkart@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Mar 2016 00:31:01 +0000 (00:31 +0000)
commit52f676095c840cba96c2e38fda279d5489c49225
tree5d389571c950117f77b4c6648ad97d75f46d8f32
parentede1ab35699f2bd41cca95befcdbec637875b8c3
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.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@198815 268f45cc-cd09-0410-ab3c-d52691b4dbfc
15 files changed:
LayoutTests/ChangeLog
LayoutTests/inspector/codemirror/prettyprinting-javascript-expected.txt
LayoutTests/inspector/codemirror/prettyprinting-javascript.html
LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/do-while-loop-expected.js [new file with mode: 0644]
LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/do-while-loop.js [new file with mode: 0644]
LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/do-while-within-if-expected.js [new file with mode: 0644]
LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/do-while-within-if.js [new file with mode: 0644]
LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/if-followed-by-while-expected.js [new file with mode: 0644]
LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/if-followed-by-while.js [new file with mode: 0644]
LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/if-while-within-do-while-expected.js [new file with mode: 0644]
LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/if-while-within-do-while.js [new file with mode: 0644]
LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/while-within-do-while-expected.js [new file with mode: 0644]
LayoutTests/inspector/codemirror/resources/prettyprinting/javascript-tests/while-within-do-while.js [new file with mode: 0644]
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Views/CodeMirrorFormatters.js