swc icon indicating copy to clipboard operation
swc copied to clipboard

TypeScript accessors end in an internal error

Open onigoetz opened this issue 2 years ago • 2 comments

Describe the bug

By taking an example from here : https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-9.html#a-nameauto-accessors-in-classes-auto-accessors-in-classes

I get a the following error:

thread '<unnamed>' panicked at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/swc_ecma_compat_es2022-0.2.2/src/class_properties/mod.rs:957:21:␊
internal error: entered unreachable code: auto_accessor pass should remove this␊
note: run with \`RUST_BACKTRACE=1\` environment variable to display a backtrace␊

Input code

export class PersonAccessor {
  accessor name: string;
  constructor(name: string) {
    this.name = name;
  }
}

Config

{
  jsc: {
    parser: {
      syntax: 'typescript',
      jsx: true,
      decorators: true,
      usingDecl: true
    },
    experimental: { keepImportAssertions: true },
    externalHelpers: true
  },
  env: {
    targets: 'Edge >= 96, Safari >= 15, iOS >= 15, Chrome >= 96, and_chr >= 96, Firefox >= 94, > 1%, not dead, not op_mini all, chrome 71',
    mode: 'entry',
    coreJs: 3
  },
  sourceMaps: true,
  module: { type: 'es6' }
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.3.101&code=H4sIAAAAAAAAA0utKMgvKlFIzkksLlYISC0qzs9zTE5OLS7OL1Ko5uVSUEiE8fISc1OtFIpLijLz0q1BMsn5eUBeaXJJfpEGsqQmRKOCQklGZrEeSEbBFqwbrKuWl6sWAHac7711AAAA&config=H4sIAAAAAAAAA22Quw7CMAxFd76i8swADAzMDCx8hBXcKigv2a7Uquq%2Fk6YPisQW3%2BvrE3s4VBW8xcCtGvIzFwlZiLc6K9IHxS4roH0iMWyTwnF1VSarRidUpHF2QJEb0ilFcjldzksCXIxCWVZuaZG8Dbbu90gTfWISWSdvNI%2BhcfQfyBikjuz3gxw1aPo7mciokRfuT446JQ7oHuQSsexmlw7w8dUW5HKg6QjzWlf4Nq0rbN8FK881WZjjB2vax5ZsAQAA

SWC Info output

Operating System:
    Platform: linux
    Arch: x64
    Machine Type: x86_64
    Version: #1 SMP Fri Jun 2 00:45:15 UTC 2023
    CPU: (6 cores)
        Models: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz

Binaries:
    Node: 18.17.1
    npm: 9.6.7
    Yarn: 4.0.2
    pnpm: N/A

Relevant Packages:
    @swc/core: 1.3.101
    @swc/helpers: 0.5.3
    @swc/types: 0.1.5
    typescript: 5.3.3

SWC Config:
    output: N/A
    .swcrc path: N/A

Next.js info:
    output: N/A

Expected behavior

I expected the accessor to be transpiled

Actual behavior

thread '<unnamed>' panicked at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/swc_ecma_compat_es2022-0.2.2/src/class_properties/mod.rs:957:21:␊
internal error: entered unreachable code: auto_accessor pass should remove this␊
note: run with \`RUST_BACKTRACE=1\` environment variable to display a backtrace␊

Version

1.3.101

Additional context

No response

onigoetz avatar Dec 20 '23 12:12 onigoetz

Configuring the decoratorVersion option correctly will enable its functionality to work.

    "transform": {
      "decoratorVersion": "2022-03"
    },

https://play.swc.rs/?version=1.3.101&code=H4sIAAAAAAAAA0utKMgvKlFIzkksLlYISC0qzs9zTE5OLS7OL1Ko5uVSUEiE8fISc1OtFIpLijLz0q1BMsn5eUBeaXJJfpEGsqQmRKOCQklGZrEeSEbBFqwbrKuWl6sWAHac7711AAAA&config=H4sIAAAAAAAAA2VQywqDQAy89ysk5xashR76Bb302vuyRtmyL5IIivjvXZ9Vektmksxk%2BlOWwYc1PLI%2BlamJihhp6xPCnRfVJgSki8iaTBQ4r6zwSFXKMm5YiTqQkkCcKKEGJ2KYeRBFNcp4D7nIi%2BtyC2wIjMvCAjnjTdXtzejgIiHzn6ZTvra4wkdBUp6rQG5%2FaPP4RmIT%2FOgnuSku%2BQ0O29gKklf2iTYi8U5hmgAXymYSXgIcQ5qfu8NvaH1kMw2GX%2BvmFNHwBf%2FIwMeMAQAA

magic-akari avatar Dec 21 '23 03:12 magic-akari