lit / lit-element

LEGACY REPO. This repository is for maintenance of the legacy LitElement library. The LitElement base class is now part of the Lit library, which is developed in the lit monorepo.
https://lit-element.polymer-project.org
BSD 3-Clause "New" or "Revised" License
4.49k stars 318 forks source link

fix babel proposal-decorators use legacy the query decorator return undefined #1138

Open WUSO01 opened 3 years ago

WUSO01 commented 3 years ago

Fixes #1121

I Write lit-element like this:

@customElement('custom-div')
export class CustomDiv extends LitElement {
  @query('#btn') btn: HTMLButtonElement

  // ....
}

And I also used babel(v7) and webpack(v4), I set @babel/plugin-proposal-decorators legacy was true

babel.config.json:

{
  "presets": [
    "@babel/env",
    "@babel/preset-typescript"
  ],
  "plugins": [
    [
      "@babel/plugin-proposal-decorators", {
        "legacy": true
      }
    ],
    [
      "@babel/plugin-proposal-class-properties"
    ]
  ]
}

When I builded i got an error: this.btn is undefined. If you change legacy todecoratorsBeforeExport, this issue won't be show.

I founded the issue cased by legacyQuery function didn't use 'return' Statement.

WUSO01 commented 3 years ago

Legacy mode will cause other problems, eg: updated lifecycle changedProperties always empty Map