question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`typescript` preset: incompatible with `+=` operator inside arrow functions, nested in ternary

See original GitHub issue

Bug Report

  • I would like to work on a fix! I have close to zero experience with Babel’s internals though. I would not be offended, if you think you can fix it yourself quicklier.

Current Behavior The typescript preset is incompatible with d3-array/cumsum.js. The issue seems to only occur for arrow functions using the += operator, nested inside a ternary. When typescript is disabled, the code compiled without any issues.

Input Code

  • Original broken d3-array/cumsum.js: REPL
  • Minimal reproduction: REPL
0 ? v => (sum += v) : v => 0;

/repl.ts: Only ‘=’ operator can be used for specifying default value. (1:13)

1 | 0 ? v => (sum += v) : v => 0;

Expected behavior/code Babel should compile the above code with typescript enabled.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:25
  • Comments:40 (17 by maintainers)

github_iconTop GitHub Comments

9reactions
IlyaSemenovcommented, Oct 30, 2020

@pelly You need to check your yarn.lock and manually merge the duplicate elements that you’ve probably got after yarn add d3-array@2.3.3:

-"d3-array@1.2.0 - 2":
-  version "2.5.1"
-  resolved "https://registry.yarnpkg.com/d3-array/-/d3-array-2.5.1.tgz#cc785e1c4b560a34b8c77af9e6709bdf3f2ee117"
-  integrity sha512-cKvAlQZUKhXInw5mosJMtAYsY3dDYwTess/WOFUQTGcr8xV04SZMJs6n6QznsqZC5vJTkvZuCgsH9fo981ysPA==
-
-d3-array@2.3.3:
+d3-array@2.3.3, "d3-array@1.2.0 - 2":
   version "2.3.3"
   resolved "https://registry.yarnpkg.com/d3-array/-/d3-array-2.3.3.tgz#e90c39fbaedccedf59fc30473092f99a0e14efa2"
   integrity sha512-syv3wp0U5aB6toP2zb2OdBkhTy1MWDsCAaYk6OXJZv+G4u7bSWEmYgxLoFyc88RQUhZYGCebW9a9UD1gFi5+MQ==

A safer approach would be to add a static resolution to package.json:

{
  "resolutions": {
    "d3-array": "2.3.3"
  }
}

and re-run yarn.

6reactions
mstsskcommented, Dec 17, 2020

I had same problem. I’m wondering if ignoring cumsum.js could be a workaround.

// babel.config.js
module.exports = function () {
  return {
    ignore: [new RegExp("d3-array/src/cumsum.js")],
    // other configs...
  }
};

Notes:

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Resolved] Upgrading to 2.2.1 breaks module compilation - help
The issue seems to only occur for arrow functions using the `+=` operator, nested inside a ternary. When `typescript` is disabled, the code ......
Read more >
javascript - Arrow Function Not Working In Ternary Operator
You have to execute the function you declared: (() => { holder.name.style.backgroundColor = holderbg holder.target.
Read more >
Arrow function expressions - JavaScript - MDN Web Docs
Arrow functions cannot use yield within their body and cannot be created as generator functions. Try it.
Read more >
Code Inspections in PHP | PhpStorm Documentation - JetBrains
Reports the parameters in function calls whose types are not compatible with the ones defined via Closure . Warning. PHPUnit ...
Read more >
Python vs JavaScript for Pythonistas
Code Blocks; Statements; Identifiers; Comments; String Literals; Variable Scopes; Switch Statements; Enumerations; Arrow Functions; Default Arguments ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found