本文介绍了我如何得到行号在coffeescript文件中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

node.js express 应用程式和 nodeunit 测试中,我广泛使用coffeescript,而不会将结果 javascript 档案储存到磁碟上避免项目clogging

In node.js express app and nodeunit tests I widely use coffeescript without saving resulting javascript files on disk to avoid project clogging by javascript translations.

当我在coffeeScript文件中遇到任何错误时,我在控制台中看到:发生错误的文件名和行号(例如37): pathTo_File / fileName.coffee:37 但我没有在我的咖啡文件中的第37行!我有两次少了行。

When I got any error in coffeeScript file I see in console: the filename where error was occured and line number (for example 37): /pathTo_File/fileName.coffee:37. But I dont have 37th line in my coffee file!!! I have two times less lines there.

我想我在输出的 javascript 文件中的第37行有错误,但我没有在磁盘上。仅限Coffeescript文件。

I guess that I got error on 37th row in my output javascript file, but I don't have it on disk. Coffeescript files only.

因此,如何在coffeescript文件中获取行号错误?

So how I can get line number with error in coffeescript file?

我知道我可以手动(使用控制台)将我的咖啡脚本文件转换为 js ,并查看行号和猜测行在我的咖啡文件中得到了这个错误。但也许有更快的东西

I understand that I can translate my coffee script file manually (using console) to js and see there line number and guess on what line I got that error on my coffee file. But maybe there is something faster.

我的IDE是WebStorm,os是osX。

My IDE is WebStorm and os is osX.

推荐答案

CoffeeScript 1.6.1及以上版本支持生成源映射,一种方式告诉您的JavaScript引擎您的CoffeeScript程序的哪部分与要评估的代码匹配。支持它的浏览器可以自动使用源映射在调试器中显示您的原始源代码。要在JavaScript文件旁边生成源地图,请将--map或-m标志传递给编译器。

CoffeeScript 1.6.1 and above include support for generating source maps, a way to tell your JavaScript engine what part of your CoffeeScript program matches up with the code being evaluated. Browsers that support it can automatically use source maps to show your original source code in the debugger. To generate source maps alongside your JavaScript files, pass the --map or -m flag to the compiler.

这篇关于我如何得到行号在coffeescript文件中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 04:55