Coffeescript中的源映射 - 错误未映射到源 [英] Source Mapping in Coffeescript - errors not mapped to source
问题描述
我刚刚意识到源映射 - 一个期待已久的功能。我印象深刻的是,许多人聚在一起,使其发生在咖啡脚本(浏览器,kickstart项目等...)
I just became aware of source mapping - a long awaited feature. I am impressed so many people got together to make it happen for coffee-script (browsers, kickstart project etc...)
我设置了一个小测试,所以我可以了解如何使用...
I set up a little test, so I could understand how to use it...
这里有一个故意的错误,因为 y
未定义
console.log 123
sq = (x)->
x * x
console.log "thats how easy: "+sq y
源映射
Source Map
{
"version": 3,
"file": "test.js",
"sourceRoot": "",
"sources": [
"test.coffee"
],
"names": [],
"mappings": ";AAAA;CAAA,CAAA,IAAA;CAAA;CAAA,CAAA,CAAA,IAAO;;CAAP,CAEA,CAAK,MAAC;CACJ,EAAI,QAAJ;CAHF,EAEK;;CAFL,CAKA,CAAA,IAAO,WAAK;CALZ"
}
Javascript
Javascript
// Generated by CoffeeScript 1.6.1
(function() {
var sq;
console.log(123);
sq = function(x) {
return x * x;
};
console.log("thats how easy: " + sq(y));
}).call(this);
//@ sourceMappingURL=test.map
Jade
Jade
html
head
script(src="test.js")
body
h1 Test Page
这似乎是工作,因为显示咖啡脚本源,我甚至可以设置断点但是图形似乎没有显示,并且似乎在javascript中设置断点的地方有点不稳定。)
This all seems to be working, because the coffee-script source is displayed, and I can even set breakpoints (but the graphic seems not to show, and it seems a little erratic in where the breakpoints are set in the javascript).
我遇到的问题是,当有一个错误,控制台报告javascript文件的行号。
The problem I am having is that when there is an error, the console reports the line number of the javascript file. How can I find out the line of the coffee-script source file that causes the error?
我在OSX 10.8.2上使用Google Chrome 23.0.1271.101版本
I am using Google Chrome Version 23.0.1271.101 on OSX 10.8.2
推荐答案
我实际上只是回答了我自己的问题非常类似于你的。您可以这里查看。
I actually just answered my own question very similar to yours. You can take a look here.
我的解决方案使用是通过browserify连接/编译所有我的coffeescript,使用coffeeify作为一个转换选项。当在browserify中将debug设置为true时,所有行号应映射回原始coffeescript源中的正确行。
The solution I am using is to concat/compile all my coffeescript with browserify,using coffeeify as a transform option. When debug is set to true in browserify, all your line numbers should map back to the correct line in your original coffeescript source.
这篇关于Coffeescript中的源映射 - 错误未映射到源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!