有没有办法调试node.js的swig模板引擎,因为在某些情况下,我不能得到发生错误的确切文件,例如
{% set temp = JSON.parse('some random string') %}这就是我在控制台中得到的上面的结果:
2015-08-13T09:38:12.254Z - error: SyntaxError: Unexpected token s
at Object.parse (native)
at Object.eval [as tpl] (eval at <anonymous> (/home/saurabh/intl/via_node/node_modules/swig/lib/swig.js:498:13), <anonymous>:6:810)
at compiled (/home/saurabh/intl/via_node/node_modules/swig/lib/swig.js:619:18)
at Object.eval [as tpl] (eval at <anonymous> (/home/saurabh/intl/via_node/node_modules/swig/lib/swig.js:498:13), <anonymous>:27:611)
at compiled (/home/saurabh/intl/via_node/node_modules/swig/lib/swig.js:619:18)
at /home/saurabh/intl/via_node/node_modules/swig/lib/swig.js:559:20
at /home/saurabh/intl/via_node/node_modules/swig/lib/swig.js:690:9
at fs.js:268:14
at Object.oncomplete (fs.js:107:15)没有提到发生错误的模板文件。
发布于 2015-08-13 18:45:11
编辑:你是对的,问题是‘一些随机字符串’,你不能JSON.parse一个字符串不是一个JSON。
所以你应该有这样的东西:
{% set temp = JSON.parse('{"test": true}') %}https://stackoverflow.com/questions/31984645
复制相似问题