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

Optional chaining with function call is wrongly compiled #2734

Closed
Austaras opened this issue Nov 12, 2021 · 1 comment · Fixed by #2611
Closed

Optional chaining with function call is wrongly compiled #2734

Austaras opened this issue Nov 12, 2021 · 1 comment · Fixed by #2611
Labels
Milestone

Comments

@Austaras
Copy link
Member

Austaras commented Nov 12, 2021

Describe the bug

swc generate an extra reference and call the function with it

Input code

const foo = {
    get() {
        return function () {
            console.log(111, this)
        }
    }
}

foo.get()?.()

Config

{}

Playground link

https://play.swc.rs/?version=1.2.106&code=H4sIAAAAAAAAA0vOzysuUUjLz1ewVajmUgCC9NQSDU0oGwSKUktKi%2FIU0krzkksy8%2FMUUCRBIBloRH5Oql5OfrqGoaGhjkJJRmaxJlxJLReErOXiAlqjBzbeXk9DEwA7uCM%2FegAAAA%3D%3D&config=H4sIAAAAAAAAA0WNSwrDMAxE76J1ts0id%2BghjKsEF%2F%2FQKBBjfPfawSU7aebpqdIXlrZK2QhYxoQS1Vy0kZbMsOKy0kKKHu3Gg1tfjBysHWG8eudTAs92oeCi28sw2RSyMPBUJh7%2BT7YuCulzjqDez27hSu1xzDuH9wRVTm4%2FOkwQUrUAAAA%3D

Expected behavior

should log 111 Window

Version

latest

Additional context

No response

@Austaras Austaras added the C-bug label Nov 12, 2021
@kdy1 kdy1 added this to the v1.2.109 milestone Nov 13, 2021
kdy1 pushed a commit that referenced this issue Nov 15, 2021
swc_ecma_transforms_compat:
- `computed_properties`: Add loose mode.
- `template_literals`: Add loose mode.
- `object_spread`: Add loose mode.
- `optional_chaining`: Add loose mode.
- `nullish_coalescing`: Add loose mode.
- `optional_chaining`: Fix #2734.
@swc-bot
Copy link
Collaborator

swc-bot commented Oct 21, 2022

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 Oct 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

3 participants