2

I am getting various unexpected empty lines when I transpile a JavaScript snippet with Babel. Here is the source code:

/**
 * Header.
 */
function header() {
  const header = 'header';
  console.log(header);
};

/**
 * Navigation.
 */
function navigation() {
  const navigation = 'navigation';
  console.log(navigation);
};

And this is what I get after I transpile it:

"use-strict";

/**
 * Header.
 */
function header() {
    var header = 'header';
    console.log(header);
}

;
/**
 * Navigation.
 */

function navigation() {
    var navigation = 'navigation';
    console.log(navigation);
}

;

Notice empty lines before semicolons and after the second function comment.

Dependencies:

"devDependencies": {
    "@babel/cli": "^7.2.3",
    "@babel/core": "^7.2.2",
    "@babel/preset-env": "^7.2.3"
}

.babelrc

{
    "presets": ["@babel/preset-env"]
}

So the question is: How do I get a clean output without those empty lines?

Interestingly, if you put the same snippet to https://babeljs.io/repl it doesn't output empty lines.

Update

As suggested by Felix Kling, after removing the semicolons I do get this:

"use strict";

/**
 * Header.
 */
function header() {
  var header = 'header';
  console.log(header);
}
/**
 * Navigation.
 */


function navigation() {
  var navigation = 'navigation';
  console.log(navigation);
}
4

0 回答 0