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 with modifier in the constructor does not work (typescript) #1456

Closed
wan2land opened this issue Mar 8, 2021 · 1 comment · Fixed by #1590
Closed

Parameter decorator with modifier in the constructor does not work (typescript) #1456

wan2land opened this issue Mar 8, 2021 · 1 comment · Fixed by #1590
Assignees
Labels
Milestone

Comments

@wan2land
Copy link

wan2land commented Mar 8, 2021

Describe the bug

Parameter decorator with modifier in the constructor does not work properly. If at least one modifier is missing, it works fine.

Input code

// not work

class MyClass {
  constructor(@Inject() readonly param1: Injected) {}
}

class MyClass {
  constructor(@Inject() public param1: Injected) {}
}

class MyClass {
  constructor(@Inject() public readonly param1: Injected) {}
}

class MyClass {
  constructor(@Inject() private param1: Injected) {}
}

class MyClass {
  constructor(@Inject() private readonly param1: Injected) {}
}

class MyClass {
  constructor(
    @Inject() public param1: Injected,
    @Inject() public param2: Injected
  ) {}  
}

// work

class MyClass {
  constructor(@Inject() param1: Injected) {}
}

class MyClass {
  constructor(
    @Inject() public readonly param1: Injected,
    @Inject() param2: Injected
  ) {}  
}

class MyClass {
  constructor(
    @Inject() param1: Injected,
    @Inject() public readonly param2: Injected
  ) {}  
}

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": false,
      "decorators": true
    },
    "transform": {
      "legacyDecorator": true,
      "decoratorMetadata": true
    }
  },
  "module": {
    "type": "commonjs"
  },
  "env": {
    "targets": "node 12"
  }
}

Expected behavior

The decorator needs to be parsed.

swc output:

class MyClass {
    constructor(
    @Inject()
    param1){
        this.param1 = param1;
    }
}

Version

    "@swc/cli": "^0.1.35",
    "@swc/core": "^1.2.50",

Additional context

Add any other context about the problem here.

@wan2land wan2land added the C-bug label Mar 8, 2021
@kdy1 kdy1 added this to the v1.2.52 milestone Mar 28, 2021
@kdy1 kdy1 modified the milestones: v1.2.52, v1.2.53, v1.2.54 Apr 10, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Apr 19, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Apr 19, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Apr 19, 2021
@kdy1 kdy1 mentioned this issue Apr 19, 2021
2 tasks
kdy1 added a commit to kdy1/swc that referenced this issue Apr 19, 2021
@kdy1 kdy1 self-assigned this Apr 19, 2021
kdy1 added a commit that referenced this issue Apr 19, 2021
swc_ecma_transforms_proposal:
 - Detect decorators in typescript parameter properties. (#1456)

swc:
 - Add tests for #1362. (#1362)
@swc-bot
Copy link
Collaborator

swc-bot commented Oct 24, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Oct 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

3 participants