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

ngAnnotate mangles sourcemaps #212

Closed
conartist6 opened this issue Nov 30, 2015 · 5 comments
Closed

ngAnnotate mangles sourcemaps #212

conartist6 opened this issue Nov 30, 2015 · 5 comments

Comments

@conartist6
Copy link

ngAnnotate sourcemaps are generally bad citizens that tend to expose the buggiest side of sourcemap implementations especially when they are one of many source mapping steps which need to be combined into a single map definitive map.

The reason is that ngAnnotate tokenizes the code and then emits a mapping for every token. When other upstream transformations generate mappings that are less granular than ngAnnotate's all hell breaks loose. I've crashed sourcemap debuggers with the results and seen dev tools do the wildest things.

The solution is simple, emit only line mappings when at all possible, like such:

var HelloController = function($scope) {
    $scope.greet = "Goodbye cruel world!";
}
//^ input
var HelloController = function($scope) {
    $scope.greet = "Goodbye cruel world!";
}
HelloController.$inject = ['$scope'];
//^ output

Maps to ->
line 1 pos 0 maps to line 1 pos 0
line 2 pos 4 maps to line 2 pos 4
line 3 pos 0 maps to line 3 pos 0
line 5 pos 0 maps to line 4 pos 0

In my testing output like the above works great. I have a patch that does the above, but mine assumes that it will always be using $inject and never creating an inline injection parameter. I'd be willing to help get it right for both cases, but I'd like to be sure there's interest first.

@olov
Copy link
Owner

olov commented Dec 1, 2015

As long as you're ready to maintain the code (i.e. fix problems with it) I'd love to get further sourcemap improvements into ng-annotate so hack away! :-)

@conartist6
Copy link
Author

Sure, I can do that. I'll see what I can work up.

@olov
Copy link
Owner

olov commented Dec 1, 2015

👍

@olov
Copy link
Owner

olov commented Dec 1, 2015

There are also two other open sourcemap issues - one that I think should be easy to fix (perhaps as a side-effect of your planned PR) and the other one bigger. #201 and #202. :-)

@olov
Copy link
Owner

olov commented Jun 8, 2016

#245

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

2 participants