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

Construction of array from array destructuring is transpiled weird (downlevelIteration) #915

Closed
merisbahti opened this issue Oct 28, 2020 · 1 comment
Labels
problem: stale Issue has not been responded to in some time solution: duplicate This issue or pull request already exists solution: workaround available There is a workaround available for this issue topic: downlevelIteration Related to tsconfig downlevelIteration

Comments

@merisbahti
Copy link

Current Behavior

[...new Array(2)] // [undefined, undefined]

is transpiled to:

[].concat(new Array(2)) // [empty × 2]

Expected behavior

I don't know, it's just that I think that we need to transpile it so that it evaluates to [undefined, undefined]

Suggested solution(s)

No suggestions, since I don't know how to fix this. Maybe check what settings we have for babel?

Additional context

None.

Your environment

 System:
    OS: Linux 4.14 Ubuntu 20.04 LTS (Focal Fossa)
    CPU: (16) x64 Intel(R) Xeon(R) CPU @ 2.30GHz
    Memory: 20.31 GB / 58.98 GB
    Container: Yes
    Shell: 5.0.16 - /bin/bash
  Binaries:
    Node: 12.19.0 - ~/.nvm/versions/node/v12.19.0/bin/node
    Yarn: 1.22.10 - ~/.nvm/versions/node/v12.19.0/bin/yarn
    npm: 6.14.8 - ~/.nvm/versions/node/v12.19.0/bin/npm
  npmPackages:
    tsdx: ^0.14.0 => 0.14.0 
    typescript: ^4.0.2 => 4.0.2 
  npmGlobalPackages:
    typescript: 4.0.3

@agilgur5 agilgur5 added solution: duplicate This issue or pull request already exists topic: downlevelIteration Related to tsconfig downlevelIteration labels Oct 28, 2020
@agilgur5
Copy link
Collaborator

agilgur5 commented Oct 29, 2020

Looks like a downlevelIteration issue. This transpilation isn't "wrong" per se, it's spec vs. non-spec; the respective Babel/TS transforms are actually intentionally written so.

Can see #760 (comment) and #659 (comment) that this seems to duplicate.
To summarize, if you're creating a Node lib, you can use --target node or specify that in browserslistrc. If you're writing a browser lib, you can set preset-env to loose: false.

Per #760 (comment), I'm looking to add warnings to usage of tsconfig.json's downlevelIteration feature and perhaps looking to change preset-env in TSDX to not set loose by default, but it's unclear if the latter is breaking as it is for another plugin mentioned there.

@agilgur5 agilgur5 added the solution: workaround available There is a workaround available for this issue label Oct 29, 2020
@agilgur5 agilgur5 changed the title Construction of array from array destructuring is transpiled wrong. Construction of array from array destructuring is transpiled weird (downlevelIteration) Oct 29, 2020
@agilgur5 agilgur5 added the problem: stale Issue has not been responded to in some time label Mar 16, 2021
kepelrs added a commit to kepelrs/nestjs-prisma-crud that referenced this issue Jul 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
problem: stale Issue has not been responded to in some time solution: duplicate This issue or pull request already exists solution: workaround available There is a workaround available for this issue topic: downlevelIteration Related to tsconfig downlevelIteration
Projects
None yet
Development

No branches or pull requests

2 participants