Add the following case to test/index.test.ts
test.only('should transform class to public field definition to cjs', async () => {
const { output, outFiles } = await run(getTestName(), {
'input.ts': `
export class Cls {
public field: string;
}
`,
'tsup.config.ts': `
export default {
format: ['cjs'],
splitting: true,
}`,
})
expect(output).toMatchSnapshot()
})
And input.js
is transformed to
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// input.ts
var Cls = class {
};
exports.Cls = Cls;
However, for target ESNext
, it is expected to be
var Cls = class {
field;
}
And if we remove splitting: true
, the code is correctly transformed to:
// index.js
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// input.ts
var input_exports = {};
__export(input_exports, {
Cls: () => Cls
});
module.exports = __toCommonJS(input_exports);
var Cls = class {
field;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Cls
});
This should be a bug because splitting
is a bundling level option, but public field transformation should be transforming level.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too