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/typescript): Support ts_enum_is_mutable with const enums #8171

Merged
merged 3 commits into from
Oct 23, 2023

Conversation

dsherret
Copy link
Contributor

Description: Bug I introduced in https://github.com/swc-project/swc/pull/8115/files (it was not implemented correctly)

@@ -4581,5 +4586,7 @@ test!(
})(D || (D = {}));
D.A = 5;
console.log(D.A);
var E;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Improvement for swc in the future might be to not emit this for const enums.

kdy1
kdy1 previously approved these changes Oct 23, 2023
Copy link
Member

@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_transforms_typescript

@kdy1 kdy1 enabled auto-merge (squash) October 23, 2023 16:52
@magic-akari
Copy link
Member

https://www.typescriptlang.org/play?#code/KYOwrgtgBAYg9nKBvAUFdUCCUC8UBMKAviigMZwgDOALlKJFAEICGATsmhk7rAgHSZipCtTgAbYP3FwA5gApWbfkwCUQA

enum Foo {
    A = 2
}

const enum Bar {
    B = Foo.A
}

console.log(Bar.B)

Could you add this test case?

@kdy1 kdy1 disabled auto-merge October 23, 2023 18:13
@kdy1 kdy1 added this to the Planned milestone Oct 23, 2023
(function(I) {
I[I["A"] = H.A] = "A";
})(I || (I = {}));
console.log(I.A);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not ideal, but it's ok output. It's a rare edge case for someone to use an enum in a const enum.

@dsherret
Copy link
Contributor Author

@magic-akari good idea! I added a test for that and for the opposite.

@dsherret dsherret requested a review from kdy1 October 23, 2023 18:35
@kdy1 kdy1 merged commit 02d0613 into swc-project:main Oct 23, 2023
143 checks passed
@kdy1 kdy1 modified the milestones: Planned, v1.3.95 Oct 24, 2023
@dsherret dsherret deleted the fix_ts_enum_is_mutable_const_enum branch October 24, 2023 18:58
@swc-project swc-project locked as resolved and limited conversation to collaborators Nov 24, 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.

3 participants