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

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

Issue 1809533003: DevTools: remove illusionary caching from String.prototype.lineEndings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: String.prototype.lineEndings -> String.prototype.computeLineEndings Created 4 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 /** 5 /**
6 * @constructor 6 * @constructor
7 * @param {!WebInspector.ASTService} astService 7 * @param {!WebInspector.ASTService} astService
8 * @param {!WebInspector.ASTSourceMap} map 8 * @param {!WebInspector.ASTSourceMap} map
9 * @param {!Array<!WebInspector.SASSProcessor.EditOperation>} editOperations 9 * @param {!Array<!WebInspector.SASSProcessor.EditOperation>} editOperations
10 */ 10 */
(...skipping 17 matching lines...) Expand all
28 changedCSSRules.addAll(rules); 28 changedCSSRules.addAll(rules);
29 } 29 }
30 30
31 // Reparse new texts, make sure changes result in anticipated AST trees. 31 // Reparse new texts, make sure changes result in anticipated AST trees.
32 var promises = []; 32 var promises = [];
33 for (var ast of this._map.models().values()) { 33 for (var ast of this._map.models().values()) {
34 if (!ast.document.hasChanged()) 34 if (!ast.document.hasChanged())
35 continue; 35 continue;
36 var promise; 36 var promise;
37 if (ast.document.url === this._map.cssURL()) 37 if (ast.document.url === this._map.cssURL())
38 promise = this._astService.parseCSS(ast.document.url, ast.docume nt.newText()); 38 promise = this._astService.parseCSS(ast.document.url, ast.docume nt.newText().value());
39 else 39 else
40 promise = this._astService.parseSCSS(ast.document.url, ast.docum ent.newText()); 40 promise = this._astService.parseSCSS(ast.document.url, ast.docum ent.newText().value());
41 promises.push(promise); 41 promises.push(promise);
42 } 42 }
43 43
44 return Promise.all(promises) 44 return Promise.all(promises)
45 .then(this._onFinished.bind(this, changedCSSRules)); 45 .then(this._onFinished.bind(this, changedCSSRules));
46 }, 46 },
47 47
48 /** 48 /**
49 * @param {!Set<!WebInspector.SASSSupport.Rule>} changedCSSRules 49 * @param {!Set<!WebInspector.SASSSupport.Rule>} changedCSSRules
50 * @param {!Array<!WebInspector.SASSSupport.AST>} changedModels 50 * @param {!Array<!WebInspector.SASSSupport.AST>} changedModels
51 * @return {?WebInspector.SASSProcessor.Result} 51 * @return {?WebInspector.SASSProcessor.Result}
52 */ 52 */
53 _onFinished: function(changedCSSRules, changedModels) 53 _onFinished: function(changedCSSRules, changedModels)
54 { 54 {
55 var nodeMapping = new Map(); 55 var nodeMapping = new Map();
56 var map = this._map.rebase(changedModels, nodeMapping); 56 var map = this._map.rebase(changedModels, nodeMapping);
57 if (!map) 57 if (!map)
58 return null; 58 return null;
59 59
60 var cssEdits = []; 60 var cssEdits = [];
61 for (var rule of changedCSSRules) { 61 for (var rule of changedCSSRules) {
62 var oldRange = rule.styleRange; 62 var oldRange = rule.styleRange;
63 var newRule = nodeMapping.get(rule); 63 var newRule = nodeMapping.get(rule);
64 var newText = newRule.styleRange.extract(newRule.document.text); 64 var newText = newRule.document.text.extract(newRule.styleRange);
65 cssEdits.push(new WebInspector.SourceEdit(newRule.document.url, oldR ange, newText)); 65 cssEdits.push(new WebInspector.SourceEdit(newRule.document.url, oldR ange, newText));
66 } 66 }
67 67
68 /** @type {!Map<string, string>} */ 68 /** @type {!Map<string, string>} */
69 var newSASSSources = new Map(); 69 var newSASSSources = new Map();
70 for (var model of changedModels) { 70 for (var model of changedModels) {
71 if (model.document.url === map.cssURL()) 71 if (model.document.url === map.cssURL())
72 continue; 72 continue;
73 newSASSSources.set(model.document.url, model.document.text); 73 newSASSSources.set(model.document.url, model.document.text.value());
74 } 74 }
75 return new WebInspector.SASSProcessor.Result(map, cssEdits, newSASSSourc es); 75 return new WebInspector.SASSProcessor.Result(map, cssEdits, newSASSSourc es);
76 } 76 }
77 } 77 }
78 78
79 /** 79 /**
80 * @constructor 80 * @constructor
81 * @param {!WebInspector.ASTSourceMap} map 81 * @param {!WebInspector.ASTSourceMap} map
82 * @param {!Array<!WebInspector.SourceEdit>} cssEdits 82 * @param {!Array<!WebInspector.SourceEdit>} cssEdits
83 * @param {!Map<string, string>} newSASSSources 83 * @param {!Map<string, string>} newSASSSources
(...skipping 10 matching lines...) Expand all
94 * @param {!WebInspector.ASTSourceMap} map 94 * @param {!WebInspector.ASTSourceMap} map
95 * @param {!Array<!WebInspector.TextRange>} ranges 95 * @param {!Array<!WebInspector.TextRange>} ranges
96 * @param {!Array<string>} newTexts 96 * @param {!Array<string>} newTexts
97 * @return {!Promise<?WebInspector.SASSProcessor.Result>} 97 * @return {!Promise<?WebInspector.SASSProcessor.Result>}
98 */ 98 */
99 WebInspector.SASSProcessor.processCSSEdits = function(astService, map, ranges, n ewTexts) 99 WebInspector.SASSProcessor.processCSSEdits = function(astService, map, ranges, n ewTexts)
100 { 100 {
101 console.assert(ranges.length === newTexts.length); 101 console.assert(ranges.length === newTexts.length);
102 var cssURL = map.cssURL(); 102 var cssURL = map.cssURL();
103 var cssText = map.cssAST().document.text; 103 var cssText = map.cssAST().document.text;
104 for (var i = 0; i < ranges.length; ++i) { 104 for (var i = 0; i < ranges.length; ++i)
105 var range = ranges[i]; 105 cssText = new WebInspector.Text(cssText.replaceRange(ranges[i], newTexts [i]));
106 var edit = new WebInspector.SourceEdit(cssURL, range, newTexts[i]); 106 return astService.parseCSS(cssURL, cssText.value())
107 cssText = edit.applyToText(cssText);
108 }
109 return astService.parseCSS(cssURL, cssText)
110 .then(onCSSParsed); 107 .then(onCSSParsed);
111 108
112 /** 109 /**
113 * @param {!WebInspector.SASSSupport.AST} newCSSAST 110 * @param {!WebInspector.SASSSupport.AST} newCSSAST
114 * @return {!Promise<?WebInspector.SASSProcessor.Result>} 111 * @return {!Promise<?WebInspector.SASSProcessor.Result>}
115 */ 112 */
116 function onCSSParsed(newCSSAST) 113 function onCSSParsed(newCSSAST)
117 { 114 {
118 //TODO(lushnikov): only diff changed styles. 115 //TODO(lushnikov): only diff changed styles.
119 var cssDiff = WebInspector.SASSSupport.diffModels(map.cssAST(), newCSSAS T); 116 var cssDiff = WebInspector.SASSSupport.diffModels(map.cssAST(), newCSSAS T);
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 * @return {!WebInspector.SASSProcessor.InsertPropertiesOperation} 536 * @return {!WebInspector.SASSProcessor.InsertPropertiesOperation}
540 */ 537 */
541 rebase: function(newMap, nodeMapping) 538 rebase: function(newMap, nodeMapping)
542 { 539 {
543 var sassAnchor = /** @type {?WebInspector.SASSSupport.Property} */(nodeM apping.get(this._sassAnchor)) || this._sassAnchor; 540 var sassAnchor = /** @type {?WebInspector.SASSSupport.Property} */(nodeM apping.get(this._sassAnchor)) || this._sassAnchor;
544 return new WebInspector.SASSProcessor.InsertPropertiesOperation(newMap, sassAnchor, this._insertBefore, this._nameTexts, this._valueTexts, this._disable dStates); 541 return new WebInspector.SASSProcessor.InsertPropertiesOperation(newMap, sassAnchor, this._insertBefore, this._nameTexts, this._valueTexts, this._disable dStates);
545 }, 542 },
546 543
547 __proto__: WebInspector.SASSProcessor.EditOperation.prototype 544 __proto__: WebInspector.SASSProcessor.EditOperation.prototype
548 } 545 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698