$: npm install
$: npm run test:node
prior Set: Set { 'a', 'b' }
with spread syntax: Set { 'a', 'b', 'e' }
with Array.from: Set { 'a', 'b', 'e' }
$: npm run test:babel
prior Set: Set { 'a', 'b' }
with spread syntax: Set { Set { 'a', 'b' }, 'e' }
with Array.from: Set { 'a', 'b', 'e' }
Demonstrates a syntax issue when compiling code using
babel-env
and settingloose
option totrue
.test-rest-spread.js
- original syntaxtest-rest-spread.babel.js
- when compiled with babelThe demonstrations above (
npm run test:node
/npm run test:babel
) illustrate that the output is not equivalent when running the original code or the code produced by babel.This line is the issue; it works normally within node, and creates a new
Set
containing the prior Set and an added value:But when processed via babel and
loose:true
, it becomes this:Which ends up creating a new Set() containing the prior one as an element, instead of spreading its contents.