From 78c6b4aa3befc0ecc8134f8cd5b5e7fa0d298295 Mon Sep 17 00:00:00 2001 From: Jonathan Ong Date: Tue, 7 Apr 2015 23:08:18 -0700 Subject: [PATCH] never pass `undefined` as an argument closes #8 --- index.js | 1 + test/index.js | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/index.js b/index.js index 7632ee7..74a82a8 100644 --- a/index.js +++ b/index.js @@ -45,6 +45,7 @@ function addWith(obj, src, exclude) { var vars = detect(src).map(function (global) { return global.name; }) .filter(function (v) { return exclude.indexOf(v) === -1 + && v !== 'undefined' }) if (vars.length === 0) return src diff --git a/test/index.js b/test/index.js index 6f7d47e..aaffaad 100644 --- a/test/index.js +++ b/test/index.js @@ -153,6 +153,15 @@ describe('addWith("obj || {}", "return this[foo]")', function () { assert(obj.fn(obj) === 'ding') done() }) + + it('does not pass `undefined` as an argument', function (done) { + var src = addWith('obj || {}', 'return this[foo]') + assert(!~src.indexOf('"undefined" in locals_for_with')) + assert(!~src.indexOf('locals_for_with.undefined')) + assert(!~src.indexOf('typeof undefined!=="undefined"?undefined:undefined')) + outputs.push(src) + done() + }) }) describe('addWith("obj", "var x = (y) => y + z; x(10);")', function () { it('keeps reference to this', function (done) {