Work around a Closure Compiler bug without a pre/post process. [via @phated]

Former-commit-id: 2b9ead74c8c29357a7d8af965b6e0702e77872a5
This commit is contained in:
John-David Dalton
2012-11-08 09:01:47 -08:00
parent a1545c60d6
commit d255f8400f
5 changed files with 58 additions and 67 deletions

View File

@@ -29,13 +29,8 @@
// 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/, '={}');
// correct overly aggressive Closure Compiler minification
source = source.replace(/prototype\s*=\s*{\s*valueOf\s*:\s*1\s*}/, 'prototype={valueOf:1,y:1}');
// unescape properties (i.e. foo["bar"] => foo.bar)
source = source.replace(/(\w)\["([^."]+)"\]/g, function(match, left, right) {

View File

@@ -215,11 +215,6 @@
// remove copyright to add later in post-compile.js
source = source.replace(/\/\*![\s\S]+?\*\//, '');
// replace `arrayRef` and `objectRef` values to avoid a bug in the Closure Compiler
source = source
.replace(/(arrayRef *= *)\[\]/, '$1Array.prototype')
.replace(/(objectRef *= *)\{\}/, '$1Object.prototype');
// add brackets to whitelisted properties so the Closure Compiler won't mung them
// http://code.google.com/closure/compiler/docs/api-tutorial3.html#export
source = source.replace(RegExp('\\.(' + propWhitelist.join('|') + ')\\b', 'g'), "['$1']");