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

calls to tslib __setFunctionName fail on Cobalt 9 #214

Open
sjamesr opened this issue Jul 14, 2023 · 5 comments
Open

calls to tslib __setFunctionName fail on Cobalt 9 #214

sjamesr opened this issue Jul 14, 2023 · 5 comments

Comments

@sjamesr
Copy link

sjamesr commented Jul 14, 2023

We've observed new behavior after upgrading our code to TypeScript 5.0. Specifically, TS5.0 emits calls to a new tslib helper function __setFunctionName. This in turn calls Object.defineProperty(x, "name", ...) on the class, which seems to fail on Cobalt 9:

          TypeError: can't redefine non-configurable property 'name' in [object HTMLScriptElement] (line 76)

We're not sure whether this is an issue with tslib, TS5.0 or with the calling code (in our case I think it's a Jasmine test). I'd be grateful for any guidance the tslib team could provide.

@jakebailey
Copy link
Member

It'd be an issue in both; this library is just the same helpers that TS emits but pulled out for common reuse.

@rbuckton

@rbuckton
Copy link
Member

Looking closer at the error in question, it seems like it's trying to set the name property of HTMLScriptElement. Can you provide an example of the emit where this error is produced? If this is somehow a reference to the existing DOM HTMLScriptElement constructor, there's no reason we should be setting a name for it, so it would be helpful to see how things got into that state.

@sjamesr
Copy link
Author

sjamesr commented Jul 24, 2023

In a TS file, we have:

function foo() {
  const clazz = class {static bar = true;}
}

The output I get from tsc is:

function foo() {
    var _a;
    const clazz = (_a = class {
        },
        __setFunctionName(_a, "clazz"),
        _a.bar = true,
        _a);
}

I think this snippet should fail on Cobalt 9 (it emits the problematic __setFunctionName call), but I haven't tried it.

@rbuckton
Copy link
Member

Per my comment earlier, I'm not sure the issue is __setFunctionName specifically, but how it is somehow being applied to an HTMLScriptElement per the TypeError in the issue description. Somehow __setFunctionName is being applied to the wrong thing in your project.

@mhausner
Copy link

mhausner commented Jul 31, 2023

We can no longer reproduce this failure. Please feel free to close the issue.

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

4 participants