Skip to content
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

Source maps: <script type="text/coffeescript"> support? #2780

Closed
ashtuchkin opened this issue Mar 5, 2013 · 23 comments
Closed

Source maps: <script type="text/coffeescript"> support? #2780

ashtuchkin opened this issue Mar 5, 2013 · 23 comments

Comments

@ashtuchkin
Copy link

Am I missing it or there's no support for source maps when compiling coffee in browser?

@vendethiel
Copy link
Collaborator

Do browsers even support that?

@kelp404
Copy link

kelp404 commented Mar 5, 2013

👍

@ashtuchkin
Copy link
Author

@Nami-Doc That's a good question. The current v3 specification allows it by using a data uri as sourceMappingUrl and additional parameter "sourcesContent". I'm not sure about the browser support though.

@ashtuchkin
Copy link
Author

Just checked - it works in Chrome 25.

@kelp404
Copy link

kelp404 commented Mar 5, 2013

include coffee-script.js
https://github.com/jashkenas/coffee-script/blob/master/extras/coffee-script.js

<script type="text/javascript" src="https://raw.github.com/jashkenas/coffee-script/master/extras/coffee-script.js"></script>
<script type="text/coffeescript">
    console.log 'coffee'
</script>

@ghost
Copy link

ghost commented Mar 5, 2013

A little off-topic, but I've wondered this for a while... what actual use case is there for <script type="text/coffeescript">? Why not precompile your code beforehand? Wouldn't that be faster in the long run?

@vendethiel
Copy link
Collaborator

in the long run?

indeed. I suppose it may be useful for testing purposes ;).

@ashtuchkin
Copy link
Author

@kelp404 Yes, I'm aware of how to use it, thank you. The question is about supporting source maps right in the browser.
@mintplant I use it for development & testing of my product extensively. The benefit is that you can do frontend-only development with a basic static files server (I mock server requests anyway).

@kelp404
Copy link

kelp404 commented Mar 6, 2013

@ashtuchkin Sorry, I got a mistake.

@hden
Copy link
Contributor

hden commented Mar 11, 2013

@ashtuchkin How did you checked comparability? Canary seems to ignore the sourcesContent option.

@ashtuchkin
Copy link
Author

I created manually the source map, encoded original text to js string, created property sourcesContent in the source map, then base64-encoded source map and added as a sourceMapUrl to the .js file. Then viewed it in Chrome Dev Tools. Chrome 25 for Linux.

@hden
Copy link
Contributor

hden commented Mar 13, 2013

Got it working in Canary, too. I think this is possible if we could...

  • port JSON.stringify() since it's not supported in IE6
  • port a permissive base64 encoder that supports utf-8, because...
    • utf-8 strings are expected in source codes
    • and btoa() is not supported in IE

I'm afraid both of them adds significant LOC to existing code base.

In other hand, If we compile to js with horrible inline source mapping, none of these limits will apply, any thought?
See what's been done by browserify for detail.

@ashtuchkin
Copy link
Author

Source mapping is only supported in latest Chromes & Firefox, why should we support it in IE6?

Sent from my iPhone

On 12.03.2013, at 20:38, Hao-kang Den [email protected] wrote:

Got it working in Canary, too. I think this is possible if we could...

port JSON.stringify() since it's not supported in IE6
port a permissive base64 encoder that supports utf-8, because...
utf-8 strings are expected in source codes
and btoa() is not supported in IE
I'm afraid both of them adds significant LOC to existing code base.

In other hand, If we compile to js with horrible inline source mapping like what's been done by browserify, none of these limits will apply, any thought?


Reply to this email directly or view it on GitHub.

@hden
Copy link
Contributor

hden commented Mar 14, 2013

Because extras/coffee-script.js need to run in all the browser that is currently supported.
Or do you suggest a user agent string or a global object check to exclude source mapping in whatever browser that does not support it?

@ashtuchkin
Copy link
Author

I would suggest first making it optional (needs to be enabled in config hash), and then check for availability of both JSON and btoa. Imho we need not rely on user agent.

This is a small feature and I agree that we should minimize impact on both cycles and file size.

Sent from my iPhone

On 13.03.2013, at 20:27, Hao-kang Den [email protected] wrote:

Because extras/coffee-script.js need to run in all the browser that is currently supported.
Or do you suggest a user agent string or a global object check to exclude source mapping in whatever browser that does not support it?


Reply to this email directly or view it on GitHub.

@mehcode
Copy link

mehcode commented Mar 14, 2013

@hden
Copy link
Contributor

hden commented Mar 14, 2013

It seems that encoded data aren't interpreted in eval'd codest

I wan wrong see the reply from @ashtuchkin below

@ashtuchkin
Copy link
Author

I've managed to make it work by adding sourceURL statement in addition to sourceMappingURL. Please, see https://github.com/ashtuchkin/coffee-browser-sourcemaps

@hden
Copy link
Contributor

hden commented Mar 16, 2013

Awsome! @ashtuchkin Are you going to make a PR? I've have a working branch based on your idea.

@jashkenas
Copy link
Owner

@hden. Want to finalize and submit your branch as a PR, if it's working?

@ashtuchkin
Copy link
Author

@hden no, feel free to submit your PR, I'll be happy to review it if needed.

@jashkenas
Copy link
Owner

It's on master now, thanks to @hden.

@braco
Copy link

braco commented Mar 18, 2013

I'm not clear on this pull, is this supposed to just work with

<script type="text/coffeescript" src="...">

?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants