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

Class fields instrumentation breaks name inferences #782

Open
NotWearingPants opened this issue May 9, 2024 · 0 comments
Open

Class fields instrumentation breaks name inferences #782

NotWearingPants opened this issue May 9, 2024 · 0 comments

Comments

@NotWearingPants
Copy link
Contributor

NotWearingPants commented May 9, 2024

Very similar to #59 (which is fixed).

This code behaves different when instrumented:

class Foo {
    field1 = function() {};
    ['field' + 2] = class {};
    static ['field' + 3] = function() {};
    static field4 = class {};
}
console.log(new Foo().field1);
console.log(new Foo().field2);
console.log(Foo.field3);
console.log(Foo.field4);

Normally it prints:

[Function: field1]
[class field2]
[Function: field3]
[class field4]

After instrumentation it prints:

[Function (anonymous)]
[class (anonymous)]
[Function (anonymous)]
[class (anonymous)]

The instrumented code contains:

class Foo {
    field1 = (cov_1m4qtsm9gj().s[0]++, function() { cov_1m4qtsm9gj().f[0]++; });
    ["field" + 2] = (cov_1m4qtsm9gj().s[1]++, class {});
    static ["field" + 3] = (cov_1m4qtsm9gj().s[2]++, function() { cov_1m4qtsm9gj().f[1]++; });
    static field4 = (cov_1m4qtsm9gj().s[3]++, class {});
}
cov_1m4qtsm9gj().s[4]++; console.log(new Foo().field1);
cov_1m4qtsm9gj().s[5]++; console.log(new Foo().field2);
cov_1m4qtsm9gj().s[6]++; console.log(Foo.field3);
cov_1m4qtsm9gj().s[7]++; console.log(Foo.field4);

so the function and class expressions can't infer their names.


Unlike #59 it's not clear where to hoist the counter to, maybe to a temp field above?

class Foo {
    _cov_0 = cov_1m4qtsm9gj().s[0]++; // <--
    field1 = function() { cov_1m4qtsm9gj().f[0]++; };
    _cov_1 = cov_1m4qtsm9gj().s[1]++; // <--
    ["field" + 2] = class {};
    static _cov_2 = cov_1m4qtsm9gj().s[2]++; // <--
    static ["field" + 3] = function() { cov_1m4qtsm9gj().f[1]++; };
    static _cov_3 = cov_1m4qtsm9gj().s[3]++; // <--
    static field4 = class {};
}

What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant