fix: global/externals

This commit is contained in:
cha0s 2022-04-04 03:08:36 -05:00
parent d2e1a6f140
commit e05bae167a
2 changed files with 27 additions and 0 deletions

View File

@ -72,6 +72,13 @@ function flattenParams(ast) {
export function hasExternalDependency(ast) { export function hasExternalDependency(ast) {
const locals = flattenParams(ast); const locals = flattenParams(ast);
locals.push(
'global',
'super',
'window',
'Math',
// ... @todo
);
const idWalker = walk({ const idWalker = walk({
Identifier: ({name}) => { Identifier: ({name}) => {
locals.push(name); locals.push(name);

View File

@ -43,11 +43,31 @@ it('can identify external dependencies', () => {
)) ))
.to.be.true; .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( expect(hasExternalDependency(
extractFunction(parse('function test(a, b) { this.whatever; }')), extractFunction(parse('function test(a, b) { this.whatever; }')),
)) ))
.to.be.false; .to.be.false;
expect(hasExternalDependency(
extractFunction(parse('function test(a, b) { this.foo.whatever }')),
))
.to.be.false;
expect(hasExternalDependency( expect(hasExternalDependency(
extractFunction(parse('function test(a, b) { console.log("HI"); }')), extractFunction(parse('function test(a, b) { console.log("HI"); }')),
)) ))