Skip to content

Commit

Permalink
Merge pull request #9 from jonathanong/never-pass-undefined-as-an-arg…
Browse files Browse the repository at this point in the history
…ument

never pass `undefined` as an argument
  • Loading branch information
ForbesLindesay committed Apr 8, 2015
2 parents 495b1f4 + 78c6b4a commit 03b473d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 03b473d

Please sign in to comment.