open-wc/custom-elements-manifest

bug: derived class extended from base class with mixin has incorrect properties

Opened this issue · 0 comments

Checklist

I created a MixinClass mixin with a single property named value: it has a default value (empty string) and a jsDoc.

/** Mixin jsDoc. */
public accessor value: string = '';

Then I have a base class named BaseElement which applies the mixin and overrides both the default and the jsDoc.

export abstract class BaseElement extends MixinClass(LitElement) {
    /** Base class jsDoc. */
    public override accessor value: string = 'Value';
}

Finally I have a derived class that extends the base class:

@customElement('derived-class')
export class DerivedElement extends BaseElement {
...
}

BUG
The derived class in the manifest has the value property as defined in the mixin and not as overridden in the base class.

{
  "kind": "field",
  "name": "value",
  "type": {
    "text": "string"
  },
  "privacy": "public",
  "default": "''",    <----------------- wrong
  "description": "Mixin jsDoc.",    <----------------- wrong
  "inheritedFrom": {
    "name": "BaseElement",
    "module": "src/base-class.ts"
  }
}

Expected behavior
I expect the derived class to have in the manifest the value property as in the base class and not as in the mixin.

Debugging your code (current state on main: 94650b6), the issue arise from the getInheritanceTree method in the manifest-helper.js file.
In the code block starting at line 99, the base class is pushed in the tree after its mixins, so in the applyInheritancePlugin function at line 23 the base class is the last of the chain.

When evaluating the code starting at line 52:

customElement[type] = customElement?.[type]?.map(item => item.name === existing.name
  ? {
      ...newItem,
      ...existing,
      ...{
        ...(newItem.type ? { type: newItem.type } : {}),
        ...(newItem.privacy ? { privacy: newItem.privacy } : {})
      }
    }
  : item);

existing is the mixin and newItem the base class, so the default and the jsDoc properties are wrongly overridden.