-
-
Notifications
You must be signed in to change notification settings - Fork 57
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
CommentRegex Doesn't Find Comments on Same Line as Code #5
Comments
Could you provide an example snippet please? AFAIK the spec requires the source map comment to be on it's own line. It's all described in this proposal. Nothing that hints at supporting the Less case. Also this post points at it needing to be on it's own line. Are you sure you are dealing with source maps and not source urls? I remember less had those. Again a snippet would be very helpful to clarify. |
I'm not entirely clear on the difference between Source Map and Source Urls, so no, I'm not sure what I'm dealing with :) Here's a link to bootstrap compiled with the options I mentioned above: http://pastebin.com/6Rb5tb40 That's not the exact code I was using when I ran into this, but it's close. |
The sourcemap is broken up in a weird manner:
I mean its all on one line! The source map needs to be on a separate line. Looks like minification broke it. I don't think that abides by the spec and would expect lots of tools to fail in parsing this out correctly. Please file a bug with the authors of the tools that generated this. |
I'm not actually seeing anywhere in the Source Map 3 Proposal that specifies that a source map needs to be on its own line. Am I being thick? The source map is read fine by chrome/firefox, so if it's not explicitly said to need to be on its own line in the spec, isn't it better to allow it? |
@thlorenz Can you point me to where it says source maps need to be on their own line? I don't see anything that conclusively states source maps are required to be on their own line in a file in the proposal but I fully acknowledge I could be missing something. Seems to me that if source maps don't explicitly need to be on their own line, then the error is with the CommentRegex. |
You may be right, but we need to confirm that other tools even handle source maps like that. Pulling out a source map with regex becomes near impossible to get right without false positives (i.e. inside a string) once you don't assume them to be on a separate line. As a test you could generate a browserify bundle and put all code on one line (including source map). |
I can confirm that Chrome and Firefox will correctly parse a source all on one line in that manner. It works for both Javsacript as well as CSS maps. (http://pastebin.com/6Rb5tb40 is successfully parsed back to it's less files.) I'm happy to put together a PR for you to add a flag for this if you want. If you're set on keeping the original regex as an option you could just add an additional regex called |
Actually if you remove Since we still have the It'd be awesome if you could PR with that change along with some tests for your particular case and some that ensure that it won't match false positives, i.e. try to pull a source map from within a string. Thanks. |
Sure thing, I'll try to put some tests together this afternoon. Changing the default behavior definitely seems more friendly. |
Actually this regex doesn't have the |
I can confirm that this pull request works for the pastebin we've been using in this thread. |
See <thlorenz/convert-source-map#5>. This is both about following the spec, and supporting real tools. This change meant lots of changes in how each method works. See the changelog.
I'm not sure if the source map spec says source map comments must be on new lines or not. If that's the case this is a bug in Less and I can post it there.
I'm using Less with the inline source map and compression options and my code and an inline source map end up on one line at the end of the file.
The commentRegex is set to only look for comments on their own line, and there are 4 tests (4, 5, 10, 11 in comment-regex.js) that fail if you remove that piece of the regex. Those tests seem specifically designed to fail if the comment isn't on it's own line so that makes sense. The tests fail but the captured parts remain the same throughout, so it seems like it would still be safe.
Thoughts on this? Is this a bug in Less's compression for allowing source maps to be stuck on the same line as code?
The text was updated successfully, but these errors were encountered: