$ 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)
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
What is the expected behavior?
I expect the code to run and print out a
1
.What do you see instead?
I see the following error.
Additional information
https://github.com/proposal-signals/signal-polyfill/tree/main