oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.7k stars 2.72k forks source link

Signals Polyfill Typescript Decorator not Working #14529

Open 81reap opened 2 hours ago

81reap commented 2 hours ago

What version of Bun is running?

1.1.30+7996d06b8

What platform is your computer?

Darwin 23.6.0 arm64 arm

What steps can reproduce the bug?

I am unable to run the

$ bun init
$ bun add signal-polyfill
$ cat index.ts
import { Signal } from "signal-polyfill";

export function signal(target) {
  const { get } = target;

  return {
    get() {
      return get.call(this).get();
    },

    set(value) {
      get.call(this).set(value);
    },

    init(value) {
      return new Signal.State(value);
    },
  };
}

export class Counter {
  @signal accessor #value = 0;

  get value() {
    return this.#value;
  }

  increment() {
    this.#value++;
  }

  decrement() {
    if (this.#value > 0) {
      this.#value--;
    }
  }
}

const c = new Counter();
c.increment();
console.log(c.value);
$ bun run index.ts
22 |   @signal accessor #value = 0;
                        ^
error: Expected ";" but found "#value"
    at /Users/prayagbhakar/Desktop/.wksp/markdown-parser/idfk/pound/signals-decorator.ts:22:20

22 |   @signal accessor #value = 0;
                               ^
error: Expected identifier but found "="
    at /Users/prayagbhakar/Desktop/.wksp/markdown-parser/idfk/pound/signals-decorator.ts:22:27

Bun v1.1.30 (macOS arm64)

What is the expected behavior?

I expect the code to run and print out a 1.

$ deno init
$ cat main.ts
import { Signal } from "npm:signal-polyfill";

export function signal(target) {
  const { get } = target;

  return {
    get() {
      return get.call(this).get();
    },

    set(value) {
      get.call(this).set(value);
    },

    init(value) {
      return new Signal.State(value);
    },
  };
}

export class Counter {
  @signal accessor #value = 0;

  get value() {
    return this.#value;
  }

  increment() {
    this.#value++;
  }

  decrement() {
    if (this.#value > 0) {
      this.#value--;
    }
  }
}

const c = new Counter();
c.increment();
console.log(c.value);
$ deno run main.ts
1

What do you see instead?

I see the following error.

$ bun run index.ts
22 |   @signal accessor #value = 0;
                        ^
error: Expected ";" but found "#value"
    at /Users/prayagbhakar/Desktop/.wksp/markdown-parser/idfk/pound/signals-decorator.ts:22:20

22 |   @signal accessor #value = 0;
                               ^
error: Expected identifier but found "="
    at /Users/prayagbhakar/Desktop/.wksp/markdown-parser/idfk/pound/signals-decorator.ts:22:27

Bun v1.1.30 (macOS arm64)

Additional information

https://github.com/proposal-signals/signal-polyfill/tree/main

81reap commented 2 hours ago

Not sure if types is the correct lable, but it is Typescript I think