Use a new shim approach for browser build, enabling Node imports to be at top level
comptime require no longer needs Civet to be in async mode! Async mode is just necessary for promises made by the user, so this is more natural.
Run comptime using vm in Node, just like repl (used by CLI). Still use eval on browser.
This isolates global variables.
Currently a bit painful to serialize... I might be missing something simpler here, but at least it seems to be working.
Improve comptime errors and imports a bit
Switching to vm actually makes dynamic import work too, on Node 21.7+. But it generates a warning, so I haven't added a test. Here's a demo:
$ civet -c --comptime (node-shim ?$)
Civet 0.7.5 REPL. Enter a blank line to transpile code.
š> x = comptime
... import { readFile } from 'fs/promises'
... JSON.parse(await readFile 'package.json').version
...
(node:33596) ExperimentalWarning: vm.USE_MAIN_CONTEXT_DEFAULT_LOADER is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
x = "0.7.5"
š>
import
s to be at top levelcomptime require
no longer needs Civet to be in async mode! Async mode is just necessary for promises made by the user, so this is more natural.vm
in Node, just likerepl
(used by CLI). Still useeval
on browser.Switching to
vm
actually makes dynamicimport
work too, on Node 21.7+. But it generates a warning, so I haven't added a test. Here's a demo: