Skip to content

reactive in coffeescript not work #491

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

Closed
gcxfd opened this issue Mar 24, 2022 · 3 comments
Closed

reactive in coffeescript not work #491

gcxfd opened this issue Mar 24, 2022 · 3 comments

Comments

@gcxfd
Copy link

gcxfd commented Mar 24, 2022

$: y = x * 2 not work

<script lang="coffee">
import '~/styl/init.styl'
import logo from ':/svg/logo.svg'
import Counter from './lib/Counter.svelte'

x = 1

$: y = x * 2

click = =>
  ++x
  return
</script>

<template lang="pug">
main
  img(src="{logo}" alt="logo")
  button(on:click="{click}")
    +if('x%2') if x%2
      +else() else
  h2 x {x} y {y}
  Counter
</template>

<style lang="stylus">
button
  width 8rem
  font-size 32px

main
  justify-content center
  align-items center
  flex-direction column
  display flex

img
  height 16rem
  width 16rem
</style>
@mrkishi
Copy link
Member

mrkishi commented Mar 24, 2022

Some info after light digging: Coffeescript seems to compile "labels" into object expressions.

This seems unlikely to be fixable on this end as there are no compiler options to change that behavior.

@Conduitry
Copy link
Member

Searching online for "svelte coffeescript", I just found https://github.com/Leftium/svelte-coffeescript-pug/blob/master/src/App.svelte which has a possible syntax for that will compile into the JS that Svelte needs for reactive blocks. It looks like it involves jumping out to JS syntax within CoffeeScript.

In short, I would not at all recommend writing Svelte components with CoffeeScript.

I'm going to close this issue, as this is functioning as (unfortunately) designed.

@gcxfd
Copy link
Author

gcxfd commented Mar 25, 2022

@mrkishi @Conduitry

I wrote a patch https://github.com/rmw-lib/coffee-label-patch make coffeescript support label

I create pull request there #493

it work , i release a preview in @rmw/svelte-preprocess

yarn add -D @rmw/svelte-preprocess @rmw/coffee-label-patch

demo video
https://www.loom.com/share/a45ffe7eeecb4115ad335b7db21f9b04?from_recorder=1&focus_title=1

the code for demo video https://github.com/rmw-lib/svelte-pug-stylus-coffee

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

3 participants