Open hanayashiki opened 10 months ago
Add the following case to test/index.test.ts
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
input.js
"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
ESNext
var Cls = class { field; }
And if we remove splitting: true, the code is correctly transformed to:
splitting: true
// 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.
splitting
Add the following case to
test/index.test.ts
And
input.js
is transformed toHowever, for target
ESNext
, it is expected to beAnd if we remove
splitting: true
, the code is correctly transformed to:This should be a bug because
splitting
is a bundling level option, but public field transformation should be transforming level.Upvote & Fund