Move generic Closure Compiler fixes into build/minify.js.

Former-commit-id: 8492f60a67cbf7a2d7d3118f9653e6997ab1d15b
This commit is contained in:
John-David Dalton
2013-01-21 01:13:51 -08:00
parent 27f1e5e2f2
commit 607abf89f7
6 changed files with 54 additions and 44 deletions

View File

@@ -24,22 +24,14 @@
* @returns {String} Returns the processed source.
*/
function postprocess(source) {
// remove old copyright/license header
// remove copyright header
source = source.replace(/^\/\**[\s\S]+?\*\/\n/, '');
// move vars exposed by the Closure Compiler into the IIFE
source = source.replace(/^((?:var (?:\w+=(?:!0|!1|null)[,;])+)?)([\s\S]*?function[^)]+\){)/, '$2$1');
// correct overly aggressive Closure Compiler advanced optimizations
source = source
.replace(/prototype\s*=\s*{\s*valueOf\s*:\s*1\s*}/, 'prototype={valueOf:1,y:1}')
.replace(/(document[^&]+&&)\s*\w+/, '$1!({toString:0}+"")');
// unescape properties (e.g. foo["bar"] => foo.bar)
source = source.replace(/(\w)\["([^."]+)"\]/g, function(match, left, right) {
return /\W/.test(right) ? match : (left + '.' + right);
});
// flip `typeof` expressions to help optimize Safari and
// correct the AMD module definition for AMD build optimizers
// (e.g. from `"number" == typeof x` to `typeof x == "number")
@@ -56,7 +48,7 @@
if (!snippet) {
return source;
}
// add new copyright/license header
// add new copyright header
var version = snippet[2];
source = licenseTemplate.replace('<%= VERSION %>', version) + '\n;' + source;