microsoft / microsoft/TypeScript
__decorate helper should not use `this` when targeting modules
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 3.7.x-dev.201xxxxx
Search Terms: __decorate this module
Code
class Foo {
@property() x = 1;
}
Expected behavior:
Top-level this reference is not emitted.
Actual behavior:
The __decrate variable is declared like:
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
Since top-level this is always undefined in modules, (this && this.__decorate) || can be omitted. It's only a few bytes, but the presence of top-level this also causes warnings in other downstream tools like Rollup.
A few other things could be fixed for an ES6+ helper, btw:
- Use
constinstead ofvar(allows for some VM optimizations) - Remove
Reflect.decorate - Don't use
arguments
Playground Link: https://www.typescriptlang.org/play/?ts=Nightly#code/MYGwhgzhAEBiD29oG8BQ1oAEAOAne2AprgC4CeAFAJTQAe0AvNAIwDcqAvkA
Related Issues: None?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the example from the linked TypeScript Playground using the reported 3.7.x-dev version or current compiler, and inspect the emitted __decorate helper. Trace the compiler entry point that emits this helper; done means module output no longer includes the top-level this reference while decorator behavior remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100