Cleanup build script comments and fix Closure Compiler bugs.

Former-commit-id: 84771ac79d6cfd7ec3b0d29586edf58d617d5577
This commit is contained in:
John-David Dalton
2012-10-23 23:54:53 -07:00
parent ad9ddc5621
commit eccf92ebaf
4 changed files with 28 additions and 19 deletions

View File

@@ -26,9 +26,17 @@
* @returns {String} Returns the processed source.
*/
function postprocess(source) {
// move vars exposed by Closure Compiler into the IIFE
// move vars exposed by the Closure Compiler into the IIFE
source = source.replace(/^((?:(['"])use strict\2;)?(?:var (?:[a-z]+=(?:!0|!1|null)[,;])+)?)([\s\S]*?function[^)]+\){)/, '$3$1');
// avoid bugs with the Closure Compiler
source = source
// correct overly aggressive Closure Compiler minification
.replace(/prototype\s*=\s*{\s*valueOf\s*:\s*1\s*}/, 'prototype={valueOf:1,y:1}')
// restore `arrayRef` and `objectRef` values modified by pre-compile.js
.replace(/= *Array.prototype/, '=[]')
.replace(/= *Object.prototype/, '={}');
// unescape properties (i.e. foo["bar"] => foo.bar)
source = source.replace(/(\w)\["([^."]+)"\]/g, function(match, left, right) {
return /\W/.test(right) ? match : (left + '.' + right);