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

Decorators: Invalid or unexpected token #3

Open
trusktr opened this issue Sep 24, 2024 · 1 comment
Open

Decorators: Invalid or unexpected token #3

trusktr opened this issue Sep 24, 2024 · 1 comment

Comments

@trusktr
Copy link

trusktr commented Sep 24, 2024

For example, try pasting this in:

import {reactive, signal} from 'classy-solid'
import {createEffect, batch} from 'solid-js'

@reactive
class MyClass {
  @signal foo = 1
  @signal bar = 2
}

const o = new MyClass()

createEffect(() => {
  console.log(o.foo, o.bar) // initially logs "1 2"
})

batch(() => {
  o.foo++
  o.bar++
})
// logs "2 3"
@bigmistqke
Copy link
Owner

The current demo has

babelTransform({
  plugins: [['proposal-decorators', { version: '2023-11' }]],
  presets: ['[email protected]'],
})

as its babel-transform configuration.
With this applied the following code works as expected:

import {reactive, signal} from 'classy-solid'
import {createEffect, batch} from '[email protected]'

@reactive
class MyClass {
  @signal foo = 1
  @signal bar = 2
}

const o = new MyClass()

createEffect(() => {
  console.log(o.foo, o.bar) // initially logs "1 2"
})

batch(() => {
  o.foo++
  o.bar++
})
// logs "2 3"

Notice that I currently had to hard set both babel-preset-solid and solid-js to 1.8.22, otherwise the decorators got compiled but it wasn't reactive, possibly due to a version mismatch? The latest version of babel-preset-solid also causes issues when importing from esm.sh, but that is a separate issue.

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

2 participants