Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addInitializer incorrectly throws if decorator throws #9078

Open
lucacasonato opened this issue Jun 18, 2024 · 0 comments · May be fixed by #9488
Open

addInitializer incorrectly throws if decorator throws #9078

lucacasonato opened this issue Jun 18, 2024 · 0 comments · May be fixed by #9488

Comments

@lucacasonato
Copy link
Contributor

Describe the bug

Calling addInitializer from a class decorator context throws if the decorator threw. As per spec this should not happen. Babel behaves correctly: https://babeljs.io/repl#?browsers=defaults%2C%20not%20ie%2011%2C%20not%20ie_mob%2011&build=&builtIns=false&corejs=3.21&spec=false&loose=false&code_lz=DYUwLgBAhgJjCSA7AlmZVjIF4gE4G4AoAMwFdEBjNAe0QhhAoAoB9AGgioA8BKCAbwhgAFrmoB3AdDhJU6TDlwQAvhAC8nMF3wrCYXAE8pFYFADOZiAEEpAAQYUIAWyZ9-qj5yhgKwgcsJCWAQUNAxsPCZXdQA-fx4iINBcMCYAIgAHczMQGDSeQiA&debug=false&forceAllTransforms=false&modules=false&shippedProposals=false&circleciRepo=&evaluate=true&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=env%2Creact%2Cstage-2%2Ctypescript&prettier=false&targets=&version=7.24.7&externalPlugins=&assumptions=%7B%7D

Input code

let addInitializer;
function dec(_, ctx) { throw { addInitializer } = ctx; }
try { class A { @dec m() {} } } catch {}

addInitializer(() => {});

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": false,
      "decorators": true
    },
    "target": "es2022",
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": false
    },
    "transform": {
      "legacyDecorator": false,
      "decoratorVersion": "2022-03"
    },
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.6.1&code=H4sIAAAAAAAAA1WMSwrEMAxD9z6FlinMDUKHdtlTlOBkaCBNIHGZT8ndx10WLSyhZ6UgcN4vOUp0Kf5CtfQ6MkssGT6wWR9g%2BQw4IVstb713HB3jRVh0kvrVnpNrDbO6SQewG33uuMROeNNAdN8wioxPLQZLfxsNdaCRAAAA&config=H4sIAAAAAAAAA3VQuwrDMAzc8xVBcwohhQ6du3btbhwluPiF5EBDyL%2FXzjuULkbSWXenG7I8hzdLuOdDLGPjBTHS1scJ9zaIT5xA6D2yJOUDFCsaOEGN0IzbrEbpSARHHKFAHU7AOOMQBLUYEh9yVVbVwgXaOcYzFxhlVdMf3UhnPCHzj6gRttXb%2FlmRhOXGkTkSaWyF7B%2Br1f9HvJBYOZsMJ7uX8go7%2B%2FSAcXU3aS8hpqDmA2%2Bwf1pv2XRA8XPdTDEVGeDHIymDMXI98WVjNn4BiKKsl6YBAAA%3D

SWC Info output

No response

Expected behavior

addInitializer does not throw.

Actual behavior

addInitializer throws.

Version

1.6.1

Additional context

This throws because SWC sets decorationState.[[Finished]] to true even if the decorator threw. This should not be the case - it should stay false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 participants