From 7995a57f7777b230d659040171a8632bd70f934a Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 1 Jul 2013 23:17:17 -0700 Subject: [PATCH] Move `support` object cleanup after unused variable cleanup in build.js. Former-commit-id: 5a334f66f6cb4b5f5fba77148ddc0406e1118f08 --- build.js | 59 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/build.js b/build.js index edb2496f5..31bcce889 100755 --- a/build.js +++ b/build.js @@ -3973,35 +3973,6 @@ return match.replace(/'Error', */, ''); }); } - // remove code used to resolve unneeded `support` properties - source = source.replace(matchVar(source, 'support'), function(match) { - return match.replace(/^ *\(function[\s\S]+?\n(( *)var ctor *=[\s\S]+?(?:\n *for.+)+\n)([\s\S]+?)}\(1\)\);\n/m, function(match, setup, indent, body) { - var modified = setup; - - if (!/support\.spliceObjects *=(?! *(?:false|true))/.test(body)) { - modified = modified.replace(/^ *object *=.+\n/m, ''); - } - if (!/support\.enumPrototypes *=(?! *(?:false|true))/.test(body) && - !/support\.nonEnumShadows *=(?! *(?:false|true))/.test(body) && - !/support\.ownLast *=(?! *(?:false|true))/.test(body)) { - modified = modified - .replace(/\bctor *=.+\s+/, '') - .replace(/^ *ctor\.prototype.+\s+.+\n/m, '') - .replace(/(?:,\n)? *props *=[^;=]+/, '') - .replace(/^ *for *\((?=prop)/, '$&var ') - } - if (!/support\.nonEnumArgs *=(?! *(?:false|true))/.test(body)) { - modified = modified.replace(/^ *for *\(.+? arguments.+\n/m, ''); - } - // cleanup the empty var statement - modified = modified.replace(/^ *var;\n/m, ''); - - // if no setup then remove IIFE - return /^\s*$/.test(modified) - ? body.replace(RegExp('^' + indent, 'gm'), indent.slice(0, -2)) - : match.replace(setup, modified); - }); - }); } // remove functions from the build @@ -4057,6 +4028,36 @@ } }()); + // remove code used to resolve unneeded `support` properties + source = source.replace(matchVar(source, 'support'), function(match) { + return match.replace(/^ *\(function[\s\S]+?\n(( *)var ctor *=[\s\S]+?(?:\n *for.+)+\n)([\s\S]+?)}\(1\)\);\n/m, function(match, setup, indent, body) { + var modified = setup; + + if (!/support\.spliceObjects *=(?! *(?:false|true))/.test(body)) { + modified = modified.replace(/^ *object *=.+\n/m, ''); + } + if (!/support\.enumPrototypes *=(?! *(?:false|true))/.test(body) && + !/support\.nonEnumShadows *=(?! *(?:false|true))/.test(body) && + !/support\.ownLast *=(?! *(?:false|true))/.test(body)) { + modified = modified + .replace(/\bctor *=.+\s+/, '') + .replace(/^ *ctor\.prototype.+\s+.+\n/m, '') + .replace(/(?:,\n)? *props *=[^;=]+/, '') + .replace(/^ *for *\((?=prop)/, '$&var ') + } + if (!/support\.nonEnumArgs *=(?! *(?:false|true))/.test(body)) { + modified = modified.replace(/^ *for *\(.+? arguments.+\n/m, ''); + } + // cleanup the empty var statement + modified = modified.replace(/^ *var;\n/m, ''); + + // if no setup then remove IIFE + return /^\s*$/.test(modified) + ? body.replace(RegExp('^' + indent, 'gm'), indent.slice(0, -2)) + : match.replace(setup, modified); + }); + }); + if (isNoDep) { // replace the `lodash.templateSettings` property assignment with a variable assignment source = source.replace(/\b(lodash\.)(?=templateSettings *=)/, 'var ');