| 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 WebInspector.SASSSupport = {}; | 4 Sass.SASSSupport = {}; |
| 5 | 5 |
| 6 /** | 6 /** |
| 7 * @param {string} url | 7 * @param {string} url |
| 8 * @param {string} content | 8 * @param {string} content |
| 9 * @return {!Promise<!WebInspector.SASSSupport.AST>} | 9 * @return {!Promise<!Sass.SASSSupport.AST>} |
| 10 */ | 10 */ |
| 11 WebInspector.SASSSupport.parseSCSS = function(url, content) { | 11 Sass.SASSSupport.parseSCSS = function(url, content) { |
| 12 var text = new WebInspector.Text(content); | 12 var text = new Common.Text(content); |
| 13 var document = new WebInspector.SASSSupport.ASTDocument(url, text); | 13 var document = new Sass.SASSSupport.ASTDocument(url, text); |
| 14 | 14 |
| 15 return WebInspector.formatterWorkerPool.runTask('parseSCSS', {content: content
}).then(onParsed); | 15 return Common.formatterWorkerPool.runTask('parseSCSS', {content: content}).the
n(onParsed); |
| 16 | 16 |
| 17 /** | 17 /** |
| 18 * @param {?MessageEvent} event | 18 * @param {?MessageEvent} event |
| 19 * @return {!WebInspector.SASSSupport.AST} | 19 * @return {!Sass.SASSSupport.AST} |
| 20 */ | 20 */ |
| 21 function onParsed(event) { | 21 function onParsed(event) { |
| 22 if (!event) | 22 if (!event) |
| 23 return new WebInspector.SASSSupport.AST(document, []); | 23 return new Sass.SASSSupport.AST(document, []); |
| 24 var data = /** @type {!Array<!Object>} */ (event.data); | 24 var data = /** @type {!Array<!Object>} */ (event.data); |
| 25 var rules = []; | 25 var rules = []; |
| 26 for (var i = 0; i < data.length; ++i) { | 26 for (var i = 0; i < data.length; ++i) { |
| 27 var rulePayload = data[i]; | 27 var rulePayload = data[i]; |
| 28 var selectors = rulePayload.selectors.map(createTextNode); | 28 var selectors = rulePayload.selectors.map(createTextNode); |
| 29 var properties = rulePayload.properties.map(createProperty); | 29 var properties = rulePayload.properties.map(createProperty); |
| 30 var range = WebInspector.TextRange.fromObject(rulePayload.styleRange); | 30 var range = Common.TextRange.fromObject(rulePayload.styleRange); |
| 31 var rule = new WebInspector.SASSSupport.Rule(document, selectors, range, p
roperties); | 31 var rule = new Sass.SASSSupport.Rule(document, selectors, range, propertie
s); |
| 32 rules.push(rule); | 32 rules.push(rule); |
| 33 } | 33 } |
| 34 return new WebInspector.SASSSupport.AST(document, rules); | 34 return new Sass.SASSSupport.AST(document, rules); |
| 35 } | 35 } |
| 36 | 36 |
| 37 /** | 37 /** |
| 38 * @param {!Object} payload | 38 * @param {!Object} payload |
| 39 */ | 39 */ |
| 40 function createTextNode(payload) { | 40 function createTextNode(payload) { |
| 41 var range = WebInspector.TextRange.fromObject(payload); | 41 var range = Common.TextRange.fromObject(payload); |
| 42 var value = text.extract(range); | 42 var value = text.extract(range); |
| 43 return new WebInspector.SASSSupport.TextNode(document, text.extract(range),
range); | 43 return new Sass.SASSSupport.TextNode(document, text.extract(range), range); |
| 44 } | 44 } |
| 45 | 45 |
| 46 /** | 46 /** |
| 47 * @param {!Object} payload | 47 * @param {!Object} payload |
| 48 */ | 48 */ |
| 49 function createProperty(payload) { | 49 function createProperty(payload) { |
| 50 var name = createTextNode(payload.name); | 50 var name = createTextNode(payload.name); |
| 51 var value = createTextNode(payload.value); | 51 var value = createTextNode(payload.value); |
| 52 return new WebInspector.SASSSupport.Property( | 52 return new Sass.SASSSupport.Property( |
| 53 document, name, value, WebInspector.TextRange.fromObject(payload.range),
payload.disabled); | 53 document, name, value, Common.TextRange.fromObject(payload.range), paylo
ad.disabled); |
| 54 } | 54 } |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 /** | 57 /** |
| 58 * @unrestricted | 58 * @unrestricted |
| 59 */ | 59 */ |
| 60 WebInspector.SASSSupport.ASTDocument = class { | 60 Sass.SASSSupport.ASTDocument = class { |
| 61 /** | 61 /** |
| 62 * @param {string} url | 62 * @param {string} url |
| 63 * @param {!WebInspector.Text} text | 63 * @param {!Common.Text} text |
| 64 */ | 64 */ |
| 65 constructor(url, text) { | 65 constructor(url, text) { |
| 66 this.url = url; | 66 this.url = url; |
| 67 this.text = text; | 67 this.text = text; |
| 68 this.edits = []; | 68 this.edits = []; |
| 69 } | 69 } |
| 70 | 70 |
| 71 /** | 71 /** |
| 72 * @return {!WebInspector.SASSSupport.ASTDocument} | 72 * @return {!Sass.SASSSupport.ASTDocument} |
| 73 */ | 73 */ |
| 74 clone() { | 74 clone() { |
| 75 return new WebInspector.SASSSupport.ASTDocument(this.url, this.text); | 75 return new Sass.SASSSupport.ASTDocument(this.url, this.text); |
| 76 } | 76 } |
| 77 | 77 |
| 78 /** | 78 /** |
| 79 * @return {boolean} | 79 * @return {boolean} |
| 80 */ | 80 */ |
| 81 hasChanged() { | 81 hasChanged() { |
| 82 return !!this.edits.length; | 82 return !!this.edits.length; |
| 83 } | 83 } |
| 84 | 84 |
| 85 /** | 85 /** |
| 86 * @return {!WebInspector.Text} | 86 * @return {!Common.Text} |
| 87 */ | 87 */ |
| 88 newText() { | 88 newText() { |
| 89 this.edits.stableSort(sequentialOrder); | 89 this.edits.stableSort(sequentialOrder); |
| 90 var text = this.text; | 90 var text = this.text; |
| 91 for (var i = this.edits.length - 1; i >= 0; --i) { | 91 for (var i = this.edits.length - 1; i >= 0; --i) { |
| 92 var range = this.edits[i].oldRange; | 92 var range = this.edits[i].oldRange; |
| 93 var newText = this.edits[i].newText; | 93 var newText = this.edits[i].newText; |
| 94 text = new WebInspector.Text(text.replaceRange(range, newText)); | 94 text = new Common.Text(text.replaceRange(range, newText)); |
| 95 } | 95 } |
| 96 return text; | 96 return text; |
| 97 | 97 |
| 98 /** | 98 /** |
| 99 * @param {!WebInspector.SourceEdit} edit1 | 99 * @param {!Common.SourceEdit} edit1 |
| 100 * @param {!WebInspector.SourceEdit} edit2 | 100 * @param {!Common.SourceEdit} edit2 |
| 101 * @return {number} | 101 * @return {number} |
| 102 */ | 102 */ |
| 103 function sequentialOrder(edit1, edit2) { | 103 function sequentialOrder(edit1, edit2) { |
| 104 var range1 = edit1.oldRange.collapseToStart(); | 104 var range1 = edit1.oldRange.collapseToStart(); |
| 105 var range2 = edit2.oldRange.collapseToStart(); | 105 var range2 = edit2.oldRange.collapseToStart(); |
| 106 if (range1.equal(range2)) | 106 if (range1.equal(range2)) |
| 107 return 0; | 107 return 0; |
| 108 return range1.follows(range2) ? 1 : -1; | 108 return range1.follows(range2) ? 1 : -1; |
| 109 } | 109 } |
| 110 } | 110 } |
| 111 }; | 111 }; |
| 112 | 112 |
| 113 /** | 113 /** |
| 114 * @unrestricted | 114 * @unrestricted |
| 115 */ | 115 */ |
| 116 WebInspector.SASSSupport.Node = class { | 116 Sass.SASSSupport.Node = class { |
| 117 /** | 117 /** |
| 118 * @param {!WebInspector.SASSSupport.ASTDocument} document | 118 * @param {!Sass.SASSSupport.ASTDocument} document |
| 119 */ | 119 */ |
| 120 constructor(document) { | 120 constructor(document) { |
| 121 this.document = document; | 121 this.document = document; |
| 122 } | 122 } |
| 123 }; | 123 }; |
| 124 | 124 |
| 125 /** | 125 /** |
| 126 * @unrestricted | 126 * @unrestricted |
| 127 */ | 127 */ |
| 128 WebInspector.SASSSupport.TextNode = class extends WebInspector.SASSSupport.Node
{ | 128 Sass.SASSSupport.TextNode = class extends Sass.SASSSupport.Node { |
| 129 /** | 129 /** |
| 130 * @param {!WebInspector.SASSSupport.ASTDocument} document | 130 * @param {!Sass.SASSSupport.ASTDocument} document |
| 131 * @param {string} text | 131 * @param {string} text |
| 132 * @param {!WebInspector.TextRange} range | 132 * @param {!Common.TextRange} range |
| 133 */ | 133 */ |
| 134 constructor(document, text, range) { | 134 constructor(document, text, range) { |
| 135 super(document); | 135 super(document); |
| 136 this.text = text; | 136 this.text = text; |
| 137 this.range = range; | 137 this.range = range; |
| 138 } | 138 } |
| 139 | 139 |
| 140 /** | 140 /** |
| 141 * @param {string} newText | 141 * @param {string} newText |
| 142 */ | 142 */ |
| 143 setText(newText) { | 143 setText(newText) { |
| 144 if (this.text === newText) | 144 if (this.text === newText) |
| 145 return; | 145 return; |
| 146 this.text = newText; | 146 this.text = newText; |
| 147 this.document.edits.push(new WebInspector.SourceEdit(this.document.url, this
.range, newText)); | 147 this.document.edits.push(new Common.SourceEdit(this.document.url, this.range
, newText)); |
| 148 } | 148 } |
| 149 | 149 |
| 150 /** | 150 /** |
| 151 * @param {!WebInspector.SASSSupport.ASTDocument} document | 151 * @param {!Sass.SASSSupport.ASTDocument} document |
| 152 * @return {!WebInspector.SASSSupport.TextNode} | 152 * @return {!Sass.SASSSupport.TextNode} |
| 153 */ | 153 */ |
| 154 clone(document) { | 154 clone(document) { |
| 155 return new WebInspector.SASSSupport.TextNode(document, this.text, this.range
.clone()); | 155 return new Sass.SASSSupport.TextNode(document, this.text, this.range.clone()
); |
| 156 } | 156 } |
| 157 | 157 |
| 158 /** | 158 /** |
| 159 * @param {!WebInspector.SASSSupport.TextNode} other | 159 * @param {!Sass.SASSSupport.TextNode} other |
| 160 * @param {!Map<!WebInspector.SASSSupport.Node, !WebInspector.SASSSupport.Node
>=} outNodeMapping | 160 * @param {!Map<!Sass.SASSSupport.Node, !Sass.SASSSupport.Node>=} outNodeMappi
ng |
| 161 * @return {boolean} | 161 * @return {boolean} |
| 162 */ | 162 */ |
| 163 match(other, outNodeMapping) { | 163 match(other, outNodeMapping) { |
| 164 if (this.text.trim() !== other.text.trim()) | 164 if (this.text.trim() !== other.text.trim()) |
| 165 return false; | 165 return false; |
| 166 if (outNodeMapping) | 166 if (outNodeMapping) |
| 167 outNodeMapping.set(this, other); | 167 outNodeMapping.set(this, other); |
| 168 return true; | 168 return true; |
| 169 } | 169 } |
| 170 }; | 170 }; |
| 171 | 171 |
| 172 /** | 172 /** |
| 173 * @unrestricted | 173 * @unrestricted |
| 174 */ | 174 */ |
| 175 WebInspector.SASSSupport.Property = class extends WebInspector.SASSSupport.Node
{ | 175 Sass.SASSSupport.Property = class extends Sass.SASSSupport.Node { |
| 176 /** | 176 /** |
| 177 * @param {!WebInspector.SASSSupport.ASTDocument} document | 177 * @param {!Sass.SASSSupport.ASTDocument} document |
| 178 * @param {!WebInspector.SASSSupport.TextNode} name | 178 * @param {!Sass.SASSSupport.TextNode} name |
| 179 * @param {!WebInspector.SASSSupport.TextNode} value | 179 * @param {!Sass.SASSSupport.TextNode} value |
| 180 * @param {!WebInspector.TextRange} range | 180 * @param {!Common.TextRange} range |
| 181 * @param {boolean} disabled | 181 * @param {boolean} disabled |
| 182 */ | 182 */ |
| 183 constructor(document, name, value, range, disabled) { | 183 constructor(document, name, value, range, disabled) { |
| 184 super(document); | 184 super(document); |
| 185 this.name = name; | 185 this.name = name; |
| 186 this.value = value; | 186 this.value = value; |
| 187 this.range = range; | 187 this.range = range; |
| 188 this.name.parent = this; | 188 this.name.parent = this; |
| 189 this.value.parent = this; | 189 this.value.parent = this; |
| 190 this.disabled = disabled; | 190 this.disabled = disabled; |
| 191 } | 191 } |
| 192 | 192 |
| 193 /** | 193 /** |
| 194 * @param {!WebInspector.SASSSupport.ASTDocument} document | 194 * @param {!Sass.SASSSupport.ASTDocument} document |
| 195 * @return {!WebInspector.SASSSupport.Property} | 195 * @return {!Sass.SASSSupport.Property} |
| 196 */ | 196 */ |
| 197 clone(document) { | 197 clone(document) { |
| 198 return new WebInspector.SASSSupport.Property( | 198 return new Sass.SASSSupport.Property( |
| 199 document, this.name.clone(document), this.value.clone(document), this.ra
nge.clone(), this.disabled); | 199 document, this.name.clone(document), this.value.clone(document), this.ra
nge.clone(), this.disabled); |
| 200 } | 200 } |
| 201 | 201 |
| 202 /** | 202 /** |
| 203 * @param {function(!WebInspector.SASSSupport.Node)} callback | 203 * @param {function(!Sass.SASSSupport.Node)} callback |
| 204 */ | 204 */ |
| 205 visit(callback) { | 205 visit(callback) { |
| 206 callback(this); | 206 callback(this); |
| 207 callback(this.name); | 207 callback(this.name); |
| 208 callback(this.value); | 208 callback(this.value); |
| 209 } | 209 } |
| 210 | 210 |
| 211 /** | 211 /** |
| 212 * @param {!WebInspector.SASSSupport.Property} other | 212 * @param {!Sass.SASSSupport.Property} other |
| 213 * @param {!Map<!WebInspector.SASSSupport.Node, !WebInspector.SASSSupport.Node
>=} outNodeMapping | 213 * @param {!Map<!Sass.SASSSupport.Node, !Sass.SASSSupport.Node>=} outNodeMappi
ng |
| 214 * @return {boolean} | 214 * @return {boolean} |
| 215 */ | 215 */ |
| 216 match(other, outNodeMapping) { | 216 match(other, outNodeMapping) { |
| 217 if (this.disabled !== other.disabled) | 217 if (this.disabled !== other.disabled) |
| 218 return false; | 218 return false; |
| 219 if (outNodeMapping) | 219 if (outNodeMapping) |
| 220 outNodeMapping.set(this, other); | 220 outNodeMapping.set(this, other); |
| 221 return this.name.match(other.name, outNodeMapping) && this.value.match(other
.value, outNodeMapping); | 221 return this.name.match(other.name, outNodeMapping) && this.value.match(other
.value, outNodeMapping); |
| 222 } | 222 } |
| 223 | 223 |
| 224 /** | 224 /** |
| 225 * @param {boolean} disabled | 225 * @param {boolean} disabled |
| 226 */ | 226 */ |
| 227 setDisabled(disabled) { | 227 setDisabled(disabled) { |
| 228 if (this.disabled === disabled) | 228 if (this.disabled === disabled) |
| 229 return; | 229 return; |
| 230 this.disabled = disabled; | 230 this.disabled = disabled; |
| 231 if (disabled) { | 231 if (disabled) { |
| 232 var oldRange1 = WebInspector.TextRange.createFromLocation(this.range.start
Line, this.range.startColumn); | 232 var oldRange1 = Common.TextRange.createFromLocation(this.range.startLine,
this.range.startColumn); |
| 233 var edit1 = new WebInspector.SourceEdit(this.document.url, oldRange1, '/*
'); | 233 var edit1 = new Common.SourceEdit(this.document.url, oldRange1, '/* '); |
| 234 var oldRange2 = WebInspector.TextRange.createFromLocation(this.range.endLi
ne, this.range.endColumn); | 234 var oldRange2 = Common.TextRange.createFromLocation(this.range.endLine, th
is.range.endColumn); |
| 235 var edit2 = new WebInspector.SourceEdit(this.document.url, oldRange2, ' */
'); | 235 var edit2 = new Common.SourceEdit(this.document.url, oldRange2, ' */'); |
| 236 this.document.edits.push(edit1, edit2); | 236 this.document.edits.push(edit1, edit2); |
| 237 return; | 237 return; |
| 238 } | 238 } |
| 239 var oldRange1 = new WebInspector.TextRange( | 239 var oldRange1 = new Common.TextRange( |
| 240 this.range.startLine, this.range.startColumn, this.range.startLine, this
.name.range.startColumn); | 240 this.range.startLine, this.range.startColumn, this.range.startLine, this
.name.range.startColumn); |
| 241 var edit1 = new WebInspector.SourceEdit(this.document.url, oldRange1, ''); | 241 var edit1 = new Common.SourceEdit(this.document.url, oldRange1, ''); |
| 242 | 242 |
| 243 var propertyText = this.document.text.extract(this.range); | 243 var propertyText = this.document.text.extract(this.range); |
| 244 var endsWithSemicolon = propertyText.slice(0, -2).trim().endsWith(';'); | 244 var endsWithSemicolon = propertyText.slice(0, -2).trim().endsWith(';'); |
| 245 var oldRange2 = new WebInspector.TextRange( | 245 var oldRange2 = new Common.TextRange( |
| 246 this.range.endLine, this.value.range.endColumn + (endsWithSemicolon ? 1
: 0), this.range.endLine, | 246 this.range.endLine, this.value.range.endColumn + (endsWithSemicolon ? 1
: 0), this.range.endLine, |
| 247 this.range.endColumn); | 247 this.range.endColumn); |
| 248 var edit2 = new WebInspector.SourceEdit(this.document.url, oldRange2, ''); | 248 var edit2 = new Common.SourceEdit(this.document.url, oldRange2, ''); |
| 249 this.document.edits.push(edit1, edit2); | 249 this.document.edits.push(edit1, edit2); |
| 250 } | 250 } |
| 251 | 251 |
| 252 remove() { | 252 remove() { |
| 253 console.assert(this.parent); | 253 console.assert(this.parent); |
| 254 var rule = this.parent; | 254 var rule = this.parent; |
| 255 var index = rule.properties.indexOf(this); | 255 var index = rule.properties.indexOf(this); |
| 256 rule.properties.splice(index, 1); | 256 rule.properties.splice(index, 1); |
| 257 this.parent = null; | 257 this.parent = null; |
| 258 | 258 |
| 259 var lineRange = new WebInspector.TextRange(this.range.startLine, 0, this.ran
ge.endLine + 1, 0); | 259 var lineRange = new Common.TextRange(this.range.startLine, 0, this.range.end
Line + 1, 0); |
| 260 var oldRange; | 260 var oldRange; |
| 261 if (this.document.text.extract(lineRange).trim() === this.document.text.extr
act(this.range).trim()) | 261 if (this.document.text.extract(lineRange).trim() === this.document.text.extr
act(this.range).trim()) |
| 262 oldRange = lineRange; | 262 oldRange = lineRange; |
| 263 else | 263 else |
| 264 oldRange = this.range; | 264 oldRange = this.range; |
| 265 this.document.edits.push(new WebInspector.SourceEdit(this.document.url, oldR
ange, '')); | 265 this.document.edits.push(new Common.SourceEdit(this.document.url, oldRange,
'')); |
| 266 } | 266 } |
| 267 }; | 267 }; |
| 268 | 268 |
| 269 /** | 269 /** |
| 270 * @unrestricted | 270 * @unrestricted |
| 271 */ | 271 */ |
| 272 WebInspector.SASSSupport.Rule = class extends WebInspector.SASSSupport.Node { | 272 Sass.SASSSupport.Rule = class extends Sass.SASSSupport.Node { |
| 273 /** | 273 /** |
| 274 * @param {!WebInspector.SASSSupport.ASTDocument} document | 274 * @param {!Sass.SASSSupport.ASTDocument} document |
| 275 * @param {!Array<!WebInspector.SASSSupport.TextNode>} selectors | 275 * @param {!Array<!Sass.SASSSupport.TextNode>} selectors |
| 276 * @param {!WebInspector.TextRange} styleRange | 276 * @param {!Common.TextRange} styleRange |
| 277 * @param {!Array<!WebInspector.SASSSupport.Property>} properties | 277 * @param {!Array<!Sass.SASSSupport.Property>} properties |
| 278 */ | 278 */ |
| 279 constructor(document, selectors, styleRange, properties) { | 279 constructor(document, selectors, styleRange, properties) { |
| 280 super(document); | 280 super(document); |
| 281 this.selectors = selectors; | 281 this.selectors = selectors; |
| 282 this.properties = properties; | 282 this.properties = properties; |
| 283 this.styleRange = styleRange; | 283 this.styleRange = styleRange; |
| 284 | 284 |
| 285 var blockStartRange = styleRange.collapseToStart(); | 285 var blockStartRange = styleRange.collapseToStart(); |
| 286 blockStartRange.startColumn -= 1; | 286 blockStartRange.startColumn -= 1; |
| 287 this.blockStart = | 287 this.blockStart = |
| 288 new WebInspector.SASSSupport.TextNode(document, this.document.text.extra
ct(blockStartRange), blockStartRange); | 288 new Sass.SASSSupport.TextNode(document, this.document.text.extract(block
StartRange), blockStartRange); |
| 289 this.blockStart.parent = this; | 289 this.blockStart.parent = this; |
| 290 | 290 |
| 291 for (var i = 0; i < this.properties.length; ++i) | 291 for (var i = 0; i < this.properties.length; ++i) |
| 292 this.properties[i].parent = this; | 292 this.properties[i].parent = this; |
| 293 | 293 |
| 294 this._hasTrailingSemicolon = | 294 this._hasTrailingSemicolon = |
| 295 !this.properties.length || this.document.text.extract(this.properties.pe
ekLast().range).endsWith(';'); | 295 !this.properties.length || this.document.text.extract(this.properties.pe
ekLast().range).endsWith(';'); |
| 296 } | 296 } |
| 297 | 297 |
| 298 /** | 298 /** |
| 299 * @param {!WebInspector.SASSSupport.ASTDocument} document | 299 * @param {!Sass.SASSSupport.ASTDocument} document |
| 300 * @return {!WebInspector.SASSSupport.Rule} | 300 * @return {!Sass.SASSSupport.Rule} |
| 301 */ | 301 */ |
| 302 clone(document) { | 302 clone(document) { |
| 303 var properties = []; | 303 var properties = []; |
| 304 for (var i = 0; i < this.properties.length; ++i) | 304 for (var i = 0; i < this.properties.length; ++i) |
| 305 properties.push(this.properties[i].clone(document)); | 305 properties.push(this.properties[i].clone(document)); |
| 306 var selectors = []; | 306 var selectors = []; |
| 307 for (var i = 0; i < this.selectors.length; ++i) | 307 for (var i = 0; i < this.selectors.length; ++i) |
| 308 selectors.push(this.selectors[i].clone(document)); | 308 selectors.push(this.selectors[i].clone(document)); |
| 309 return new WebInspector.SASSSupport.Rule(document, selectors, this.styleRang
e.clone(), properties); | 309 return new Sass.SASSSupport.Rule(document, selectors, this.styleRange.clone(
), properties); |
| 310 } | 310 } |
| 311 | 311 |
| 312 /** | 312 /** |
| 313 * @param {function(!WebInspector.SASSSupport.Node)} callback | 313 * @param {function(!Sass.SASSSupport.Node)} callback |
| 314 */ | 314 */ |
| 315 visit(callback) { | 315 visit(callback) { |
| 316 callback(this); | 316 callback(this); |
| 317 for (var i = 0; i < this.selectors.length; ++i) | 317 for (var i = 0; i < this.selectors.length; ++i) |
| 318 callback(this.selectors[i]); | 318 callback(this.selectors[i]); |
| 319 callback(this.blockStart); | 319 callback(this.blockStart); |
| 320 for (var i = 0; i < this.properties.length; ++i) | 320 for (var i = 0; i < this.properties.length; ++i) |
| 321 this.properties[i].visit(callback); | 321 this.properties[i].visit(callback); |
| 322 } | 322 } |
| 323 | 323 |
| 324 /** | 324 /** |
| 325 * @param {!WebInspector.SASSSupport.Rule} other | 325 * @param {!Sass.SASSSupport.Rule} other |
| 326 * @param {!Map<!WebInspector.SASSSupport.Node, !WebInspector.SASSSupport.Node
>=} outNodeMapping | 326 * @param {!Map<!Sass.SASSSupport.Node, !Sass.SASSSupport.Node>=} outNodeMappi
ng |
| 327 * @return {boolean} | 327 * @return {boolean} |
| 328 */ | 328 */ |
| 329 match(other, outNodeMapping) { | 329 match(other, outNodeMapping) { |
| 330 if (this.selectors.length !== other.selectors.length) | 330 if (this.selectors.length !== other.selectors.length) |
| 331 return false; | 331 return false; |
| 332 if (this.properties.length !== other.properties.length) | 332 if (this.properties.length !== other.properties.length) |
| 333 return false; | 333 return false; |
| 334 if (outNodeMapping) | 334 if (outNodeMapping) |
| 335 outNodeMapping.set(this, other); | 335 outNodeMapping.set(this, other); |
| 336 var result = this.blockStart.match(other.blockStart, outNodeMapping); | 336 var result = this.blockStart.match(other.blockStart, outNodeMapping); |
| 337 for (var i = 0; result && i < this.selectors.length; ++i) | 337 for (var i = 0; result && i < this.selectors.length; ++i) |
| 338 result = result && this.selectors[i].match(other.selectors[i], outNodeMapp
ing); | 338 result = result && this.selectors[i].match(other.selectors[i], outNodeMapp
ing); |
| 339 for (var i = 0; result && i < this.properties.length; ++i) | 339 for (var i = 0; result && i < this.properties.length; ++i) |
| 340 result = result && this.properties[i].match(other.properties[i], outNodeMa
pping); | 340 result = result && this.properties[i].match(other.properties[i], outNodeMa
pping); |
| 341 return result; | 341 return result; |
| 342 } | 342 } |
| 343 | 343 |
| 344 _addTrailingSemicolon() { | 344 _addTrailingSemicolon() { |
| 345 if (this._hasTrailingSemicolon || !this.properties) | 345 if (this._hasTrailingSemicolon || !this.properties) |
| 346 return; | 346 return; |
| 347 this._hasTrailingSemicolon = true; | 347 this._hasTrailingSemicolon = true; |
| 348 this.document.edits.push( | 348 this.document.edits.push( |
| 349 new WebInspector.SourceEdit(this.document.url, this.properties.peekLast(
).range.collapseToEnd(), ';')); | 349 new Common.SourceEdit(this.document.url, this.properties.peekLast().rang
e.collapseToEnd(), ';')); |
| 350 } | 350 } |
| 351 | 351 |
| 352 /** | 352 /** |
| 353 * @param {?WebInspector.SASSSupport.Property} anchorProperty | 353 * @param {?Sass.SASSSupport.Property} anchorProperty |
| 354 * @param {!Array<string>} nameTexts | 354 * @param {!Array<string>} nameTexts |
| 355 * @param {!Array<string>} valueTexts | 355 * @param {!Array<string>} valueTexts |
| 356 * @param {!Array<boolean>} disabledStates | 356 * @param {!Array<boolean>} disabledStates |
| 357 * @return {!Array<!WebInspector.SASSSupport.Property>} | 357 * @return {!Array<!Sass.SASSSupport.Property>} |
| 358 */ | 358 */ |
| 359 insertProperties(anchorProperty, nameTexts, valueTexts, disabledStates) { | 359 insertProperties(anchorProperty, nameTexts, valueTexts, disabledStates) { |
| 360 console.assert( | 360 console.assert( |
| 361 nameTexts.length === valueTexts.length && valueTexts.length === disabled
States.length, | 361 nameTexts.length === valueTexts.length && valueTexts.length === disabled
States.length, |
| 362 'Input array should be of the same size.'); | 362 'Input array should be of the same size.'); |
| 363 | 363 |
| 364 this._addTrailingSemicolon(); | 364 this._addTrailingSemicolon(); |
| 365 var newProperties = []; | 365 var newProperties = []; |
| 366 var index = anchorProperty ? this.properties.indexOf(anchorProperty) : -1; | 366 var index = anchorProperty ? this.properties.indexOf(anchorProperty) : -1; |
| 367 for (var i = 0; i < nameTexts.length; ++i) { | 367 for (var i = 0; i < nameTexts.length; ++i) { |
| 368 var nameText = nameTexts[i]; | 368 var nameText = nameTexts[i]; |
| 369 var valueText = valueTexts[i]; | 369 var valueText = valueTexts[i]; |
| 370 var disabled = disabledStates[i]; | 370 var disabled = disabledStates[i]; |
| 371 this.document.edits.push(this._insertPropertyEdit(anchorProperty, nameText
, valueText, disabled)); | 371 this.document.edits.push(this._insertPropertyEdit(anchorProperty, nameText
, valueText, disabled)); |
| 372 | 372 |
| 373 var name = new WebInspector.SASSSupport.TextNode( | 373 var name = new Sass.SASSSupport.TextNode( |
| 374 this.document, nameText, WebInspector.TextRange.createFromLocation(0,
0)); | 374 this.document, nameText, Common.TextRange.createFromLocation(0, 0)); |
| 375 var value = new WebInspector.SASSSupport.TextNode( | 375 var value = new Sass.SASSSupport.TextNode( |
| 376 this.document, valueText, WebInspector.TextRange.createFromLocation(0,
0)); | 376 this.document, valueText, Common.TextRange.createFromLocation(0, 0)); |
| 377 var newProperty = new WebInspector.SASSSupport.Property( | 377 var newProperty = new Sass.SASSSupport.Property( |
| 378 this.document, name, value, WebInspector.TextRange.createFromLocation(
0, 0), disabled); | 378 this.document, name, value, Common.TextRange.createFromLocation(0, 0),
disabled); |
| 379 | 379 |
| 380 this.properties.splice(index + i + 1, 0, newProperty); | 380 this.properties.splice(index + i + 1, 0, newProperty); |
| 381 newProperty.parent = this; | 381 newProperty.parent = this; |
| 382 newProperties.push(newProperty); | 382 newProperties.push(newProperty); |
| 383 } | 383 } |
| 384 return newProperties; | 384 return newProperties; |
| 385 } | 385 } |
| 386 | 386 |
| 387 /** | 387 /** |
| 388 * @param {?WebInspector.SASSSupport.Property} anchorProperty | 388 * @param {?Sass.SASSSupport.Property} anchorProperty |
| 389 * @param {string} nameText | 389 * @param {string} nameText |
| 390 * @param {string} valueText | 390 * @param {string} valueText |
| 391 * @param {boolean} disabled | 391 * @param {boolean} disabled |
| 392 * @return {!WebInspector.SourceEdit} | 392 * @return {!Common.SourceEdit} |
| 393 */ | 393 */ |
| 394 _insertPropertyEdit(anchorProperty, nameText, valueText, disabled) { | 394 _insertPropertyEdit(anchorProperty, nameText, valueText, disabled) { |
| 395 var anchorRange = anchorProperty ? anchorProperty.range : this.blockStart.ra
nge; | 395 var anchorRange = anchorProperty ? anchorProperty.range : this.blockStart.ra
nge; |
| 396 var indent = this._computePropertyIndent(); | 396 var indent = this._computePropertyIndent(); |
| 397 var leftComment = disabled ? '/* ' : ''; | 397 var leftComment = disabled ? '/* ' : ''; |
| 398 var rightComment = disabled ? ' */' : ''; | 398 var rightComment = disabled ? ' */' : ''; |
| 399 var newText = String.sprintf('\n%s%s%s: %s;%s', indent, leftComment, nameTex
t, valueText, rightComment); | 399 var newText = String.sprintf('\n%s%s%s: %s;%s', indent, leftComment, nameTex
t, valueText, rightComment); |
| 400 return new WebInspector.SourceEdit(this.document.url, anchorRange.collapseTo
End(), newText); | 400 return new Common.SourceEdit(this.document.url, anchorRange.collapseToEnd(),
newText); |
| 401 } | 401 } |
| 402 | 402 |
| 403 /** | 403 /** |
| 404 * @return {string} | 404 * @return {string} |
| 405 */ | 405 */ |
| 406 _computePropertyIndent() { | 406 _computePropertyIndent() { |
| 407 var indentProperty = this.properties.find(property => !property.range.isEmpt
y()); | 407 var indentProperty = this.properties.find(property => !property.range.isEmpt
y()); |
| 408 var result = ''; | 408 var result = ''; |
| 409 if (indentProperty) { | 409 if (indentProperty) { |
| 410 result = this.document.text.extract(new WebInspector.TextRange( | 410 result = this.document.text.extract(new Common.TextRange( |
| 411 indentProperty.range.startLine, 0, indentProperty.range.startLine, ind
entProperty.range.startColumn)); | 411 indentProperty.range.startLine, 0, indentProperty.range.startLine, ind
entProperty.range.startColumn)); |
| 412 } else { | 412 } else { |
| 413 var lineNumber = this.blockStart.range.startLine; | 413 var lineNumber = this.blockStart.range.startLine; |
| 414 var columnNumber = this.blockStart.range.startColumn; | 414 var columnNumber = this.blockStart.range.startColumn; |
| 415 var baseLine = this.document.text.extract(new WebInspector.TextRange(lineN
umber, 0, lineNumber, columnNumber)); | 415 var baseLine = this.document.text.extract(new Common.TextRange(lineNumber,
0, lineNumber, columnNumber)); |
| 416 result = WebInspector.TextUtils.lineIndent(baseLine) + WebInspector.module
Setting('textEditorIndent').get(); | 416 result = Common.TextUtils.lineIndent(baseLine) + Common.moduleSetting('tex
tEditorIndent').get(); |
| 417 } | 417 } |
| 418 return result.isWhitespace() ? result : ''; | 418 return result.isWhitespace() ? result : ''; |
| 419 } | 419 } |
| 420 }; | 420 }; |
| 421 | 421 |
| 422 /** | 422 /** |
| 423 * @unrestricted | 423 * @unrestricted |
| 424 */ | 424 */ |
| 425 WebInspector.SASSSupport.AST = class extends WebInspector.SASSSupport.Node { | 425 Sass.SASSSupport.AST = class extends Sass.SASSSupport.Node { |
| 426 /** | 426 /** |
| 427 * @param {!WebInspector.SASSSupport.ASTDocument} document | 427 * @param {!Sass.SASSSupport.ASTDocument} document |
| 428 * @param {!Array<!WebInspector.SASSSupport.Rule>} rules | 428 * @param {!Array<!Sass.SASSSupport.Rule>} rules |
| 429 */ | 429 */ |
| 430 constructor(document, rules) { | 430 constructor(document, rules) { |
| 431 super(document); | 431 super(document); |
| 432 this.rules = rules; | 432 this.rules = rules; |
| 433 for (var i = 0; i < rules.length; ++i) | 433 for (var i = 0; i < rules.length; ++i) |
| 434 rules[i].parent = this; | 434 rules[i].parent = this; |
| 435 } | 435 } |
| 436 | 436 |
| 437 /** | 437 /** |
| 438 * @return {!WebInspector.SASSSupport.AST} | 438 * @return {!Sass.SASSSupport.AST} |
| 439 */ | 439 */ |
| 440 clone() { | 440 clone() { |
| 441 var document = this.document.clone(); | 441 var document = this.document.clone(); |
| 442 var rules = []; | 442 var rules = []; |
| 443 for (var i = 0; i < this.rules.length; ++i) | 443 for (var i = 0; i < this.rules.length; ++i) |
| 444 rules.push(this.rules[i].clone(document)); | 444 rules.push(this.rules[i].clone(document)); |
| 445 return new WebInspector.SASSSupport.AST(document, rules); | 445 return new Sass.SASSSupport.AST(document, rules); |
| 446 } | 446 } |
| 447 | 447 |
| 448 /** | 448 /** |
| 449 * @param {!WebInspector.SASSSupport.AST} other | 449 * @param {!Sass.SASSSupport.AST} other |
| 450 * @param {!Map<!WebInspector.SASSSupport.Node, !WebInspector.SASSSupport.Node
>=} outNodeMapping | 450 * @param {!Map<!Sass.SASSSupport.Node, !Sass.SASSSupport.Node>=} outNodeMappi
ng |
| 451 * @return {boolean} | 451 * @return {boolean} |
| 452 */ | 452 */ |
| 453 match(other, outNodeMapping) { | 453 match(other, outNodeMapping) { |
| 454 if (other.document.url !== this.document.url) | 454 if (other.document.url !== this.document.url) |
| 455 return false; | 455 return false; |
| 456 if (other.rules.length !== this.rules.length) | 456 if (other.rules.length !== this.rules.length) |
| 457 return false; | 457 return false; |
| 458 if (outNodeMapping) | 458 if (outNodeMapping) |
| 459 outNodeMapping.set(this, other); | 459 outNodeMapping.set(this, other); |
| 460 var result = true; | 460 var result = true; |
| 461 for (var i = 0; result && i < this.rules.length; ++i) | 461 for (var i = 0; result && i < this.rules.length; ++i) |
| 462 result = result && this.rules[i].match(other.rules[i], outNodeMapping); | 462 result = result && this.rules[i].match(other.rules[i], outNodeMapping); |
| 463 return result; | 463 return result; |
| 464 } | 464 } |
| 465 | 465 |
| 466 /** | 466 /** |
| 467 * @param {function(!WebInspector.SASSSupport.Node)} callback | 467 * @param {function(!Sass.SASSSupport.Node)} callback |
| 468 */ | 468 */ |
| 469 visit(callback) { | 469 visit(callback) { |
| 470 callback(this); | 470 callback(this); |
| 471 for (var i = 0; i < this.rules.length; ++i) | 471 for (var i = 0; i < this.rules.length; ++i) |
| 472 this.rules[i].visit(callback); | 472 this.rules[i].visit(callback); |
| 473 } | 473 } |
| 474 | 474 |
| 475 /** | 475 /** |
| 476 * @param {number} lineNumber | 476 * @param {number} lineNumber |
| 477 * @param {number} columnNumber | 477 * @param {number} columnNumber |
| 478 * @return {?WebInspector.SASSSupport.TextNode} | 478 * @return {?Sass.SASSSupport.TextNode} |
| 479 */ | 479 */ |
| 480 findNodeForPosition(lineNumber, columnNumber) { | 480 findNodeForPosition(lineNumber, columnNumber) { |
| 481 this._ensureNodePositionsIndex(); | 481 this._ensureNodePositionsIndex(); |
| 482 var index = this._sortedTextNodes.lowerBound({lineNumber: lineNumber, column
Number: columnNumber}, nodeComparator); | 482 var index = this._sortedTextNodes.lowerBound({lineNumber: lineNumber, column
Number: columnNumber}, nodeComparator); |
| 483 var node = this._sortedTextNodes[index]; | 483 var node = this._sortedTextNodes[index]; |
| 484 if (!node) | 484 if (!node) |
| 485 return null; | 485 return null; |
| 486 return node.range.containsLocation(lineNumber, columnNumber) ? node : null; | 486 return node.range.containsLocation(lineNumber, columnNumber) ? node : null; |
| 487 | 487 |
| 488 /** | 488 /** |
| 489 * @param {!{lineNumber: number, columnNumber: number}} position | 489 * @param {!{lineNumber: number, columnNumber: number}} position |
| 490 * @param {!WebInspector.SASSSupport.TextNode} textNode | 490 * @param {!Sass.SASSSupport.TextNode} textNode |
| 491 * @return {number} | 491 * @return {number} |
| 492 */ | 492 */ |
| 493 function nodeComparator(position, textNode) { | 493 function nodeComparator(position, textNode) { |
| 494 return textNode.range.compareToPosition(position.lineNumber, position.colu
mnNumber); | 494 return textNode.range.compareToPosition(position.lineNumber, position.colu
mnNumber); |
| 495 } | 495 } |
| 496 } | 496 } |
| 497 | 497 |
| 498 _ensureNodePositionsIndex() { | 498 _ensureNodePositionsIndex() { |
| 499 if (this._sortedTextNodes) | 499 if (this._sortedTextNodes) |
| 500 return; | 500 return; |
| 501 this._sortedTextNodes = []; | 501 this._sortedTextNodes = []; |
| 502 this.visit(onNode.bind(this)); | 502 this.visit(onNode.bind(this)); |
| 503 this._sortedTextNodes.sort(nodeComparator); | 503 this._sortedTextNodes.sort(nodeComparator); |
| 504 | 504 |
| 505 /** | 505 /** |
| 506 * @param {!WebInspector.SASSSupport.Node} node | 506 * @param {!Sass.SASSSupport.Node} node |
| 507 * @this {WebInspector.SASSSupport.AST} | 507 * @this {Sass.SASSSupport.AST} |
| 508 */ | 508 */ |
| 509 function onNode(node) { | 509 function onNode(node) { |
| 510 if (!(node instanceof WebInspector.SASSSupport.TextNode)) | 510 if (!(node instanceof Sass.SASSSupport.TextNode)) |
| 511 return; | 511 return; |
| 512 this._sortedTextNodes.push(node); | 512 this._sortedTextNodes.push(node); |
| 513 } | 513 } |
| 514 | 514 |
| 515 /** | 515 /** |
| 516 * @param {!WebInspector.SASSSupport.TextNode} text1 | 516 * @param {!Sass.SASSSupport.TextNode} text1 |
| 517 * @param {!WebInspector.SASSSupport.TextNode} text2 | 517 * @param {!Sass.SASSSupport.TextNode} text2 |
| 518 * @return {number} | 518 * @return {number} |
| 519 */ | 519 */ |
| 520 function nodeComparator(text1, text2) { | 520 function nodeComparator(text1, text2) { |
| 521 return WebInspector.TextRange.comparator(text1.range, text2.range); | 521 return Common.TextRange.comparator(text1.range, text2.range); |
| 522 } | 522 } |
| 523 } | 523 } |
| 524 }; | 524 }; |
| 525 | 525 |
| 526 /** @enum {string} */ | 526 /** @enum {string} */ |
| 527 WebInspector.SASSSupport.PropertyChangeType = { | 527 Sass.SASSSupport.PropertyChangeType = { |
| 528 PropertyAdded: 'PropertyAdded', | 528 PropertyAdded: 'PropertyAdded', |
| 529 PropertyRemoved: 'PropertyRemoved', | 529 PropertyRemoved: 'PropertyRemoved', |
| 530 PropertyToggled: 'PropertyToggled', | 530 PropertyToggled: 'PropertyToggled', |
| 531 ValueChanged: 'ValueChanged', | 531 ValueChanged: 'ValueChanged', |
| 532 NameChanged: 'NameChanged' | 532 NameChanged: 'NameChanged' |
| 533 }; | 533 }; |
| 534 | 534 |
| 535 /** | 535 /** |
| 536 * @unrestricted | 536 * @unrestricted |
| 537 */ | 537 */ |
| 538 WebInspector.SASSSupport.PropertyChange = class { | 538 Sass.SASSSupport.PropertyChange = class { |
| 539 /** | 539 /** |
| 540 * @param {!WebInspector.SASSSupport.PropertyChangeType} type | 540 * @param {!Sass.SASSSupport.PropertyChangeType} type |
| 541 * @param {!WebInspector.SASSSupport.Rule} oldRule | 541 * @param {!Sass.SASSSupport.Rule} oldRule |
| 542 * @param {!WebInspector.SASSSupport.Rule} newRule | 542 * @param {!Sass.SASSSupport.Rule} newRule |
| 543 * @param {number} oldPropertyIndex | 543 * @param {number} oldPropertyIndex |
| 544 * @param {number} newPropertyIndex | 544 * @param {number} newPropertyIndex |
| 545 */ | 545 */ |
| 546 constructor(type, oldRule, newRule, oldPropertyIndex, newPropertyIndex) { | 546 constructor(type, oldRule, newRule, oldPropertyIndex, newPropertyIndex) { |
| 547 this.type = type; | 547 this.type = type; |
| 548 this.oldRule = oldRule; | 548 this.oldRule = oldRule; |
| 549 this.newRule = newRule; | 549 this.newRule = newRule; |
| 550 this.oldPropertyIndex = oldPropertyIndex; | 550 this.oldPropertyIndex = oldPropertyIndex; |
| 551 this.newPropertyIndex = newPropertyIndex; | 551 this.newPropertyIndex = newPropertyIndex; |
| 552 } | 552 } |
| 553 | 553 |
| 554 /** | 554 /** |
| 555 * @return {?WebInspector.SASSSupport.Property} | 555 * @return {?Sass.SASSSupport.Property} |
| 556 */ | 556 */ |
| 557 oldProperty() { | 557 oldProperty() { |
| 558 return this.oldRule.properties[this.oldPropertyIndex] || null; | 558 return this.oldRule.properties[this.oldPropertyIndex] || null; |
| 559 } | 559 } |
| 560 | 560 |
| 561 /** | 561 /** |
| 562 * @return {?WebInspector.SASSSupport.Property} | 562 * @return {?Sass.SASSSupport.Property} |
| 563 */ | 563 */ |
| 564 newProperty() { | 564 newProperty() { |
| 565 return this.newRule.properties[this.newPropertyIndex] || null; | 565 return this.newRule.properties[this.newPropertyIndex] || null; |
| 566 } | 566 } |
| 567 }; | 567 }; |
| 568 | 568 |
| 569 /** | 569 /** |
| 570 * @unrestricted | 570 * @unrestricted |
| 571 */ | 571 */ |
| 572 WebInspector.SASSSupport.ASTDiff = class { | 572 Sass.SASSSupport.ASTDiff = class { |
| 573 /** | 573 /** |
| 574 * @param {string} url | 574 * @param {string} url |
| 575 * @param {!WebInspector.SASSSupport.AST} oldAST | 575 * @param {!Sass.SASSSupport.AST} oldAST |
| 576 * @param {!WebInspector.SASSSupport.AST} newAST | 576 * @param {!Sass.SASSSupport.AST} newAST |
| 577 * @param {!Map<!WebInspector.SASSSupport.TextNode, !WebInspector.SASSSupport.
TextNode>} mapping | 577 * @param {!Map<!Sass.SASSSupport.TextNode, !Sass.SASSSupport.TextNode>} mappi
ng |
| 578 * @param {!Array<!WebInspector.SASSSupport.PropertyChange>} changes | 578 * @param {!Array<!Sass.SASSSupport.PropertyChange>} changes |
| 579 */ | 579 */ |
| 580 constructor(url, oldAST, newAST, mapping, changes) { | 580 constructor(url, oldAST, newAST, mapping, changes) { |
| 581 this.url = url; | 581 this.url = url; |
| 582 this.mapping = mapping; | 582 this.mapping = mapping; |
| 583 this.changes = changes; | 583 this.changes = changes; |
| 584 this.oldAST = oldAST; | 584 this.oldAST = oldAST; |
| 585 this.newAST = newAST; | 585 this.newAST = newAST; |
| 586 } | 586 } |
| 587 }; | 587 }; |
| 588 | 588 |
| 589 /** | 589 /** |
| 590 * @param {!WebInspector.SASSSupport.AST} oldAST | 590 * @param {!Sass.SASSSupport.AST} oldAST |
| 591 * @param {!WebInspector.SASSSupport.AST} newAST | 591 * @param {!Sass.SASSSupport.AST} newAST |
| 592 * @return {!WebInspector.SASSSupport.ASTDiff} | 592 * @return {!Sass.SASSSupport.ASTDiff} |
| 593 */ | 593 */ |
| 594 WebInspector.SASSSupport.diffModels = function(oldAST, newAST) { | 594 Sass.SASSSupport.diffModels = function(oldAST, newAST) { |
| 595 console.assert(oldAST.rules.length === newAST.rules.length, 'Not implemented f
or rule diff.'); | 595 console.assert(oldAST.rules.length === newAST.rules.length, 'Not implemented f
or rule diff.'); |
| 596 console.assert(oldAST.document.url === newAST.document.url, 'Diff makes sense
for models with the same url.'); | 596 console.assert(oldAST.document.url === newAST.document.url, 'Diff makes sense
for models with the same url.'); |
| 597 var T = WebInspector.SASSSupport.PropertyChangeType; | 597 var T = Sass.SASSSupport.PropertyChangeType; |
| 598 var changes = []; | 598 var changes = []; |
| 599 /** @type {!Map<!WebInspector.SASSSupport.TextNode, !WebInspector.SASSSupport.
TextNode>} */ | 599 /** @type {!Map<!Sass.SASSSupport.TextNode, !Sass.SASSSupport.TextNode>} */ |
| 600 var mapping = new Map(); | 600 var mapping = new Map(); |
| 601 for (var i = 0; i < oldAST.rules.length; ++i) { | 601 for (var i = 0; i < oldAST.rules.length; ++i) { |
| 602 var oldRule = oldAST.rules[i]; | 602 var oldRule = oldAST.rules[i]; |
| 603 var newRule = newAST.rules[i]; | 603 var newRule = newAST.rules[i]; |
| 604 computeRuleDiff(mapping, oldRule, newRule); | 604 computeRuleDiff(mapping, oldRule, newRule); |
| 605 } | 605 } |
| 606 return new WebInspector.SASSSupport.ASTDiff(oldAST.document.url, oldAST, newAS
T, mapping, changes); | 606 return new Sass.SASSSupport.ASTDiff(oldAST.document.url, oldAST, newAST, mappi
ng, changes); |
| 607 | 607 |
| 608 /** | 608 /** |
| 609 * @param {!WebInspector.SASSSupport.PropertyChangeType} type | 609 * @param {!Sass.SASSSupport.PropertyChangeType} type |
| 610 * @param {!WebInspector.SASSSupport.Rule} oldRule | 610 * @param {!Sass.SASSSupport.Rule} oldRule |
| 611 * @param {!WebInspector.SASSSupport.Rule} newRule | 611 * @param {!Sass.SASSSupport.Rule} newRule |
| 612 * @param {number} oldPropertyIndex | 612 * @param {number} oldPropertyIndex |
| 613 * @param {number} newPropertyIndex | 613 * @param {number} newPropertyIndex |
| 614 */ | 614 */ |
| 615 function addChange(type, oldRule, newRule, oldPropertyIndex, newPropertyIndex)
{ | 615 function addChange(type, oldRule, newRule, oldPropertyIndex, newPropertyIndex)
{ |
| 616 changes.push( | 616 changes.push( |
| 617 new WebInspector.SASSSupport.PropertyChange(type, oldRule, newRule, oldP
ropertyIndex, newPropertyIndex)); | 617 new Sass.SASSSupport.PropertyChange(type, oldRule, newRule, oldPropertyI
ndex, newPropertyIndex)); |
| 618 } | 618 } |
| 619 | 619 |
| 620 /** | 620 /** |
| 621 * @param {!Map<!WebInspector.SASSSupport.TextNode, !WebInspector.SASSSupport.
TextNode>} mapping | 621 * @param {!Map<!Sass.SASSSupport.TextNode, !Sass.SASSSupport.TextNode>} mappi
ng |
| 622 * @param {!WebInspector.SASSSupport.Rule} oldRule | 622 * @param {!Sass.SASSSupport.Rule} oldRule |
| 623 * @param {!WebInspector.SASSSupport.Rule} newRule | 623 * @param {!Sass.SASSSupport.Rule} newRule |
| 624 */ | 624 */ |
| 625 function computeRuleDiff(mapping, oldRule, newRule) { | 625 function computeRuleDiff(mapping, oldRule, newRule) { |
| 626 var oldLines = []; | 626 var oldLines = []; |
| 627 for (var i = 0; i < oldRule.properties.length; ++i) | 627 for (var i = 0; i < oldRule.properties.length; ++i) |
| 628 oldLines.push(oldRule.properties[i].name.text.trim() + ':' + oldRule.prope
rties[i].value.text.trim()); | 628 oldLines.push(oldRule.properties[i].name.text.trim() + ':' + oldRule.prope
rties[i].value.text.trim()); |
| 629 var newLines = []; | 629 var newLines = []; |
| 630 for (var i = 0; i < newRule.properties.length; ++i) | 630 for (var i = 0; i < newRule.properties.length; ++i) |
| 631 newLines.push(newRule.properties[i].name.text.trim() + ':' + newRule.prope
rties[i].value.text.trim()); | 631 newLines.push(newRule.properties[i].name.text.trim() + ':' + newRule.prope
rties[i].value.text.trim()); |
| 632 var diff = WebInspector.Diff.lineDiff(oldLines, newLines); | 632 var diff = Diff.Diff.lineDiff(oldLines, newLines); |
| 633 diff = WebInspector.Diff.convertToEditDiff(diff); | 633 diff = Diff.Diff.convertToEditDiff(diff); |
| 634 | 634 |
| 635 var p1 = 0, p2 = 0; | 635 var p1 = 0, p2 = 0; |
| 636 for (var i = 0; i < diff.length; ++i) { | 636 for (var i = 0; i < diff.length; ++i) { |
| 637 var token = diff[i]; | 637 var token = diff[i]; |
| 638 if (token[0] === WebInspector.Diff.Operation.Delete) { | 638 if (token[0] === Diff.Diff.Operation.Delete) { |
| 639 for (var j = 0; j < token[1]; ++j) | 639 for (var j = 0; j < token[1]; ++j) |
| 640 addChange(T.PropertyRemoved, oldRule, newRule, p1++, p2); | 640 addChange(T.PropertyRemoved, oldRule, newRule, p1++, p2); |
| 641 } else if (token[0] === WebInspector.Diff.Operation.Insert) { | 641 } else if (token[0] === Diff.Diff.Operation.Insert) { |
| 642 for (var j = 0; j < token[1]; ++j) | 642 for (var j = 0; j < token[1]; ++j) |
| 643 addChange(T.PropertyAdded, oldRule, newRule, p1, p2++); | 643 addChange(T.PropertyAdded, oldRule, newRule, p1, p2++); |
| 644 } else { | 644 } else { |
| 645 for (var j = 0; j < token[1]; ++j) | 645 for (var j = 0; j < token[1]; ++j) |
| 646 computePropertyDiff(mapping, oldRule, newRule, p1++, p2++); | 646 computePropertyDiff(mapping, oldRule, newRule, p1++, p2++); |
| 647 } | 647 } |
| 648 } | 648 } |
| 649 } | 649 } |
| 650 | 650 |
| 651 /** | 651 /** |
| 652 * @param {!Map<!WebInspector.SASSSupport.TextNode, !WebInspector.SASSSupport.
TextNode>} mapping | 652 * @param {!Map<!Sass.SASSSupport.TextNode, !Sass.SASSSupport.TextNode>} mappi
ng |
| 653 * @param {!WebInspector.SASSSupport.Rule} oldRule | 653 * @param {!Sass.SASSSupport.Rule} oldRule |
| 654 * @param {!WebInspector.SASSSupport.Rule} newRule | 654 * @param {!Sass.SASSSupport.Rule} newRule |
| 655 * @param {number} oldPropertyIndex | 655 * @param {number} oldPropertyIndex |
| 656 * @param {number} newPropertyIndex | 656 * @param {number} newPropertyIndex |
| 657 */ | 657 */ |
| 658 function computePropertyDiff(mapping, oldRule, newRule, oldPropertyIndex, newP
ropertyIndex) { | 658 function computePropertyDiff(mapping, oldRule, newRule, oldPropertyIndex, newP
ropertyIndex) { |
| 659 var oldProperty = oldRule.properties[oldPropertyIndex]; | 659 var oldProperty = oldRule.properties[oldPropertyIndex]; |
| 660 var newProperty = newRule.properties[newPropertyIndex]; | 660 var newProperty = newRule.properties[newPropertyIndex]; |
| 661 mapping.set(oldProperty.name, newProperty.name); | 661 mapping.set(oldProperty.name, newProperty.name); |
| 662 mapping.set(oldProperty.value, newProperty.value); | 662 mapping.set(oldProperty.value, newProperty.value); |
| 663 if (oldProperty.name.text.trim() !== newProperty.name.text.trim()) | 663 if (oldProperty.name.text.trim() !== newProperty.name.text.trim()) |
| 664 addChange(T.NameChanged, oldRule, newRule, oldPropertyIndex, newPropertyIn
dex); | 664 addChange(T.NameChanged, oldRule, newRule, oldPropertyIndex, newPropertyIn
dex); |
| 665 if (oldProperty.value.text.trim() !== newProperty.value.text.trim()) | 665 if (oldProperty.value.text.trim() !== newProperty.value.text.trim()) |
| 666 addChange(T.ValueChanged, oldRule, newRule, oldPropertyIndex, newPropertyI
ndex); | 666 addChange(T.ValueChanged, oldRule, newRule, oldPropertyIndex, newPropertyI
ndex); |
| 667 if (oldProperty.disabled !== newProperty.disabled) | 667 if (oldProperty.disabled !== newProperty.disabled) |
| 668 addChange(T.PropertyToggled, oldRule, newRule, oldPropertyIndex, newProper
tyIndex); | 668 addChange(T.PropertyToggled, oldRule, newRule, oldPropertyIndex, newProper
tyIndex); |
| 669 } | 669 } |
| 670 }; | 670 }; |
| OLD | NEW |