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

Side by Side Diff: third_party/WebKit/LayoutTests/inspector/sass/sass-test.js

Issue 1504923008: DevTools: [SASS] implement AST differ. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sass-module-2
Patch Set: Created 5 years 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 var initialize_SassTest = function() { 1 var initialize_SassTest = function() {
2 2
3 InspectorTest.preloadModule("sass"); 3 InspectorTest.preloadModule("sass");
4 4
5 InspectorTest.dumpAST = function(ast) 5 InspectorTest.dumpAST = function(ast)
6 { 6 {
7 var lines = [String.sprintf("=== AST === %s", ast.document.url)]; 7 var lines = [String.sprintf("=== AST === %s", ast.document.url)];
8 for (var i = 0; i < ast.rules.length; ++i) { 8 for (var i = 0; i < ast.rules.length; ++i) {
9 var rule = ast.rules[i]; 9 var rule = ast.rules[i];
10 lines.push(String.sprintf("rule %d: \"%s\"", i, rule.selector)); 10 lines.push(String.sprintf("rule %d: \"%s\"", i, rule.selector));
(...skipping 26 matching lines...) Expand all
37 lines.push(String.sprintf("range: %s", property.range.toString())); 37 lines.push(String.sprintf("range: %s", property.range.toString()));
38 lines.push(String.sprintf("disabled: %s", property.disabled)); 38 lines.push(String.sprintf("disabled: %s", property.disabled));
39 return lines; 39 return lines;
40 } 40 }
41 41
42 function dumpTextNode(textNode) 42 function dumpTextNode(textNode)
43 { 43 {
44 return [String.sprintf("range: %s", textNode.range.toString())]; 44 return [String.sprintf("range: %s", textNode.range.toString())];
45 } 45 }
46 46
47 function indent(lines) 47 }
48
49 function indent(lines)
50 {
51 return lines.map(line => " " + line);
52 }
53
54 InspectorTest.dumpASTDiff = function(diff)
55 {
56 InspectorTest.addResult("=== Diff ===");
57 var changesPerRule = new Map();
58 for (var change of diff.changes) {
59 var oldRule = change.oldRule;
60 var ruleChanges = changesPerRule.get(oldRule);
61 if (!ruleChanges) {
62 ruleChanges = [];
63 changesPerRule.set(oldRule, ruleChanges);
64 }
65 ruleChanges.push(change);
66 }
67 var T = WebInspector.SASSSupport.PropertyChangeType;
68 for (var rule of changesPerRule.keys()) {
69 var changes = changesPerRule.get(rule);
70 var names = [];
71 var values = [];
72 for (var property of rule.properties) {
73 names.push(str(property.name, " "));
74 values.push(str(property.value));
75 }
76 for (var i = changes.length - 1; i >= 0; --i) {
77 var change = changes[i];
78 var newProperty = change.newRule.properties[change.newPropertyIndex] ;
79 var oldProperty = change.oldRule.properties[change.oldPropertyIndex] ;
80 switch (change.type) {
81 case T.PropertyAdded:
82 names.splice(change.oldPropertyIndex, 0, str(newProperty.name, " [+] "));
83 values.splice(change.oldPropertyIndex, 0, str(newProperty.value) );
84 break;
85 case T.PropertyRemoved:
86 names[change.oldPropertyIndex] = str(oldProperty.name, "[-] ");
87 break;
88 case T.PropertyToggled:
89 names[change.oldPropertyIndex] = str(oldProperty.name, "[T] ");
90 break;
91 case T.NameChanged:
92 names[change.oldPropertyIndex] = str(oldProperty.name, "[M] ");
93 break;
94 case T.ValueChanged:
95 values[change.oldPropertyIndex] = str(oldProperty.value, "[M] ") ;
96 break;
97 }
98 }
99 InspectorTest.addResult("Changes for rule: " + rule.selector);
100 names = indent(names);
101 for (var i = 0; i < names.length; ++i)
102 InspectorTest.addResult(names[i] + ": " + values[i]);
103 }
104
105 function str(node, prefix)
48 { 106 {
49 return lines.map(line => " " + line); 107 prefix = prefix || "";
108 return prefix + node.text.trim();
50 } 109 }
51 } 110 }
52 111
53 InspectorTest.validateASTRanges = function(ast) 112 InspectorTest.validateASTRanges = function(ast)
54 { 113 {
55 var invalidNodes = []; 114 var invalidNodes = [];
56 for (var rule of ast.rules) { 115 for (var rule of ast.rules) {
57 for (var property of rule.properties) { 116 for (var property of rule.properties) {
58 validate(property.name); 117 validate(property.name);
59 validate(property.value); 118 validate(property.value);
(...skipping 30 matching lines...) Expand all
90 149
91 InspectorTest.parseCSS = function(url, text) 150 InspectorTest.parseCSS = function(url, text)
92 { 151 {
93 if (!cssParser) 152 if (!cssParser)
94 cssParser = new WebInspector.CSSParser(); 153 cssParser = new WebInspector.CSSParser();
95 return WebInspector.SASSSupport.parseCSS(cssParser, url, text); 154 return WebInspector.SASSSupport.parseCSS(cssParser, url, text);
96 } 155 }
97 156
98 } 157 }
99 158
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698