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

Inconsistent variable naming #6602

Closed
0x0blu opened this issue Dec 8, 2022 · 4 comments
Closed

Inconsistent variable naming #6602

0x0blu opened this issue Dec 8, 2022 · 4 comments
Labels

Comments

@0x0blu
Copy link

0x0blu commented Dec 8, 2022

Describe the bug

SWC generates wrong variable names if it collides with object type definition key.

In the image you can see that it transpiles event to event1 everywhere except in the last line, which of course throws an error.

Screenshot 2022-12-08 at 17 53 45

Input code

import type X from './types';

const event = {};

setTimeout(() => {
  console.log(event)

  const actions: { [event in string]?: void } = {};

  console.log(event)
}, 1000);

Config

No response

Playground link

https://play.swc.rs/?version=1.3.21&code=H4sIAAAAAAAAA22MywrCMBBF9%2FmKu2sCUuO2pfoTLgRxIXUsgSZTkrEgIf9u62Pn7t7D4Tg%2FcRTIcyKccI%2FsUdXb9aaqVarnkAQ0UxB0yGVBieToPPFDtDbo9sgKWD0eqR550G%2FbqC8VXHtxy2iQcf6UXECS6MJwOTSY2d1QfvW%2FqbLBzlprWvUCa1ejba8AAAA%3D&config=H4sIAAAAAAAAA0WNSwrDMAxE76J1FsWLLnKHHsK4SnDxD40CDcZ3rx1cspNmnp4qfeBorVSsgGVMOJPaL62kZ2E48UVpIUWPNhvArS9WdtaOMMzDmF6HnMETWCj65LdzyFyORRi4K5v28Cdbd8X8PkZQr3%2BX80ntdsw7j9cEVQ5uPx%2Bqcl%2B4AAAA

Expected behavior

Variable name to be consistent across its lifetime.

Actual behavior

No response

Version

1.3.21

Additional context

No response

@0x0blu 0x0blu added the C-bug label Dec 8, 2022
@hyf0
Copy link
Contributor

hyf0 commented Dec 8, 2022

I guess it's the same problem as #6533, which was fixed in #6597. You might need to wait for the next version of swc.

@hyf0
Copy link
Contributor

hyf0 commented Dec 9, 2022

You would see the problem solved in 1.3.22

@0x0blu
Copy link
Author

0x0blu commented Dec 9, 2022

Super. Really appreciate the speedy response.

@0x0blu 0x0blu closed this as completed Dec 9, 2022
@swc-bot
Copy link
Collaborator

swc-bot commented Jan 8, 2023

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Jan 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

3 participants