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

helper set is incorrectly renamed when it needs protection #9663

Closed
unbyte opened this issue Oct 21, 2024 · 1 comment · Fixed by #9666
Closed

helper set is incorrectly renamed when it needs protection #9663

unbyte opened this issue Oct 21, 2024 · 1 comment · Fixed by #9666
Assignees
Labels
Milestone

Comments

@unbyte
Copy link
Contributor

unbyte commented Oct 21, 2024

Describe the bug

The set function reassigns itself internally.
When eval exists within the scope, the set function's name should be protected, but it's incorrectly renamed to set1, causing the helpers to fail to execute properly.

It was introduced by #9546

Input code

class A {
	world = false
}

eval("hello")

class B extends A {
	constructor() {
		super()
	}

	set hello(v) {
		super.world = v
	}

	get hello() {
		return super.world
	}
}

Config

No response

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.7.37-nightly-20241021.1&code=H4sIAAAAAAAAA03NPQ6DMAwF4Dk%2BhcUUlt6Aob1JFFwYrKSynYBUcffyUxCbZX%2FvOXJQxSd%2BwU1ZuMcO34GVYAGgGtg3IzHnpgWIO30hzUap%2F4diTmpSomXx7bZwWj60zuDWBqdkuBf4ers%2Bzlf1UMOlDiRkRRLe7OaWH0dO9hOsAAAA&config=H4sIAAAAAAAAA12PSw6DMAxE95wCed1tNz1BNz2ElRoU5HxkBwmEuHsDJLRll3ljjydL07YwqIFHu%2BRnFhFFSU6dic4%2B4ZQJkHGoRmxMcKvuoJvVISvtaD0cSIJeuyAuu35krhilp7SH6b2kAIegVFMKoymReOQncSTRi%2Bust93829Kh7%2FkSkrEJLgqp%2FndsSk9w4T3uW%2BX3aY6b2tZc8IPCOWn1VWfPC98aR%2Fb6AXANGa1PAQAA

SWC Info output

No response

Expected behavior

keep name set

Actual behavior

set is renamed to set1 while usages are still set

function set1(target, property, value, receiver) {
    if (typeof Reflect !== "undefined" && Reflect.set) {
        set1 = Reflect.set;
    } else {
        set1 = function set1(target, property, value, receiver) {
            var base = _super_prop_base(target, property);
            var desc;
            if (base) {
                desc = Object.getOwnPropertyDescriptor(base, property);
                if (desc.set) {
                    desc.set.call(receiver, value);
                    return true;
                } else if (!desc.writable) {
                    return false;
                }
            }
            desc = Object.getOwnPropertyDescriptor(receiver, property);
            if (desc) {
                if (!desc.writable) {
                    return false;
                }
                desc.value = value;
                Object.defineProperty(receiver, property, desc);
            } else {
                _define_property(receiver, property, value);
            }
            return true;
        };
    }
    return set1(target, property, value, receiver);
}
function _set(target, property, value, receiver, isStrict) {
    var s = set(target, property, value, receiver || target);
    if (!s && isStrict) {
        throw new Error("failed to set property");
    }
    return value;
}

Version

1.7.36

Additional context

No response

@unbyte unbyte added the C-bug label Oct 21, 2024
@kdy1 kdy1 self-assigned this Oct 22, 2024
@kdy1 kdy1 added this to the Planned milestone Oct 22, 2024
kdy1 pushed a commit that referenced this issue Oct 22, 2024
**Description:**

Check `preserved` in normal renaming mode

**Related issue:**

 - Closes #9663
@kdy1 kdy1 modified the milestones: Planned, 1.7.38 Oct 26, 2024
@swc-bot
Copy link
Collaborator

swc-bot commented Nov 25, 2024

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 Nov 25, 2024
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