From 6435aaa64f6290178029a6628e97d4f0e26bc312 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 27 Feb 2013 09:10:13 -0800 Subject: [PATCH] Ensure the `exports` object is not a DOM element. [closes #197] Former-commit-id: 3adb679f7f4d7a64e0bc37ed80a443c211a17510 --- build.js | 6 +++--- lodash.js | 4 ++-- test/index.html | 8 +++++++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/build.js b/build.js index 25e7cd48e..fecf38d9b 100755 --- a/build.js +++ b/build.js @@ -529,7 +529,7 @@ ' _ = lodash;', ' lodash.templates = lodash.extend(lodash.templates || {}, templates);', ' });', - " } else if (freeExports) {", + " } else if (freeExports && !freeExports.nodeType) {", " _ = require('" + options.moduleId + "');", " if (freeModule) {", ' (freeModule.exports = templates).templates = templates;', @@ -2417,9 +2417,9 @@ } // remove `if (freeExports) {...}` if it's empty if (isAMD && isGlobal) { - source = source.replace(/(?: *\/\/.*\n)* *(?:else )?if *\(freeExports\) *{\s*}\n+/, ''); + source = source.replace(/(?: *\/\/.*\n)* *(?:else )?if *\(freeExports.*?\) *{\s*}\n+/, ''); } else { - source = source.replace(/(?: *\/\/.*\n)* *(?:else )?if *\(freeExports\) *{\s*}(?:\s*else *{([\s\S]+?) *})?\n+/, '$1\n'); + source = source.replace(/(?: *\/\/.*\n)* *(?:else )?if *\(freeExports.*?\) *{\s*}(?:\s*else *{([\s\S]+?) *})?\n+/, '$1\n'); } }()); diff --git a/lodash.js b/lodash.js index c0e8d332a..1298be31e 100644 --- a/lodash.js +++ b/lodash.js @@ -173,7 +173,7 @@ nativeRandom = Math.random; /** Detect various environments */ - var isIeOpera = !!context.attachEvent, + var isIeOpera = reNative.test(context.attachEvent), isJSC = !/\n{2,}/.test(Function()), isV8 = nativeBind && !/\n|true/.test(nativeBind + isIeOpera); @@ -5224,7 +5224,7 @@ }); } // check for `exports` after `define` in case a build optimizer adds an `exports` object - else if (freeExports) { + else if (freeExports && !freeExports.nodeType) { // in Node.js or RingoJS v0.8.0+ if (freeModule) { (freeModule.exports = _)._ = _; diff --git a/test/index.html b/test/index.html index 182971f21..70a207f25 100644 --- a/test/index.html +++ b/test/index.html @@ -4,12 +4,18 @@ Lo-Dash Test Suite + -
+
+