Skip to content

fix: prevent transpilation issues by using this to reference static props #11088

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

Merged
merged 1 commit into from
Dec 18, 2024

Conversation

jcfranco
Copy link
Member

@jcfranco jcfranco commented Dec 17, 2024

Related Issue: #10731

Summary

Referencing the class would cause incorrect JS output in certain vite builds:

source ✅

class i {
  static {
    this.DECIMALS = 100;
  }
  static {
    this.SHIFT = BigInt("1" + "0".repeat(i.DECIMALS));
  }
}

transpiled ❌

var b = class {
  static{this.DECIMALS = 100;}
  static{this.SHIFT = BigInt("1" + "0".repeat(b.DECIMALS));} // TypeError: Cannot read properties of undefined (reading 'DECIMALS')
}

@github-actions github-actions bot added the bug Bug reports for broken functionality. Issues should include a reproduction of the bug. label Dec 17, 2024
@jcfranco jcfranco requested a review from benelan December 17, 2024 21:27
@jcfranco jcfranco added the skip visual snapshots Pull requests that do not need visual regression testing. label Dec 17, 2024
Copy link
Member

@benelan benelan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! 🧹

@jcfranco jcfranco merged commit e78fa27 into dev Dec 18, 2024
17 checks passed
@jcfranco jcfranco deleted the jcfranco/improve-big-number-transpilation branch December 18, 2024 01:42
benelan pushed a commit that referenced this pull request Feb 8, 2025
… props (#11088)

**Related Issue:** #10731

## Summary

Referencing the class would cause incorrect JS output in certain vite
builds:

**source ✅**
```ts
class i {
  static {
    this.DECIMALS = 100;
  }
  static {
    this.SHIFT = BigInt("1" + "0".repeat(i.DECIMALS));
  }
}
```

**transpiled ❌**

```ts
var b = class {
  static{this.DECIMALS = 100;}
  static{this.SHIFT = BigInt("1" + "0".repeat(b.DECIMALS));} // TypeError: Cannot read properties of undefined (reading 'DECIMALS')
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug reports for broken functionality. Issues should include a reproduction of the bug. skip visual snapshots Pull requests that do not need visual regression testing.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants