Skip to content

当存在装饰器语法时,tsdown 构建 ts 类型报错 #203

@KingAmo

Description

@KingAmo

Reproduction link or steps

代码示例

// 一个简单的装饰器:用于监听 accessor 的读写
function LogAccessor(target: any, context: ClassAccessorDecoratorContext) {
  const { name } = context

  return {
    get(this: any, originalGet: () => any) {
      console.log(`[Decorator] 读取属性: ${String(name)}`)
      return originalGet.call(this)
    },
    set(this: any, originalSet: (value: any) => void, value: any) {
      console.log(`[Decorator] 设置属性: ${String(name)} = ${value}`)
      originalSet.call(this, value)
    },
  }
}

export class Product {
  // 使用了装饰器的 accessor
  @LogAccessor
  accessor price: number = 100

  @LogAccessor
  accessor name: string = '未命名商品'
}

Describe the bug

当代码中有装饰器的语法时,配置 dts:true,构建报错如下:
报错日志
[plugin rolldown-plugin-dts:fake-js] /xxx/src/models/searchTab.d.ts:36:13
SyntaxError: This experimental syntax requires enabling the parser plugin: "decoratorAutoAccessors". (36:13)
at constructor (file:///xxx/node_modules/rolldown-plugin-dts/node_modules/@babel/parser/lib/index.js:314:19

System Info

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.

Contributions

  • I am willing to submit a PR to fix this issue
  • I am willing to submit a PR with failing tests (actually just go ahead and do it, thanks!)

Compensating engineering work will speed up resolution and support the project

  • I'm willing to offer $16 for financial support

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions