Skip to content

Operator "in" shouldn't be removed #11246

@Themezv

Description

@Themezv

Describe the bug

The in operator triggers the has trap when used with a Proxy. Because of this, it must not be removed or replaced during minification, as doing so can change the program’s behavior.

Input code

const TRACK_MEMO_SYMBOL = Symbol();

const obj = new Proxy({}, {
    has: (target, p) => {
        if(p === TRACK_MEMO_SYMBOL) {
            console.log('sideEffect')
        }
        return target[p]
    }
})

TRACK_MEMO_SYMBOL in obj;

Config

Link to the code that reproduces this issue

https://play.swc.rs/?version=1.15.0&code=H4sIAAAAAAAAA0vOzysuUQgJcnT2jvd19fWPD470dfL3UbBVCK7MTcrP0dC05uJKBivKT8oCCuellisEFOVXVGpU1%2BooVHMpAEFGYrGVgkZJYlF6aomOQoGmgq0dVAYEMtM0ChRsbW0xbdFEUgUCIHvyc1L1cvLTNdSLM1NSXdPSUpNL1DXhqmrhrKLUktKiPAWIpdEFsVwQ6VpNLi5M32TmgVxvzQUAKX5Q6u4AAAA%3D&config=H4sIAAAAAAAAA31Vu3LjMAzs%2FRUe1dekuCuuvslMivsGDi2CMnIUqSFAx5qM%2F%2F1APWzHgdxZWCxAvNafu%2F2%2Beae2%2Bb3%2FlJ%2FyMdhMkK%2FfYqExsj2LpeFxAGozDtz8WFGmCnkbCCbTZUYatrkDriygn4t7E1IiWN0XW48R%2FXifsE39kIHoziZWiVd6iExf%2BQuW00cFOJd7%2ByGlADY%2BQYwlg5Ghg6wFblMIdiAwJ5uVKPWlNiMlLUUFC4MzQ06DikeHjClKTiW1A%2BtMmxxoGGZoGU%2BghHWSTXiRpECNWmEHh9J105gf2HCyoVgGBTlPQ5H3KlGPCYmNL1GrZAY3ujCDS3sfmehNBi45fue9J4wbU%2FkHIB0IlijaHrS4k4eXjdpi%2B6dMjF6WlkcFlw3XqozQSVMNolc6WzsDmVGbZgZXWqidbbXnLPBG%2BwgdGPBedkUJTR%2FI7VFLWu88eQWQ%2BVqvbdUMmOsdbuD1JJ7Ar1Il6wu2ePSWj9sojf0hqce00oGPyT1xkFFw2oaz6MR52MZLdCCrAU51KaQC9VbZcDJh0stvyyH3ISFNF9JhVopHD1n0aYovL4vxclXn3sbuJgNfBFoKgYxVUW24V1%2Fokd9EPGRf3Z%2Bb2s7c3cJv%2BuTKFHj526grM4v9r%2BbmtEr7teQG6e%2FKrGXsLv8ByFij44IGAAA%3D

SWC Info output

No response

Expected behavior

Expression shouldn't be removed

Actual behavior

expression TRACK_MEMO_SYMBOL in obj; removed

No response

Version

1.3.5, 1.15.0

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions