Closed
Description
Bug Report
π Search Terms
comments, removeComments, implicit semicolon
π Version & Regression Information
I first noticed this in version 4.2.4. I have not tried earlier versions. It is still happening as of 4.3.5.
β― Playground Link
π» Code
When removeComments: false
and target: es5
, the following code:
const foo = 100;
const getHeight = () =>
`${
// A lengthy comment
foo
}px`;
generates this output
"use strict";
var foo = 100;
var getHeight = function () {
return
// A lengthy comment
foo + "px";
};
π Actual behavior
The outputted code is incorrect due to the 'implicit semicolon' immediately after the return
. Instead of returning "100px"
the generated getHeight
function returns undefined
and the foo + "px";
statement is unreachable code.
π Expected behavior
I would instead expect the output to be more like this (note additional parentheses).
"use strict";
var foo = 100;
var getHeight = function () {
return (
// A lengthy comment
foo + "px");
};