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

Append to a provided source map #668

Closed
Tracked by #1892
simonexmachina opened this issue Nov 19, 2014 · 9 comments
Closed
Tracked by #1892

Append to a provided source map #668

simonexmachina opened this issue Nov 19, 2014 · 9 comments

Comments

@simonexmachina
Copy link
Contributor

It's possible to have source files that have already undergone some preprocessing (this is the common case in broccoli-sass) before they're handed to libsass. In this case it's not possible for libsass to maintain the mapping all the way back to the original source files.

The solution to this is add the ability to provide a source map to libsass which contains the previous mappings, and then libsass would append to this source map with its own transformations.

  • What can I do to help make this possible?
  • Do we already have the ability to parse a source map into our in-memory structure, or would this need to be added?
  • What options would we want for this? Maybe append_source_map?
@mgreter
Copy link
Contributor

mgreter commented Nov 19, 2014

I have ported some perl code to c++ in a side project to get something going.
So far I can read source maps (V3) and have the basic classes in place.
I guess what you are looking for is a remap function!?
https://github.com/mgreter/sourcemap.cpp

@simonexmachina
Copy link
Contributor Author

Are we currently using this library in libsass? Also, be aware that I know basically nothing about C++ 😄 (even though I did write the initial sourcesContent implementation for libsass!).

  • What do we use to create the source maps in libsass?
  • Would it be possible to simply parse a provided source map into our in-memory source map and then add to it from there?

@mgreter
Copy link
Contributor

mgreter commented Dec 6, 2014

You need to be more specific what you mean by "add" or "append"!? This is not really possible with source-maps!?? But I'm pretty sure what you are looking for is something I already implemented for webmerge (I called it remap). But no, this is not yet part of libsass!

| What do we use to create the source maps in libsass:
You give libsass some input and we will create some output. The source-map will map tokens in the output back to the input, simple as that. Unfortunately I do not really understand the second question! But I guess I know what you want to do. Let me give an example:

You (as the pre-processor) have two input files which you combine to one output file. You create a valid source-map for this operation. Now you give your output to libsass, which will generate the final css and another source-map. the libsass source-map will only point back to the "intermediate" input file (the one the pre-processor generated), but in reality it should point back to the two original input files, right!? This would be exactly the use case for my "remap" function. This is really just an operation on two source-map (it just "connects" the pointers from source-map b to a).

The custom importers already have an argument to pass a srcmap for exactly this reason, but so far we do not have anything implemented (it is just already defined on the API). As you may see, I'm currenty developing a C++ library to abtract most of this stuff for libsass. Once this is in place it should be much easier to work with source-maps from a coding stand-point.

@simonexmachina
Copy link
Contributor Author

Okay great, thanks. Your guess is exactly right, so it looks like remap is what we want to use. I'm not a C++ developer, so it will be difficult for me to do this myself :(

If I understand correctly:

  • We could use sourcemap.cpp to create two SrcMap instances - one from the preprocessor source map and the one for the libsass source map
  • Use the remap function to combine the two source maps into one

It looks to me that the natural place for this to live would be libsass itself. Ideally I'd like to be able to provide a source map to libsass and have it perform this remap on the source map that it produces. Do you agree? How would this fit into the roadmap? What can I do to help?

@mgreter
Copy link
Contributor

mgreter commented Dec 8, 2014

That's exactly what my intensions are. It's just much easier to develop this as a standalone library first, and I can re-use it for webmerge to replace my slow perl implementation. For libsassinput files, it should IMO check if there is a sourceMappingUrl. If so, it should automatically remap it. We still have a few problems with source-maps themselve in libsass, so don't expect anything soon!

@simonexmachina
Copy link
Contributor Author

Awesome, thanks for that. Totally understand that you've got higher priorities, but definitely looking forward to seeing this when it arrives.

@mgreter
Copy link
Contributor

mgreter commented Jan 22, 2016

I created a collective ticket to keep track this and other "non-urgent" feature requests, in order to keep the issue tracker a bit more clean for the more 1st aid issues. I would like to encourage everybody interested in this particular feature to add their comments into this closed issue anyway.

Thanks for your understanding and your contribution!

@mgreter mgreter closed this as completed Jan 22, 2016
@mgreter mgreter removed this from the 3.4 milestone Jan 22, 2016
@zigotica
Copy link

zigotica commented Jan 4, 2017

Hi @mgreter @aexmachina

Is fixing the Source Map feature in any milestone? I know you might have other priorities, but I'd really love to see it working. This would help fine tune development quite a lot for many teams.

Thank you

@flops
Copy link

flops commented Jun 29, 2017

I think this is a close one, correct me if i'm wrong.

sass/node-sass#1584

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

4 participants