OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 Selector: "Selector", | 205 Selector: "Selector", |
206 Style: "Style", | 206 Style: "Style", |
207 PropertyName: "PropertyName", | 207 PropertyName: "PropertyName", |
208 PropertyValue: "PropertyValue", | 208 PropertyValue: "PropertyValue", |
209 AtRule: "AtRule", | 209 AtRule: "AtRule", |
210 }; | 210 }; |
211 | 211 |
212 FormatterWorker.parseCSS = function(params) | 212 FormatterWorker.parseCSS = function(params) |
213 { | 213 { |
214 var chunkSize = 100000; // characters per data chunk | 214 var chunkSize = 100000; // characters per data chunk |
215 var totalLength = params.content.length; | |
216 var lines = params.content.split("\n"); | 215 var lines = params.content.split("\n"); |
217 var chunkCount = FormatterWorker._chunkCount(totalLength, chunkSize); | |
218 var rules = []; | 216 var rules = []; |
219 var processedChunkCharacters = 0; | 217 var processedChunkCharacters = 0; |
220 var currentChunk = 0; | |
221 | 218 |
222 var state = FormatterWorker.CSSParserStates.Initial; | 219 var state = FormatterWorker.CSSParserStates.Initial; |
223 var rule; | 220 var rule; |
224 var property; | 221 var property; |
225 var UndefTokenType = {}; | 222 var UndefTokenType = {}; |
226 | 223 |
227 /** | 224 /** |
228 * @param {string} tokenValue | 225 * @param {string} tokenValue |
229 * @param {?string} tokenTypes | 226 * @param {?string} tokenTypes |
230 * @param {number} column | 227 * @param {number} column |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 state = FormatterWorker.CSSParserStates.Initial; | 298 state = FormatterWorker.CSSParserStates.Initial; |
302 } else if (!tokenType["comment"]) { | 299 } else if (!tokenType["comment"]) { |
303 property.value += tokenValue; | 300 property.value += tokenValue; |
304 } | 301 } |
305 break; | 302 break; |
306 default: | 303 default: |
307 console.assert(false, "Unknown CSS parser state."); | 304 console.assert(false, "Unknown CSS parser state."); |
308 } | 305 } |
309 processedChunkCharacters += newColumn - column; | 306 processedChunkCharacters += newColumn - column; |
310 if (processedChunkCharacters > chunkSize) { | 307 if (processedChunkCharacters > chunkSize) { |
311 postMessage({ chunk: rules, total: chunkCount, index: currentChunk++
}); | 308 postMessage({ chunk: rules, isLastChunk: false }); |
312 rules = []; | 309 rules = []; |
313 processedChunkCharacters = 0; | 310 processedChunkCharacters = 0; |
314 } | 311 } |
315 } | 312 } |
316 var tokenizer = FormatterWorker.createTokenizer("text/css"); | 313 var tokenizer = FormatterWorker.createTokenizer("text/css"); |
317 var lineNumber; | 314 var lineNumber; |
318 for (lineNumber = 0; lineNumber < lines.length; ++lineNumber) { | 315 for (lineNumber = 0; lineNumber < lines.length; ++lineNumber) { |
319 var line = lines[lineNumber]; | 316 var line = lines[lineNumber]; |
320 tokenizer(line, processToken); | 317 tokenizer(line, processToken); |
321 } | 318 } |
322 postMessage({ chunk: rules, total: chunkCount, index: currentChunk++ }); | 319 postMessage({ chunk: rules, isLastChunk: true }); |
323 } | 320 } |
324 | 321 |
325 /** | 322 /** |
326 * @param {string} content | 323 * @param {string} content |
327 * @param {!{original: !Array.<number>, formatted: !Array.<number>}} mapping | 324 * @param {!{original: !Array.<number>, formatted: !Array.<number>}} mapping |
328 * @param {number} offset | 325 * @param {number} offset |
329 * @param {number} formattedOffset | 326 * @param {number} formattedOffset |
330 * @param {string} indentString | 327 * @param {string} indentString |
331 * @return {string} | 328 * @return {string} |
332 */ | 329 */ |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 | 497 |
501 /** | 498 /** |
502 * @type {!{tokenizer}} | 499 * @type {!{tokenizer}} |
503 */ | 500 */ |
504 var exports = { tokenizer: null }; | 501 var exports = { tokenizer: null }; |
505 importScripts("UglifyJS/parse-js.js"); | 502 importScripts("UglifyJS/parse-js.js"); |
506 var parse = exports; | 503 var parse = exports; |
507 | 504 |
508 importScripts("JavaScriptFormatter.js"); | 505 importScripts("JavaScriptFormatter.js"); |
509 importScripts("CSSFormatter.js"); | 506 importScripts("CSSFormatter.js"); |
OLD | NEW |