| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 WebInspector.SASSSupport = {} | 5 WebInspector.SASSSupport = {} |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * @param {string} url | 8 * @param {string} url |
| 9 * @param {string} content | 9 * @param {string} content |
| 10 * @return {!Promise<!WebInspector.SASSSupport.AST>} | 10 * @return {!Promise<!WebInspector.SASSSupport.AST>} |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 * @return {!WebInspector.SASSSupport.AST} | 21 * @return {!WebInspector.SASSSupport.AST} |
| 22 */ | 22 */ |
| 23 function onParsed(event) | 23 function onParsed(event) |
| 24 { | 24 { |
| 25 if (!event) | 25 if (!event) |
| 26 return new WebInspector.SASSSupport.AST(document, []); | 26 return new WebInspector.SASSSupport.AST(document, []); |
| 27 var data = /** @type {!Array<!Object>} */(event.data); | 27 var data = /** @type {!Array<!Object>} */(event.data); |
| 28 var rules = []; | 28 var rules = []; |
| 29 for (var i = 0; i < data.length; ++i) { | 29 for (var i = 0; i < data.length; ++i) { |
| 30 var rulePayload = data[i]; | 30 var rulePayload = data[i]; |
| 31 var selectorText = ""; | 31 var selectors = rulePayload.selectors.map(createTextNode); |
| 32 if (rulePayload.selectors.length) { | |
| 33 var first = rulePayload.selectors[0]; | |
| 34 var last = rulePayload.selectors.peekLast(); | |
| 35 var selectorRange = new WebInspector.TextRange(first.startLine,
first.startColumn, last.endLine, last.endColumn); | |
| 36 selectorText = text.extract(selectorRange); | |
| 37 } | |
| 38 var properties = rulePayload.properties.map(createProperty); | 32 var properties = rulePayload.properties.map(createProperty); |
| 39 var range = WebInspector.TextRange.fromObject(rulePayload.styleRange
); | 33 var range = WebInspector.TextRange.fromObject(rulePayload.styleRange
); |
| 40 var rule = new WebInspector.SASSSupport.Rule(document, selectorText,
range, properties); | 34 var rule = new WebInspector.SASSSupport.Rule(document, selectors, ra
nge, properties); |
| 41 rules.push(rule); | 35 rules.push(rule); |
| 42 } | 36 } |
| 43 return new WebInspector.SASSSupport.AST(document, rules); | 37 return new WebInspector.SASSSupport.AST(document, rules); |
| 44 } | 38 } |
| 45 | 39 |
| 46 /** | 40 /** |
| 47 * @param {!Object} payload | 41 * @param {!Object} payload |
| 48 */ | 42 */ |
| 49 function createTextNode(payload) | 43 function createTextNode(payload) |
| 50 { | 44 { |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 this.document.edits.push(new WebInspector.SourceEdit(this.document.url,
oldRange, "")); | 272 this.document.edits.push(new WebInspector.SourceEdit(this.document.url,
oldRange, "")); |
| 279 }, | 273 }, |
| 280 | 274 |
| 281 __proto__: WebInspector.SASSSupport.Node.prototype | 275 __proto__: WebInspector.SASSSupport.Node.prototype |
| 282 } | 276 } |
| 283 | 277 |
| 284 /** | 278 /** |
| 285 * @constructor | 279 * @constructor |
| 286 * @extends {WebInspector.SASSSupport.Node} | 280 * @extends {WebInspector.SASSSupport.Node} |
| 287 * @param {!WebInspector.SASSSupport.ASTDocument} document | 281 * @param {!WebInspector.SASSSupport.ASTDocument} document |
| 288 * @param {string} selector | 282 * @param {!Array<!WebInspector.SASSSupport.TextNode>} selectors |
| 289 * @param {!WebInspector.TextRange} styleRange | 283 * @param {!WebInspector.TextRange} styleRange |
| 290 * @param {!Array<!WebInspector.SASSSupport.Property>} properties | 284 * @param {!Array<!WebInspector.SASSSupport.Property>} properties |
| 291 */ | 285 */ |
| 292 WebInspector.SASSSupport.Rule = function(document, selector, styleRange, propert
ies) | 286 WebInspector.SASSSupport.Rule = function(document, selectors, styleRange, proper
ties) |
| 293 { | 287 { |
| 294 WebInspector.SASSSupport.Node.call(this, document); | 288 WebInspector.SASSSupport.Node.call(this, document); |
| 295 this.selector = selector; | 289 this.selectors = selectors; |
| 296 this.properties = properties; | 290 this.properties = properties; |
| 297 this.styleRange = styleRange; | 291 this.styleRange = styleRange; |
| 298 for (var i = 0; i < this.properties.length; ++i) | 292 for (var i = 0; i < this.properties.length; ++i) |
| 299 this.properties[i].parent = this; | 293 this.properties[i].parent = this; |
| 300 | 294 |
| 301 this._hasTrailingSemicolon = !this.properties.length || this.document.text.e
xtract(this.properties.peekLast().range).endsWith(";"); | 295 this._hasTrailingSemicolon = !this.properties.length || this.document.text.e
xtract(this.properties.peekLast().range).endsWith(";"); |
| 302 } | 296 } |
| 303 | 297 |
| 304 WebInspector.SASSSupport.Rule.prototype = { | 298 WebInspector.SASSSupport.Rule.prototype = { |
| 305 /** | 299 /** |
| 306 * @param {!WebInspector.SASSSupport.ASTDocument} document | 300 * @param {!WebInspector.SASSSupport.ASTDocument} document |
| 307 * @return {!WebInspector.SASSSupport.Rule} | 301 * @return {!WebInspector.SASSSupport.Rule} |
| 308 */ | 302 */ |
| 309 clone: function(document) | 303 clone: function(document) |
| 310 { | 304 { |
| 311 var properties = []; | 305 var properties = []; |
| 312 for (var i = 0; i < this.properties.length; ++i) | 306 for (var i = 0; i < this.properties.length; ++i) |
| 313 properties.push(this.properties[i].clone(document)); | 307 properties.push(this.properties[i].clone(document)); |
| 314 return new WebInspector.SASSSupport.Rule(document, this.selector, this.s
tyleRange.clone(), properties); | 308 var selectors = []; |
| 309 for (var i = 0; i < this.selectors.length; ++i) |
| 310 selectors.push(this.selectors[i].clone(document)); |
| 311 return new WebInspector.SASSSupport.Rule(document, selectors, this.style
Range.clone(), properties); |
| 315 }, | 312 }, |
| 316 | 313 |
| 317 /** | 314 /** |
| 318 * @param {function(!WebInspector.SASSSupport.Node)} callback | 315 * @param {function(!WebInspector.SASSSupport.Node)} callback |
| 319 */ | 316 */ |
| 320 visit: function(callback) | 317 visit: function(callback) |
| 321 { | 318 { |
| 322 callback(this); | 319 callback(this); |
| 320 for (var i = 0; i < this.selectors.length; ++i) |
| 321 callback(this.selectors[i]); |
| 323 for (var i = 0; i < this.properties.length; ++i) | 322 for (var i = 0; i < this.properties.length; ++i) |
| 324 this.properties[i].visit(callback); | 323 this.properties[i].visit(callback); |
| 325 }, | 324 }, |
| 326 | 325 |
| 327 /** | 326 /** |
| 328 * @param {!WebInspector.SASSSupport.Rule} other | 327 * @param {!WebInspector.SASSSupport.Rule} other |
| 329 * @param {!Map<!WebInspector.SASSSupport.Node, !WebInspector.SASSSupport.No
de>=} outNodeMapping | 328 * @param {!Map<!WebInspector.SASSSupport.Node, !WebInspector.SASSSupport.No
de>=} outNodeMapping |
| 330 * @return {boolean} | 329 * @return {boolean} |
| 331 */ | 330 */ |
| 332 match: function(other, outNodeMapping) | 331 match: function(other, outNodeMapping) |
| 333 { | 332 { |
| 334 if (this.selector !== other.selector) | 333 if (this.selectors.length !== other.selectors.length) |
| 335 return false; | 334 return false; |
| 336 if (this.properties.length !== other.properties.length) | 335 if (this.properties.length !== other.properties.length) |
| 337 return false; | 336 return false; |
| 338 if (outNodeMapping) | 337 if (outNodeMapping) |
| 339 outNodeMapping.set(this, other); | 338 outNodeMapping.set(this, other); |
| 340 var result = true; | 339 var result = true; |
| 340 for (var i = 0; result && i < this.selectors.length; ++i) |
| 341 result = result && this.selectors[i].match(other.selectors[i], outNo
deMapping); |
| 341 for (var i = 0; result && i < this.properties.length; ++i) | 342 for (var i = 0; result && i < this.properties.length; ++i) |
| 342 result = result && this.properties[i].match(other.properties[i], out
NodeMapping); | 343 result = result && this.properties[i].match(other.properties[i], out
NodeMapping); |
| 343 return result; | 344 return result; |
| 344 }, | 345 }, |
| 345 | 346 |
| 346 _addTrailingSemicolon: function() | 347 _addTrailingSemicolon: function() |
| 347 { | 348 { |
| 348 if (this._hasTrailingSemicolon || !this.properties) | 349 if (this._hasTrailingSemicolon || !this.properties) |
| 349 return; | 350 return; |
| 350 this._hasTrailingSemicolon = true; | 351 this._hasTrailingSemicolon = true; |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 mapping.set(oldProperty.name, newProperty.name); | 668 mapping.set(oldProperty.name, newProperty.name); |
| 668 mapping.set(oldProperty.value, newProperty.value); | 669 mapping.set(oldProperty.value, newProperty.value); |
| 669 if (oldProperty.name.text.trim() !== newProperty.name.text.trim()) | 670 if (oldProperty.name.text.trim() !== newProperty.name.text.trim()) |
| 670 addChange(T.NameChanged, oldRule, newRule, oldPropertyIndex, newProp
ertyIndex); | 671 addChange(T.NameChanged, oldRule, newRule, oldPropertyIndex, newProp
ertyIndex); |
| 671 if (oldProperty.value.text.trim() !== newProperty.value.text.trim()) | 672 if (oldProperty.value.text.trim() !== newProperty.value.text.trim()) |
| 672 addChange(T.ValueChanged, oldRule, newRule, oldPropertyIndex, newPro
pertyIndex); | 673 addChange(T.ValueChanged, oldRule, newRule, oldPropertyIndex, newPro
pertyIndex); |
| 673 if (oldProperty.disabled !== newProperty.disabled) | 674 if (oldProperty.disabled !== newProperty.disabled) |
| 674 addChange(T.PropertyToggled, oldRule, newRule, oldPropertyIndex, new
PropertyIndex); | 675 addChange(T.PropertyToggled, oldRule, newRule, oldPropertyIndex, new
PropertyIndex); |
| 675 } | 676 } |
| 676 } | 677 } |
| OLD | NEW |