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

feat(es/minifier): Detect TypeScript enum initialization pattern #8986

Merged
merged 11 commits into from
May 30, 2024

Conversation

kdy1
Copy link
Member

@kdy1 kdy1 commented May 28, 2024

Description:

We can optimize

var Foo;
Foo || Foo = {};

This code looks strange, but

enum Foo {
    a = 1,
    b = 2,
}

transpiles to

var Foo;
(function(Foo) {
    Foo[Foo["a"] = 1] = "a";
    Foo[Foo["b"] = 2] = "b";
})(Foo || (Foo = {}));

and after minification it becomes

var Foo, Foo1;
(Foo1 = Foo || (Foo = {}))[Foo1.a = 1] = "a", Foo1[Foo1.b = 2] = "b";

@kdy1 kdy1 added this to the Planned milestone May 28, 2024
@kdy1 kdy1 self-assigned this May 28, 2024
Copy link

changeset-bot bot commented May 28, 2024

⚠️ No Changeset found

Latest commit: 9b7bb1c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@kdy1 kdy1 changed the title feat(es/minifier): Optimize TypeScript enums feat(es/minifier): Detect TypeScript enum initialization pattern May 28, 2024
@kdy1 kdy1 marked this pull request as ready for review May 28, 2024 04:13
@kdy1 kdy1 requested a review from a team as a code owner May 28, 2024 04:13
kodiakhq[bot]
kodiakhq bot previously approved these changes May 28, 2024
@kdy1 kdy1 requested a review from magic-akari May 29, 2024 04:31
@kdy1 kdy1 enabled auto-merge (squash) May 30, 2024 04:55
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

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.

reset ci

@kdy1 kdy1 merged commit cc8c155 into swc-project:main May 30, 2024
146 checks passed
@kdy1 kdy1 deleted the m3 branch May 30, 2024 14:01
@kdy1 kdy1 removed this from the Planned milestone Jun 5, 2024
@kdy1 kdy1 added this to the v1.5.25 milestone Jun 5, 2024
kdy1 added a commit to kdy1/swc that referenced this pull request Jun 11, 2024
kdy1 added a commit that referenced this pull request Jun 11, 2024
**Description:**

This reverts commit cc8c155 because it caused a regression in the next.js canary.

 - Canary version: `15.0.0-canary.12`


**Related issue:**

 - Reverts #8986
@swc-project swc-project locked as resolved and limited conversation to collaborators Jul 5, 2024
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.

3 participants