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.

No support for optional chaining syntax

See original GitHub issue

What is your Scenario?

I have a site which loads a code with the following line

this._pageLabels?.[this._currentPageNumber - 1] ?? null;

HH transforms it to the

__get$(this._pageLabels,this._currentPageNumber-1) ?? null;

and this code throws an error during runtime

Uncaught (in promise) Error: Cannot read property '0' of null at Function.t._error (hammerhead.js:12) at value (hammerhead.js:12)

The logic in transformed code is different.

I managed to get it working by extending createPropertyGetWrapper / createComputedPropertyGetWrapper with optional flag and changing the logic of method but I don’t know if this is a correct solution.

The site is an internal one so I cannot share the url

What is the Current behavior?

HH transformed code with optional chaining syntax have the different logic than the original one

What is the Expected behavior?

HH should detect optional chaining and perform a proper transformation

What is your public website URL? (or attach your complete example)

Private

What is your TestCafe test code?

I’ve been using proxy

Your complete configuration file

No response

Your complete test report

No response

Screenshots

No response

Steps to Reproduce

  1. Find a site with optional chaining code
  2. Try to use proxy on the site
  3. Site code breaks

TestCafe version

testcafe-hammerhead 24.2.1

Node.js version

No response

Command-line arguments

Browser name(s) and version(s)

No response

Platform(s) and version(s)

No response

Other

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:29 (8 by maintainers)

github_iconTop GitHub Comments

5reactions
miherlosevcommented, Feb 7, 2022

Opted for switching testcafe to a transpiled version of my script as a workaround.

We intend to fix the bug as soon as possible, so I would recommend that you wait for the fix.

1reaction
AlexanderZhigcommented, Apr 20, 2022

Hi guys! I take TC version 1.18.6, that uses testcafe-hammerhead": “24.5.18” and the problem is still present: I get the following code d=(t&&t[“function.from”])??null converted to d=t&&t[“function.from”]??null that leads to Uncaught SyntaxError: Unexpected token ‘??’

Read more comments on GitHub >

github_iconTop Results From Across the Web

Optional chaining (?.) - JavaScript - MDN Web Docs - Mozilla
The optional chaining ( ?. ) operator accesses an object's property or calls a function. If the object accessed or function called is ......
Read more >
How to Use Optional Chaining in JavaScript - freeCodeCamp
Optional chaining lives up to its name. In the chain of object property access we can check that each value is not undefined...
Read more >
Optional chaining '?.' - The Modern JavaScript Tutorial
The optional chaining ?. is a safe way to access nested object properties, even if an intermediate property doesn't exist.
Read more >
How to use optional chaining in Node.js 12 - Stack Overflow
Optional chaining is currently not supported in Node.js version 13 and below. It will be supported from Node.js version 14 and most of...
Read more >
no-unsafe-optional-chaining - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
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