Open ShawnHuang opened 11 years ago
not sure if I get the idea. Are you talking about multi line input?
Chrome dev tool's rule is multi line input. I think it's difficult to implement. Chrome-remote-interface's repl used repl module, and its rule that I guess is to detect some keywords (function, if, while) and to let users to complete code scope. I can't differ crconsole which also use repl module from that, but I try to write a sample with the repl module that also has the same feature.
multiline input would be tricky with repl/readline. Node starts 'multiline mode' when there is syntax error - see https://github.com/joyent/node/blob/master/lib/repl.js#L296
Not sure if that is desired behaviour at all. Maybe we should trigger this only by some errors, like "Unexpected end of input"
OK, I got it. Thanks for your reply
Feel free to try to implement it yourself :)
I will try it:)
I try to replace the eval function with the following code, but I am not sure that there is no bugs at that code. :)
https://github.com/sidorares/crconsole/blob/master/index.js#L272
var err, result;
try{
var script = require("vm").createScript(cmd.slice(1, -2), {
filename: filename,
displayErrors: false
});
} catch (e){
err = e;
}
var mess = !!err;
if(mess) cb(err, result);
else{
this.client.Runtime.evaluate({expression: cmd.slice(1, -2), generatePreview: true}, function(err, resp) {
return cb(null, resp);
});
}
It will throw exceptions for some valid code, for example if you reference on the right hand side variable which is defined in remote context but not defined locally. I suggest to use esprima and check if it can build complete AST as a flag
Oh!! Let me think about it. Thank you!
I think it would be better if we can type a scope in crconsole. Just like typing in chrome dev tool and chrome-remote-interface's repl.