当评估 _.template 并且发生 ReferenceError 时,节点 JS 冻结

Node JS FREEZES when _.template is evaluated and a ReferenceError happens

我在 Node JS 中发现了 http://underscorejs.org/ 的奇怪行为:

当我们评估模板函数时发生引用错误,Node JS 将冻结!

示例:

示例 1:快乐的一天场景:

var template = "<%= test %>";
var compiledTemplate = _.template(template);
var result = compiledTemplate({test:1});
console.log(result);

//RESULT (both BROWSER and NODE JS):
//1

示例 2:编译错误场景(关闭前的额外 =):

var template = "<%= test =%>";
var compiledTemplate = _.template(template);
var result = compiledTemplate({test:1});
console.log(result);

//RESULT (both BROWSER and NODE JS):
//uncaughtException { [SyntaxError: Unexpected token )]

示例 3:评估错误场景(未定义测试):

var template = "<%= test %>";
var compiledTemplate = _.template(template);
var result = compiledTemplate({no_test_defined:1});
console.log(result);

//RESULT (BROWSER):
//Uncaught ReferenceError: test is not defined
//RESULT (NODE JS):
//Node JS FREEZES - nothing happens, neither and error is thrown, neither the flow goes on

有人遇到过类似的行为吗?任何解决方案的提示?我真的需要在 try/catch 块中捕获异常...

干杯!

奥斯卡

经过一番排查,我终于找到了问题所在。

当我在 Webstorm DEBUGGER 中 运行 时,会发生这种行为(Node JS FREEZES)。当我在命令行中 运行 它时,我按预期工作。有什么事我会在Webstorm issues里搜索

干杯!!!!

奥斯卡