Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Bug]: keepNames: true doesn't keep class name when function returns the class directly #8513

Description

@hi-ogawa

Reproduction link or steps

REPL: https://repl.rolldown.rs/#eNp9Uktu3DAMvQohFPAEGDjo1ttuiywKdKeNRqZn3JEpQ6KaKQZedtcjNJfLSULR+UyCJIYhiR89Pj7qbAbTnc1IPZ5azvVMpnuxt8ZXc5pjYjjDzx/fwWW4iT3W4wJDihM0JHZXUmhAPkuWrq/h/u4f8GHM0EfM1DDcxnS0NBTyPEYCn9BxRdlcwdkSQEIuSfzB5ayF8MRI/Us1zVosLbWKfpZ8pBwDtiHuNxeILbkJr0Bo4GlGz9hDI4EGdoXBeS4uqOPL1+aJ7v+/K91KM6vrI6oSgs9paoYw1f2xLwmp45K9mJ82YEkGgKbjVHDZmhRD6OMttXJpGPcX83on8mZyPQ4j4TcNP8/t6ZqKIErVVEl0Jej+fGGj0o80F+5ghWwnZNeqa1t15gPCMAbMkDGsiu/+qFckZxFRfnT+AOx2FSwWVjRFrlrU9Yg430jjuYPa8lYHruscHA8xTd362BpxLlUeUWV2/uj22P7KUaRY9XjlW5XQQtb0OMu0kPyI2RqpXx9UBRKk35ImdTCzWR4A4qIItQ==

import { URL as NodeURL } from 'node:url'    

// ❌ this doesn't work
function createURL() {
  return class URL extends NodeURL {
  }
}         
console.log(createURL().name) // expected 'URL' but actual 'URL$1'

// ✅ this works
// function createURL() {
//   class URL extends NodeURL {
//   }
//   return URL
// }         
// console.log(createURL().name)

The build output:

import { URL } from "node:url";

//#region \0rolldown/runtime.js
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", {
	value,
	configurable: true
});

//#endregion
//#region index.ts
function createURL() {
	return class URL$1 extends URL {};
}
console.log(createURL().name);

//#endregion
export {  };

What is expected?

The running the build output above logs URL.

What is actually happening?

The running the build output above logs URL$1.

System Info

REPL

Any additional comments?

Vitest had this pattern and we just found Rollup has the issue vitest-dev/vitest#9767. I tested it on Rolldown and found that it's also same, so reported here.

Metadata

Metadata

Labels

No labels
No labels

Type

Fields

Priority

None yet

Effort

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions