Description
kcd-scripts
version: 7.5.3node
version: 12.20.0npm
(oryarn
) version: 6.14.8
Relevant code or config
export function createFunc1() {
function func() {
}
return func
}
export function createFunc2() {
function func() {
}
const name = func.name // not returned, just used
return func
}
What you did:
Run kcd-scripts build
What happened:
The output is
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createFunc1 = createFunc1;
exports.createFunc2 = createFunc2;
function createFunc1() {
return function () {};
}
function createFunc2() {
function func() {}
func.name; // not returned, just used
return func;
}
Reproduction repository:
Problem description:
The name of the function returned in createFunc1
gets removed thanks to babel-plugin-minify-dead-code-elimination
. This is causing me problems in a node package (specifically a testing library) where the name gets removed and consequently does not appear in stack traces which hurts debugability when things go wrong.
I can understand the desire to remove this when building for browsers (reduced bundle size), but I don't personally see many advantages to this for a node/test package.
Suggested solution:
There is an option to keep function names in the plugin, so we could set that the be true and keep the rest of the functionality. We could use the isTest
flag to conditionally set the option for tests only.
Similarly, we could use the isTest
flag to remove the plugin all together for tests.
Either solution would suffice for my issue. I'm also happy to submit the PR for this change if you agree with it and can advise me which approach is your preference.