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

Deno bundle error with constructor property initialisation #9773

Closed
c4spar opened this issue Mar 12, 2021 · 2 comments · Fixed by #9774
Closed

Deno bundle error with constructor property initialisation #9773

c4spar opened this issue Mar 12, 2021 · 2 comments · Fixed by #9774

Comments

@c4spar
Copy link

c4spar commented Mar 12, 2021

Following example works with deno run but fails after bundling it with deno bundle.

Example code:

export class Foo {
  bar = this.options.bar;
  constructor(
    protected options: { bar: string },
  ) {}
}

console.log(
  new Foo({ bar: "baz" }),
);

Bundled code:

class Foo1 {
    bar = this.options.bar;
    constructor(options){
        this.options = options;
    }
}
console.log(new Foo1({
    bar: "baz"
}));
export { Foo1 as Foo };

Error message:

error: Uncaught TypeError: Cannot read property 'bar' of undefined
    bar = this.options.bar;
                       ^
    at Foo1.<instance_members_initializer> (file:///bundle.js:2:24)
    at new Foo1 (file:///bundle.js:3:16)
    at file:///bundle.js:7:13

Version:

deno 1.8.1 (release, x86_64-apple-darwin)
v8 9.0.257.3
typescript 4.2.2
@nayeemrmn
Copy link
Collaborator

This was fixed in swc-project/swc#930. We need to add a typescript_class_properties pass for it, but there were bugs/complications: swc-project/swc#987.

@nayeemrmn
Copy link
Collaborator

Actually, we ultimately decided to have "useDefineForClassFields": true in our internal tsconfig (#7148 (comment)), so tsc (the unbundled behaviour) would match the current behaviour of swc and we would consolidate like that instead.

It seems we added "useDefineForClassFields" on the sly to the list of ignored compiler options in #7228 and documented it in #9196... but grepping through the code base I don't see anywhere it's actually set to true 😅

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

Successfully merging a pull request may close this issue.

2 participants