Skip to content

Throw error for duplicated methods, even if only the first one is decorated. #84

@nicolo-ribaudo

Description

@nicolo-ribaudo

Take a look at this Babel test:

function decorate(el) {
  el.descriptor.value.decorated = true;
  return el;
}

class A {
  @decorate
  method() {
    return 1;
  }

  method() {
    return 2;
  }
}

expect(new A().method.decorated).toBe(true);
expect(new A().method()).toBe(2);

Per the current spec, if an element is overwritten by an element with the same name, the value is replaced but the old decorators are kept.
I find it very confusing that the method passed to the decorator isthe second one and not the first one, I think it would be better to throw.

The same motivation doesn't apply to the following example example, but I think it should also throw to avoid refactoring hazards.

class A {
  method() {
    return 1;
  }

  @decorate
  method() {
    return 2;
  }
}

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