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

Decorator init order is incorrect #7404

Open
jridgewell opened this issue May 16, 2023 · 0 comments · May be fixed by #8762
Open

Decorator init order is incorrect #7404

jridgewell opened this issue May 16, 2023 · 0 comments · May be fixed by #8762
Assignees
Labels
Milestone

Comments

@jridgewell
Copy link
Contributor

Describe the bug

From today's TC39 meeting, the committee has decided to reverse the order of initializers.

Input code

function minusTwo({ set, get }) {
  return {
    set(v) {
      set.call(this, v - 2)
    },
    init(v) {
      return v - 2;
    }
  }	
}

function timesFour({ set, get }) {
  return {
    set(v) {
      set.call(this, v * 4)
    },
    init(v) {
      return v * 4;
    }
  }	
}

class Foo {
  @minusTwo @timesFour accessor bar = 5;
}

const foo = new Foo();
console.log({ init: foo.bar });

foo.bar = 5;	
console.log({ set: foo.bar });

Config

{
  "jsc": {
    "transform": {
      "useDefineForClassFields": true,
      "decoratorVersion": "2022-03"
    },
    "parser": {
      "syntax": "typescript",
      "decorators": true
    },
    "target": "es2015",
    "loose": false,
  },
  "module": {
    "type": "es6"
  },
  "isModule": true,
  "minify": false
}

Playground link

https://play.swc.rs/?version=1.3.58&code=H4sIAAAAAAAAA6WQQQ7CIBBF13KKv2xN7cLoxqaJq57AC1RClYQyCUPtwnB3Aa2JrkzcAH%2Fm%2FckfhslKr8li1Hbi00zFHax8hYvyCCXuAnDKT87mJ1KzuJUvkWUte2MKf9Vc4YYNtmXuhSpf2uoPw2tYBpsnGM%2BwEkGIYQnj9ai4o8n9m2aN3W9pIvidRpqeGR1Rpo%2FLB%2BH4TodeSsVMDufeocW%2ByT6y7DFEXwur5jShKJtcJqNqQ5e4VQpySFCdrCH2xSLSnNUXHhf7pB%2B9EpXkuAEAAA%3D%3D&config=H4sIAAAAAAAAA2WPMQ%2BCMBCFd34FuVkTrNHBVcPm6t7A1dSUHrkriYTw3y1gCcbt7vV77%2FWGLM%2FhJRVc8iGOcQmsvRjiZpWi2Ane0FiPJfHVaZHSoqslIoE73CWsxopYB%2BIHsljy8R1UodS%2BOMLMjAsKrWZB3jZI74N%2BT4bQtygV2zbAf3Cq%2FEkLmp8YJi%2BKKg6nrw8ckWCUjXYyf3I2QEN153BzcSxczGdYISv3hKUTobHemj4FZuMHZWKX0j0BAAA%3D

Expected behavior

The set and init logs should be equivalent, because init runs minusTwo's init first then timesFour's.

"{init: 12}"
"{set: 12}"

Actual behavior

The set and init logs are different, because init runs timesFour's init first then minusTwo's.

"{init: 18}"
"{set: 12}"

Version

1.3.58

Additional context

No response

@kdy1 kdy1 added this to the Planned milestone May 17, 2023
@kdy1 kdy1 self-assigned this May 17, 2023
@kdy1 kdy1 linked a pull request Mar 19, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants