Skip to content

Typescript enum value with as syntax cause swc crash #11761

@fireairforce

Description

@fireairforce

Describe the bug

Just as the playground shows:

Image

It seems typescript can work for the case:

https://www.typescriptlang.org/play/?#code/KYDwDg9gTgLgBMAdgVwLZwErAGYBUCeYwcA3gFBxxhQRGz5wC8cA5AIxstwCGAzj4nwAaCggBuSeMxYAmGVz4DhZAL5kyAYwiJeEADbAAdHogBzABRY8hI9VrB6QzDgJFDwCYhgBKANxA

Input code

export enum RefType {
  property = '11' as any,
  event = '22' as any,
}

console.log(RefType.property, RefType.event);

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": false
    },
    "target": "es2015",
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": false
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": true,
  "isModule": true
}

Link to the code that reproduces this issue

https://play.swc.rs/?version=1.15.21&code=H4sIAAAAAAAAA0utKMgvKlFIzSvNVQhKTQupLEhVqOZSUCgoyi9ILSqpVLBVUDc0VFdILFZIzKvUAcqklqXmlYCEjYwQwrVcXMn5ecX5Oal6OfnpGlCT9GCm6MDM1gPr1rQGAHzWVCt3AAAA&config=H4sIAAAAAAAAA1WPQQ7CIBBF95yCzNqFmujCO3gIgtMGQ4Ew00TS9O4FCmp3zPv%2F82cWISW8ScNDLvmZh6AiYfzOmVByrD6ZAKeApKMJDKeuMhVpUJawonVXgFUckUsK6Xq%2B3FoCrPeEPdHYZJwZ0n%2Bn9lOISHQ0Fqtyo8Vjo2itMPnXXMV2S9l33%2BAOP1Mv4zjXf8HQswcLE%2BsG5sj54hYBAAA%3D

SWC Info output

No response

Expected behavior

work normal as typescript.

Actual behavior

it will get crash

Version

1.15.21

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions