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(transformer/logic-assignment-operator): always create IdentifierReferences with ReferenceId #7745

Conversation

overlookmotel
Copy link
Contributor

@overlookmotel overlookmotel commented Dec 9, 2024

Use TransformCtx::duplicate_expression (introduced in #7754) to decide when to create temp vars for member expression object and computed property.

This fixes a bug where IdentifierReferences created when transforming key in object[key] &&= value were created without a ReferenceId (due to clone_in).

We didn't catch this before because Babel's test fixtures only cover object[key++] &&= value not the simpler object[key] &&= value. Add tests for this.

Copy link

graphite-app bot commented Dec 9, 2024

Your org has enabled the Graphite merge queue for merging into main

Add the label “0-merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

@github-actions github-actions bot added A-transformer Area - Transformer / Transpiler C-test Category - Testing. Code is missing test cases, or a PR is adding them labels Dec 9, 2024
@overlookmotel overlookmotel marked this pull request as ready for review December 9, 2024 15:13
@overlookmotel
Copy link
Contributor Author

I'm seeing weird interactions between logical assignment operator + class properties transforms. I thought the fault might be in logical assignment operator transform, so that's why I added these tests. But no! They pass. 😢

@overlookmotel overlookmotel marked this pull request as draft December 9, 2024 15:16
@overlookmotel overlookmotel force-pushed the 12-09-test_transformer_logic-assignment-operator_add_more_tests branch from 0c38523 to 61df605 Compare December 9, 2024 15:19
@overlookmotel
Copy link
Contributor Author

overlookmotel commented Dec 9, 2024

Ah ha no! I made a mistake in the tests. The problem is in this transform. I'll try to fix.

Copy link

codspeed-hq bot commented Dec 9, 2024

CodSpeed Performance Report

Merging #7745 will not alter performance

Comparing 12-09-test_transformer_logic-assignment-operator_add_more_tests (e48769a) with 12-09-refactor_transformer_duplicate_expression_do_not_produce_temp_var_for_super_ (5e49bbd)

Summary

✅ 29 untouched benchmarks

@overlookmotel overlookmotel changed the title test(transformer/logic-assignment-operator): add more tests fix(transformer/logic-assignment-operator): always create IdentifierReferences with ReferenceId Dec 9, 2024
@overlookmotel overlookmotel added C-bug Category - Bug and removed C-test Category - Testing. Code is missing test cases, or a PR is adding them labels Dec 9, 2024
@overlookmotel overlookmotel marked this pull request as ready for review December 9, 2024 22:12
@overlookmotel
Copy link
Contributor Author

@Dunqing Could you please take a look and make sure I'm not missing anything? I think this simplification of the code retains its original behavior, but I don't know this transform, so I might have made a mistake.

@overlookmotel overlookmotel marked this pull request as draft December 9, 2024 22:23
@overlookmotel overlookmotel marked this pull request as ready for review December 9, 2024 22:28
@overlookmotel
Copy link
Contributor Author

overlookmotel commented Dec 9, 2024

There is one thing I changed. Previously some MemberExpressions were created with optional: computed_expr.optional. But I've just got optional: false.

I think this is OK, because object?.prop &&= value and object?.[prop] &&= value are invalid syntax, so optional should always be false anyway. I think...

@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Dec 10, 2024
Copy link

graphite-app bot commented Dec 10, 2024

Merge activity

…Reference`s with `ReferenceId` (#7745)

Use `TransformCtx::duplicate_expression` (introduced in #7754) to decide when to create temp vars for member expression object and computed property.

This fixes a bug where `IdentifierReference`s created when transforming `key` in `object[key] &&= value` were created without a `ReferenceId` (due to `clone_in`).

We didn't catch this before because Babel's test fixtures only cover `object[key++] &&= value` not the simpler `object[key] &&= value`. Add tests for this.
Dunqing pushed a commit that referenced this pull request Dec 10, 2024
… for `super` (#7757)

`TransformCtx::duplicate_expression` method introduced in #7754 don't create a temp var for `super`. This prepares it for use in logical assignment operator transform (#7745).
@Dunqing Dunqing force-pushed the 12-09-refactor_transformer_duplicate_expression_do_not_produce_temp_var_for_super_ branch from 5e49bbd to 9c2a1b6 Compare December 10, 2024 02:30
@Dunqing Dunqing requested a review from Boshen as a code owner December 10, 2024 02:30
@Dunqing Dunqing force-pushed the 12-09-test_transformer_logic-assignment-operator_add_more_tests branch from 3b141c6 to e48769a Compare December 10, 2024 02:31
Dunqing pushed a commit that referenced this pull request Dec 10, 2024
`TraverseCtx::is_static` was only used in logical assignment operators transform, and #7745 removed that usage. So remove this method. `TransformCtx::duplicate_expression` fulfills the same role.
Base automatically changed from 12-09-refactor_transformer_duplicate_expression_do_not_produce_temp_var_for_super_ to main December 10, 2024 02:53
@graphite-app graphite-app bot merged commit e48769a into main Dec 10, 2024
29 checks passed
@graphite-app graphite-app bot deleted the 12-09-test_transformer_logic-assignment-operator_add_more_tests branch December 10, 2024 02:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0-merge Merge with Graphite Merge Queue A-transformer Area - Transformer / Transpiler C-bug Category - Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants