kcd-scripts version: 7.5.3
node version: 12.20.0
npm (or yarn) 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:
Babel REPL
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.
kcd-scriptsversion: 7.5.3nodeversion: 12.20.0npm(oryarn) version: 6.14.8Relevant code or config
What you did:
Run
kcd-scripts buildWhat happened:
The output is
Reproduction repository:
Babel REPL
Problem description:
The name of the function returned in
createFunc1gets removed thanks tobabel-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
isTestflag to conditionally set the option for tests only.Similarly, we could use the
isTestflag 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.