| OLD | NEW |
| 1 /** | 1 /** |
| 2 * @license | 2 * @license |
| 3 * Copyright (c) 2014 The Polymer Project Authors. All rights reserved. | 3 * Copyright (c) 2014 The Polymer Project Authors. All rights reserved. |
| 4 * This code may only be used under the BSD style license found at http://polyme
r.github.io/LICENSE.txt | 4 * This code may only be used under the BSD style license found at http://polyme
r.github.io/LICENSE.txt |
| 5 * The complete set of authors may be found at http://polymer.github.io/AUTHORS.
txt | 5 * The complete set of authors may be found at http://polymer.github.io/AUTHORS.
txt |
| 6 * The complete set of contributors may be found at http://polymer.github.io/CON
TRIBUTORS.txt | 6 * The complete set of contributors may be found at http://polymer.github.io/CON
TRIBUTORS.txt |
| 7 * Code distributed by Google as part of the polymer project is also | 7 * Code distributed by Google as part of the polymer project is also |
| 8 * subject to an additional IP rights grant found at http://polymer.github.io/PA
TENTS.txt | 8 * subject to an additional IP rights grant found at http://polymer.github.io/PA
TENTS.txt |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 // jshint node: true | 11 // jshint node: true |
| 12 | 12 |
| 13 var cssom = require('cssom'); | |
| 14 var fs = require('fs'); | 13 var fs = require('fs'); |
| 15 var path = require('path'); | 14 var path = require('path'); |
| 16 var uglify = require('uglify-js'); | 15 var uglify = require('uglify-js'); |
| 17 var url = require('url'); | 16 var url = require('url'); |
| 18 var whacko = require('whacko'); | 17 var whacko = require('whacko'); |
| 19 | 18 |
| 20 var constants = require('./constants.js'); | 19 var constants = require('./constants.js'); |
| 21 var optparser = require('./optparser.js'); | 20 var optparser = require('./optparser.js'); |
| 22 var pathresolver = require('./pathresolver'); | 21 var pathresolver = require('./pathresolver'); |
| 23 var utils = require('./utils'); | 22 var utils = require('./utils'); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 js_err.detail = e.message + ' at line: ' + e.line + ' col: ' + e.col; | 192 js_err.detail = e.message + ' at line: ' + e.line + ' col: ' + e.col; |
| 194 js_err.content = content; | 193 js_err.content = content; |
| 195 js_err.toString = function() { | 194 js_err.toString = function() { |
| 196 return this.message + '\n' + this.detail + '\n' + this.content; | 195 return this.message + '\n' + this.detail + '\n' + this.content; |
| 197 }; | 196 }; |
| 198 throw js_err; | 197 throw js_err; |
| 199 } | 198 } |
| 200 } | 199 } |
| 201 | 200 |
| 202 function compressCSS(content) { | 201 function compressCSS(content) { |
| 203 var out; | 202 // remove newlines |
| 204 try { | 203 var out = content.replace(/[\r\n]/g, ''); |
| 205 var ast = cssom.parse(content); | 204 // remove css comments (/* ... */) |
| 206 out = ast.toString(); | 205 out = out.replace(/\/\*(.+?)\*\//g, ''); |
| 207 } catch (e) { | 206 // remove duplicate whitespace |
| 208 if (options.verbose) { | 207 out = out.replace(/\s{2,}/g, ' '); |
| 209 console.log('Error parsing CSS:', e.toString()); | 208 return out; |
| 210 console.log('Falling back to removing newlines only'); | |
| 211 } | |
| 212 out = content; | |
| 213 } finally { | |
| 214 return out.replace(/[\r\n]/g, ''); | |
| 215 } | |
| 216 } | 209 } |
| 217 | 210 |
| 218 function removeCommentsAndWhitespace($) { | 211 function removeCommentsAndWhitespace($) { |
| 219 function walk(node) { | 212 function walk(node) { |
| 220 var content, c; | 213 var content, c; |
| 221 if (!node) { | 214 if (!node) { |
| 222 return; | 215 return; |
| 223 } else if (isCommentOrEmptyTextNode(node)) { | 216 } else if (isCommentOrEmptyTextNode(node)) { |
| 224 $(node).remove(); | 217 $(node).remove(); |
| 225 return true; | 218 return true; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 if(options.verbose) { | 340 if(options.verbose) { |
| 348 console.log('Import Dependency deduplicated'); | 341 console.log('Import Dependency deduplicated'); |
| 349 } | 342 } |
| 350 el.remove(); | 343 el.remove(); |
| 351 } | 344 } |
| 352 }); | 345 }); |
| 353 } | 346 } |
| 354 | 347 |
| 355 exports.processDocument = handleMainDocument; | 348 exports.processDocument = handleMainDocument; |
| 356 exports.setOptions = setOptions; | 349 exports.setOptions = setOptions; |
| OLD | NEW |