Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 of 3 tasks
DavideMininni-Fincons opened this issue Nov 7, 2024 · 0 comments
Open
2 of 3 tasks

Comments

@DavideMininni-Fincons
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant