Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork6.6k
fix(jest-snapshot): Fix a potential bug when using babel and improve performance#14036
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
) { | ||
throw new Error('Jest: no snapshot insert location found'); | ||
} | ||
// A hack to prevent unexpected line breaks in the generated code | ||
node.loc!.end.line = node.loc!.start.line; |
liuxingbaoyuMar 29, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Actually only this line is the fix, the rest are refactorings.😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Awesome, thanks! 👍
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Uh oh!
There was an error while loading.Please reload this page.
Summary
While I was fixing a babel issue, I discovered that jest was expecting buggy behavior.
retainLines
will try to keep the original code and the new code on the same line.When we replace
123\n456
with the single-line content123456
.The previous babel would ignore the position of
)
and generate this.And new babel will generate
jest was relying on the previous behavior, the PR fixes this.
Ref:babel/babel#15515
In addition, I also found that
@babel/traverse
is being used in the current code to traverse the AST generated by other than@babel/parser
, which is a bit unexpected.But since it's been that long, it seems like it's good enough for this simple usage.
I just replaced it with
traverse
from@babel/types
, which has very simple functionality and is much faster.(Maybe 10x)Test plan
CI green