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 InspectorTest.sassWorkspaceAdapter().trackSources(sourceMap); |
| 55 maybeStartLoading(); |
| 56 } |
| 57 |
| 58 function maybeStartLoading() |
| 59 { |
| 60 if (!sourceMap || !tokenizerFactory) |
| 61 return; |
| 62 var client = InspectorTest.sassWorkspaceAdapter().trackSources(sourceMap
); |
| 63 WebInspector.SASSLiveSourceMap._loadMapping(client, InspectorTest.cssPar
ser(), tokenizerFactory, sourceMap) |
| 64 .then(callback) |
| 65 .then(() => client.dispose()) |
| 66 } |
9 } | 67 } |
10 | 68 |
11 InspectorTest.dumpAST = function(ast) | 69 InspectorTest.dumpAST = function(ast) |
12 { | 70 { |
13 var lines = [String.sprintf("=== AST === %s", ast.document.url)]; | 71 var lines = [String.sprintf("=== AST === %s", ast.document.url)]; |
14 for (var i = 0; i < ast.rules.length; ++i) { | 72 for (var i = 0; i < ast.rules.length; ++i) { |
15 var rule = ast.rules[i]; | 73 var rule = ast.rules[i]; |
16 lines.push(String.sprintf("rule %d: \"%s\"", i, rule.selector)); | 74 lines.push(String.sprintf("rule %d: \"%s\"", i, rule.selector)); |
17 var ruleLines = dumpRule(rule); | 75 var ruleLines = dumpRule(rule); |
18 lines = lines.concat(indent(ruleLines)); | 76 lines = lines.concat(indent(ruleLines)); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 } | 191 } |
134 return ast; | 192 return ast; |
135 | 193 |
136 function validate(textNode) | 194 function validate(textNode) |
137 { | 195 { |
138 if (textNode.range.extract(textNode.document.text) !== textNode.text) | 196 if (textNode.range.extract(textNode.document.text) !== textNode.text) |
139 invalidNodes.push(textNode); | 197 invalidNodes.push(textNode); |
140 } | 198 } |
141 } | 199 } |
142 | 200 |
143 InspectorTest.validateMapping = function(mapping, cssAST, sassModels) | 201 InspectorTest.validateMapping = function(mapping) |
144 { | 202 { |
145 InspectorTest.addResult("Mapped CSS: " + mapping._cssToSass.size); | 203 InspectorTest.addResult("Mapped CSS: " + mapping._cssToSass.size); |
146 InspectorTest.addResult("Mapped SCSS: " + mapping._sassToCss.size); | 204 InspectorTest.addResult("Mapped SCSS: " + mapping._sassToCss.size); |
147 var cssNodes = mapping._cssToSass.keysArray(); | 205 var cssNodes = mapping._cssToSass.keysArray(); |
148 var staleCSS = 0; | 206 var staleCSS = 0; |
149 var staleSASS = 0; | 207 var staleSASS = 0; |
150 for (var i = 0; i < cssNodes.length; ++i) { | 208 for (var i = 0; i < cssNodes.length; ++i) { |
151 var cssNode = cssNodes[i]; | 209 var cssNode = cssNodes[i]; |
152 staleCSS += cssNode.document !== cssAST.document ? 1 : 0; | 210 staleCSS += cssNode.document !== mapping.cssAST().document ? 1 : 0; |
153 var sassNode = mapping.toSASSNode(cssNode); | 211 var sassNode = mapping.toSASSNode(cssNode); |
154 var sassAST = sassModels.get(sassNode.document.url); | 212 var sassAST = mapping.sassModels().get(sassNode.document.url); |
155 staleSASS += sassNode.document !== sassAST.document ? 1 : 0; | 213 staleSASS += sassNode.document !== sassAST.document ? 1 : 0; |
156 } | 214 } |
157 if (staleCSS || staleSASS) { | 215 if (staleCSS || staleSASS) { |
158 InspectorTest.addResult("ERROR: found stale entries"); | 216 InspectorTest.addResult("ERROR: found stale entries"); |
159 InspectorTest.addResult(" -stale CSS: " + staleCSS); | 217 InspectorTest.addResult(" -stale CSS: " + staleCSS); |
160 InspectorTest.addResult(" -stale SASS: " + staleSASS); | 218 InspectorTest.addResult(" -stale SASS: " + staleSASS); |
161 } else { | 219 } else { |
162 InspectorTest.addResult("No stale entries found."); | 220 InspectorTest.addResult("No stale entries found."); |
163 } | 221 } |
164 } | 222 } |
165 | 223 |
166 InspectorTest.parseSCSS = function(url, text) | 224 InspectorTest.updateCSSText = function(url, newText) |
167 { | 225 { |
168 return self.runtime.instancePromise(WebInspector.TokenizerFactory) | 226 var headers = InspectorTest.cssModel.styleSheetIdsForURL(url) |
169 .then(onTokenizer); | 227 .map(styleSheetId => InspectorTest.cssModel.styleSheetHeaderForId(styleS
heetId)); |
170 | 228 return Promise.all(headers.map(header => header._setContentPromise(newText))
); |
171 function onTokenizer(tokenizer) | |
172 { | |
173 return WebInspector.SASSSupport.parseSCSS(url, text, tokenizer); | |
174 } | |
175 } | 229 } |
176 | 230 |
177 var cssParser = null; | 231 InspectorTest.updateSASSText = function(url, newText) |
178 | |
179 InspectorTest.parseCSS = function(url, text) | |
180 { | 232 { |
181 if (!cssParser) | 233 var uiSourceCode = WebInspector.workspace.uiSourceCodeForURL(url); |
182 cssParser = new WebInspector.CSSParser(); | 234 uiSourceCode.addRevision(newText); |
183 return WebInspector.SASSSupport.parseCSS(cssParser, url, text); | |
184 } | 235 } |
185 | 236 |
186 } | 237 } |
187 | 238 |
OLD | NEW |