diff --git a/packages/code/src/function.js b/packages/code/src/function.js index 7ce6881..2606337 100644 --- a/packages/code/src/function.js +++ b/packages/code/src/function.js @@ -72,6 +72,13 @@ function flattenParams(ast) { export function hasExternalDependency(ast) { const locals = flattenParams(ast); + locals.push( + 'global', + 'super', + 'window', + 'Math', + // ... @todo + ); const idWalker = walk({ Identifier: ({name}) => { locals.push(name); diff --git a/packages/code/test/function.js b/packages/code/test/function.js index a4491ce..630dc46 100644 --- a/packages/code/test/function.js +++ b/packages/code/test/function.js @@ -43,11 +43,31 @@ it('can identify external dependencies', () => { )) .to.be.true; + expect(hasExternalDependency( + extractFunction(parse('function test(a, b) { c.a.b; }')), + )) + .to.be.true; + + expect(hasExternalDependency( + extractFunction(parse('function test(a, b) { c.d; }')), + )) + .to.be.true; + + expect(hasExternalDependency( + extractFunction(parse('function test(a, b) { Math.min(a, b); }')), + )) + .to.be.false; + expect(hasExternalDependency( extractFunction(parse('function test(a, b) { this.whatever; }')), )) .to.be.false; + expect(hasExternalDependency( + extractFunction(parse('function test(a, b) { this.foo.whatever }')), + )) + .to.be.false; + expect(hasExternalDependency( extractFunction(parse('function test(a, b) { console.log("HI"); }')), ))