| Index: third_party/WebKit/Source/devtools/front_end/formatter_worker/CSSFormatter.js
|
| diff --git a/third_party/WebKit/Source/devtools/front_end/formatter_worker/CSSFormatter.js b/third_party/WebKit/Source/devtools/front_end/formatter_worker/CSSFormatter.js
|
| index 944adb9f910bcb675b5a27f93b3150be1dc02d8f..555e8f04efdc677877247ae463bf3fe8bd8d6c5d 100644
|
| --- a/third_party/WebKit/Source/devtools/front_end/formatter_worker/CSSFormatter.js
|
| +++ b/third_party/WebKit/Source/devtools/front_end/formatter_worker/CSSFormatter.js
|
| @@ -27,95 +27,93 @@
|
| * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| */
|
| -
|
| /**
|
| - * @constructor
|
| - * @param {!WebInspector.FormattedContentBuilder} builder
|
| + * @unrestricted
|
| */
|
| -WebInspector.CSSFormatter = function(builder)
|
| -{
|
| +WebInspector.CSSFormatter = class {
|
| + /**
|
| + * @param {!WebInspector.FormattedContentBuilder} builder
|
| + */
|
| + constructor(builder) {
|
| this._builder = builder;
|
| -};
|
| + }
|
|
|
| -WebInspector.CSSFormatter.prototype = {
|
| - /**
|
| - * @param {string} text
|
| - * @param {!Array.<number>} lineEndings
|
| - * @param {number} fromOffset
|
| - * @param {number} toOffset
|
| - */
|
| - format: function(text, lineEndings, fromOffset, toOffset)
|
| - {
|
| - this._lineEndings = lineEndings;
|
| - this._fromOffset = fromOffset;
|
| - this._toOffset = toOffset;
|
| - this._lastLine = -1;
|
| - this._state = {};
|
| - var tokenize = WebInspector.createTokenizer("text/css");
|
| - var oldEnforce = this._builder.setEnforceSpaceBetweenWords(false);
|
| - tokenize(text.substring(this._fromOffset, this._toOffset), this._tokenCallback.bind(this));
|
| - this._builder.setEnforceSpaceBetweenWords(oldEnforce);
|
| - },
|
| + /**
|
| + * @param {string} text
|
| + * @param {!Array.<number>} lineEndings
|
| + * @param {number} fromOffset
|
| + * @param {number} toOffset
|
| + */
|
| + format(text, lineEndings, fromOffset, toOffset) {
|
| + this._lineEndings = lineEndings;
|
| + this._fromOffset = fromOffset;
|
| + this._toOffset = toOffset;
|
| + this._lastLine = -1;
|
| + this._state = {};
|
| + var tokenize = WebInspector.createTokenizer('text/css');
|
| + var oldEnforce = this._builder.setEnforceSpaceBetweenWords(false);
|
| + tokenize(text.substring(this._fromOffset, this._toOffset), this._tokenCallback.bind(this));
|
| + this._builder.setEnforceSpaceBetweenWords(oldEnforce);
|
| + }
|
|
|
| - /**
|
| - * @param {string} token
|
| - * @param {?string} type
|
| - * @param {number} startPosition
|
| - */
|
| - _tokenCallback: function(token, type, startPosition)
|
| - {
|
| - startPosition += this._fromOffset;
|
| - var startLine = this._lineEndings.lowerBound(startPosition);
|
| - if (startLine !== this._lastLine)
|
| - this._state.eatWhitespace = true;
|
| - if (/^property/.test(type) && !this._state.inPropertyValue)
|
| - this._state.seenProperty = true;
|
| - this._lastLine = startLine;
|
| - var isWhitespace = /^\s+$/.test(token);
|
| - if (isWhitespace) {
|
| - if (!this._state.eatWhitespace)
|
| - this._builder.addSoftSpace();
|
| - return;
|
| - }
|
| - this._state.eatWhitespace = false;
|
| - if (token === "\n")
|
| - return;
|
| + /**
|
| + * @param {string} token
|
| + * @param {?string} type
|
| + * @param {number} startPosition
|
| + */
|
| + _tokenCallback(token, type, startPosition) {
|
| + startPosition += this._fromOffset;
|
| + var startLine = this._lineEndings.lowerBound(startPosition);
|
| + if (startLine !== this._lastLine)
|
| + this._state.eatWhitespace = true;
|
| + if (/^property/.test(type) && !this._state.inPropertyValue)
|
| + this._state.seenProperty = true;
|
| + this._lastLine = startLine;
|
| + var isWhitespace = /^\s+$/.test(token);
|
| + if (isWhitespace) {
|
| + if (!this._state.eatWhitespace)
|
| + this._builder.addSoftSpace();
|
| + return;
|
| + }
|
| + this._state.eatWhitespace = false;
|
| + if (token === '\n')
|
| + return;
|
|
|
| - if (token !== "}") {
|
| - if (this._state.afterClosingBrace)
|
| - this._builder.addNewLine(true);
|
| - this._state.afterClosingBrace = false;
|
| - }
|
| - if (token === "}") {
|
| - if (this._state.inPropertyValue)
|
| - this._builder.addNewLine();
|
| - this._builder.decreaseNestingLevel();
|
| - this._state.afterClosingBrace = true;
|
| - this._state.inPropertyValue = false;
|
| - } else if (token === ":" && !this._state.inPropertyValue && this._state.seenProperty) {
|
| - this._builder.addToken(token, startPosition);
|
| - this._builder.addSoftSpace();
|
| - this._state.eatWhitespace = true;
|
| - this._state.inPropertyValue = true;
|
| - this._state.seenProperty = false;
|
| - return;
|
| - } else if (token === "{") {
|
| - this._builder.addSoftSpace();
|
| - this._builder.addToken(token, startPosition);
|
| - this._builder.addNewLine();
|
| - this._builder.increaseNestingLevel();
|
| - return;
|
| - }
|
| + if (token !== '}') {
|
| + if (this._state.afterClosingBrace)
|
| + this._builder.addNewLine(true);
|
| + this._state.afterClosingBrace = false;
|
| + }
|
| + if (token === '}') {
|
| + if (this._state.inPropertyValue)
|
| + this._builder.addNewLine();
|
| + this._builder.decreaseNestingLevel();
|
| + this._state.afterClosingBrace = true;
|
| + this._state.inPropertyValue = false;
|
| + } else if (token === ':' && !this._state.inPropertyValue && this._state.seenProperty) {
|
| + this._builder.addToken(token, startPosition);
|
| + this._builder.addSoftSpace();
|
| + this._state.eatWhitespace = true;
|
| + this._state.inPropertyValue = true;
|
| + this._state.seenProperty = false;
|
| + return;
|
| + } else if (token === '{') {
|
| + this._builder.addSoftSpace();
|
| + this._builder.addToken(token, startPosition);
|
| + this._builder.addNewLine();
|
| + this._builder.increaseNestingLevel();
|
| + return;
|
| + }
|
|
|
| - this._builder.addToken(token, startPosition);
|
| + this._builder.addToken(token, startPosition);
|
|
|
| - if (type === "comment" && !this._state.inPropertyValue && !this._state.seenProperty)
|
| - this._builder.addNewLine();
|
| - if (token === ";" && this._state.inPropertyValue) {
|
| - this._state.inPropertyValue = false;
|
| - this._builder.addNewLine();
|
| - } else if (token === "}") {
|
| - this._builder.addNewLine();
|
| - }
|
| + if (type === 'comment' && !this._state.inPropertyValue && !this._state.seenProperty)
|
| + this._builder.addNewLine();
|
| + if (token === ';' && this._state.inPropertyValue) {
|
| + this._state.inPropertyValue = false;
|
| + this._builder.addNewLine();
|
| + } else if (token === '}') {
|
| + this._builder.addNewLine();
|
| }
|
| + }
|
| };
|
|
|