Skip to content

Commit

Permalink
fix: prevent transpilation issues by using this to reference static…
Browse files Browse the repository at this point in the history
… 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')
}
```
  • Loading branch information
jcfranco authored Dec 18, 2024
1 parent fc7b65f commit e78fa27
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/calcite-components/src/utils/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class BigDecimal {

static ROUNDED = true; // numbers are truncated (false) or rounded (true)

static SHIFT = BigInt("1" + "0".repeat(BigDecimal.DECIMALS)); // derived constant
static SHIFT = BigInt("1" + "0".repeat(this.DECIMALS)); // derived constant

constructor(input: string | BigDecimal) {
if (input instanceof BigDecimal) {
Expand Down

0 comments on commit e78fa27

Please sign in to comment.