/
var
/
www
/
greso.tech
/
server
/
nsm
/
node_modules
/
falafel
/
example
/
/var/www/greso.tech/server/nsm/node_modules/falafel/example
mkdir
upload
Name
Size
Mode
Actions
array.js
326
0644
edit
dl
rm
keyword.js
418
0644
edit
dl
rm
prompt.js
1220
0644
edit
dl
rm
Edit:
/var/www/greso.tech/server/nsm/node_modules/falafel/example/prompt.js
(1220B)
var falafel = require('../'); var vm = require('vm'); var termExps = [ 'Identifier', 'CallExpression', 'BinaryExpression', 'UpdateExpression', 'UnaryExpression' ].reduce(function (acc, key) { acc[key] = true; return acc }, {}); function terminated (node) { for (var p = node; p.parent; p = p.parent) { if (termExps[p.type]) return true; } return false; } var src = '{"a":[2,~9,prompt(":d")],"b":4,"c":prompt("beep"),"d":6}'; var offsets = []; var output = falafel('(' + src + ')', function (node) { var isLeaf = node.parent && !terminated(node.parent) && terminated(node) ; if (isLeaf) { var s = node.source(); var prompted = false; var res = vm.runInNewContext('(' + s + ')', { prompt : function (x) { setTimeout(function () { node.update(x.toUpperCase()); }, Math.random() * 50); prompted = true; } }); if (!prompted) { var s_ = JSON.stringify(res); node.update(s_); } } }); setTimeout(function () { console.log(src); console.log('---'); console.log(output); }, 200);
Save
cmd:
run