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 #31

Open
nickdima opened this issue Nov 26, 2014 · 5 comments
Open

Source Maps #31

nickdima opened this issue Nov 26, 2014 · 5 comments

Comments

@nickdima
Copy link

Is coffee-react-transform creating source maps?

@AsaAyers
Copy link
Contributor

I started working on this this morning.

Here is a sample of what it's producing right now. Javascript uses //# sourceMappingURL=... but that isn't valid CoffeeScript, so I currently have it using #//# sourceMappingURL=... in the hopes that it would work with existing tools. It doesn't. However exorcist detects sourceMappingURL doesn't pick up this version of it.

Even if I had sourcemaps 100% working right now though, they aren't useful yet. CoffeeScript would need to consume the sourcemaps as part of what it does. If it just ignores the line as a normal comment then what you end up sending to the browser will only go back to React.createElement("div", ...) and not <div>...</div>

I'd like CoffeeLint to consume them so it doesn't complain about things like line length based on transformed lines.

@jescalan
Copy link

I would say this is a valid request, and they actually can be useful immediately. It's not coffeescript's job to consume and generate multi-stage sourcemaps, and it won't ever do this, realistically. When you are running a 2-step compile like this on your own, you need to do the sourcemap management yourself.

So basically you'd run this transform, save away the sourcemap, then run the coffee transform, save that sourcemap, and combine the two using something like this library in whatever build pipeline you are using.

@jsdf
Copy link
Owner

jsdf commented Mar 12, 2015

Oh hey that is a pretty neat idea, I wasn't aware of that library

@benjie
Copy link
Contributor

benjie commented Apr 19, 2015

If you prefer you can use Mozilla's source-map library's applySourceMap method like apply-source-map does:

var Sauce = require('source-map')
var Consumer = Sauce.SourceMapConsumer
var Generator = Sauce.SourceMapGenerator

module.exports = function (map, from) {
  var generator = Generator.fromSourceMap(new Consumer(map))
  generator.applySourceMap(new Consumer(from))
  return generator.toString()
}

I've used this in my latest project, parallel-transpile, which uses Webpack loaders to transpile content via multiple steps from one folder to another using all your processors (multicore). I've not yet integrated CJSX source maps, but I'd certainly like to!

@jescalan
Copy link

This is the same thing that multi-stage-sourcemap does internally, just wraps it so it's a little bit less confusing and fewer lines of code 😀

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

No branches or pull requests

5 participants