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 set to a constructor parameter #734

Closed
mdoi2 opened this issue Feb 1, 2021 · 1 comment
Closed

Decorator set to a constructor parameter #734

mdoi2 opened this issue Feb 1, 2021 · 1 comment

Comments

@mdoi2
Copy link

mdoi2 commented Feb 1, 2021

The code when transpiling the decorator set in the constructor parameter seems to differ in processing from the code output from tsc.

As an effect of this, I have found that when I transpile and run code that uses the Inversify.js decorator, I get an error.

I have prepared this repository as a sample of what happens.
https://github.com/m-doi2/esbuild-ctor-param-decorator-bug-sample

In summary, there are the following differences between esbuild and tsc.

// tsc
Ninja = __decorate([
    inversify_1.injectable(),
    __param(0, inversify_1.inject(exports.Symbols.Katana)),
    __param(1, inversify_1.inject(exports.Symbols.Shuriken))
], Ninja);
// esbuild
__decorate([
  __param(0, import_inversify.inject(Symbols.Katana)),
  __param(1, import_inversify.inject(Symbols.Shuriken))
], Ninja.prototype, "constructor", 1);
Ninja = __decorate([
  import_inversify.injectable()
], Ninja);

It seems that tsc sets the parameter decorator directly to the class, while esbuild sets the parameter decorator to the prototype constructor.

Therefore, the following modification will work correctly.

// esbuild (fixed)
Ninja = __decorate([
  import_inversify.injectable(),
  __param(0, import_inversify.inject(Symbols.Katana)),
  __param(1, import_inversify.inject(Symbols.Shuriken))
], Ninja);

If this helps with this project, I'd be happy.

@evanw
Copy link
Owner

evanw commented Feb 1, 2021

Ah, I wasn't aware of constructor behaving this way. Thanks for the report. This is indeed a bug. I can fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants