Skip to content

Mobx computed decorator not support decorators stage 2 proposal #2744

Closed
@WUSO01

Description

Using babel7 and mobx6, Babel's config:

  "plugins": [
    ["@babel/plugin-proposal-decorators", {
        "decoratorsBeforeExport": true
    }],
    ["@babel/plugin-proposal-class-properties", {
        "loose": true
    }]
  ]

Mini demo:

import { customElement, html } from 'lit-element'
import { MobxLitElement } from '@adobe/lit-mobx'
import { observable, action, computed } from 'mobx'

class Counter {
  @observable
  public count = 1

  @computed
  get doubleCount () {
    return this.count * 2
  }

  @action
  public increment() {
    this.count++
  }
}

const counter = new Counter()

@customElement('custom-container')
class CustomContainer extends MobxLitElement {
  private store = counter

  public render() {
    return html`
      <p>Count is: ${this.store.count}</p>
      <p>MaxCount is: ${this.store.doubleCount}</p>
    `
  }
}

Intended outcome:

The count should be equal 1, doubleCount equal 2

Actual outcome:

Got error:
error

If i remove computed decorator' s code, or don't remove computed, change decoratorsBeforeExport to legacy, This error won't be show again.

Why I just don't change decoratorsBeforeExport to legacy, Because use legacy will cause another problem.

How to reproduce the issue:

I putted this demo on Github branch "mobx"

Versions
mobx: V6.0.4

babel: V7

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions