dot.dot.dot.exampol

This commit is contained in:
Captain Nick Lucifer* 2023-03-10 23:21:16 +05:45
commit a0bc2d79de
406 changed files with 34577 additions and 0 deletions

31
node_modules/burrito/test/ast.js generated vendored Normal file
View file

@ -0,0 +1,31 @@
var test = require('tap').test;
var burrito = require('../');
var vm = require('vm');
test('ast', function (t) {
t.plan(2);
var ast = burrito.parse('f(g(h(5)))', false, true);
var src = burrito(ast, function (node) {
if (node.name === 'call') {
node.wrap(function (s) {
return 'z(' + s + ')';
});
}
});
var times = 0;
t.equal(
vm.runInNewContext(src, {
f : function (x) { return x + 1 },
g : function (x) { return x + 2 },
h : function (x) { return x + 3 },
z : function (x) {
times ++;
return x * 10;
},
}),
(((((5 + 3) * 10) + 2) * 10) + 1) * 10
);
t.equal(times, 3);
});

52
node_modules/burrito/test/err.js generated vendored Normal file
View file

@ -0,0 +1,52 @@
var test = require('tap').test;
var burrito = require('../');
test('wrap error', function (t) {
t.plan(6);
try {
var src = burrito('f() && g()', function (node) {
if (node.name === 'binary') node.wrap('h(%a, %b')
});
t.fail('should have blown up');
}
catch (err) {
t.ok(err.message.match(/unexpected/i));
t.ok(err instanceof SyntaxError);
t.ok(!err.stack.match(/uglify-js/));
t.equal(err.line, 0);
t.equal(err.col, 10);
t.equal(err.pos, 10);
}
});
test('non string', function (t) {
t.plan(3);
t.throws(function () {
burrito.parse(new Buffer('[]'));
});
t.throws(function () {
burrito.parse(new String('[]'));
});
t.throws(function () {
burrito.parse();
});
});
test('syntax error', function (t) {
t.plan(3);
try {
var src = burrito('f() && g())', function (node) {
if (node.name === 'binary') node.wrap('h(%a, %b)')
});
assert.fail('should have blown up');
}
catch (err) {
t.ok(err.message.match(/unexpected/i));
t.ok(err instanceof SyntaxError);
t.ok(!err.stack.match(/uglify-js/));
}
});

9
node_modules/burrito/test/fail.js generated vendored Normal file
View file

@ -0,0 +1,9 @@
var burrito = require('../');
var test = require('tap').test;
var fs = require('fs');
var src = fs.readFileSync(__dirname + '/fail/src.js', 'utf8');
test('fail', function (t) {
burrito(src, function (node) {});
t.end();
});

60
node_modules/burrito/test/fail/src.js generated vendored Normal file
View file

@ -0,0 +1,60 @@
var path = require('path')
module.exports = function(fs, ready) {
var global_files = {}
var recurse = function(dir, okay) {
fs.readdir(dir, function(err, dir_files) {
var countdown = 0
, files = []
, dirs = []
, checked = 0
dir_files.forEach(function(file, idx, all) {
fs.stat(path.join(dir, file), function(err, stat) {
if(stat.isDirectory() && !/node_modules/g.test(dir)) {
dirs.push(file)
} else if(/\.js$/g.test(file)) {
files.push(file)
}
if(++checked >= dir_files.length)
recurse_dirs()
})
})
function recurse_dirs() {
var total = 0
dirs.forEach(function(this_dir) {
recurse(path.join(dir, this_dir), function(err, data) {
if(++total >= dirs.length)
recurse_files()
})
})
if(!dirs.length)
recurse_files()
}
function recurse_files() {
var total = 0
files.forEach(function(file) {
fs.readFile(path.join(dir, file), 'utf8', function(err, src) {
global_files[path.join(dir, file)] = src
++total >= files.length &&
okay(null, global_files)
})
})
if(!files.length)
okay(null, global_files)
}
if(!dir_files.length)
okay(null, global_files)
})
}
recurse('.', ready)
}

92
node_modules/burrito/test/label.js generated vendored Normal file
View file

@ -0,0 +1,92 @@
var test = require('tap').test;
var burrito = require('../');
test('call label', function (t) {
t.plan(1);
burrito('foo(10)', function (node) {
if (node.name === 'call') {
t.equal(node.label(), 'foo');
}
});
});
test('var label', function (t) {
t.plan(1);
burrito('var x = 2', function (node) {
if (node.name === 'var') {
t.same(node.label(), [ 'x' ]);
}
});
});
test('vars label', function (t) {
t.plan(1);
burrito('var x = 2, y = 3', function (node) {
if (node.name === 'var') {
t.same(node.label(), [ 'x', 'y' ]);
}
});
});
test('defun label', function (t) {
t.plan(1);
burrito('function moo () {}', function (node) {
if (node.name === 'defun') {
t.same(node.label(), 'moo');
}
});
});
test('function label', function (t) {
t.plan(1);
burrito('(function zzz () {})()', function (node) {
if (node.name === 'function') {
t.same(node.label(), 'zzz');
}
});
});
test('anon function label', function (t) {
t.plan(1);
burrito('(function () {})()', function (node) {
if (node.name === 'function') {
t.equal(node.label(), null);
}
});
});
test('dot call label', function (t) {
t.plan(1);
burrito('process.nextTick(fn)', function (node) {
if (node.name === 'call') {
t.equal(node.label(), 'nextTick');
}
});
});
test('triple dot label', function (t) {
t.plan(1);
burrito('a.b.c(fn)', function (node) {
if (node.name === 'call') {
t.equal(node.label(), 'c');
}
});
});
test('expr label', function (t) {
t.plan(1);
burrito('a.b[x+1](fn)', function (node) {
if (node.name === 'call') {
t.ok(node.label() === null);
}
});
});

34
node_modules/burrito/test/microwave.js generated vendored Normal file
View file

@ -0,0 +1,34 @@
var test = require('tap').test;
var burrito = require('../');
test('microwave', function (t) {
t.plan(4);
var context = {
f : function (x) { return x + 1 },
g : function (x) { return x + 2 },
h : function (x) { return x + 3 },
z : function (x) {
t.ok(true); // 3 times
return x * 10;
},
};
var res = burrito.microwave('f(g(h(5)))', context, function (node) {
if (node.name === 'call') {
node.wrap(function (s) {
return 'z(' + s + ')';
});
}
});
t.equal(res, (((((5 + 3) * 10) + 2) * 10) + 1) * 10);
});
test('empty context', function (t) {
var res = burrito.microwave('Math.sin(2)', function (node) {
if (node.name === 'num') node.wrap('Math.PI / %s');
});
t.equal(res, 1);
t.end();
});

27
node_modules/burrito/test/parent.js generated vendored Normal file
View file

@ -0,0 +1,27 @@
var test = require('tap').test;
var burrito = require('../');
test('check parent', function (t) {
t.plan(5);
var src = 'Math.tan(0) + Math.sin(0)';
var res = burrito.microwave(src, function (node) {
if (node.name === 'binary') {
node.wrap('%a - %b');
}
else if (node.name === 'num') {
t.equal(node.parent().value[0][0], 'dot');
var fn = node.parent().value[0][2];
if (fn === 'sin') {
node.wrap('Math.PI / 2');
}
else if (fn === 'tan') {
node.wrap('Math.PI / 4');
}
else t.fail('Unknown fn');
}
});
t.equal(res, Math.tan(Math.PI / 4) - Math.sin(Math.PI / 2)); // ~ 0
});

159
node_modules/burrito/test/wrap.js generated vendored Normal file
View file

@ -0,0 +1,159 @@
var test = require('tap').test;
var burrito = require('../');
var vm = require('vm');
test('preserve ternary parentheses', function (t) {
var originalSource = '"anything" + (x ? y : z) + "anything"';
var burritoSource = burrito(originalSource, function (node) {
// do nothing. we just want to check that ternary parens are persisted
});
var ctxt = {
x : false,
y : 'y_'+~~(Math.random()*10),
z : 'z_'+~~(Math.random()*10)
};
var expectedOutput = vm.runInNewContext(originalSource, ctxt);
var burritoOutput = vm.runInNewContext(burritoSource, ctxt);
t.equal(burritoOutput, expectedOutput);
ctxt.x = true;
expectedOutput = vm.runInNewContext(originalSource, ctxt);
burritoOutput = vm.runInNewContext(burritoSource, ctxt);
t.equal(burritoOutput, expectedOutput);
t.end();
});
test('wrap calls', function (t) {
t.plan(20);
var src = burrito('f() && g(h())\nfoo()', function (node) {
if (node.name === 'call') node.wrap('qqq(%s)');
if (node.name === 'binary') node.wrap('bbb(%s)');
t.ok(node.state);
t.equal(this, node.state);
});
var times = { bbb : 0, qqq : 0 };
var res = [];
vm.runInNewContext(src, {
bbb : function (x) {
times.bbb ++;
res.push(x);
return x;
},
qqq : function (x) {
times.qqq ++;
res.push(x);
return x;
},
f : function () { return true },
g : function (h) {
t.equal(h, 7);
return h !== 7
},
h : function () { return 7 },
foo : function () { return 'foo!' },
});
t.same(res, [
true, // f()
7, // h()
false, // g(h())
false, // f() && g(h())
'foo!', // foo()
]);
t.equal(times.bbb, 1);
t.equal(times.qqq, 4);
t.end();
});
test('wrap fn', function (t) {
var src = burrito('f(g(h(5)))', function (node) {
if (node.name === 'call') {
node.wrap(function (s) {
return 'z(' + s + ')';
});
}
});
var times = 0;
t.equal(
vm.runInNewContext(src, {
f : function (x) { return x + 1 },
g : function (x) { return x + 2 },
h : function (x) { return x + 3 },
z : function (x) {
times ++;
return x * 10;
},
}),
(((((5 + 3) * 10) + 2) * 10) + 1) * 10
);
t.equal(times, 3);
t.end();
});
test('binary string', function (t) {
var src = 'z(x + y)';
var context = {
x : 3,
y : 4,
z : function (n) { return n * 10 },
};
var res = burrito.microwave(src, context, function (node) {
if (node.name === 'binary') {
node.wrap('%a*2 - %b*2');
}
});
t.equal(res, 10 * (3*2 - 4*2));
t.end();
});
test('binary fn', function (t) {
var src = 'z(x + y)';
var context = {
x : 3,
y : 4,
z : function (n) { return n * 10 },
};
var res = burrito.microwave(src, context, function (node) {
if (node.name === 'binary') {
node.wrap(function (expr, a, b) {
return '(' + a + ')*2 - ' + '(' + b + ')*2';
});
}
});
t.equal(res, 10 * (3*2 - 4*2));
t.end();
});
test('intersperse', function (t) {
var src = '(' + (function () {
f();
g();
}).toString() + ')()';
var times = { f : 0, g : 0, zzz : 0 };
var context = {
f : function () { times.f ++ },
g : function () { times.g ++ },
zzz : function () { times.zzz ++ },
};
burrito.microwave(src, context, function (node) {
if (node.name === 'stat') node.wrap('{ zzz(); %s }');
});
t.same(times, { f : 1, g : 1, zzz : 3 });
t.end();
});