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

fix(es/minifier): Preserve cooked while compressing template literals #7773

Merged
merged 10 commits into from
Aug 17, 2023

Conversation

kdy1
Copy link
Member

@kdy1 kdy1 commented Aug 7, 2023

@kdy1 kdy1 added this to the Planned milestone Aug 7, 2023
@kdy1 kdy1 self-assigned this Aug 7, 2023
@kdy1 kdy1 changed the title fix(es/minifier): Fix handling of template literals in minify() fix(es/minifier): Fix handling of template literals Aug 7, 2023
kdy1 added 2 commits August 8, 2023 05:45

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@kdy1 kdy1 changed the title fix(es/minifier): Fix handling of template literals fix(es/minifier): Preserve cooked while compressing template literals Aug 7, 2023
@kdy1 kdy1 requested a review from jridgewell August 7, 2023 20:47
@kdy1 kdy1 marked this pull request as ready for review August 7, 2023 20:47
kodiakhq[bot]
kodiakhq bot previously approved these changes Aug 7, 2023
Copy link
Member Author

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

swc-bump:

  • swc_ecma_minifier

Copy link
Contributor

@jridgewell jridgewell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this algorithm is still faulty. We never reinitialize cur_cooked to a Some(_), so we'll only push cooked values for the first quasi? What about all the other quasis?

I think the better algorithm here is to just peek the last item in quasis, and mutate the value directly when we find a string literal.

kodiakhq[bot]
kodiakhq bot previously approved these changes Aug 16, 2023
@kdy1
Copy link
Member Author

kdy1 commented Aug 16, 2023

I added logic for setting cur_cooked to None to ensure that we only set cooked of the new template literal strings if all elements have cooked set.

Copy link
Contributor

@jridgewell jridgewell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point is that that the second quasi in the following situations will not have a cooked value, when it should:

foo`
  \x<-invalid, so no cooked
  ${'this breaks splits the quasis'}
  this should have a cooked
`;

foo`
  \x<-invalid, so no cooked
  ${'this breaks splits the quasis'}
  this should have a cooked
  ${'this breaks splits the quasis'}
  this should also have a cooked
`;

@kdy1 kdy1 requested a review from jridgewell August 17, 2023 02:56
@kdy1 kdy1 enabled auto-merge (squash) August 17, 2023 03:32
Copy link
Collaborator

@swc-bot swc-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review comment generated by auto-rebase script

@kdy1 kdy1 merged commit 05990a9 into swc-project:main Aug 17, 2023
@kdy1 kdy1 deleted the issue-7770 branch August 17, 2023 04:35
@kdy1 kdy1 modified the milestones: Planned, v1.3.78 Aug 17, 2023
@swc-project swc-project locked as resolved and limited conversation to collaborators Sep 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Some parts of template literals are copied with minify()
3 participants