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): optional-catch-binding unused variable side effect #2822

Conversation

rzvxa
Copy link
Collaborator

@rzvxa rzvxa commented Mar 26, 2024

Before this PR for this given case:

const _unused = "It's a lie, They gonna use me:(";
try {
    throw 0;
} catch {
  console.log(_unused);
}

We would've generated this:

const _unused = "It's a lie, They gonna use me:(";
try {
    throw 0;
} catch (_unused) {
  console.log(_unused);
}

This is incorrect, This PR aims to use the CreateVars trait in order to ensure the variable uniqueness.

Now it would output this:

const _unused = "It's a lie, They gonna use me:(";
try {
    throw 0;
} catch (_unused2) {
  console.log(_unused);
}

@github-actions github-actions bot added the A-transformer Area - Transformer / Transpiler label Mar 26, 2024
Copy link
Collaborator Author

rzvxa commented Mar 26, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @rzvxa and the rest of your teammates on Graphite Graphite

Copy link

codspeed-hq bot commented Mar 26, 2024

CodSpeed Performance Report

Merging #2822 will not alter performance

Comparing 03-26-fix_transformer_fix_optional-catch-binding_unsued_variable_side_effect (8afa459) with main (8c6936a)

Summary

✅ 34 untouched benchmarks

@rzvxa rzvxa changed the title fix(transformer): fix optional-catch-binding unsued variable side effect. fix(transformer): fix optional-catch-binding unused variable side effect Mar 26, 2024
@rzvxa rzvxa requested a review from Boshen March 26, 2024 11:37
@rzvxa rzvxa marked this pull request as ready for review March 26, 2024 11:44
@rzvxa rzvxa changed the title fix(transformer): fix optional-catch-binding unused variable side effect fix(transformer): optional-catch-binding unused variable side effect Mar 26, 2024
…fix_transformer_fix_optional-catch-binding_unsued_variable_side_effect
@Dunqing
Copy link
Member

Dunqing commented Mar 27, 2024

There are no snapshots updated?

@rzvxa
Copy link
Collaborator Author

rzvxa commented Mar 27, 2024

There are no snapshots updated?

No the tests on eslint don't consider this so it was passing anyway.

@rzvxa
Copy link
Collaborator Author

rzvxa commented Mar 27, 2024

@Dunqing I can add the appropriate tests to the eslint if you find it relative to oxc.

@Dunqing
Copy link
Member

Dunqing commented Mar 27, 2024

@Dunqing I can add the appropriate tests to the eslint if you find it relative to oxc.

I prefer to add the test here. But this is babel repo 😅 https://github.com/babel/babel/blob/f856fc22d05bf886d1a58c5c91490e1af8f90c44/packages/babel-plugin-transform-optional-catch-binding/test/fixtures/optional-catch-bindings

@rzvxa
Copy link
Collaborator Author

rzvxa commented Mar 27, 2024

I prefer to add the test here. But this is babel repo 😅 https://github.com/babel/babel/blob/f856fc22d05bf886d1a58c5c91490e1af8f90c44/packages/babel-plugin-transform-optional-catch-binding/test/fixtures/optional-catch-bindings

I agree, We may want to add our set of unit tests on top of esbuild compatibility checks. However, I would add a try-catch-shadow case there when I get the time. Even if we don't rely on it, It would be net positive.

@Boshen Boshen merged commit 528744c into main Mar 27, 2024
32 checks passed
@Boshen Boshen deleted the 03-26-fix_transformer_fix_optional-catch-binding_unsued_variable_side_effect branch March 27, 2024 05:53
Boshen pushed a commit that referenced this pull request Mar 27, 2024
…ses (#2835)

Related to:
#2822 (comment)

Although `babel` has a lot of test cases, we still need to add edge
cases that `babel` doesn't have.

This PR will allow us to add out test cases to
`/root/oxc/tasks/transform_conformance/tests`. The directory structure
is consistent with `babel`

For example
```shell
# cd /root/oxc/tasks/transform_conformance/tests
- babel-transform-plugin–optional-catch-binding
   - test
       - fixtures
           - your tests # add test cases here
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-transformer Area - Transformer / Transpiler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants