Skip to content

this inside jsx-template inside a constructor of a derived class causes transformation-bug #2141

Description

@bigmistqke

Describe the bug

When a template is written inside the constructor of a derived class and this is accessed inside the template, the following error is thrown: Uncaught ReferenceError: Must call super constructor in derived class before accessing 'this' or returning from derived constructor.

The following code

abstract class Root {
}

class Derived extends Root {
  constructor() {
    super();
    <div>{this.test}</div>;
  }
}

new Derived();

will become

import { template as _$template } from "solid-js/web";
import { insert as _$insert } from "solid-js/web";
var _tmpl$ = /*#__PURE__*/_$template(`<div>`);
class Root {}
class Derived extends Root {
  constructor() {
    const _self$ = this;
    super();
    (() => {
      var _el$ = _tmpl$();
      _$insert(_el$, () => _self$.test);
      return _el$;
    })();
  }
}
new Derived();

const _self$ = this; should be set after super() when the class is extended.

Your Example Website or App

https://playground.solidjs.com/anonymous/51a44967-beca-46ba-9332-a9cfa8d81c5d

Steps to Reproduce the Bug or Issue

  1. open link
  2. look at error in console
  3. look at transformed output

Expected behavior

using jsx-template inside a class-constructor to not cause issues.

Screenshots or Videos

No response

Platform

  • OS: [e.g. macOS, Windows, Linux]
  • Browser: [e.g. Chrome, Safari, Firefox]
  • Version: [e.g. 91.1]

Additional context

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions