squint icon indicating copy to clipboard operation
squint copied to clipboard

Unchecked set + multiarity function is broken

Open lilactown opened this issue 2 years ago • 1 comments

(unchecked-set js/global "foo" (fn ([]) ([a])))

Expected result: It outputs valid JS

Actual result: Fails with the following message

(global["foo"] = let f1 = function (var_args) {
                 ^^^

SyntaxError: Unexpected strict mode reserved word
    at ESMLoader.moduleStrategy (node:internal/modules/esm/translators:119:18)
    at ESMLoader.moduleProvider (node:internal/modules/esm/loader:483:14)
    at async link (node:internal/modules/esm/module_job:67:21)

lilactown avatar Aug 23 '22 06:08 lilactown

You can work around this for now by binding the function in a let:

(let [x (fn ...)] x)

borkdude avatar Aug 23 '22 08:08 borkdude

Seems to work now:

$ ./node_cli.js -e '(unchecked-set js/global "foo" (fn ([]) ([a] a))) (prn (foo 1))'
1

borkdude avatar Dec 16 '23 15:12 borkdude