diff options
| author | 2022-05-11 00:56:35 -0700 | |
|---|---|---|
| committer | 2022-05-11 00:56:35 -0700 | |
| commit | 3c87fbfd37f36a409c704ea3f5e2701eb0126c44 (patch) | |
| tree | 0f89aa932a7a15b12cf239895194990c6d898cff /src/js_printer.zig | |
| parent | fd00950852c3f3bf49d9ce8f6a175753ad0167fd (diff) | |
| download | bun-3c87fbfd37f36a409c704ea3f5e2701eb0126c44.tar.gz bun-3c87fbfd37f36a409c704ea3f5e2701eb0126c44.tar.zst bun-3c87fbfd37f36a409c704ea3f5e2701eb0126c44.zip | |
[bun.js] Implement `import.meta.require`
This allows synchronous dynamic loading of `.node`, `.json`, and `.toml` files.
It is not a CommonJS require, but it can be used that way so long as the content is not JavaScript.
Diffstat (limited to 'src/js_printer.zig')
| -rw-r--r-- | src/js_printer.zig | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/src/js_printer.zig b/src/js_printer.zig index 7b4a469ae..b086d97fc 100644 --- a/src/js_printer.zig +++ b/src/js_printer.zig @@ -3588,15 +3588,11 @@ pub fn NewPrinter( const quotes = p.bestQuoteCharForString(import_record.path.text, true); p.print("var "); p.printSymbol(s.namespace_ref); - p.print(" = "); - - p.print( - \\((path, cache, process) => {var mod = cache.get(path); if (mod) return mod.exports; mod = {exports: {}};process.dlopen(mod, path); cache.set(path, mod); return mod.exports;})( - ); + p.print(" = import.meta.require("); p.print(quotes); p.printUTF8StringEscapedQuotes(import_record.path.text, quotes); p.print(quotes); - p.print(", (globalThis[globalThis.Symbol.for('_dlcache')] ||= new globalThis.Map()), globalThis.process);"); + p.print(")"); p.printSemicolonAfterStatement(); } } |
