Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

311
Visualizações
Call `super` on JavaScript instance method

I'm attempting to call super on an instance method of an ES6 style class, and I'm getting parcel/babel build errors.

@parcel/transformer-babel: 'super' is only allowed in object methods and classes. (1291:21)

My code effectively looks like this

class BaseClass {
    constructor(params) {
        this.params = params;
    }

    matches(other) {
        // do some matching logic
        return true; // or false
    }
}

class MyClass extends BaseClass {
    matches(other) {
        let match = super.matches(other);
        // do some additional matching logic
        return true; // or false
    }

}

The error is when I call super.matches(other) in MyClass.

All the documentation I can find on super talks about its use in constructor, which is fine, and its use in static methods, but I have found no mention of instance methods.

Does this just not work in JS, am I doing it wrong, or is it something to do with the babel transformer or parcel?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Parcel v2 supports transpiling es6 class syntax by default using swc. One "gotcha" is that if it detects a .babelrc/babel.config.json file in your project, it will switch to transpiling using babel, and then it is up to you to make sure that the config you provided will transpile classes.

According to the docs:

if you're only using @babel/preset-env, @babel/preset-typescript, and @babel/preset-react, Babel may no longer be necessary. Parcel supports all of these features automatically without a Babel config, and Parcel's default transpiler is much faster than Babel.

So the first thing I would try is just deleting any .babelrc/babel.config.json files in your project so you can try it out with swc. If that doesn't work (maybe because you're doing something else that swc doesn't support), make sure that @babel/preset-env is included in your babel config.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda