-
Notifications
You must be signed in to change notification settings - Fork 451
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
[Bug]: Array.sort in hoist-jest might reversing all statements #4185
Comments
@hanjunspirit I think I have a similar problem. How did you debug it? How did you get the compiled code? I think in my case also the order of the statements is somehow mixed up. Although I import the class definition on top of the file I get the following error:
I'm a little bit lost because I don't know how to debug and therefore I can not create a repo with reproduction and without a repo I can not create a bug report. |
If someone else has the same problem, we found a workaround that works for us (probably that's not possible in every project). We were able to reference the problematic file in Nevertheless, a long-term solution would be better than a workaround. We also expect that the hoisting "feature" of jest breaks our code. It's super hard to create a repo that reproduces the problem. We think that our problem is very similar to what @hanjunspirit encountered. |
Version
27.1.5
Steps to reproduce
for the code:
Expected behavior
Actual behavior
It will be compiled into:
This leads to Base class not being found, causing an error.
Debug log
Additional context
This piece of code has different results in different versions of Node.js:
[1,2,3].sort(() => 1)
For example,
in Node.js 10.24.0, it returns
[3, 2, 1]
,But in Node.js 12.18.3, it returns
[1, 2, 3]
This depends on the implementation of the sort algorithm, and the result is unstable.
So for the sort in hoist-jest(#3498), if all isJestGlobalImport and isHoistableStatement return false, it might reversing all statements.
Environment
The text was updated successfully, but these errors were encountered: