--- a/devtools/client/shared/css-parsing-utils.js
+++ b/devtools/client/shared/css-parsing-utils.js
@@ -509,17 +509,17 @@ function RuleRewriter(rule, inputString)
RuleRewriter.prototype = {
/**
* An internal function to complete initialization and set some
* properties for further processing.
*
* @param {Number} index The index of the property to modify
*/
- completeInitialization: function(index) {
+ completeInitialization: function (index) {
if (index < 0) {
throw new Error("Invalid index " + index + ". Expected positive integer");
}
// |decl| is the declaration to be rewritten, or null if there is no
// declaration corresponding to |index|.
// |result| is used to accumulate the result text.
if (index < this.declarations.length) {
this.decl = this.declarations[index];
@@ -535,17 +535,17 @@ RuleRewriter.prototype = {
* examines the rule's existing text to guess the indentation to use;
* unlike |getDefaultIndentation|, which examines the entire style
* sheet.
*
* @param {String} string the input text
* @param {Number} offset the offset at which to compute the indentation
* @return {String} the indentation at the indicated position
*/
- getIndentation: function(string, offset) {
+ getIndentation: function (string, offset) {
let originalOffset = offset;
for (--offset; offset >= 0; --offset) {
let c = string[offset];
if (c === "\r" || c === "\n" || c === "\f") {
return string.substring(offset + 1, originalOffset);
}
if (c !== " " && c !== "\t") {
// Found some non-whitespace character before we found a newline
@@ -568,17 +568,17 @@ RuleRewriter.prototype = {
*
* @param {String} text The input text. This should include the trailing ";".
* @return {Array} An array of the form [anySanitized, text], where
* |anySanitized| is a boolean that indicates
* whether anything substantive has changed; and
* where |text| is the text that has been rewritten
* to be "lexically safe".
*/
- sanitizePropertyValue: function(text) {
+ sanitizePropertyValue: function (text) {
let lexer = DOMUtils.getCSSLexer(text);
let result = "";
let previousOffset = 0;
let braceDepth = 0;
let anySanitized = false;
while (true) {
let token = lexer.nextToken();
@@ -631,33 +631,33 @@ RuleRewriter.prototype = {
* Start at |index| and skip whitespace
* backward in |string|. Return the index of the first
* non-whitespace character, or -1 if the entire string was
* whitespace.
* @param {String} string the input string
* @param {Number} index the index at which to start
* @return {Number} index of the first non-whitespace character, or -1
*/
- skipWhitespaceBackward: function(string, index) {
+ skipWhitespaceBackward: function (string, index) {
for (--index;
index >= 0 && (string[index] === " " || string[index] === "\t");
--index) {
// Nothing.
}
return index;
},
/**
* Terminate a given declaration, if needed.
*
* @param {Number} index The index of the rule to possibly
* terminate. It might be invalid, so this
* function must check for that.
*/
- maybeTerminateDecl: function(index) {
+ maybeTerminateDecl: function (index) {
if (index < 0 || index >= this.declarations.length
// No need to rewrite declarations in comments.
|| ("commentOffsets" in this.declarations[index])) {
return;
}
let termDecl = this.declarations[index];
let endIndex = termDecl.offsets[1];
@@ -695,48 +695,48 @@ RuleRewriter.prototype = {
* Sanitize the given property value and return the sanitized form.
* If the property is rewritten during sanitization, make a note in
* |changedDeclarations|.
*
* @param {String} text The property text.
* @param {Number} index The index of the property.
* @return {String} The sanitized text.
*/
- sanitizeText: function(text, index) {
+ sanitizeText: function (text, index) {
let [anySanitized, sanitizedText] = this.sanitizePropertyValue(text);
if (anySanitized) {
this.changedDeclarations[index] = sanitizedText;
}
return sanitizedText;
},
/**
* Rename a declaration.
*
* @param {Number} index index of the property in the rule.
* @param {String} name current name of the property
* @param {String} newName new name of the property
*/
- renameProperty: function(index, name, newName) {
+ renameProperty: function (index, name, newName) {
this.completeInitialization(index);
this.result += CSS.escape(newName);
// We could conceivably compute the name offsets instead so we
// could preserve white space and comments on the LHS of the ":".
this.completeCopying(this.decl.colonOffsets[0]);
},
/**
* Enable or disable a declaration
*
* @param {Number} index index of the property in the rule.
* @param {String} name current name of the property
* @param {Boolean} isEnabled true if the property should be enabled;
* false if it should be disabled
*/
- setPropertyEnabled: function(index, name, isEnabled) {
+ setPropertyEnabled: function (index, name, isEnabled) {
this.completeInitialization(index);
const decl = this.decl;
let copyOffset = decl.offsets[1];
if (isEnabled) {
// Enable it. First see if the comment start can be deleted.
let commentStart = decl.commentOffsets[0];
if (EMPTY_COMMENT_START_RX.test(this.result.substring(commentStart))) {
this.result = this.result.substring(0, commentStart);
@@ -780,33 +780,33 @@ RuleRewriter.prototype = {
/**
* Return a promise that will be resolved to the default indentation
* of the rule. This is a helper for internalCreateProperty.
*
* @return {Promise} a promise that will be resolved to a string
* that holds the default indentation that should be used
* for edits to the rule.
*/
- getDefaultIndentation: function() {
+ getDefaultIndentation: function () {
return this.rule.parentStyleSheet.guessIndentation();
},
/**
* An internal function to create a new declaration. This does all
* the work of |createProperty|.
*
* @param {Number} index index of the property in the rule.
* @param {String} name name of the new property
* @param {String} value value of the new property
* @param {String} priority priority of the new property; either
* the empty string or "important"
* @return {Promise} a promise that is resolved when the edit has
* completed
*/
- internalCreateProperty: Task.async(function*(index, name, value, priority) {
+ internalCreateProperty: Task.async(function* (index, name, value, priority) {
this.completeInitialization(index);
let newIndentation = "";
if (this.hasNewLine) {
if (this.declarations.length > 0) {
newIndentation = this.getIndentation(this.inputString,
this.declarations[0].offsets[0]);
} else if (this.defaultIndentation) {
newIndentation = this.defaultIndentation;
@@ -854,17 +854,17 @@ RuleRewriter.prototype = {
* Create a new declaration.
*
* @param {Number} index index of the property in the rule.
* @param {String} name name of the new property
* @param {String} value value of the new property
* @param {String} priority priority of the new property; either
* the empty string or "important"
*/
- createProperty: function(index, name, value, priority) {
+ createProperty: function (index, name, value, priority) {
this.editPromise = this.internalCreateProperty(index, name, value,
priority);
},
/**
* Set a declaration's value.
*
* @param {Number} index index of the property in the rule.
@@ -872,22 +872,23 @@ RuleRewriter.prototype = {
* the rule does not support setRuleText;
* generally for setting properties
* on an element's style.
* @param {String} name the property's name
* @param {String} value the property's value
* @param {String} priority the property's priority, either the empty
* string or "important"
*/
- setProperty: function(index, name, value, priority) {
+ setProperty: function (index, name, value, priority) {
this.completeInitialization(index);
// We might see a "set" on a previously non-existent property; in
// that case, act like "create".
if (!this.decl) {
- return this.createProperty(index, name, value, priority);
+ this.createProperty(index, name, value, priority);
+ return;
}
// Note that this assumes that "set" never operates on disabled
// properties.
this.result += this.inputString.substring(this.decl.offsets[0],
this.decl.colonOffsets[1]) +
this.sanitizeText(value, index);
@@ -899,17 +900,17 @@ RuleRewriter.prototype = {
},
/**
* Remove a declaration.
*
* @param {Number} index index of the property in the rule.
* @param {String} name the name of the property to remove
*/
- removeProperty: function(index, name) {
+ removeProperty: function (index, name) {
this.completeInitialization(index);
let copyOffset = this.decl.offsets[1];
// Maybe removing this rule left us with a completely blank
// line. In this case, we'll delete the whole thing. We only
// bother with this if we're looking at sources that already
// have a newline somewhere.
if (this.hasNewLine) {
let nlOffset = this.skipWhitespaceBackward(this.result,
@@ -929,44 +930,44 @@ RuleRewriter.prototype = {
/**
* An internal function to copy any trailing text to the output
* string.
*
* @param {Number} copyOffset Offset into |inputString| of the
* final text to copy to the output string.
*/
- completeCopying: function(copyOffset) {
+ completeCopying: function (copyOffset) {
// Add the trailing text.
this.result += this.inputString.substring(copyOffset);
},
/**
* Apply the modifications in this object to the associated rule.
*
* @return {Promise} A promise which will be resolved when the modifications
* are complete.
*/
- apply: function() {
+ apply: function () {
return promise.resolve(this.editPromise).then(() => {
return this.rule.setRuleText(this.result);
});
},
/**
* Get the result of the rewriting. This is used for testing.
*
* @return {object} an object of the form {changed: object, text: string}
* |changed| is an object where each key is
* the index of a property whose value had to be
* rewritten during the sanitization process, and
* whose value is the new text of the property.
* |text| is the rewritten text of the rule.
*/
- getResult: function() {
+ getResult: function () {
return {changed: this.changedDeclarations, text: this.result};
},
};
/**
* Returns an array of the parsed CSS selector value and type given a string.
*
* The components making up the CSS selector can be extracted into 3 different