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): Allow expr_simplifier to do arithmetic with string literals #8683

Merged
merged 7 commits into from
Mar 4, 2024

Conversation

levi-nz
Copy link
Contributor

@levi-nz levi-nz commented Mar 2, 2024

Description:
This PR implements the feature described for the issue in #8682.

Related issue:

@levi-nz levi-nz requested a review from a team as a code owner March 2, 2024 20:06
Copy link

changeset-bot bot commented Mar 2, 2024

⚠️ No Changeset found

Latest commit: efbabf5

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

@CLAassistant
Copy link

CLAassistant commented Mar 2, 2024

CLA assistant check
All committers have signed the CLA.

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.

Can you run UPDATE=1 cargo test --test projects --test tsc from ./crates/swc?

@levi-nz
Copy link
Contributor Author

levi-nz commented Mar 3, 2024

Can you run UPDATE=1 cargo test --test projects --test tsc from ./crates/swc?

Looks all good on my end:
test result: ok. 4562 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 8.87s

@kdy1
Copy link
Member

kdy1 commented Mar 3, 2024

It will never fail with UPDATE=1, but it will modify files.

@levi-nz
Copy link
Contributor Author

levi-nz commented Mar 3, 2024

It will never fail with UPDATE=1, but it will modify files.

Got it. Two files have changed, here are the new versions:

enumConstantMemberWithString.2.minified.js:

//// [enumConstantMemberWithString.ts]
var T1, T2, T3, T4, T5, T11, T21, T31;
(T11 = T1 || (T1 = {})).a = "1", T11.b = "12", T11.c = "123", T11[T11.d = NaN] = "d", T11.e = "a1", (T21 = T2 || (T2 = {})).a = "1", T21.b = "12", (T31 = T3 || (T3 = {})).a = "1", T31.b = "12", T31[T31.c = 1] = "c", T31[T31.d = 3] = "d", (T4 || (T4 = {})).a = "1", (T5 || (T5 = {})).a = "12";

The only thing that has changed here is T11.d = "a" - "a" -> T11.d = NaN. When running "a" - "a" in NodeJS it yields NaN so this seems to be correct, but I'm not sure if that's correct in terms of this unit test.

enumConstantMemberWithTemplateLiterals.2.minified.js:

//// [enumConstantMemberWithTemplateLiterals.ts]
var T1, T2, T3, T4, T5, T6, T21, T41, T51, T61;
(T1 || (T1 = {})).a = "1", (T21 = T2 || (T2 = {})).a = "1", T21.b = "2", T21[T21.c = 3] = "c", (T3 || (T3 = {})).a = "11", (T41 = T4 || (T4 = {})).a = "1", T41.b = "11", T41.c = "12", T41.d = "21", T41.e = "211", (T51 = T5 || (T5 = {})).a = "1", T51.b = "12", T51.c = "123", T51[T51.d = 1] = "d", T51[T51.e = 0] = "e", T51.f = "11", T51.g = "123", T51[T51.h = 1] = "h", (T61 = T6 || (T6 = {}))[T61.a = 1] = "a", T61[T61.b = 2] = "b";

The only thing that has changed here is T51.e = "1" - "1" -> T51.e = 0, which also seems to be correct like the first case above, but again I'm not sure if that's correct in the context of this unit test.

@kdy1 kdy1 self-assigned this Mar 4, 2024
@kdy1
Copy link
Member

kdy1 commented Mar 4, 2024

Please commit those files

@kdy1 kdy1 changed the title Allow expr_simplifier to do arithmetic with string literals feat(es/minifier): Allow expr_simplifier to do arithmetic with string literals Mar 4, 2024
@kdy1 kdy1 added this to the Planned milestone Mar 4, 2024
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_optimization

@kdy1 kdy1 enabled auto-merge (squash) March 4, 2024 10:35
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 7e05adf into swc-project:main Mar 4, 2024
142 checks passed
@kdy1 kdy1 modified the milestones: Planned, v1.4.3 Mar 5, 2024
@swc-project swc-project locked as resolved and limited conversation to collaborators Apr 4, 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.

expr_simplifier does not handle numeric operations involving strings
4 participants