Changeset 196098 in webkit


Ignore:
Timestamp:
Feb 3, 2016 4:56:22 PM (8 years ago)
Author:
commit-queue@webkit.org
Message:

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

Patch by Joseph Pecoraro <Joseph Pecoraro> 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.

Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r196084 r196098  
     12016-02-03  Joseph Pecoraro  <pecoraro@apple.com>
     2
     3        Web Inspector: JS PrettyPrinting unary - and + issues
     4        https://bugs.webkit.org/show_bug.cgi?id=134007
     5        <rdar://problem/17351953>
     6
     7        Reviewed by Timothy Hatcher.
     8
     9        * inspector/codemirror/prettyprinting-javascript-expected.txt:
     10        * inspector/codemirror/prettyprinting-javascript.html:
     11        * inspector/codemirror/resources/prettyprinting/javascript-tests/unary-binary-operators-expected.js: Added.
     12        * inspector/codemirror/resources/prettyprinting/javascript-tests/unary-binary-operators.js: Added.
     13        New tests for unary and some binary operators in JavaScript pretty printing.
     14
    1152016-02-03  Brent Fulgham  <bfulgham@apple.com>
    216
  • trunk/LayoutTests/inspector/codemirror/prettyprinting-javascript-expected.txt

    r189500 r196098  
    1212PASS
    1313
     14-- Running test case: CodeMirror.PrettyPrinting.JavaScript.unary-binary-operators.js
     15PASS
     16
  • trunk/LayoutTests/inspector/codemirror/prettyprinting-javascript.html

    r189500 r196098  
    1313        "resources/prettyprinting/javascript-tests/single-statement-blocks.js",
    1414        "resources/prettyprinting/javascript-tests/switch-case-default.js",
     15        "resources/prettyprinting/javascript-tests/unary-binary-operators.js",
    1516    ]);
    1617
  • trunk/Source/WebInspectorUI/ChangeLog

    r196076 r196098  
     12016-02-03  Joseph Pecoraro  <pecoraro@apple.com>
     2
     3        Web Inspector: JS PrettyPrinting unary - and + issues
     4        https://bugs.webkit.org/show_bug.cgi?id=134007
     5        <rdar://problem/17351953>
     6
     7        Reviewed by Timothy Hatcher.
     8
     9        * UserInterface/Views/CodeMirrorFormatters.js:
     10        (shouldHaveSpaceBeforeToken):
     11        (shouldHaveSpaceAfterLastToken):
     12        (removeLastNewline):
     13        (modifyStateForTokenPre):
     14        (modifyStateForTokenPost):
     15
    1162016-02-03  Dave Hyatt  <hyatt@apple.com>
    217
  • trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorFormatters.js

    r188325 r196098  
    3636                return lastToken && /\bkeyword\b/.test(lastToken) && (lastContent !== "function" && lastContent !== "typeof" && lastContent !== "instanceof");
    3737            if (content === ":") // Ternary.
    38                 return (state.lexical.type === "stat" || state.lexical.type === ")");
     38                return (state.lexical.type === "stat" || state.lexical.type === ")" || state.lexical.type === "]");
    3939            return false;
    4040        }
     
    4444
    4545        if (/\boperator\b/.test(token)) {
     46            if (!lastToken && (content === "+" || content === "-" || content === "~") && (lastContent !== ")" && lastContent !== "]")) // Possible Unary +/-.
     47                return false;
    4648            if (content === "!") // Unary ! should not be confused with "!=".
    4749                return false;
    48             return "+-/*&&||!===+=-=>=<=?".indexOf(content) >= 0; // Operators.
     50            return "+-/*%&&||!===+=-=>=<=?".indexOf(content) >= 0; // Operators.
    4951        }
    5052
     
    8789            return false;
    8890
    89         return ",+-/*&&||:!===+=-=>=<=?".indexOf(lastContent) >= 0; // Operators.
     91        // If this unary operator did not have a leading expression it is probably unary.
     92        if ((lastContent === "+" || lastContent === "-" || lastContent === "~") && !state._jsPrettyPrint.unaryOperatorHadLeadingExpr)
     93            return false;
     94
     95        return ",+-/*%&&||:!===+=-=>=<=?".indexOf(lastContent) >= 0; // Operators.
    9096    },
    9197
     
    121127                return "};".indexOf(lastContent) >= 0;
    122128            if (content === ":") // Ternary.
    123                 return lastContent === "}" && (state.lexical.type === "stat" || state.lexical.type === ")");
     129                return lastContent === "}" && (state.lexical.type === "stat" || state.lexical.type === ")" || state.lexical.type === "]");
    124130            if (",().".indexOf(content) >= 0) // "})", "}.bind", "function() { ... }()", or "}, false)".
    125131                return lastContent === "}";
     
    195201                openBraceStartMarkers: [],  // Keep track of non-single statement blocks.
    196202                openBraceTrackingCount: -1, // Keep track of "{" and "}" in non-single statement blocks.
     203                unaryOperatorHadLeadingExpr: false, // Try to detect if a unary operator had a leading expression and therefore may be binary.
    197204            };
    198205        }
     
    304311            state._jsPrettyPrint.shouldDedent = false;
    305312        }
     313
     314        if ((content === "+" || content === "-" || content === "~") && (lastContent === ")" || lastContent === "]" || /\b(?:variable|number)\b/.test(lastToken)))
     315            state._jsPrettyPrint.unaryOperatorHadLeadingExpr = true;
     316        else
     317            state._jsPrettyPrint.unaryOperatorHadLeadingExpr = false;
    306318    }
    307319});
Note: See TracChangeset for help on using the changeset viewer.