runem / lit-analyzer

Monorepository for tools that analyze lit-html templates
MIT License
318 stars 36 forks source link

@openwc/scoped-elements support #152

Open mckamyk opened 3 years ago

mckamyk commented 3 years ago

It appears that elements that are not defined with customElement(...), but rather static get scopedElements() {...} via the @openwc/scoped-elements package are not getting any hints in the consuming element's code.

For example, here's the child element:

// SKIPPING @customElement('child-element') in favor of using it as a scoped element.
export default class ChildElement extends LitElement {
  @property({type: String}) text = '';
  render() { 
    return html`<h1>${this.text}</h1>` 
  }  
}

And the consumer:

import {ScopedElementsMixin} from '@openwc/scoped-elements';
// import './childElement.ts' // NOT doing this in favor of scoped elements.
import ChildElement from './childElement.ts';

export default class ParentElement extends ScopedElementsMixin(LitElement) {
  static get scopedElements() {
    return {
      'child-element': ChildElement,
    }
  }

  render() {
    return html`
      <child-element text="hello"></child-element'> // 
    ` // ^^ this doesn't have any hinting whatsoever, unless I define it with customElement
  }
}

It is worth noting, that if I simply add the @customElement('child-element') decorator before the child's class declaration, the hinting works correctly.

Is there a way we can get the plugin to look for the values in the static get scopedElements() {...} ?