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

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

Issue 2769843003: DevTools: split text_utils out of common module (Closed)
Patch Set: rebaseline Created 3 years, 9 months 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 Sass.SASSProcessor = class { 7 Sass.SASSProcessor = class {
8 /** 8 /**
9 * @param {!Sass.ASTService} astService 9 * @param {!Sass.ASTService} astService
10 * @param {!Sass.ASTSourceMap} map 10 * @param {!Sass.ASTSourceMap} map
(...skipping 20 matching lines...) Expand all
31 * @param {!Sass.SASSSupport.Property} sassProperty 31 * @param {!Sass.SASSSupport.Property} sassProperty
32 * @return {!Array<!Sass.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 {!Sass.ASTService} astService 39 * @param {!Sass.ASTService} astService
40 * @param {!Sass.ASTSourceMap} map 40 * @param {!Sass.ASTSourceMap} map
41 * @param {!Array<!Common.TextRange>} ranges 41 * @param {!Array<!TextUtils.TextRange>} ranges
42 * @param {!Array<string>} newTexts 42 * @param {!Array<string>} newTexts
43 * @return {!Promise<?SDK.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 Common.Text(cssText.replaceRange(ranges[i], newTexts[i])); 50 cssText = new TextUtils.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 {!Sass.SASSSupport.AST} newCSSAST 54 * @param {!Sass.SASSSupport.AST} newCSSAST
55 * @return {!Promise<?SDK.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 {?SDK.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.
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 Common.SourceEdit(newRule.document.url, oldRange, newTex t)); 157 cssEdits.push(new TextUtils.SourceEdit(newRule.document.url, oldRange, new Text));
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 SDK.SourceMap.EditResult(map, cssEdits, newSASSSources); 167 return new SDK.SourceMap.EditResult(map, cssEdits, newSASSSources);
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 rebase(newMap, nodeMapping) { 532 rebase(newMap, nodeMapping) {
533 var sassRule = /** @type {?Sass.SASSSupport.Rule} */ (nodeMapping.get(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 {?Sass.SASSSupport.Property} */ (nodeMapping.get(this._afterSA SSProperty)) || 535 /** @type {?Sass.SASSSupport.Property} */ (nodeMapping.get(this._afterSA SSProperty)) ||
536 this._afterSASSProperty : 536 this._afterSASSProperty :
537 null; 537 null;
538 return new Sass.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