Current Dev State

This commit is contained in:
Tim Lorsbach
2025-06-23 20:13:54 +02:00
parent b4f9bb277d
commit ded50edaa2
22617 changed files with 4345095 additions and 174 deletions

View File

@ -0,0 +1,17 @@
var test = require('tape');
var detect = require('../');
var fs = require('fs');
var src = fs.readFileSync(__dirname + '/files/argument.js');
test('parameters from inline arguments', function (t) {
t.plan(3);
var scope = detect(src);
t.same(scope.globals.implicit, []);
t.same(scope.globals.exported, []);
t.same(scope.locals, {
'body.0': [ 'a' ],
'': [ 'foo' ],
'body.0.body.body.1.argument': [ 'c' ]
});
});

View File

@ -0,0 +1,13 @@
var test = require('tape');
var detect = require('../');
var fs = require('fs');
var src = fs.readFileSync(__dirname + '/files/assign_implicit.js');
test('assign from an implicit global', function (t) {
t.plan(3);
var scope = detect(src);
t.same(scope.globals.implicit, [ 'bar' ]);
t.same(scope.globals.exported, []);
t.same(scope.locals, { '': [ 'foo' ] });
});

View File

@ -0,0 +1,17 @@
var test = require('tape');
var detect = require('../');
var fs = require('fs');
var src = fs.readFileSync(__dirname + '/files/detect.js');
test('check locals and globals', function (t) {
t.plan(3);
var scope = detect(src);
t.same(scope.globals.implicit, [
'w', 'foo', 'process', 'console', 'AAA', 'BBB', 'CCC', 'xyz'
]);
t.same(scope.globals.exported, [
'w', 'RAWR', 'BLARG', 'ZZZ'
]);
t.same(scope.locals[''], [ 'x', 'y', 'z', 'beep' ]);
});

View File

@ -0,0 +1,6 @@
function foo () {
var a;
return function (c) {
a = c;
};
}

View File

@ -0,0 +1,2 @@
var foo;
foo = bar;

View File

@ -0,0 +1 @@
console.log(Buffer('abc'))

View File

@ -0,0 +1 @@
console.log(Buffer.isBuffer('whatever'))

View File

@ -0,0 +1 @@
console.log(Buffer)

View File

@ -0,0 +1,32 @@
var x = 5;
var y = 3, z = 2;
w.foo();
w = 2;
RAWR=444;
RAWR.foo();
BLARG=3;
foo(function () {
var BAR = 3;
process.nextTick(function (ZZZZZZZZZZZZ) {
console.log('beep boop');
var xyz = 4;
x += 10;
x.zzzzzz;
ZZZ=6;
});
function doom () {
if (AAA.aaa) {}
BBB.bbb = 3;
var z = 2 + CCC.x * 5;
}
ZZZ.foo();
});
function beep () {}
console.log(xyz);

View File

@ -0,0 +1,11 @@
test_label1: while(true) {
break test_label1;
continue test_label1;
}
function nest() {
test_label2: while(true) {
break test_label2;
continue test_label2;
}
};

View File

@ -0,0 +1,6 @@
exports.foo = function () {
return bar;
};
exports.bar = function (bar) {
return bar;
};

View File

@ -0,0 +1,6 @@
function foo (x) {
var a = x;
return function (c) {
a += c;
};
}

View File

@ -0,0 +1 @@
module.exports = {foo: bar}

View File

@ -0,0 +1,5 @@
function foo() {
return {
bar: true
}
}

View File

@ -0,0 +1,2 @@
exports.filename = __filename;
exports.dirname = __dirname;

View File

@ -0,0 +1,7 @@
function foo() {
try {
} catch (ex) {
foo(ex)
}
}

View File

@ -0,0 +1,13 @@
var test = require('tape');
var detect = require('../');
var fs = require('fs');
var src = fs.readFileSync(__dirname + '/files/labels.js');
test('globals on the right-hand of a colon in an object literal', function (t) {
t.plan(3);
var scope = detect(src);
t.same(scope.globals.implicit, []);
t.same(scope.globals.exported, []);
t.same(scope.locals, { '': [ 'nest' ], 'body.1': [] });
});

View File

@ -0,0 +1,18 @@
var test = require('tape');
var detect = require('../');
var fs = require('fs');
var src = fs.readFileSync(__dirname + '/files/multiple-exports.js');
test('multiple-exports', function (t) {
t.plan(3);
var scope = detect(src);
t.same(scope.globals.implicit.sort(), ['bar', 'exports'].sort());
t.same(scope.globals.exported, []);
t.same(scope.locals, {
'':[],
'body.1.expression.right': ['bar'],
'body.0.expression.right': []
});
});

View File

@ -0,0 +1,17 @@
var test = require('tape');
var detect = require('../');
var fs = require('fs');
var src = fs.readFileSync(__dirname + '/files/named_arg.js');
test('named argument parameter', function (t) {
t.plan(3);
var scope = detect(src);
t.same(scope.globals.implicit, []);
t.same(scope.globals.exported, []);
t.same(scope.locals, {
'body.0': [ 'a', 'x' ],
'': [ 'foo' ],
'body.0.body.body.1.argument': [ 'c' ]
});
});

View File

@ -0,0 +1,16 @@
var test = require('tape');
var detect = require('../');
var fs = require('fs');
var src = fs.readFileSync(__dirname + '/files/obj.js');
test('globals on the right-hand of a colon in an object literal', function (t) {
t.plan(3);
var scope = detect(src);
t.same(
scope.globals.implicit.sort(),
[ 'bar', 'module' ].sort()
);
t.same(scope.globals.exported, []);
t.same(scope.locals, { '': [] });
});

View File

@ -0,0 +1,3 @@
{
"browserify": { "transform": "brfs" }
}

View File

@ -0,0 +1,41 @@
var test = require('tape');
var detect = require('../');
var fs = require('fs');
var src = {
call: fs.readFileSync(__dirname + '/files/buffer_call.js'),
isbuffer: fs.readFileSync(__dirname + '/files/buffer_isbuffer.js'),
v: fs.readFileSync(__dirname + '/files/buffer_var.js')
};
test('implicit props: call', function (t) {
t.plan(3);
var scope = detect(src.call);
t.deepEqual(scope.locals, { '': [] });
t.deepEqual(scope.globals.implicit, [ 'console', 'Buffer' ]);
t.deepEqual(scope.globals.implicitProperties, {
console: [ 'log' ],
Buffer: [ '()' ]
})
});
test('implicit props: isBuffer', function (t) {
t.plan(3);
var scope = detect(src.isbuffer);
t.deepEqual(scope.locals, { '': [] });
t.deepEqual(scope.globals.implicit, [ 'console', 'Buffer' ]);
t.deepEqual(scope.globals.implicitProperties, {
console: [ 'log' ],
Buffer: [ 'isBuffer' ]
})
});
test('implicit props: var', function (t) {
t.plan(3);
var scope = detect(src.v);
t.deepEqual(scope.locals, { '': [] });
t.deepEqual(scope.globals.implicit, [ 'console', 'Buffer' ]);
t.deepEqual(scope.globals.implicitProperties, {
console: [ 'log' ],
Buffer: [ '*' ]
})
});

View File

@ -0,0 +1,13 @@
var test = require('tape');
var detect = require('../');
var fs = require('fs');
var src = fs.readFileSync(__dirname + '/files/return_hash.js');
test('return hash', function (t) {
t.plan(3);
var scope = detect(src);
t.same(scope.globals.implicit, []);
t.same(scope.globals.exported, []);
t.same(scope.locals, { 'body.0': [], '': [ 'foo' ] });
});

View File

@ -0,0 +1,16 @@
var test = require('tape');
var detect = require('../');
var fs = require('fs');
var src = fs.readFileSync(__dirname + '/files/right_hand.js');
test('globals on the right-hand of assignment', function (t) {
t.plan(3);
var scope = detect(src);
t.same(
scope.globals.implicit.sort(),
[ 'exports', '__dirname', '__filename' ].sort()
);
t.same(scope.globals.exported, []);
t.same(scope.locals, { '': [] });
});

View File

@ -0,0 +1,19 @@
var test = require('tape');
var detect = require('../');
var fs = require('fs');
var src = '#!/beep/boop blah\n'
+ fs.readFileSync(__dirname + '/files/detect.js')
;
test('shebangs', function (t) {
t.plan(3);
var scope = detect(src);
t.same(scope.globals.implicit, [
'w', 'foo', 'process', 'console', 'AAA', 'BBB', 'CCC', 'xyz'
]);
t.same(scope.globals.exported, [
'w', 'RAWR', 'BLARG', 'ZZZ'
]);
t.same(scope.locals[''], [ 'x', 'y', 'z', 'beep' ]);
});

View File

@ -0,0 +1,13 @@
var test = require('tape');
var detect = require('../');
var fs = require('fs');
var src = fs.readFileSync(__dirname + '/files/try_catch.js');
test('the exception in a try catch block is a local', function (t) {
t.plan(3);
var scope = detect(src);
t.same(scope.globals.implicit, []);
t.same(scope.globals.exported, []);
t.same(scope.locals, { '': [ 'foo' ], 'body.0': [ 'ex' ] });
});