From d31471c6a1bfd94a6c6cd7c3c87cba135280edcb Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 19 May 2012 23:53:00 -0400 Subject: [PATCH] Correct the minified AMD signature for AMD build optimizers and unescape whitelisted properties from Uglified source. Former-commit-id: 93ccbb77d376b39a1b5dd38cbe74f9b4d4382e3f --- build/post-compile.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/build/post-compile.js b/build/post-compile.js index d369082cd..7f64f20f3 100644 --- a/build/post-compile.js +++ b/build/post-compile.js @@ -22,14 +22,32 @@ * @returns {String} Returns the processed source. */ function postprocess(source) { + // exit early if snippet isn't found + var snippet = /VERSION\s*:\s*([\'"])(.*?)\1/.exec(source); + if (!snippet) { + return source; + } + // set the version - var license = licenseTemplate.replace('@VERSION', (/VERSION\s*:\s*([\'"])(.*?)\1/).exec(source).pop()); + var license = licenseTemplate.replace('@VERSION', snippet[2]); + // move vars exposed by Closure Compiler into the IIFE source = source.replace(/^([^(\n]+)\s*(\(function[^)]+\){)/, '$2$1'); + // use double quotes consistently source = source.replace(/'use strict'/, '"use strict"'); + + // unescape properties (i.e. foo["bar"] => foo.bar) + source = source.replace(/(\w)\["([^."]+)"\]/g, '$1.$2'); + + // correct AMD module definition for AMD build optimizers + source = source.replace(/("function")==(typeof define)&&\(?("object")==(typeof define\.amd)(&&define\.amd)\)?/, '$2==$1&&$4==$3$5'); + // add license - return license + '\n;' + source; + source = license + '\n;' + source; + + // add trailing semicolon + return source.replace(/[\s;]*$/, ';'); } /*--------------------------------------------------------------------------*/