Skip to content

Super call in bound class method can't be transpiled #5104

@philippotto

Description

@philippotto

I have transform-class-properties enabled, but super calls in bound class methods do not work (webpack aborts transpilation).

Input Code

Repl

class B {
  c() {
    
  }
}

class Works extends B {
  c() {
    super.c();
  }
}

class Fails extends B {
  c = () => {
    super.c();
  }
}

Babel Configuration (.babelrc, package.json, cli command)

{
  presets: [
    ["env", {
      "targets": {
        "browsers": [
          "last 3 Chrome versions",
          "last 3 Firefox versions",
          "last 2 Edge versions",
          "last 1 Safari versions",
          "last 1 iOS versions"
        ]
      },
      "exclude": [
        "transform-regenerator"
      ]
    }],
    "react",
  ],
  plugins: [
    "transform-async-to-generator",
    "transform-class-properties",
    "transform-flow-strip-types",
  ]
}

Expected Behavior

It should transpile successfully and make the super call.

Current Behavior

Webpack aborts transpilation.

Possible Solution

As a workaround, I currently use SuperClassName.prototype.methodName.call(this); instead of super.methodName() as a work around. I think the transpiler could generate exactly the same?

Your Environment

software version
Babel 6.21.0
node 5.10.1
npm 3.8.3
Operating System Win10

Metadata

Metadata

Assignees

No one assigned

    Labels

    Spec: Class FieldsoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions