Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sass/SASSProcessor.js

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

Powered by Google App Engine
This is Rietveld 408576698