| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 | |
| 5 /** | 4 /** |
| 6 * @constructor | 5 * @unrestricted |
| 7 * @param {!WebInspector.ASTService} astService | |
| 8 * @param {!WebInspector.ASTSourceMap} map | |
| 9 * @param {!Array<!WebInspector.SASSProcessor.EditOperation>} editOperations | |
| 10 */ | 6 */ |
| 11 WebInspector.SASSProcessor = function(astService, map, editOperations) | 7 WebInspector.SASSProcessor = class { |
| 12 { | 8 /** |
| 9 * @param {!WebInspector.ASTService} astService |
| 10 * @param {!WebInspector.ASTSourceMap} map |
| 11 * @param {!Array<!WebInspector.SASSProcessor.EditOperation>} editOperations |
| 12 */ |
| 13 constructor(astService, map, editOperations) { |
| 13 this._astService = astService; | 14 this._astService = astService; |
| 14 this._map = map; | 15 this._map = map; |
| 15 this._editOperations = editOperations; | 16 this._editOperations = editOperations; |
| 16 }; | 17 } |
| 17 | 18 |
| 18 WebInspector.SASSProcessor.prototype = { | 19 /** |
| 19 /** | 20 * @param {!WebInspector.ASTSourceMap} map |
| 20 * @return {!Promise<?WebInspector.SourceMap.EditResult>} | 21 * @param {!WebInspector.SASSSupport.Property} cssProperty |
| 21 */ | 22 * @return {?WebInspector.SASSSupport.Property} |
| 22 _mutate: function() | 23 */ |
| 23 { | 24 static _toSASSProperty(map, cssProperty) { |
| 24 /** @type {!Set<!WebInspector.SASSSupport.Rule>} */ | |
| 25 var changedCSSRules = new Set(); | |
| 26 for (var editOperation of this._editOperations) { | |
| 27 var rules = editOperation.perform(); | |
| 28 changedCSSRules.addAll(rules); | |
| 29 } | |
| 30 | |
| 31 // Reparse new texts, make sure changes result in anticipated AST trees. | |
| 32 var promises = []; | |
| 33 for (var ast of this._map.models().values()) { | |
| 34 if (!ast.document.hasChanged()) | |
| 35 continue; | |
| 36 var promise; | |
| 37 if (ast.document.url === this._map.compiledURL()) | |
| 38 promise = this._astService.parseCSS(ast.document.url, ast.docume
nt.newText().value()); | |
| 39 else | |
| 40 promise = this._astService.parseSCSS(ast.document.url, ast.docum
ent.newText().value()); | |
| 41 promises.push(promise); | |
| 42 } | |
| 43 | |
| 44 return Promise.all(promises) | |
| 45 .then(this._onFinished.bind(this, changedCSSRules)); | |
| 46 }, | |
| 47 | |
| 48 /** | |
| 49 * @param {!Set<!WebInspector.SASSSupport.Rule>} changedCSSRules | |
| 50 * @param {!Array<!WebInspector.SASSSupport.AST>} changedModels | |
| 51 * @return {?WebInspector.SourceMap.EditResult} | |
| 52 */ | |
| 53 _onFinished: function(changedCSSRules, changedModels) | |
| 54 { | |
| 55 var nodeMapping = new Map(); | |
| 56 var map = this._map.rebase(changedModels, nodeMapping); | |
| 57 if (!map) | |
| 58 return null; | |
| 59 | |
| 60 var cssEdits = []; | |
| 61 for (var rule of changedCSSRules) { | |
| 62 var oldRange = rule.styleRange; | |
| 63 var newRule = nodeMapping.get(rule); | |
| 64 var newText = newRule.document.text.extract(newRule.styleRange); | |
| 65 cssEdits.push(new WebInspector.SourceEdit(newRule.document.url, oldR
ange, newText)); | |
| 66 } | |
| 67 | |
| 68 /** @type {!Map<string, string>} */ | |
| 69 var newSASSSources = new Map(); | |
| 70 for (var model of changedModels) { | |
| 71 if (model.document.url === map.compiledURL()) | |
| 72 continue; | |
| 73 newSASSSources.set(model.document.url, model.document.text.value()); | |
| 74 } | |
| 75 return new WebInspector.SourceMap.EditResult(map, cssEdits, newSASSSourc
es); | |
| 76 } | |
| 77 }; | |
| 78 | |
| 79 /** | |
| 80 * @param {!WebInspector.ASTSourceMap} map | |
| 81 * @param {!WebInspector.SASSSupport.Property} cssProperty | |
| 82 * @return {?WebInspector.SASSSupport.Property} | |
| 83 */ | |
| 84 WebInspector.SASSProcessor._toSASSProperty = function(map, cssProperty) | |
| 85 { | |
| 86 var sassName = map.toSourceNode(cssProperty.name); | 25 var sassName = map.toSourceNode(cssProperty.name); |
| 87 return sassName ? sassName.parent : null; | 26 return sassName ? sassName.parent : null; |
| 88 }; | 27 } |
| 89 | 28 |
| 90 /** | 29 /** |
| 91 * @param {!WebInspector.ASTSourceMap} map | 30 * @param {!WebInspector.ASTSourceMap} map |
| 92 * @param {!WebInspector.SASSSupport.Property} sassProperty | 31 * @param {!WebInspector.SASSSupport.Property} sassProperty |
| 93 * @return {!Array<!WebInspector.SASSSupport.Property>} | 32 * @return {!Array<!WebInspector.SASSSupport.Property>} |
| 94 */ | 33 */ |
| 95 WebInspector.SASSProcessor._toCSSProperties = function(map, sassProperty) | 34 static _toCSSProperties(map, sassProperty) { |
| 96 { | |
| 97 return map.toCompiledNodes(sassProperty.name).map(name => name.parent); | 35 return map.toCompiledNodes(sassProperty.name).map(name => name.parent); |
| 98 }; | 36 } |
| 99 | 37 |
| 100 /** | 38 /** |
| 101 * @param {!WebInspector.ASTService} astService | 39 * @param {!WebInspector.ASTService} astService |
| 102 * @param {!WebInspector.ASTSourceMap} map | 40 * @param {!WebInspector.ASTSourceMap} map |
| 103 * @param {!Array<!WebInspector.TextRange>} ranges | 41 * @param {!Array<!WebInspector.TextRange>} ranges |
| 104 * @param {!Array<string>} newTexts | 42 * @param {!Array<string>} newTexts |
| 105 * @return {!Promise<?WebInspector.SourceMap.EditResult>} | 43 * @return {!Promise<?WebInspector.SourceMap.EditResult>} |
| 106 */ | 44 */ |
| 107 WebInspector.SASSProcessor.processCSSEdits = function(astService, map, ranges, n
ewTexts) | 45 static processCSSEdits(astService, map, ranges, newTexts) { |
| 108 { | |
| 109 console.assert(ranges.length === newTexts.length); | 46 console.assert(ranges.length === newTexts.length); |
| 110 var cssURL = map.compiledURL(); | 47 var cssURL = map.compiledURL(); |
| 111 var cssText = map.compiledModel().document.text; | 48 var cssText = map.compiledModel().document.text; |
| 112 for (var i = 0; i < ranges.length; ++i) | 49 for (var i = 0; i < ranges.length; ++i) |
| 113 cssText = new WebInspector.Text(cssText.replaceRange(ranges[i], newTexts
[i])); | 50 cssText = new WebInspector.Text(cssText.replaceRange(ranges[i], newTexts[i
])); |
| 114 return astService.parseCSS(cssURL, cssText.value()) | 51 return astService.parseCSS(cssURL, cssText.value()).then(onCSSParsed); |
| 115 .then(onCSSParsed); | |
| 116 | 52 |
| 117 /** | 53 /** |
| 118 * @param {!WebInspector.SASSSupport.AST} newCSSAST | 54 * @param {!WebInspector.SASSSupport.AST} newCSSAST |
| 119 * @return {!Promise<?WebInspector.SourceMap.EditResult>} | 55 * @return {!Promise<?WebInspector.SourceMap.EditResult>} |
| 120 */ | 56 */ |
| 121 function onCSSParsed(newCSSAST) | 57 function onCSSParsed(newCSSAST) { |
| 122 { | 58 if (newCSSAST.rules.length !== map.compiledModel().rules.length) |
| 123 if (newCSSAST.rules.length !== map.compiledModel().rules.length) | 59 return Promise.resolve(/** @type {?WebInspector.SourceMap.EditResult} */
(null)); |
| 124 return Promise.resolve(/** @type {?WebInspector.SourceMap.EditResult
} */(null)); | 60 // TODO(lushnikov): only diff changed styles. |
| 125 // TODO(lushnikov): only diff changed styles. | 61 var cssDiff = WebInspector.SASSSupport.diffModels(map.compiledModel(), new
CSSAST); |
| 126 var cssDiff = WebInspector.SASSSupport.diffModels(map.compiledModel(), n
ewCSSAST); | 62 var edits = WebInspector.SASSProcessor._editsFromCSSDiff(cssDiff, map); |
| 127 var edits = WebInspector.SASSProcessor._editsFromCSSDiff(cssDiff, map); | 63 |
| 128 | 64 // Determine AST trees which will change and clone them. |
| 129 // Determine AST trees which will change and clone them. | 65 var changedURLs = new Set(edits.map(edit => edit.sassURL)); |
| 130 var changedURLs = new Set(edits.map(edit => edit.sassURL)); | 66 changedURLs.add(map.compiledURL()); |
| 131 changedURLs.add(map.compiledURL()); | 67 var clonedModels = []; |
| 132 var clonedModels = []; | 68 for (var url of changedURLs) |
| 133 for (var url of changedURLs) | 69 clonedModels.push(map.modelForURL(url).clone()); |
| 134 clonedModels.push(map.modelForURL(url).clone()); | 70 |
| 135 | 71 // Rebase map and edits onto a cloned AST trees. |
| 136 // Rebase map and edits onto a cloned AST trees. | 72 var nodeMapping = new Map(); |
| 137 var nodeMapping = new Map(); | 73 var rebasedMap = /** @type {!WebInspector.ASTSourceMap} */ (map.rebase(clo
nedModels, nodeMapping)); |
| 138 var rebasedMap = /** @type {!WebInspector.ASTSourceMap} */(map.rebase(cl
onedModels, nodeMapping)); | 74 console.assert(rebasedMap); |
| 139 console.assert(rebasedMap); | 75 var rebasedEdits = edits.map(edit => edit.rebase(rebasedMap, nodeMapping))
; |
| 140 var rebasedEdits = edits.map(edit => edit.rebase(rebasedMap, nodeMapping
)); | 76 |
| 141 | 77 return new WebInspector.SASSProcessor(astService, rebasedMap, rebasedEdits
)._mutate(); |
| 142 return new WebInspector.SASSProcessor(astService, rebasedMap, rebasedEdi
ts)._mutate(); | 78 } |
| 143 } | 79 } |
| 144 }; | 80 |
| 145 | 81 /** |
| 146 /** | 82 * @param {!WebInspector.SASSSupport.ASTDiff} cssDiff |
| 147 * @param {!WebInspector.SASSSupport.ASTDiff} cssDiff | 83 * @param {!WebInspector.ASTSourceMap} map |
| 148 * @param {!WebInspector.ASTSourceMap} map | 84 * @return {!Array<!WebInspector.SASSProcessor.EditOperation>} |
| 149 * @return {!Array<!WebInspector.SASSProcessor.EditOperation>} | 85 */ |
| 150 */ | 86 static _editsFromCSSDiff(cssDiff, map) { |
| 151 WebInspector.SASSProcessor._editsFromCSSDiff = function(cssDiff, map) | |
| 152 { | |
| 153 var T = WebInspector.SASSSupport.PropertyChangeType; | 87 var T = WebInspector.SASSSupport.PropertyChangeType; |
| 154 var operations = []; | 88 var operations = []; |
| 155 for (var i = 0; i < cssDiff.changes.length; ++i) { | 89 for (var i = 0; i < cssDiff.changes.length; ++i) { |
| 156 var change = cssDiff.changes[i]; | 90 var change = cssDiff.changes[i]; |
| 157 var operation = null; | 91 var operation = null; |
| 158 if (change.type === T.ValueChanged || change.type === T.NameChanged) | 92 if (change.type === T.ValueChanged || change.type === T.NameChanged) |
| 159 operation = WebInspector.SASSProcessor.SetTextOperation.fromCSSChang
e(change, map); | 93 operation = WebInspector.SASSProcessor.SetTextOperation.fromCSSChange(ch
ange, map); |
| 160 else if (change.type === T.PropertyToggled) | 94 else if (change.type === T.PropertyToggled) |
| 161 operation = WebInspector.SASSProcessor.TogglePropertyOperation.fromC
SSChange(change, map); | 95 operation = WebInspector.SASSProcessor.TogglePropertyOperation.fromCSSCh
ange(change, map); |
| 162 else if (change.type === T.PropertyRemoved) | 96 else if (change.type === T.PropertyRemoved) |
| 163 operation = WebInspector.SASSProcessor.RemovePropertyOperation.fromC
SSChange(change, map); | 97 operation = WebInspector.SASSProcessor.RemovePropertyOperation.fromCSSCh
ange(change, map); |
| 164 else if (change.type === T.PropertyAdded) | 98 else if (change.type === T.PropertyAdded) |
| 165 operation = WebInspector.SASSProcessor.InsertPropertiesOperation.fro
mCSSChange(change, map); | 99 operation = WebInspector.SASSProcessor.InsertPropertiesOperation.fromCSS
Change(change, map); |
| 166 if (!operation) { | 100 if (!operation) { |
| 167 WebInspector.console.error("Operation ignored: " + change.type); | 101 WebInspector.console.error('Operation ignored: ' + change.type); |
| 168 continue; | 102 continue; |
| 169 } | 103 } |
| 170 | 104 |
| 171 var merged = false; | 105 var merged = false; |
| 172 for (var j = 0; !merged && j < operations.length; ++j) | 106 for (var j = 0; !merged && j < operations.length; ++j) |
| 173 merged = operations[j].merge(operation); | 107 merged = operations[j].merge(operation); |
| 174 if (!merged) | 108 if (!merged) |
| 175 operations.push(operation); | 109 operations.push(operation); |
| 176 } | 110 } |
| 177 return operations; | 111 return operations; |
| 112 } |
| 113 |
| 114 /** |
| 115 * @return {!Promise<?WebInspector.SourceMap.EditResult>} |
| 116 */ |
| 117 _mutate() { |
| 118 /** @type {!Set<!WebInspector.SASSSupport.Rule>} */ |
| 119 var changedCSSRules = new Set(); |
| 120 for (var editOperation of this._editOperations) { |
| 121 var rules = editOperation.perform(); |
| 122 changedCSSRules.addAll(rules); |
| 123 } |
| 124 |
| 125 // Reparse new texts, make sure changes result in anticipated AST trees. |
| 126 var promises = []; |
| 127 for (var ast of this._map.models().values()) { |
| 128 if (!ast.document.hasChanged()) |
| 129 continue; |
| 130 var promise; |
| 131 if (ast.document.url === this._map.compiledURL()) |
| 132 promise = this._astService.parseCSS(ast.document.url, ast.document.newTe
xt().value()); |
| 133 else |
| 134 promise = this._astService.parseSCSS(ast.document.url, ast.document.newT
ext().value()); |
| 135 promises.push(promise); |
| 136 } |
| 137 |
| 138 return Promise.all(promises).then(this._onFinished.bind(this, changedCSSRule
s)); |
| 139 } |
| 140 |
| 141 /** |
| 142 * @param {!Set<!WebInspector.SASSSupport.Rule>} changedCSSRules |
| 143 * @param {!Array<!WebInspector.SASSSupport.AST>} changedModels |
| 144 * @return {?WebInspector.SourceMap.EditResult} |
| 145 */ |
| 146 _onFinished(changedCSSRules, changedModels) { |
| 147 var nodeMapping = new Map(); |
| 148 var map = this._map.rebase(changedModels, nodeMapping); |
| 149 if (!map) |
| 150 return null; |
| 151 |
| 152 var cssEdits = []; |
| 153 for (var rule of changedCSSRules) { |
| 154 var oldRange = rule.styleRange; |
| 155 var newRule = nodeMapping.get(rule); |
| 156 var newText = newRule.document.text.extract(newRule.styleRange); |
| 157 cssEdits.push(new WebInspector.SourceEdit(newRule.document.url, oldRange,
newText)); |
| 158 } |
| 159 |
| 160 /** @type {!Map<string, string>} */ |
| 161 var newSASSSources = new Map(); |
| 162 for (var model of changedModels) { |
| 163 if (model.document.url === map.compiledURL()) |
| 164 continue; |
| 165 newSASSSources.set(model.document.url, model.document.text.value()); |
| 166 } |
| 167 return new WebInspector.SourceMap.EditResult(map, cssEdits, newSASSSources); |
| 168 } |
| 178 }; | 169 }; |
| 179 | 170 |
| 171 |
| 180 /** | 172 /** |
| 181 * @constructor | 173 * @unrestricted |
| 182 * @param {!WebInspector.ASTSourceMap} map | |
| 183 * @param {string} sassURL | |
| 184 */ | 174 */ |
| 185 WebInspector.SASSProcessor.EditOperation = function(map, sassURL) | 175 WebInspector.SASSProcessor.EditOperation = class { |
| 186 { | 176 /** |
| 177 * @param {!WebInspector.ASTSourceMap} map |
| 178 * @param {string} sassURL |
| 179 */ |
| 180 constructor(map, sassURL) { |
| 187 this.map = map; | 181 this.map = map; |
| 188 this.sassURL = sassURL; | 182 this.sassURL = sassURL; |
| 183 } |
| 184 |
| 185 /** |
| 186 * @param {!WebInspector.SASSProcessor.EditOperation} other |
| 187 * @return {boolean} |
| 188 */ |
| 189 merge(other) { |
| 190 return false; |
| 191 } |
| 192 |
| 193 /** |
| 194 * @return {!Array<!WebInspector.SASSSupport.Rule>} |
| 195 */ |
| 196 perform() { |
| 197 return []; |
| 198 } |
| 199 |
| 200 /** |
| 201 * @param {!WebInspector.ASTSourceMap} newMap |
| 202 * @param {!Map<!WebInspector.SASSSupport.Node, !WebInspector.SASSSupport.Node
>} nodeMapping |
| 203 * @return {!WebInspector.SASSProcessor.EditOperation} |
| 204 */ |
| 205 rebase(newMap, nodeMapping) { |
| 206 return this; |
| 207 } |
| 189 }; | 208 }; |
| 190 | 209 |
| 191 WebInspector.SASSProcessor.EditOperation.prototype = { | |
| 192 /** | |
| 193 * @param {!WebInspector.SASSProcessor.EditOperation} other | |
| 194 * @return {boolean} | |
| 195 */ | |
| 196 merge: function(other) | |
| 197 { | |
| 198 return false; | |
| 199 }, | |
| 200 | |
| 201 /** | |
| 202 * @return {!Array<!WebInspector.SASSSupport.Rule>} | |
| 203 */ | |
| 204 perform: function() | |
| 205 { | |
| 206 return []; | |
| 207 }, | |
| 208 | |
| 209 /** | |
| 210 * @param {!WebInspector.ASTSourceMap} newMap | |
| 211 * @param {!Map<!WebInspector.SASSSupport.Node, !WebInspector.SASSSupport.No
de>} nodeMapping | |
| 212 * @return {!WebInspector.SASSProcessor.EditOperation} | |
| 213 */ | |
| 214 rebase: function(newMap, nodeMapping) | |
| 215 { | |
| 216 return this; | |
| 217 }, | |
| 218 }; | |
| 219 | |
| 220 /** | 210 /** |
| 221 * @constructor | 211 * @unrestricted |
| 222 * @extends {WebInspector.SASSProcessor.EditOperation} | |
| 223 * @param {!WebInspector.ASTSourceMap} map | |
| 224 * @param {!WebInspector.SASSSupport.TextNode} sassNode | |
| 225 * @param {string} newText | |
| 226 */ | 212 */ |
| 227 WebInspector.SASSProcessor.SetTextOperation = function(map, sassNode, newText) | 213 WebInspector.SASSProcessor.SetTextOperation = class extends WebInspector.SASSPro
cessor.EditOperation { |
| 228 { | 214 /** |
| 229 WebInspector.SASSProcessor.EditOperation.call(this, map, sassNode.document.u
rl); | 215 * @param {!WebInspector.ASTSourceMap} map |
| 216 * @param {!WebInspector.SASSSupport.TextNode} sassNode |
| 217 * @param {string} newText |
| 218 */ |
| 219 constructor(map, sassNode, newText) { |
| 220 super(map, sassNode.document.url); |
| 230 this._sassNode = sassNode; | 221 this._sassNode = sassNode; |
| 231 this._newText = newText; | 222 this._newText = newText; |
| 232 }; | 223 } |
| 233 | 224 |
| 234 /** | 225 /** |
| 235 * @param {!WebInspector.SASSSupport.PropertyChange} change | 226 * @param {!WebInspector.SASSSupport.PropertyChange} change |
| 236 * @param {!WebInspector.ASTSourceMap} map | 227 * @param {!WebInspector.ASTSourceMap} map |
| 237 * @return {?WebInspector.SASSProcessor.SetTextOperation} | 228 * @return {?WebInspector.SASSProcessor.SetTextOperation} |
| 238 */ | 229 */ |
| 239 WebInspector.SASSProcessor.SetTextOperation.fromCSSChange = function(change, map
) | 230 static fromCSSChange(change, map) { |
| 240 { | 231 var oldProperty = /** @type {!WebInspector.SASSSupport.Property} */ (change.
oldProperty()); |
| 241 var oldProperty = /** @type {!WebInspector.SASSSupport.Property} */(change.o
ldProperty()); | 232 var newProperty = /** @type {!WebInspector.SASSSupport.Property} */ (change.
newProperty()); |
| 242 var newProperty = /** @type {!WebInspector.SASSSupport.Property} */(change.n
ewProperty()); | 233 console.assert(oldProperty && newProperty, 'SetTextOperation must have both
oldProperty and newProperty'); |
| 243 console.assert(oldProperty && newProperty, "SetTextOperation must have both
oldProperty and newProperty"); | |
| 244 var newValue = null; | 234 var newValue = null; |
| 245 var sassNode = null; | 235 var sassNode = null; |
| 246 if (change.type === WebInspector.SASSSupport.PropertyChangeType.NameChanged)
{ | 236 if (change.type === WebInspector.SASSSupport.PropertyChangeType.NameChanged)
{ |
| 247 newValue = newProperty.name.text; | 237 newValue = newProperty.name.text; |
| 248 sassNode = map.toSourceNode(oldProperty.name); | 238 sassNode = map.toSourceNode(oldProperty.name); |
| 249 } else { | 239 } else { |
| 250 newValue = newProperty.value.text; | 240 newValue = newProperty.value.text; |
| 251 sassNode = map.toSourceNode(oldProperty.value); | 241 sassNode = map.toSourceNode(oldProperty.value); |
| 252 } | 242 } |
| 253 if (!sassNode) | 243 if (!sassNode) |
| 254 return null; | 244 return null; |
| 255 return new WebInspector.SASSProcessor.SetTextOperation(map, sassNode, newVal
ue); | 245 return new WebInspector.SASSProcessor.SetTextOperation(map, sassNode, newVal
ue); |
| 246 } |
| 247 |
| 248 /** |
| 249 * @override |
| 250 * @param {!WebInspector.SASSProcessor.EditOperation} other |
| 251 * @return {boolean} |
| 252 */ |
| 253 merge(other) { |
| 254 if (!(other instanceof WebInspector.SASSProcessor.SetTextOperation)) |
| 255 return false; |
| 256 return this._sassNode === other._sassNode; |
| 257 } |
| 258 |
| 259 /** |
| 260 * @override |
| 261 * @return {!Array<!WebInspector.SASSSupport.Rule>} |
| 262 */ |
| 263 perform() { |
| 264 this._sassNode.setText(this._newText); |
| 265 var nodes = this.map.toCompiledNodes(this._sassNode); |
| 266 for (var node of nodes) |
| 267 node.setText(this._newText); |
| 268 |
| 269 var cssRules = nodes.map(textNode => textNode.parent.parent); |
| 270 return cssRules; |
| 271 } |
| 272 |
| 273 /** |
| 274 * @override |
| 275 * @param {!WebInspector.ASTSourceMap} newMap |
| 276 * @param {!Map<!WebInspector.SASSSupport.Node, !WebInspector.SASSSupport.Node
>} nodeMapping |
| 277 * @return {!WebInspector.SASSProcessor.SetTextOperation} |
| 278 */ |
| 279 rebase(newMap, nodeMapping) { |
| 280 var sassNode = |
| 281 /** @type {?WebInspector.SASSSupport.TextNode} */ (nodeMapping.get(this.
_sassNode)) || this._sassNode; |
| 282 return new WebInspector.SASSProcessor.SetTextOperation(newMap, sassNode, thi
s._newText); |
| 283 } |
| 256 }; | 284 }; |
| 257 | 285 |
| 258 WebInspector.SASSProcessor.SetTextOperation.prototype = { | |
| 259 /** | |
| 260 * @override | |
| 261 * @param {!WebInspector.SASSProcessor.EditOperation} other | |
| 262 * @return {boolean} | |
| 263 */ | |
| 264 merge: function(other) | |
| 265 { | |
| 266 if (!(other instanceof WebInspector.SASSProcessor.SetTextOperation)) | |
| 267 return false; | |
| 268 return this._sassNode === other._sassNode; | |
| 269 }, | |
| 270 | |
| 271 /** | |
| 272 * @override | |
| 273 * @return {!Array<!WebInspector.SASSSupport.Rule>} | |
| 274 */ | |
| 275 perform: function() | |
| 276 { | |
| 277 this._sassNode.setText(this._newText); | |
| 278 var nodes = this.map.toCompiledNodes(this._sassNode); | |
| 279 for (var node of nodes) | |
| 280 node.setText(this._newText); | |
| 281 | |
| 282 var cssRules = nodes.map(textNode => textNode.parent.parent); | |
| 283 return cssRules; | |
| 284 }, | |
| 285 | |
| 286 /** | |
| 287 * @override | |
| 288 * @param {!WebInspector.ASTSourceMap} newMap | |
| 289 * @param {!Map<!WebInspector.SASSSupport.Node, !WebInspector.SASSSupport.No
de>} nodeMapping | |
| 290 * @return {!WebInspector.SASSProcessor.SetTextOperation} | |
| 291 */ | |
| 292 rebase: function(newMap, nodeMapping) | |
| 293 { | |
| 294 var sassNode = /** @type {?WebInspector.SASSSupport.TextNode} */(nodeMap
ping.get(this._sassNode)) || this._sassNode; | |
| 295 return new WebInspector.SASSProcessor.SetTextOperation(newMap, sassNode,
this._newText); | |
| 296 }, | |
| 297 | |
| 298 __proto__: WebInspector.SASSProcessor.EditOperation.prototype | |
| 299 }; | |
| 300 | 286 |
| 301 /** | 287 /** |
| 302 * @constructor | 288 * @unrestricted |
| 303 * @extends {WebInspector.SASSProcessor.EditOperation} | |
| 304 * @param {!WebInspector.ASTSourceMap} map | |
| 305 * @param {!WebInspector.SASSSupport.Property} sassProperty | |
| 306 * @param {boolean} newDisabled | |
| 307 */ | 289 */ |
| 308 WebInspector.SASSProcessor.TogglePropertyOperation = function(map, sassProperty,
newDisabled) | 290 WebInspector.SASSProcessor.TogglePropertyOperation = class extends WebInspector.
SASSProcessor.EditOperation { |
| 309 { | 291 /** |
| 310 WebInspector.SASSProcessor.EditOperation.call(this, map, sassProperty.docume
nt.url); | 292 * @param {!WebInspector.ASTSourceMap} map |
| 293 * @param {!WebInspector.SASSSupport.Property} sassProperty |
| 294 * @param {boolean} newDisabled |
| 295 */ |
| 296 constructor(map, sassProperty, newDisabled) { |
| 297 super(map, sassProperty.document.url); |
| 311 this._sassProperty = sassProperty; | 298 this._sassProperty = sassProperty; |
| 312 this._newDisabled = newDisabled; | 299 this._newDisabled = newDisabled; |
| 313 }; | 300 } |
| 314 | 301 |
| 315 /** | 302 /** |
| 316 * @param {!WebInspector.SASSSupport.PropertyChange} change | 303 * @param {!WebInspector.SASSSupport.PropertyChange} change |
| 317 * @param {!WebInspector.ASTSourceMap} map | 304 * @param {!WebInspector.ASTSourceMap} map |
| 318 * @return {?WebInspector.SASSProcessor.TogglePropertyOperation} | 305 * @return {?WebInspector.SASSProcessor.TogglePropertyOperation} |
| 319 */ | 306 */ |
| 320 WebInspector.SASSProcessor.TogglePropertyOperation.fromCSSChange = function(chan
ge, map) | 307 static fromCSSChange(change, map) { |
| 321 { | 308 var oldCSSProperty = /** @type {!WebInspector.SASSSupport.Property} */ (chan
ge.oldProperty()); |
| 322 var oldCSSProperty = /** @type {!WebInspector.SASSSupport.Property} */(chang
e.oldProperty()); | 309 console.assert(oldCSSProperty, 'TogglePropertyOperation must have old CSS pr
operty'); |
| 323 console.assert(oldCSSProperty, "TogglePropertyOperation must have old CSS pr
operty"); | |
| 324 var sassProperty = WebInspector.SASSProcessor._toSASSProperty(map, oldCSSPro
perty); | 310 var sassProperty = WebInspector.SASSProcessor._toSASSProperty(map, oldCSSPro
perty); |
| 325 if (!sassProperty) | 311 if (!sassProperty) |
| 326 return null; | 312 return null; |
| 327 var newDisabled = change.newProperty().disabled; | 313 var newDisabled = change.newProperty().disabled; |
| 328 return new WebInspector.SASSProcessor.TogglePropertyOperation(map, sassPrope
rty, newDisabled); | 314 return new WebInspector.SASSProcessor.TogglePropertyOperation(map, sassPrope
rty, newDisabled); |
| 315 } |
| 316 |
| 317 /** |
| 318 * @override |
| 319 * @param {!WebInspector.SASSProcessor.EditOperation} other |
| 320 * @return {boolean} |
| 321 */ |
| 322 merge(other) { |
| 323 if (!(other instanceof WebInspector.SASSProcessor.TogglePropertyOperation)) |
| 324 return false; |
| 325 return this._sassProperty === other._sassProperty; |
| 326 } |
| 327 |
| 328 /** |
| 329 * @override |
| 330 * @return {!Array<!WebInspector.SASSSupport.Rule>} |
| 331 */ |
| 332 perform() { |
| 333 this._sassProperty.setDisabled(this._newDisabled); |
| 334 var cssProperties = WebInspector.SASSProcessor._toCSSProperties(this.map, th
is._sassProperty); |
| 335 for (var property of cssProperties) |
| 336 property.setDisabled(this._newDisabled); |
| 337 |
| 338 var cssRules = cssProperties.map(property => property.parent); |
| 339 return cssRules; |
| 340 } |
| 341 |
| 342 /** |
| 343 * @override |
| 344 * @param {!WebInspector.ASTSourceMap} newMap |
| 345 * @param {!Map<!WebInspector.SASSSupport.Node, !WebInspector.SASSSupport.Node
>} nodeMapping |
| 346 * @return {!WebInspector.SASSProcessor.TogglePropertyOperation} |
| 347 */ |
| 348 rebase(newMap, nodeMapping) { |
| 349 var sassProperty = |
| 350 /** @type {?WebInspector.SASSSupport.Property} */ (nodeMapping.get(this.
_sassProperty)) || this._sassProperty; |
| 351 return new WebInspector.SASSProcessor.TogglePropertyOperation(newMap, sassPr
operty, this._newDisabled); |
| 352 } |
| 329 }; | 353 }; |
| 330 | 354 |
| 331 WebInspector.SASSProcessor.TogglePropertyOperation.prototype = { | |
| 332 /** | |
| 333 * @override | |
| 334 * @param {!WebInspector.SASSProcessor.EditOperation} other | |
| 335 * @return {boolean} | |
| 336 */ | |
| 337 merge: function(other) | |
| 338 { | |
| 339 if (!(other instanceof WebInspector.SASSProcessor.TogglePropertyOperatio
n)) | |
| 340 return false; | |
| 341 return this._sassProperty === other._sassProperty; | |
| 342 }, | |
| 343 | |
| 344 /** | |
| 345 * @override | |
| 346 * @return {!Array<!WebInspector.SASSSupport.Rule>} | |
| 347 */ | |
| 348 perform: function() | |
| 349 { | |
| 350 this._sassProperty.setDisabled(this._newDisabled); | |
| 351 var cssProperties = WebInspector.SASSProcessor._toCSSProperties(this.map
, this._sassProperty); | |
| 352 for (var property of cssProperties) | |
| 353 property.setDisabled(this._newDisabled); | |
| 354 | |
| 355 var cssRules = cssProperties.map(property => property.parent); | |
| 356 return cssRules; | |
| 357 }, | |
| 358 | |
| 359 /** | |
| 360 * @override | |
| 361 * @param {!WebInspector.ASTSourceMap} newMap | |
| 362 * @param {!Map<!WebInspector.SASSSupport.Node, !WebInspector.SASSSupport.No
de>} nodeMapping | |
| 363 * @return {!WebInspector.SASSProcessor.TogglePropertyOperation} | |
| 364 */ | |
| 365 rebase: function(newMap, nodeMapping) | |
| 366 { | |
| 367 var sassProperty = /** @type {?WebInspector.SASSSupport.Property} */(nod
eMapping.get(this._sassProperty)) || this._sassProperty; | |
| 368 return new WebInspector.SASSProcessor.TogglePropertyOperation(newMap, sa
ssProperty, this._newDisabled); | |
| 369 }, | |
| 370 | |
| 371 __proto__: WebInspector.SASSProcessor.EditOperation.prototype | |
| 372 }; | |
| 373 | 355 |
| 374 /** | 356 /** |
| 375 * @constructor | 357 * @unrestricted |
| 376 * @extends {WebInspector.SASSProcessor.EditOperation} | |
| 377 * @param {!WebInspector.ASTSourceMap} map | |
| 378 * @param {!WebInspector.SASSSupport.Property} sassProperty | |
| 379 */ | 358 */ |
| 380 WebInspector.SASSProcessor.RemovePropertyOperation = function(map, sassProperty) | 359 WebInspector.SASSProcessor.RemovePropertyOperation = class extends WebInspector.
SASSProcessor.EditOperation { |
| 381 { | 360 /** |
| 382 WebInspector.SASSProcessor.EditOperation.call(this, map, sassProperty.docume
nt.url); | 361 * @param {!WebInspector.ASTSourceMap} map |
| 362 * @param {!WebInspector.SASSSupport.Property} sassProperty |
| 363 */ |
| 364 constructor(map, sassProperty) { |
| 365 super(map, sassProperty.document.url); |
| 383 this._sassProperty = sassProperty; | 366 this._sassProperty = sassProperty; |
| 384 }; | 367 } |
| 385 | 368 |
| 386 /** | 369 /** |
| 387 * @param {!WebInspector.SASSSupport.PropertyChange} change | 370 * @param {!WebInspector.SASSSupport.PropertyChange} change |
| 388 * @param {!WebInspector.ASTSourceMap} map | 371 * @param {!WebInspector.ASTSourceMap} map |
| 389 * @return {?WebInspector.SASSProcessor.RemovePropertyOperation} | 372 * @return {?WebInspector.SASSProcessor.RemovePropertyOperation} |
| 390 */ | 373 */ |
| 391 WebInspector.SASSProcessor.RemovePropertyOperation.fromCSSChange = function(chan
ge, map) | 374 static fromCSSChange(change, map) { |
| 392 { | 375 var removedProperty = /** @type {!WebInspector.SASSSupport.Property} */ (cha
nge.oldProperty()); |
| 393 var removedProperty = /** @type {!WebInspector.SASSSupport.Property} */(chan
ge.oldProperty()); | 376 console.assert(removedProperty, 'RemovePropertyOperation must have removed C
SS property'); |
| 394 console.assert(removedProperty, "RemovePropertyOperation must have removed C
SS property"); | |
| 395 var sassProperty = WebInspector.SASSProcessor._toSASSProperty(map, removedPr
operty); | 377 var sassProperty = WebInspector.SASSProcessor._toSASSProperty(map, removedPr
operty); |
| 396 if (!sassProperty) | 378 if (!sassProperty) |
| 397 return null; | 379 return null; |
| 398 return new WebInspector.SASSProcessor.RemovePropertyOperation(map, sassPrope
rty); | 380 return new WebInspector.SASSProcessor.RemovePropertyOperation(map, sassPrope
rty); |
| 381 } |
| 382 |
| 383 /** |
| 384 * @override |
| 385 * @param {!WebInspector.SASSProcessor.EditOperation} other |
| 386 * @return {boolean} |
| 387 */ |
| 388 merge(other) { |
| 389 if (!(other instanceof WebInspector.SASSProcessor.RemovePropertyOperation)) |
| 390 return false; |
| 391 return this._sassProperty === other._sassProperty; |
| 392 } |
| 393 |
| 394 /** |
| 395 * @override |
| 396 * @return {!Array<!WebInspector.SASSSupport.Rule>} |
| 397 */ |
| 398 perform() { |
| 399 var cssProperties = WebInspector.SASSProcessor._toCSSProperties(this.map, th
is._sassProperty); |
| 400 var cssRules = cssProperties.map(property => property.parent); |
| 401 this._sassProperty.remove(); |
| 402 for (var cssProperty of cssProperties) { |
| 403 cssProperty.remove(); |
| 404 this.map.removeMapping(cssProperty.name, this._sassProperty.name); |
| 405 this.map.removeMapping(cssProperty.value, this._sassProperty.value); |
| 406 } |
| 407 |
| 408 return cssRules; |
| 409 } |
| 410 |
| 411 /** |
| 412 * @override |
| 413 * @param {!WebInspector.ASTSourceMap} newMap |
| 414 * @param {!Map<!WebInspector.SASSSupport.Node, !WebInspector.SASSSupport.Node
>} nodeMapping |
| 415 * @return {!WebInspector.SASSProcessor.RemovePropertyOperation} |
| 416 */ |
| 417 rebase(newMap, nodeMapping) { |
| 418 var sassProperty = |
| 419 /** @type {?WebInspector.SASSSupport.Property} */ (nodeMapping.get(this.
_sassProperty)) || this._sassProperty; |
| 420 return new WebInspector.SASSProcessor.RemovePropertyOperation(newMap, sassPr
operty); |
| 421 } |
| 399 }; | 422 }; |
| 400 | 423 |
| 401 WebInspector.SASSProcessor.RemovePropertyOperation.prototype = { | |
| 402 /** | |
| 403 * @override | |
| 404 * @param {!WebInspector.SASSProcessor.EditOperation} other | |
| 405 * @return {boolean} | |
| 406 */ | |
| 407 merge: function(other) | |
| 408 { | |
| 409 if (!(other instanceof WebInspector.SASSProcessor.RemovePropertyOperatio
n)) | |
| 410 return false; | |
| 411 return this._sassProperty === other._sassProperty; | |
| 412 }, | |
| 413 | |
| 414 /** | |
| 415 * @override | |
| 416 * @return {!Array<!WebInspector.SASSSupport.Rule>} | |
| 417 */ | |
| 418 perform: function() | |
| 419 { | |
| 420 var cssProperties = WebInspector.SASSProcessor._toCSSProperties(this.map
, this._sassProperty); | |
| 421 var cssRules = cssProperties.map(property => property.parent); | |
| 422 this._sassProperty.remove(); | |
| 423 for (var cssProperty of cssProperties) { | |
| 424 cssProperty.remove(); | |
| 425 this.map.removeMapping(cssProperty.name, this._sassProperty.name); | |
| 426 this.map.removeMapping(cssProperty.value, this._sassProperty.value); | |
| 427 } | |
| 428 | |
| 429 return cssRules; | |
| 430 }, | |
| 431 | |
| 432 /** | |
| 433 * @override | |
| 434 * @param {!WebInspector.ASTSourceMap} newMap | |
| 435 * @param {!Map<!WebInspector.SASSSupport.Node, !WebInspector.SASSSupport.No
de>} nodeMapping | |
| 436 * @return {!WebInspector.SASSProcessor.RemovePropertyOperation} | |
| 437 */ | |
| 438 rebase: function(newMap, nodeMapping) | |
| 439 { | |
| 440 var sassProperty = /** @type {?WebInspector.SASSSupport.Property} */(nod
eMapping.get(this._sassProperty)) || this._sassProperty; | |
| 441 return new WebInspector.SASSProcessor.RemovePropertyOperation(newMap, sa
ssProperty); | |
| 442 }, | |
| 443 | |
| 444 __proto__: WebInspector.SASSProcessor.EditOperation.prototype | |
| 445 }; | |
| 446 | 424 |
| 447 /** | 425 /** |
| 448 * @constructor | 426 * @unrestricted |
| 449 * @extends {WebInspector.SASSProcessor.EditOperation} | |
| 450 * @param {!WebInspector.ASTSourceMap} map | |
| 451 * @param {!WebInspector.SASSSupport.Rule} sassRule | |
| 452 * @param {?WebInspector.SASSSupport.Property} afterSASSProperty | |
| 453 * @param {!Array<string>} propertyNames | |
| 454 * @param {!Array<string>} propertyValues | |
| 455 * @param {!Array<boolean>} disabledStates | |
| 456 */ | 427 */ |
| 457 WebInspector.SASSProcessor.InsertPropertiesOperation = function(map, sassRule, a
fterSASSProperty, propertyNames, propertyValues, disabledStates) | 428 WebInspector.SASSProcessor.InsertPropertiesOperation = class extends WebInspecto
r.SASSProcessor.EditOperation { |
| 458 { | 429 /** |
| 430 * @param {!WebInspector.ASTSourceMap} map |
| 431 * @param {!WebInspector.SASSSupport.Rule} sassRule |
| 432 * @param {?WebInspector.SASSSupport.Property} afterSASSProperty |
| 433 * @param {!Array<string>} propertyNames |
| 434 * @param {!Array<string>} propertyValues |
| 435 * @param {!Array<boolean>} disabledStates |
| 436 */ |
| 437 constructor(map, sassRule, afterSASSProperty, propertyNames, propertyValues, d
isabledStates) { |
| 459 console.assert(propertyNames.length === propertyValues.length && propertyVal
ues.length === disabledStates.length); | 438 console.assert(propertyNames.length === propertyValues.length && propertyVal
ues.length === disabledStates.length); |
| 460 WebInspector.SASSProcessor.EditOperation.call(this, map, sassRule.document.u
rl); | 439 super(map, sassRule.document.url); |
| 461 this._sassRule = sassRule; | 440 this._sassRule = sassRule; |
| 462 this._afterSASSProperty = afterSASSProperty; | 441 this._afterSASSProperty = afterSASSProperty; |
| 463 this._nameTexts = propertyNames; | 442 this._nameTexts = propertyNames; |
| 464 this._valueTexts = propertyValues; | 443 this._valueTexts = propertyValues; |
| 465 this._disabledStates = disabledStates; | 444 this._disabledStates = disabledStates; |
| 466 }; | 445 } |
| 467 | 446 |
| 468 /** | 447 /** |
| 469 * @param {!WebInspector.SASSSupport.PropertyChange} change | 448 * @param {!WebInspector.SASSSupport.PropertyChange} change |
| 470 * @param {!WebInspector.ASTSourceMap} map | 449 * @param {!WebInspector.ASTSourceMap} map |
| 471 * @return {?WebInspector.SASSProcessor.InsertPropertiesOperation} | 450 * @return {?WebInspector.SASSProcessor.InsertPropertiesOperation} |
| 472 */ | 451 */ |
| 473 WebInspector.SASSProcessor.InsertPropertiesOperation.fromCSSChange = function(ch
ange, map) | 452 static fromCSSChange(change, map) { |
| 474 { | |
| 475 var sassRule = null; | 453 var sassRule = null; |
| 476 var afterSASSProperty = null; | 454 var afterSASSProperty = null; |
| 477 if (change.oldPropertyIndex) { | 455 if (change.oldPropertyIndex) { |
| 478 var cssAnchor = change.oldRule.properties[change.oldPropertyIndex - 1].n
ame; | 456 var cssAnchor = change.oldRule.properties[change.oldPropertyIndex - 1].nam
e; |
| 479 var sassAnchor = map.toSourceNode(cssAnchor); | 457 var sassAnchor = map.toSourceNode(cssAnchor); |
| 480 afterSASSProperty = sassAnchor ? sassAnchor.parent : null; | 458 afterSASSProperty = sassAnchor ? sassAnchor.parent : null; |
| 481 sassRule = afterSASSProperty ? afterSASSProperty.parent : null; | 459 sassRule = afterSASSProperty ? afterSASSProperty.parent : null; |
| 482 } else { | 460 } else { |
| 483 var cssAnchor = change.oldRule.blockStart; | 461 var cssAnchor = change.oldRule.blockStart; |
| 484 var sassAnchor = map.toSourceNode(cssAnchor); | 462 var sassAnchor = map.toSourceNode(cssAnchor); |
| 485 sassRule = sassAnchor ? sassAnchor.parent : null; | 463 sassRule = sassAnchor ? sassAnchor.parent : null; |
| 486 } | 464 } |
| 487 if (!sassRule) | 465 if (!sassRule) |
| 488 return null; | 466 return null; |
| 489 var insertedProperty = /** @type {!WebInspector.SASSSupport.Property} */(cha
nge.newProperty()); | 467 var insertedProperty = /** @type {!WebInspector.SASSSupport.Property} */ (ch
ange.newProperty()); |
| 490 console.assert(insertedProperty, "InsertPropertiesOperation must have insert
ed CSS property"); | 468 console.assert(insertedProperty, 'InsertPropertiesOperation must have insert
ed CSS property'); |
| 491 var names = [insertedProperty.name.text]; | 469 var names = [insertedProperty.name.text]; |
| 492 var values = [insertedProperty.value.text]; | 470 var values = [insertedProperty.value.text]; |
| 493 var disabledStates = [insertedProperty.disabled]; | 471 var disabledStates = [insertedProperty.disabled]; |
| 494 return new WebInspector.SASSProcessor.InsertPropertiesOperation(map, sassRul
e, afterSASSProperty, names, values, disabledStates); | 472 return new WebInspector.SASSProcessor.InsertPropertiesOperation( |
| 473 map, sassRule, afterSASSProperty, names, values, disabledStates); |
| 474 } |
| 475 |
| 476 /** |
| 477 * @override |
| 478 * @param {!WebInspector.SASSProcessor.EditOperation} other |
| 479 * @return {boolean} |
| 480 */ |
| 481 merge(other) { |
| 482 if (!(other instanceof WebInspector.SASSProcessor.InsertPropertiesOperation)
) |
| 483 return false; |
| 484 if (this._sassRule !== other._sassRule || this._afterSASSProperty !== other.
_afterSASSProperty) |
| 485 return false; |
| 486 var names = new Set(this._nameTexts); |
| 487 for (var i = 0; i < other._nameTexts.length; ++i) { |
| 488 var nameText = other._nameTexts[i]; |
| 489 if (names.has(nameText)) |
| 490 continue; |
| 491 this._nameTexts.push(nameText); |
| 492 this._valueTexts.push(other._valueTexts[i]); |
| 493 this._disabledStates.push(other._disabledStates[i]); |
| 494 } |
| 495 return true; |
| 496 } |
| 497 |
| 498 /** |
| 499 * @override |
| 500 * @return {!Array<!WebInspector.SASSSupport.Rule>} |
| 501 */ |
| 502 perform() { |
| 503 var newSASSProperties = this._sassRule.insertProperties( |
| 504 this._afterSASSProperty, this._nameTexts, this._valueTexts, this._disabl
edStates); |
| 505 var cssRules = []; |
| 506 var afterCSSProperties = []; |
| 507 if (this._afterSASSProperty) { |
| 508 afterCSSProperties = WebInspector.SASSProcessor._toCSSProperties(this.map,
this._afterSASSProperty); |
| 509 cssRules = afterCSSProperties.map(property => property.parent); |
| 510 } else { |
| 511 cssRules = this.map.toCompiledNodes(this._sassRule.blockStart).map(blockSt
art => blockStart.parent); |
| 512 } |
| 513 for (var i = 0; i < cssRules.length; ++i) { |
| 514 var cssRule = cssRules[i]; |
| 515 var afterCSSProperty = afterCSSProperties.length ? afterCSSProperties[i] :
null; |
| 516 var newCSSProperties = |
| 517 cssRule.insertProperties(afterCSSProperty, this._nameTexts, this._valu
eTexts, this._disabledStates); |
| 518 for (var j = 0; j < newCSSProperties.length; ++j) { |
| 519 this.map.addMapping(newCSSProperties[j].name, newSASSProperties[j].name)
; |
| 520 this.map.addMapping(newCSSProperties[j].value, newSASSProperties[j].valu
e); |
| 521 } |
| 522 } |
| 523 return cssRules; |
| 524 } |
| 525 |
| 526 /** |
| 527 * @override |
| 528 * @param {!WebInspector.ASTSourceMap} newMap |
| 529 * @param {!Map<!WebInspector.SASSSupport.Node, !WebInspector.SASSSupport.Node
>} nodeMapping |
| 530 * @return {!WebInspector.SASSProcessor.InsertPropertiesOperation} |
| 531 */ |
| 532 rebase(newMap, nodeMapping) { |
| 533 var sassRule = /** @type {?WebInspector.SASSSupport.Rule} */ (nodeMapping.ge
t(this._sassRule)) || this._sassRule; |
| 534 var afterSASSProperty = this._afterSASSProperty ? |
| 535 /** @type {?WebInspector.SASSSupport.Property} */ (nodeMapping.get(this.
_afterSASSProperty)) || |
| 536 this._afterSASSProperty : |
| 537 null; |
| 538 return new WebInspector.SASSProcessor.InsertPropertiesOperation( |
| 539 newMap, sassRule, afterSASSProperty, this._nameTexts, this._valueTexts,
this._disabledStates); |
| 540 } |
| 495 }; | 541 }; |
| 496 | 542 |
| 497 WebInspector.SASSProcessor.InsertPropertiesOperation.prototype = { | 543 |
| 498 /** | |
| 499 * @override | |
| 500 * @param {!WebInspector.SASSProcessor.EditOperation} other | |
| 501 * @return {boolean} | |
| 502 */ | |
| 503 merge: function(other) | |
| 504 { | |
| 505 if (!(other instanceof WebInspector.SASSProcessor.InsertPropertiesOperat
ion)) | |
| 506 return false; | |
| 507 if (this._sassRule !== other._sassRule || this._afterSASSProperty !== ot
her._afterSASSProperty) | |
| 508 return false; | |
| 509 var names = new Set(this._nameTexts); | |
| 510 for (var i = 0; i < other._nameTexts.length; ++i) { | |
| 511 var nameText = other._nameTexts[i]; | |
| 512 if (names.has(nameText)) | |
| 513 continue; | |
| 514 this._nameTexts.push(nameText); | |
| 515 this._valueTexts.push(other._valueTexts[i]); | |
| 516 this._disabledStates.push(other._disabledStates[i]); | |
| 517 } | |
| 518 return true; | |
| 519 }, | |
| 520 | |
| 521 /** | |
| 522 * @override | |
| 523 * @return {!Array<!WebInspector.SASSSupport.Rule>} | |
| 524 */ | |
| 525 perform: function() | |
| 526 { | |
| 527 var newSASSProperties = this._sassRule.insertProperties(this._afterSASSP
roperty, this._nameTexts, this._valueTexts, this._disabledStates); | |
| 528 var cssRules = []; | |
| 529 var afterCSSProperties = []; | |
| 530 if (this._afterSASSProperty) { | |
| 531 afterCSSProperties = WebInspector.SASSProcessor._toCSSProperties(thi
s.map, this._afterSASSProperty); | |
| 532 cssRules = afterCSSProperties.map(property => property.parent); | |
| 533 } else { | |
| 534 cssRules = this.map.toCompiledNodes(this._sassRule.blockStart).map(b
lockStart => blockStart.parent); | |
| 535 } | |
| 536 for (var i = 0; i < cssRules.length; ++i) { | |
| 537 var cssRule = cssRules[i]; | |
| 538 var afterCSSProperty = afterCSSProperties.length ? afterCSSPropertie
s[i] : null; | |
| 539 var newCSSProperties = cssRule.insertProperties(afterCSSProperty, th
is._nameTexts, this._valueTexts, this._disabledStates); | |
| 540 for (var j = 0; j < newCSSProperties.length; ++j) { | |
| 541 this.map.addMapping(newCSSProperties[j].name, newSASSProperties[
j].name); | |
| 542 this.map.addMapping(newCSSProperties[j].value, newSASSProperties
[j].value); | |
| 543 } | |
| 544 } | |
| 545 return cssRules; | |
| 546 }, | |
| 547 | |
| 548 /** | |
| 549 * @override | |
| 550 * @param {!WebInspector.ASTSourceMap} newMap | |
| 551 * @param {!Map<!WebInspector.SASSSupport.Node, !WebInspector.SASSSupport.No
de>} nodeMapping | |
| 552 * @return {!WebInspector.SASSProcessor.InsertPropertiesOperation} | |
| 553 */ | |
| 554 rebase: function(newMap, nodeMapping) | |
| 555 { | |
| 556 var sassRule = /** @type {?WebInspector.SASSSupport.Rule} */(nodeMapping
.get(this._sassRule)) || this._sassRule; | |
| 557 var afterSASSProperty = this._afterSASSProperty ? /** @type {?WebInspect
or.SASSSupport.Property} */(nodeMapping.get(this._afterSASSProperty)) || this._a
fterSASSProperty : null; | |
| 558 return new WebInspector.SASSProcessor.InsertPropertiesOperation(newMap,
sassRule, afterSASSProperty, this._nameTexts, this._valueTexts, this._disabledSt
ates); | |
| 559 }, | |
| 560 | |
| 561 __proto__: WebInspector.SASSProcessor.EditOperation.prototype | |
| 562 }; | |
| OLD | NEW |