You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ReferenceError: Must call super constructor in derived class before accessing 'this' or returning from derived constructor #3559
I expect for super() calls and this accesses to be the same in the compiled code as in the source code
Actual
My super() calls come after my accesses to this in version 0.19.10, but not earlier.
Details
I'm doing the migration from 0.19.9 -> 0.19.10, and I think there may have been a regression in the behavior of super() that may have been introduced by #3538. In particular, I have this constructor that starts with a call to super(). In 0.19.9, this block is being compiled as follows:
constructor(){super();// A hash from the attribute name to its corresponding reactive and parserthis.#props ={};// A hash from the render state key to its corresponding reactive (returned from the setup method)this.#renderState =/* @__PURE__ */newMap();// The render method from the component definitionthis.#render =passedRender;// The css string or function from the component definitionthis.#css =css;// The template string from the component definitionthis.#template =template;// Whether or not the component is currently connected to the domthis.#isConnected =false;// All of the contexts to connect to// https://github.com/webcomponents-cg/community-protocols/blob/main/proposals/context.mdthis.#contexts =/* @__PURE__ */newMap();
but in 0.19.10, I am getting the super call after the accesses to this:
constructor() {
// A hash from the attribute name to its corresponding reactive and parser
this.#props = {};
// A hash from the render state key to its corresponding reactive (returned from the setup method)
this.#renderState = /* @__PURE__ */ new Map();
// The render method from the component definition
this.#render = passedRender;
// The css string or function from the component definition
this.#css = css;
// The template string from the component definition
this.#template = template;
// Whether or not the component is currently connected to the dom
this.#isConnected = false;
// All of the contexts to connect to
// https://github.com/webcomponents-cg/community-protocols/blob/main/proposals/context.md
this.#contexts = /* @__PURE__ */ new Map();
super();
It looks like this is happening when TypeScript's useDefineForClassFields setting is false and all class fields lack initializers. In this case the trigger is the contextState: any; class field declaration. Changing that to contextState: any = undefined; no longer triggers the bug.
Activity
evanw commentedon Dec 20, 2023
It looks like this is happening when TypeScript's
useDefineForClassFieldssetting isfalseand all class fields lack initializers. In this case the trigger is thecontextState: any;class field declaration. Changing that tocontextState: any = undefined;no longer triggers the bug.doug-wade commentedon Jan 1, 2024
Thanks @evanw! That worked like a charm -- thanks for the quick and effective response.
fix evanw#3559: fix recent class transform regression