4

So I'm using babel-cli and it seems to be moving my comments to different lines. Is there any way I can tell babel to leave comments alone?

For instance:

console.log('woof');
// <debug>
x = () => {

   console.log('woof');

}
// </debug>

x();

Transpiles to:

console.log('woof'); // <debug>

x = function x() {
  console.log('woof');
}; // </debug>


x();

When I want it to be:

console.log('woof'); 
// <debug>

x = function x() {
  console.log('woof');
}; 
// </debug>


x();

This is my config:

{
"presets": [
    [
        "@babel/preset-env", {
            "targets": {
                "ie": "11"
            }
        }
    ]
],
"plugins": [
    "@babel/plugin-transform-object-assign"
]
}
vsemozhebuty
  • 12,992
  • 1
  • 26
  • 26
user1375026
  • 403
  • 4
  • 12
  • 23
  • 1
    I actually found a way of doing this but wondering if it's correct. I've added "retainLines": true to my config and seems to do the trick. https://babeljs.io/docs/en/options#retainlines If anyone could confirm, that would be great. – user1375026 Feb 15 '19 at 18:17
  • I am not sure whether enabling `retainLines` option would result in any confusion on debugging later, but I can confirm this makes the issue go away. – Shahroq Aug 10 '20 at 09:39

0 Answers0