aurelia / aurelia/cli

Babel loose config option causes issues with spread transform

Open
#1,000 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
402
Forks
134
PR merge metrics
No merged PRs in 30d

Description

**I'm submitting a bug report**
**I'm submitting a feature request**

* **Library Version:**
1.0.0-beta7

**Please tell us about your environment:**
* **Operating System:**
all

* **Node Version:**
6.2.0

* **NPM Version:**
8.11.3

* **Browser:**
all

* **Language:**
ESNext

* **Loader/bundler:**
all

**Current behavior:**
Babel config specifies `loose: true`. This causes issues when using the spread (`...`) operator with a `Set` object. Specifically, the code:

```javascript
this.foo = [...new Set([1, 2, 3])];
```

is transpiled to

```javascript
this.foo = new Set([1, 2, 3]).concat();
```

This is a problem, as `Set` objects do not have a `concat` method. This transpilation is a consequence of having `loose: true` in `.babelrc.js`, per this issue: https://github.com/babel/babel/issues/7958 . As mentioned in the linked issue, this is the expected behavior when using `loose: true`, and is not a bug in Babel or the spread transformer.

Simply setting `loose: false` will fix this issue.

This issue was originally reported on StackOverflow here: https://stackoverflow.com/questions/53696962/aurelia-not-transpiling-set-and-spread-operator-correctly
* **What is the expected behavior?**
Spread operator to be transpiled correctly with `Set` objects.

* **What is the motivation / use case for changing the behavior?**
Make transpilation work correctly.

Contributor guide

Open the contributing guide

Research direction

Inspect .babelrc.js and the Babel spread-transform configuration first. Reproduce the reported Set spread example with loose mode enabled, then verify the configuration change against the expected transpiled output. Done means the CLI no longer produces a concat call for Set spread, or the issue is documented as configuration behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
cli, tooling
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.