-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
line number mapping for debug #558
Comments
So some thoughts:
|
Might be worth looking at this also: Maybe this same type of strategy could be used so that firebug could step through javascript line by line, but display the coffeescript code instead. Tough project, but could turn into something pretty killer! |
I'd be glad to help someone out with this ticket, but I'm not going to be spearheading it myself ... so closing as |
Alright -- this ticket now has life again, in Firefox at least: https://bugzilla.mozilla.org/show_bug.cgi?id=618650 Reopening... |
Quick helpful workaround: Include each line of the original coffeescript source inside a block comment before the js code that it generated. You could include the original coffeescript source lune numbers in the comments. That would at least help simplify the learning and debugging process. |
Mascara has a source-line mapping utility that only works in Firefox. It's quite possible to implement something similar:
Run on Try CoffeeScript. Firefox only, though. |
Related code: Closure Compiler (JS -> JS) ...can generate source-to-source mappings:
SourceMapLegacy.java has comments describing the format. ...can generate mappings using the same format, but with more file info: commit: "changed emit() return type from a string to list of strings and kids" commit: "source-to-source mappings! (same format as Closure Compiler)" ** exception-server ** An exception logging/viewing server has been written (in NodeJS) that uses these mappings to convert an exception's stack information into pre-compilation code snippets with TextMate URLs. (your compilers/scripts send the server (code_sha1, mapping)s and (sha1, code)s at compile-time) I'll post it [REDACTED TIMEFRAME] when it's more documented/polished. ** common-exception ** ...can extract file/line/[col] information from NodeJS, Firefox, Chrome, Safari |
Crazy idea: What if when the CoffeeScript was compiled to JavaScript, it was done such that the lines corresponded 1:1 by placing multi-line JavaScript conversions on a single line. |
I suspect it is crazy, but it would be useful. I actually do that with https://github.com/pmuellr/scooj , but only because the source is largely unprocessed JavaScript anyway. The nice thing is that even though you see some grungy code in the debugger, you do know the exact line number to go to in your editor. |
I suggest a --debug coffee parameter that does something like this:
to become:
this would work Browser independent and i think(im not a coffescript compiler expert, though) it could be implement without big hassles. |
Let's define some terms:Def a "compiler" compiles a non-empty set of "source file"s to exactly one "compiled file" Defs
Notes:
Defs
See my writeup of CCMF[H]: https://gist.github.com/769845 |
.linenoRecall: adding .lineno to each node instance is a solved problem: With no side effects, that |
Let's get this done! (Please? Please? Please?)CoffeeScript should support both
(1) might need to wait for some format finalization, but (2) does not. And the I'm trying to do a FOSS triple-launch in [REDACTED TIMEFRAME]:
(all three are written in CoffeeScript) ...and it would be really, really awesome to have CoffeeScript CCMFH support before then so I can integrate it. Imagine being able to hit Command-R and have jashkenas/coffee-script-tmbundle compile, invoke node, and then represent the resulting exception in a beautiful and convenient mapping-following way with CoffeeScript source links and code snippets... |
Some modest proposalsThe Good (but more complex and possibly slower)Something like what PYXC-PJ does. EDIT: e.g. Throw compileNode: (o) -> ... something(o, ["throw ", @expression, ";"]) Instead of having the main compilation function return a string, have it return a BAR. BAR ::= ELEMENT-list ELEMENT ::= string | FOO | BAR FOO ::= something which can 1. provide the code fragment for that subtree 2. provide the ((line, col) -> (source line)) mapping information for that fragment Some function can then use the resulting BAR to generate both
PYXC-PJ commits:
I'm not a Would I think The Good could be done without deferring .compile, but that might be harder. The Bad (but simple (though verbose) to implement and possibly faster)Something like what Closure Compiler does. Instead of the beatifully concise current something.startNode this something.add "throw {" something.addSubnode @expression, o # addSubnode: (node, o) -> # ... # node.compile o # ... something.add ";" something.endNode() This would invoke the The FuglyHave whatever methods invoke ((() -> token = newUniqueToken() ( "/*FUGLY:#{token}:@lineno*/" + [...].compileNode([...]) + "/*/FUGLY:#{token}*/" ) )()) ...and write a crazy function that uses the resulting text monstrosity to generate (comment-free JS, a CCMFH file) This would be totally insane, but it would work and it would involve the least modification to |
I'll work on a something(o, ["throw ", @expression, ";"]) approach |
BAR-ification of https://github.com/andrewschaaf/coffee-script/commits/master After each change, I run git checkout -- lib && cake build && cake build && cake test && git status and confirm that the tests pass and that no |
From #coffeescript yesterday: my point about a codegen method's "//#{@child.compile o}" vs "#{@child.compile o}//" was that the codegen method currently discards the information distinguishing the two. the relativeCharOffset of each kid matters. one option would be for the codegen method to store that information in its kids e.g. for Throw ("throw #{@expression...};"), @expression.relativeCharOffset = "throw ".length but this could make the codegen methods uglier than with the BAR-returning approach with the BAR-returning approach, the Base method calling the codegen method can process the BAR immediately, computing the flattenedCodeString as usual and (processing the mapping implications if mapping:true) BAR-returning codegen methods are a way to abstract out the mapping-handling code from the outside, you're still calling the top node's .compile or .compileWithMapping |
1 similar comment
From #coffeescript yesterday: my point about a codegen method's "//#{@child.compile o}" vs "#{@child.compile o}//" was that the codegen method currently discards the information distinguishing the two. the relativeCharOffset of each kid matters. one option would be for the codegen method to store that information in its kids e.g. for Throw ("throw #{@expression...};"), @expression.relativeCharOffset = "throw ".length but this could make the codegen methods uglier than with the BAR-returning approach with the BAR-returning approach, the Base method calling the codegen method can process the BAR immediately, computing the flattenedCodeString as usual and (processing the mapping implications if mapping:true) BAR-returning codegen methods are a way to abstract out the mapping-handling code from the outside, you're still calling the top node's .compile or .compileWithMapping |
About ten years ago I wrote som crude source-to-source compilers for Perl and C++ which I called Pyrl and Cython. They simply gave you pythonish indent-syntax. They had the flag -p for pretty output and some other for line-to-line, which esentially means that it simply made sure that lines in the output ended up in the same line number as in the input, no matter if certain lines became 'ugly' because of code stacking. Simple solution. Works in all environments (like Jake that compiles the coffee-makefile from inside it's script), any editor, etc., shouldn't be to hard to implement? |
How hard would it be to add an option to have the js output include a call to a custom trace function on every function call? The param could be the callee function name and optionally the original line number and file. This would really help debug those cases where the code doesn't finish because I forgot to call something else at the end of a callback. These cases drive me crazy and cause me to put log calls all over the place. The convention could be that if a specific function exists at the top level then the feature is enabled and that function is called.
|
For reference, here is a related webkit ticket: https://bugs.webkit.org/show_bug.cgi?id=30933 |
In my fantasy world V8 and other engines would be broken into a separate parser and byte-code interpreter while retaining the same JS semantics. |
Just want to toss out a major +1 to preserving line numbers, i.e. mapping 1:1 from source Coffee line # to generated JS line #. The excellent Streamline.js library has this option for its transformations, and it has proved invaluable. Btw, if it helps, our platform is Node. We too compile dynamically w/out generating JS files, so things like line-numbers-in-comments aren't helpful. Our use case also isn't e.g. Firebug debugging generally but more "my program threw an error on line 512, where is that?" Thanks in advance! Excitedly looking forward to seeing what comes of this. |
+1 for this |
Anyone in the NYC area interested in meeting up for a line-mapping mini-hackathon on Sunday the 15th? |
No, but I'd personally donate beer money. This needs to be done. On May 4, 2011, at 10:27 AM, [email protected] wrote:
|
+1 I'd send some coffee + beer money too for this, it would be the biggest evolution for CoffeeScript |
I'm surprised that no one has ever implemented one of the several quick On Wed, May 4, 2011 at 6:14 PM, tanepiper <
Mark Hahn |
I'll actually be in the NYC area on the 15th with nothing to do. I may be up for this. |
+1 for some way of debugging coffeescript. It would be really helpful. |
That's fantastic. I'd love to try and get one of the branches merged, and a release cut, for when it lands in Chrome proper. |
Source maps are in chrome proper - version 18 has support. There's a nice explanation here which, incidentally, calls us out. |
Is there a coffee fork that enables source maps compatible with chrome 18's new feature? |
I'm looking forward to test this in chrome 18 :) |
+1 I'm waiting for this feature to start taking seriously coffeescript |
Note IDEs that provide their own debugging environment can do the source mapping as well, they just need the sourcemap from coffeescript. For example JetBrains IDEA has a feature request for this (http://youtrack.jetbrains.com/issue/IDEA-84442) and Firefox still has this issue that folks can vote for (https://bugzilla.mozilla.org/show_bug.cgi?id=618650), but neither is going to move until they have something generating sourcemaps for them to play with. |
Chrome 19 is now out, is there any progress on this? I'm really looking forward to debug directly in CoffeeScript. |
'Fraid there's nothing to report yet progress-wise, but it's next on the list. |
You're all amazing and we love you. I've been using Coffeescript on a production project for the last two months and I'm absolutely in love with it. This would just be a little extra frosting on the cake. |
Awesome guys, can't wait for this to land. |
I realize I'm way late to an old and overlong thread, but wanted to throw another offbeat hybrid idea out there: Indicate the two different "line" numbers by using two different line-end conventions in the same compiled file. For example, the compiled/JS line numbers would be indicated by traditional line-ends (CR/LF/CRLF), and the original-source line-numbers by some other harmless whitespace, such as FF (0x0C) or VB (0x0B). That is, every JS line has a traditional line-length and line-end (no overlong lines), but only those representing another line forward in the CS source also include the new-convention secondary line-end. (And, this approach also allows for multiple source-line-ends to a single output line-end.) Code editors and line-reporting code could offer a toggle for how they number lines.. or simply report both when dual conventions are noticed in the file. For example...
...where the ';83' indicates the secondary-convention line-number. |
Given that Redux now supports this. What is the implication for this repo? Politics aside, and speaking strictly pragmatically for the benefit of new users such as myself, should we be switching to redux as the future compiler of choice? |
@wamatt: I would recommend sticking with this more stable compiler for serious projects for now as the kinks are worked out of my compiler over the next few months. That said, if you can go over the compiled output manually (or if your program has good test coverage and your tests still pass), and it looks good to you -- which it really should for most programs -- go ahead and take advantage of the source map support. |
@michaelficarra Thanks, that sounds sensible. Keep up the great work! :) |
What's the status on this? @michaelficarra's Redux compiler seems to support them and there is at least one pull request for support in this compiler but relatively little discussion from the maintainers. Is sourcemap support still something being planned? Is something holding it back? Just looking for updates. |
@devongovett -- I think the status is basically what you said ... they work in Redux, and there are a couple of probably working branches with pull requests over here as well. One in particular I've been keeping my eye on and corresponding via email about, that looks very promising. That said, I'd like to wrap up one new release of CoffeeScript with official "literate" support before starting to look at 'em in earnest. If you want to help move things along, feel free. |
PONG, 3 years after |
Oh, wow, we can finally close this. The oldest open CoffeeScript issue. Well, here goes 😄. edit: Actually, I forgot about the recently re-opened issue #77. That issue's even older than me. |
Congratulations! |
Unfortunately 🍰 was a lie ;-) Thank you! |
Woot! |
Awesome ticket :-) |
Check this project. https://npmjs.org/package/coffee-join/ |
wow |
There's been some email chit-chat regarding support coffeescript in the existing browser debuggers. The basic idea is to include information in the generated JavaScript files that the debuggers can make use of to display the original coffeescript source, and deal with line mapping issues between the CoffeeScript source and generated JavaScript.
Thought I'd go ahead and open up an issue for discussion.
The text was updated successfully, but these errors were encountered: