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

Parameter decorator applied on a symbol method cannot acquire the method instance #5962

Open
CMCDragonkai opened this issue Sep 27, 2022 · 2 comments
Labels

Comments

@CMCDragonkai
Copy link

CMCDragonkai commented Sep 27, 2022

Describe the bug

When using a parameter decorator such as:

function context(target: any, key: string | symbol, index: number) {
  const method = target[key];
  console.log('WHAT IS THIS?', method);
  // The `method` should not be undefined
}

const symbolFunction = Symbol('sym');

class X {
  regularFunc(@context ctx) { }

  async asyncFunct(@context ctx) { }

  [symbolFunction](@context ctx): Promise<void> {
    return new Promise((resolve) => void resolve());
  }
}

We get an output like:

WHAT IS THIS? [Function: regularFunc]
WHAT IS THIS? [AsyncFunction: asyncFunct]
WHAT IS THIS? undefined

This does not occur on tsc. With tsc (via ts-node), we get:

WHAT IS THIS? [Function: regularFunc]
WHAT IS THIS? [AsyncFunction: asyncFunct]
WHAT IS THIS? [Function: [sym]]

Input code

function context(target: any, key: string | symbol, index: number) {
  const method = target[key];
  console.log('WHAT IS THIS?', method);
  // The `method` should not be undefined
}

const symbolFunction = Symbol('sym');

class X {
  regularFunc(@context ctx) { }

  async asyncFunct(@context ctx) { }

  [symbolFunction](@context ctx): Promise<void> {
    return new Promise((resolve) => void resolve());
  }
}

Config

{
        "jsc": {
          "parser": {
            "syntax": "typescript",
            "dynamicImport": true,
            "tsx": true,
            "decorators": true,
          },
          "target": "es2022",
          "keepClassNames": true,
        },
      }

Playground link

No response

Expected behavior

It should show:

WHAT IS THIS? [Function: regularFunc]
WHAT IS THIS? [AsyncFunction: asyncFunct]
WHAT IS THIS? [Function: [sym]]

Actual behavior

WHAT IS THIS? [Function: regularFunc]
WHAT IS THIS? [AsyncFunction: asyncFunct]
WHAT IS THIS? undefined

Version

1.3.3

Additional context

No response

@CMCDragonkai

This comment has been minimized.

@swc-project swc-project temporarily blocked CMCDragonkai Feb 5, 2023
@kdy1
Copy link
Member

kdy1 commented Feb 5, 2023

@CMCDragonkai No, if you want issue prioritization please contact me via DM

@kdy1 kdy1 assigned kdy1 and unassigned kdy1 Feb 9, 2023
@kdy1 kdy1 removed their assignment Apr 18, 2023
@kdy1 kdy1 removed this from the Planned milestone Apr 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants