这是indexloc提供的服务,不要输入任何密码
Skip to content

Pass through useDefineForClassFields into SWC plugin #1311

@joelgallant

Description

@joelgallant

High level problem: when I don't want tsup to build target > es2021, but do use emitDecoratorMetadata, I'm forced to opt-in to SWC transforms that break my legacy decorators.

See

tsup/src/esbuild/swc.ts

Lines 32 to 41 in 769aa49

parser: {
syntax: isTs ? 'typescript' : 'ecmascript',
decorators: true,
},
transform: {
legacyDecorator: true,
decoratorMetadata: true,
},
keepClassNames: true,
target: 'es2022',

Note that esbuild automatically detects the useDefineForClassFields tsconfig option. But SWC does not (automatically).

Two things:

  1. Set the transform option like so https://swc.rs/docs/configuration/compilation#jsctransformusedefineforclassfields inferred via target or from the user's tsconfig
  2. Set the target based on that of tsup config? I'm not sure if the hardcoded es2022 is intentional / for a reason (ie esbuild for down-level it better)

I'd be happy to try and do this in a PR

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