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

Side by Side Diff: third_party/WebKit/Source/devtools/scripts/namespaces.js

Issue 2626143004: DevTools: move from Common module - Geometry and CSSShadowModel (Closed)
Patch Set: minimize test diff Created 3 years, 11 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
« no previous file with comments | « third_party/WebKit/Source/devtools/scripts/extract_module/extract_module.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 const fs = require('fs'); 1 const fs = require('fs');
2 2
3 const TARGET_MODULE = 'UI';
4
3 function depends(module, from) 5 function depends(module, from)
4 { 6 {
5 if (module === from) 7 if (module === from)
6 return true; 8 return true;
7 var desc = descriptors[module]; 9 var desc = descriptors[module];
8 if (!desc) 10 if (!desc)
9 return false; 11 return false;
10 for (var dep of desc.dependencies || []) { 12 for (var dep of desc.dependencies || []) {
11 if (dep === from) 13 if (dep === from)
12 return true; 14 return true;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 var globalVariableMatch = line.match(/^var ([a-z_A-Z0-9]+)\s*(\=)/); 53 var globalVariableMatch = line.match(/^var ([a-z_A-Z0-9]+)\s*(\=)/);
52 var match = globalVariableMatch; 54 var match = globalVariableMatch;
53 55
54 if (!match) 56 if (!match)
55 continue; 57 continue;
56 var name = match[1]; 58 var name = match[1];
57 var weight = line.endsWith(name + ";") ? 2 : 1; 59 var weight = line.endsWith(name + ";") ? 2 : 1;
58 60
59 var newName; 61 var newName;
60 62
61 newName = moduleName + "." + name; 63 newName = TARGET_MODULE + "." + name;
62 var existing = map.get(name); 64 var existing = map.get(name);
63 if (existing && existing.weight > weight) 65 if (existing && existing.weight > weight)
64 continue; 66 continue;
65 if (existing && existing.weight === weight && newName !== existing.name) 67 if (existing && existing.weight === weight && newName !== existing.name)
66 console.log("Conflict: " + newName + " vs " + existing.name + " " + weight); 68 console.log("Conflict: " + newName + " vs " + existing.name + " " + weight);
67 map.set(name, {name:newName, weight}); 69 map.set(name, {name:newName, weight});
68 } 70 }
69 } 71 }
70 72
71 function write(filePath) 73 function write(filePath)
72 { 74 {
73 var content = fs.readFileSync(filePath).toString(); 75 var content = fs.readFileSync(filePath).toString();
74 var newContent = content; 76 var newContent = content;
75 for (var key of sortedKeys) { 77 for (var key of sortedKeys) {
76 var originalIdentifier = key; 78 var originalIdentifier = key;
77 var newIdentifier = map.get(key).name; 79 var newIdentifier = map.get(key).name;
78 newContent = newContent.split("\n").map(function (line) { 80 newContent = newContent.split("\n").map(line => processLine(line, origin alIdentifier, newIdentifier)).join("\n");
79 return processLine(line);
80 }).join("\n");
81 } 81 }
82 82
83 if (content !== newContent) 83 if (content !== newContent)
84 fs.writeFileSync(filePath, newContent); 84 fs.writeFileSync(filePath, newContent);
85 } 85 }
86 86
87 function processLine(line) { 87 function processLine(line, originalIdentifier, newIdentifier) {
88 // Add transformation logic 88 return line.replace(new RegExp(`^var ${originalIdentifier}`, "g"), `${newIde ntifier}`)
89 return line; 89 .replace(new RegExp(`^function ${originalIdentifier}`, "g"), `${newIdentif ier} = function`)
90 .replace(new RegExp(`^${originalIdentifier}\\.`, "g"), `${newIdentifier}.` )
91 .replace(new RegExp(`([^."'])(\\b${originalIdentifier}\\b)(?!(\.js|[ ]|['] ))`, "g"), usageReplacer);
92
93 function usageReplacer(match, p1) {
94 return [p1, newIdentifier].join("");
95 }
90 } 96 }
91 97
92 function walkSync(currentDirPath, process, json) { 98 function walkSync(currentDirPath, process, json) {
93 var path = require('path'); 99 var path = require('path');
94 fs.readdirSync(currentDirPath).forEach(function (name) { 100 fs.readdirSync(currentDirPath).forEach(function (name) {
95 var filePath = path.join(currentDirPath, name); 101 var filePath = path.join(currentDirPath, name);
96 var stat = fs.statSync(filePath); 102 var stat = fs.statSync(filePath);
97 if (stat.isFile() && (filePath.endsWith(".js") || filePath.endsWith(".ht ml") || filePath.endsWith(".xhtml") || filePath.endsWith("-expected.txt") || (js on && filePath.endsWith(".json")))) { 103 if (stat.isFile() && (filePath.endsWith(".js") || filePath.endsWith(".ht ml") || filePath.endsWith(".xhtml") || filePath.endsWith("-expected.txt") || (js on && filePath.endsWith(".json")))) {
98 if (filePath.includes("ExtensionAPI.js")) 104 if (filePath.includes("ExtensionAPI.js"))
99 return; 105 return;
100 if (filePath.includes("externs.js")) 106 if (filePath.includes("externs.js"))
101 return; 107 return;
102 if (filePath.includes("eslint") || filePath.includes("lighthouse-bac kground.js") || filePath.includes("/cm/") || filePath.includes("/xterm.js/") || filePath.includes("/acorn/") || filePath.includes("/gonzales-scss")) 108 if (filePath.includes("eslint") || filePath.includes("lighthouse-bac kground.js") || filePath.includes("/cm/") || filePath.includes("/xterm.js/") || filePath.includes("/acorn/") || filePath.includes("/gonzales-scss"))
103 return; 109 return;
104 if (filePath.includes("/cm_modes/") && !filePath.includes("DefaultCo deMirror") && !filePath.includes("module.json")) 110 if (filePath.includes("/cm_modes/") && !filePath.includes("DefaultCo deMirror") && !filePath.includes("module.json"))
105 return; 111 return;
106 process(filePath); 112 process(filePath);
107 } else if (stat.isDirectory()) { 113 } else if (stat.isDirectory()) {
108 walkSync(filePath, process, json); 114 walkSync(filePath, process, json);
109 } 115 }
110 }); 116 });
111 } 117 }
112 118
113 walkSync('front_end', read); 119 walkSync('front_end', read);
114 120
115 sortedKeys = Array.from(map.keys()); 121 sortedKeys = Array.from(map.keys());
116 sortedKeys.sort((a, b) => a.localeCompare(b)); 122 sortedKeys.sort((a, b) => a.localeCompare(b));
117 123 sortedKeys = ['Size', 'Insets', 'Constraints'];
118 for (var key of sortedKeys) 124 for (var key of sortedKeys)
119 console.log(key + " => " + map.get(key).name); 125 console.log(key + " => " + map.get(key).name);
120 126
121 walkSync('front_end', write, true); 127 walkSync('front_end', write, true);
122 128
123 walkSync('../../LayoutTests/http/tests/inspector', write, false); 129 walkSync('../../LayoutTests/http/tests/inspector', write, false);
124 walkSync('../../LayoutTests/http/tests/inspector-enabled', write, false); 130 walkSync('../../LayoutTests/http/tests/inspector-enabled', write, false);
125 walkSync('../../LayoutTests/http/tests/inspector-protocol', write, false); 131 walkSync('../../LayoutTests/http/tests/inspector-protocol', write, false);
126 walkSync('../../LayoutTests/http/tests/inspector-unit', write, false); 132 walkSync('../../LayoutTests/http/tests/inspector-unit', write, false);
127 walkSync('../../LayoutTests/inspector', write, false); 133 walkSync('../../LayoutTests/inspector', write, false);
128 walkSync('../../LayoutTests/inspector-enabled', write, false); 134 walkSync('../../LayoutTests/inspector-enabled', write, false);
129 walkSync('../../LayoutTests/inspector-protocol', write, false); 135 walkSync('../../LayoutTests/inspector-protocol', write, false);
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/scripts/extract_module/extract_module.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698