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

DEV: updates js transpiler to use babel 7 #10627

Merged
merged 3 commits into from Sep 15, 2020

Conversation

jjaffeux
Copy link
Contributor

@jjaffeux jjaffeux commented Sep 8, 2020

Updates our js transpiler code to use Babel 7.11.6

List of changes in this commit:

  • Updates plugins, babel plugins all have a new version which doesn't contain -es2015- anymore
  • Drops transform-es2015-classes this plugin shouldn't be needed now that we don't support IE
  • Drops check-es2015-constants, checking constants is now part of babel and the check-constants plugin is deprecated. As a result the behavior slightly changed, and is now wrapping every const call in a readOnlyError function which would throw if assigned a new value. This explains the modified spec.
  • Adds proposal-optional-chaining
const obj = {
  foo: {
    bar: {
      baz: 42,
    },
  },
};

const baz = obj?.foo?.bar?.baz; // 42
// IN
const ex = "before
after";
//                ^ There's a U+2028 char between 'before' and 'after'


// OUT
const ex = "before\u2028after";
//                ^ There's a U+2028 char between 'before' and 'after'
var object = {};
var foo = object.foo ?? "default"; // default
let a;
let b = 2;
a ||= b; // 2
let budget = 1_000_000_000_000;
console.log(budget === 10 ** 12); // true
let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };
console.log(x); // 1
console.log(y); // 2
console.log(z); // { a: 3, b: 4 }
try {

} catch {

} finally {
  // ensures finally is available in every browsers
}

@jjaffeux
Copy link
Contributor Author

jjaffeux commented Sep 8, 2020

The backend error seems legit and related: https://github.com/discourse/discourse/pull/10627/checks?check_run_id=1085914427

Will investigate.

Updates our js transpiler code to use Babel 7.11.6

List of changes in this commit:

- Updates plugins, babel plugins all have a new version which doesn't contain -es2015- anymore
- Drops (transform-es2015-classes)[https://babeljs.io/docs/en/babel-plugin-transform-classes] this plugin shouldn't be needed now that we don't support IE
- Drops check-es2015-constants, checking constants is now part of babel and the check-constants plugin is deprecated. As a result the behavior slightly changed, and is now wrapping every const call in a readOnlyError function which would throw if assigned a new value. This explains the modified spec.
- Adds (proposal-optional-chaining)[https://babeljs.io/docs/en/babel-plugin-proposal-optional-chaining]

```javascript
const obj = {
  foo: {
    bar: {
      baz: 42,
    },
  },
};

const baz = obj?.foo?.bar?.baz; // 42
```

- Adds (proposal-json-strings)[https://babeljs.io/docs/en/babel-plugin-proposal-json-strings]

```javascript
// IN
const ex = "before
after";
//                ^ There's a U+2028 char between 'before' and 'after'

// OUT
const ex = "before\u2028after";
//                ^ There's a U+2028 char between 'before' and 'after'
```

- Adds (proposal-nullish-coalescing-operator)[https://babeljs.io/docs/en/babel-plugin-proposal-nullish-coalescing-operator]

```javascript
var object = {};
var foo = object.foo ?? "default"; // default
```

- Adds (proposal-logical-assignment-operators)[https://babeljs.io/docs/en/babel-plugin-proposal-logical-assignment-operators]

```javascript
let a;
let b = 2;
a ||= b; // 2
```

- Adds (proposal-numeric-separator)[https://babeljs.io/docs/en/babel-plugin-proposal-numeric-separator]

```javascript
let budget = 1_000_000_000_000;
console.log(budget === 10 ** 12); // true
```

- Adds proposal-object-rest-spread https://babeljs.io/docs/en/babel-plugin-proposal-object-rest-spread

```javascript
let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };
console.log(x); // 1
console.log(y); // 2
console.log(z); // { a: 3, b: 4 }
```

- Adds proposal-optional-catch-binding https://babeljs.io/docs/en/babel-plugin-proposal-optional-catch-binding

```javascript
try {

} catch {

} finally {
  // ensures finally is available in every browsers
}
```

- Adds improved regex support for firefox through [transform-dotall-regex](https://babeljs.io/docs/en/next/babel-plugin-transform-dotall-regex.html) and [proposal-unicode-property-regex](https://babeljs.io/docs/en/babel-plugin-proposal-unicode-property-regex)

- Adds (for-await...of)[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of] support for Edge through [proposal-async-generator-functions](https://babeljs.io/docs/en/babel-plugin-proposal-async-generator-functions)
@jjaffeux jjaffeux changed the title DEV: updates js transpiler DEV: updates js transpiler to use babel 7 Sep 9, 2020
the failues are due to minor differences in the ouput due to new plugins and updated babel
@jjaffeux jjaffeux merged commit bbddce4 into discourse:master Sep 15, 2020
@jjaffeux jjaffeux deleted the update-transpiler branch September 15, 2020 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants