fix: global/externals
This commit is contained in:
parent
d2e1a6f140
commit
e05bae167a
|
@ -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);
|
||||||
|
|
|
@ -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"); }')),
|
||||||
))
|
))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user