Skip to content

Enable support for JS stage 4 features#861

Merged
twokul merged 2 commits into3.0-betafrom
twokul/babel-params
Feb 3, 2021
Merged

Enable support for JS stage 4 features#861
twokul merged 2 commits into3.0-betafrom
twokul/babel-params

Conversation

@twokul
Copy link
Contributor

@twokul twokul commented Feb 3, 2021

Enables support for JS stage 4 features.

Nullish Coalescing
const response = {
  settings: {
    nullValue: null,
    height: 400,
    animationDuration: 0,
    headerText: '',
    showSplashScreen: false
  }
};

const undefinedValue = response.settings.undefinedValue ?? 'some other default'; // result: 'some other default'
const nullValue = response.settings.nullValue ?? 'some other default'; // result: 'some other default'
Numeric Separator
1_000_000_000           // Ah, so a billion
101_475_938.38          // And this is hundreds of millions

let fee = 123_00;       // $123 (12300 cents, apparently)
let fee = 12_300;       // $12,300 (woah, that fee!)
let amount = 12345_00;  // 12,345 (1234500 cents, apparently)
let amount = 123_4500;  // 123.45 (4-fixed financial)
let amount = 1_234_500; // 1,234,500

0.000_001 // 1 millionth
1e10_000  // 10^10000

// Binary
let nibbles = 0b1010_0001_1000_0101;

// Hex Litral
let message = 0xA0_B0_C0;

// Octal Literal
let x = 0o1234_5670;
Optional Catch Binding
try {
  throwAnException();
} catch {
  console.log('we do not care about error object here, carry on');
}

Enables support for JS stage 4 features.

- [Nullish Coalescing](https://github.com/tc39/proposal-nullish-coalescing)
- [Numeric Separator](https://github.com/tc39/proposal-numeric-separator)
- [Optional Catch Binding](https://github.com/tc39/proposal-optional-catch-binding)

<details>

<summary>Nullish Coalescing</summary>

```javascript
const response = {
  settings: {
    nullValue: null,
    height: 400,
    animationDuration: 0,
    headerText: '',
    showSplashScreen: false
  }
};

const undefinedValue = response.settings.undefinedValue ?? 'some other default'; // result: 'some other default'
const nullValue = response.settings.nullValue ?? 'some other default'; // result: 'some other default'
```

</details>

<details>

<summary>Numeric Separator</summary>

```javascript
1_000_000_000           // Ah, so a billion
101_475_938.38          // And this is hundreds of millions

let fee = 123_00;       // $123 (12300 cents, apparently)
let fee = 12_300;       // $12,300 (woah, that fee!)
let amount = 12345_00;  // 12,345 (1234500 cents, apparently)
let amount = 123_4500;  // 123.45 (4-fixed financial)
let amount = 1_234_500; // 1,234,500

0.000_001 // 1 millionth
1e10_000  // 10^10000

// Binary
let nibbles = 0b1010_0001_1000_0101;

// Hex Litral
let message = 0xA0_B0_C0;

// Octal Literal
let x = 0o1234_5670;
```

</details>

<details>

<summary>Optional Catch Binding</summary>

```javascript
try {
  throwAnException();
} catch {
  console.log('we do not care about error object here, carry on');
}
```

</details>
@twokul twokul requested review from bantic and mixonic February 3, 2021 13:56
@twokul twokul marked this pull request as ready for review February 3, 2021 14:05
Co-authored-by: Matthew Beale <matt.beale@addepar.com>
@twokul twokul merged commit e2676bb into 3.0-beta Feb 3, 2021
@twokul twokul deleted the twokul/babel-params branch February 3, 2021 14:31
twokul added a commit that referenced this pull request Feb 3, 2021
A follow up on #861.

ET does not use `@babel/preset-env` (arguably, it should) so we have to
add the plugins we need manually. I forgot to do that in #861 - my bad.

One of the practical implications of this is that the consumers that do
not have these plugins enabled, will crash.
twokul added a commit that referenced this pull request Feb 3, 2021
A follow up on #861.

ET does not use `@babel/preset-env` (arguably, it should) so we have to
add the plugins we need manually. I forgot to do that in #861 - my bad.

One of the practical implications of this is that the consumers that do
not have these plugins enabled, will crash.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants