Open Vijar opened 9 years ago
CLA is valid!
Thanks @Vijar trying it now: I have an issue with recast and babeljs, let me investigate first :-)
I do agree console.log
shouldn't be stripped by this loader, it's also a job for the Uglifier.
@Vijar I believe recast introduces a new level of complexities :-)
This code with an inline jsx comment didn't work with the strip-loader when running the babeljs-loader first:
render() {
return (
<p>
{ /* inline jsx comment */ }
</p>
);
}
recast throws an error:
Module build failed: Error: Comment location overlaps with node location
because babel puts the comment on the bottom of the file (https://github.com/babel/babel/issues/459, https://github.com/babel/babel/issues/672). So recast is safer than a regexp, on the other side it put some limitations we should be aware of.
@gpbl, I actually did try to preserve comments but recast doesn't play nice with comments at all! :(
I think we may have to do what fixmyjs guys did, create a v2.0 release with recast because it is safer, but still maintain a legacy version which still uses your wider regexp PR. We can address the pros/cons of each in the README.
@Vijar :+1: thanks!
I got this working with recast. Mainly took inspiration from fixmyjs.
This would fix #4
However, this is now backwards incompatible since we can no longer strip
console.log
or any other CallExpressions that are considered MemberExpressions. We can only strip Identifiers such as 'debug' or 'assert'.I actually don't think this loader should be stripping console.log statements anyway, so I actually don't mind the breaking version.
@gpbl, if you can test this branch for your code and give me a +1, I will merge.