OLD | NEW |
---|---|
1 var initialize_SassTest = function() { | 1 var initialize_SassTest = function() { |
2 | 2 |
3 InspectorTest.preloadModule("sass"); | 3 InspectorTest.preloadModule("sass"); |
4 | 4 |
5 InspectorTest.loadSourceMap = function(header, callback) | 5 var sassWorkspaceAdapter = null; |
6 InspectorTest.sassWorkspaceAdapter = function() | |
6 { | 7 { |
8 if (!sassWorkspaceAdapter) | |
9 sassWorkspaceAdapter = new WebInspector.SASSWorkspaceAdapter(InspectorTe st.cssModel, WebInspector.workspace, WebInspector.networkMapping); | |
10 return sassWorkspaceAdapter; | |
11 } | |
12 | |
13 var cssParser = null; | |
14 | |
15 InspectorTest.cssParser = function() | |
16 { | |
17 if (!cssParser) | |
18 cssParser = new WebInspector.CSSParser(); | |
19 return cssParser; | |
20 } | |
21 | |
22 InspectorTest.parseCSS = function(url, text) | |
23 { | |
24 return WebInspector.SASSSupport.parseCSS(InspectorTest.cssParser(), url, tex t); | |
25 } | |
26 | |
27 InspectorTest.parseSCSS = function(url, text) | |
28 { | |
29 return self.runtime.instancePromise(WebInspector.TokenizerFactory) | |
30 .then(onTokenizer); | |
31 | |
32 function onTokenizer(tokenizer) | |
33 { | |
34 return WebInspector.SASSSupport.parseSCSS(url, text, tokenizer); | |
35 } | |
36 } | |
37 | |
38 InspectorTest.loadASTMapping = function(header, callback) | |
39 { | |
40 console.assert(header.cssModel() === InspectorTest.sassWorkspaceAdapter()._c ssModel, "The header could not be processed by main target workspaceAdapter"); | |
41 var tokenizerFactory = null; | |
42 var sourceMap = null; | |
43 | |
7 var completeSourceMapURL = WebInspector.ParsedURL.completeURL(header.sourceU RL, header.sourceMapURL); | 44 var completeSourceMapURL = WebInspector.ParsedURL.completeURL(header.sourceU RL, header.sourceMapURL); |
8 WebInspector.SourceMap.load(completeSourceMapURL, header.sourceURL, callback ); | 45 WebInspector.SourceMap.load(completeSourceMapURL, header.sourceURL, onSource MapLoaded); |
46 | |
47 self.runtime.instancePromise(WebInspector.TokenizerFactory) | |
48 .then(tf => tokenizerFactory = tf) | |
49 .then(maybeStartLoading); | |
50 | |
51 function onSourceMapLoaded(sm) | |
52 { | |
53 sourceMap = sm; | |
54 maybeStartLoading(); | |
55 } | |
56 | |
57 function maybeStartLoading() | |
58 { | |
59 if (!sourceMap || !tokenizerFactory) | |
60 return; | |
61 var client = InspectorTest.sassWorkspaceAdapter().trackSources(sourceMap ); | |
62 WebInspector.SASSLiveSourceMap._loadMapping(client, InspectorTest.cssPar ser(), tokenizerFactory, sourceMap) | |
63 .then(callback) | |
64 .then(() => client.dispose()) | |
65 } | |
9 } | 66 } |
10 | 67 |
11 InspectorTest.dumpAST = function(ast) | 68 InspectorTest.dumpAST = function(ast) |
12 { | 69 { |
13 var lines = [String.sprintf("=== AST === %s", ast.document.url)]; | 70 var lines = [String.sprintf("=== AST === %s", ast.document.url)]; |
14 for (var i = 0; i < ast.rules.length; ++i) { | 71 for (var i = 0; i < ast.rules.length; ++i) { |
15 var rule = ast.rules[i]; | 72 var rule = ast.rules[i]; |
16 lines.push(String.sprintf("rule %d: \"%s\"", i, rule.selector)); | 73 lines.push(String.sprintf("rule %d: \"%s\"", i, rule.selector)); |
17 var ruleLines = dumpRule(rule); | 74 var ruleLines = dumpRule(rule); |
18 lines = lines.concat(indent(ruleLines)); | 75 lines = lines.concat(indent(ruleLines)); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 } | 190 } |
134 return ast; | 191 return ast; |
135 | 192 |
136 function validate(textNode) | 193 function validate(textNode) |
137 { | 194 { |
138 if (textNode.range.extract(textNode.document.text) !== textNode.text) | 195 if (textNode.range.extract(textNode.document.text) !== textNode.text) |
139 invalidNodes.push(textNode); | 196 invalidNodes.push(textNode); |
140 } | 197 } |
141 } | 198 } |
142 | 199 |
143 InspectorTest.validateMapping = function(mapping, cssAST, sassModels) | 200 InspectorTest.validateMapping = function(mapping) |
144 { | 201 { |
145 InspectorTest.addResult("Mapped CSS: " + mapping._cssToSass.size); | 202 InspectorTest.addResult("Mapped CSS: " + mapping._cssToSass.size); |
146 InspectorTest.addResult("Mapped SCSS: " + mapping._sassToCss.size); | 203 InspectorTest.addResult("Mapped SCSS: " + mapping._sassToCss.size); |
147 var cssNodes = mapping._cssToSass.keysArray(); | 204 var cssNodes = mapping._cssToSass.keysArray(); |
148 var staleCSS = 0; | 205 var staleCSS = 0; |
149 var staleSASS = 0; | 206 var staleSASS = 0; |
150 for (var i = 0; i < cssNodes.length; ++i) { | 207 for (var i = 0; i < cssNodes.length; ++i) { |
151 var cssNode = cssNodes[i]; | 208 var cssNode = cssNodes[i]; |
152 staleCSS += cssNode.document !== cssAST.document ? 1 : 0; | 209 staleCSS += cssNode.document !== mapping.cssAST().document ? 1 : 0; |
153 var sassNode = mapping.toSASSNode(cssNode); | 210 var sassNode = mapping.toSASSNode(cssNode); |
154 var sassAST = sassModels.get(sassNode.document.url); | 211 var sassAST = mapping.sassModels().get(sassNode.document.url); |
155 staleSASS += sassNode.document !== sassAST.document ? 1 : 0; | 212 staleSASS += sassNode.document !== sassAST.document ? 1 : 0; |
156 } | 213 } |
157 if (staleCSS || staleSASS) { | 214 if (staleCSS || staleSASS) { |
158 InspectorTest.addResult("ERROR: found stale entries"); | 215 InspectorTest.addResult("ERROR: found stale entries"); |
159 InspectorTest.addResult(" -stale CSS: " + staleCSS); | 216 InspectorTest.addResult(" -stale CSS: " + staleCSS); |
160 InspectorTest.addResult(" -stale SASS: " + staleSASS); | 217 InspectorTest.addResult(" -stale SASS: " + staleSASS); |
161 } else { | 218 } else { |
162 InspectorTest.addResult("No stale entries found."); | 219 InspectorTest.addResult("No stale entries found."); |
163 } | 220 } |
164 } | 221 } |
165 | 222 |
166 InspectorTest.parseSCSS = function(url, text) | 223 InspectorTest.updateCSSText = function(url, newText) |
167 { | 224 { |
168 return self.runtime.instancePromise(WebInspector.TokenizerFactory) | 225 var styleSheetIds = InspectorTest.cssModel.styleSheetIdsForURL(url) |
dgozman
2016/01/28 01:11:52
semicolon missing
| |
169 .then(onTokenizer); | 226 var promises = styleSheetIds.map(id => InspectorTest.cssModel.setStyleSheetT ext(id, newText, true)); |
170 | 227 return Promise.all(promises); |
171 function onTokenizer(tokenizer) | |
172 { | |
173 return WebInspector.SASSSupport.parseSCSS(url, text, tokenizer); | |
174 } | |
175 } | 228 } |
176 | 229 |
177 var cssParser = null; | 230 InspectorTest.updateSASSText = function(url, newText) |
178 | |
179 InspectorTest.parseCSS = function(url, text) | |
180 { | 231 { |
181 if (!cssParser) | 232 var uiSourceCode = WebInspector.workspace.uiSourceCodeForURL(url); |
182 cssParser = new WebInspector.CSSParser(); | 233 uiSourceCode.addRevision(newText); |
183 return WebInspector.SASSSupport.parseCSS(cssParser, url, text); | |
184 } | 234 } |
185 | 235 |
186 } | 236 } |
187 | 237 |
OLD | NEW |