Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/bun-types/bun.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3054,9 +3054,13 @@ declare module "bun" {
/**
* Enable REPL mode transforms:
* - Wraps top-level inputs that appear to be object literals (inputs starting with '{' without trailing ';') in parentheses
* - Hoists all declarations as var for REPL persistence across vm.runInContext calls
* - Hoists the declarations the input wrote as var for REPL persistence across vm.runInContext calls.
* A helper import or a temporary that the transpiler adds stays inside the IIFE
* - Wraps last expression in { __proto__: null, value: expr } for result capture
* - Wraps code in sync/async IIFE to avoid parentheses around object literals
* - Wraps code in sync/async IIFE to avoid parentheses around object literals.
* The IIFE is async, and the result is a Promise, if the input has a top-level await or an import,
* or if the transpiler imports helpers for it (decorators, `accessor`, a lowered `using`, automatic JSX).
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
* An import becomes an `import()` call: with `vm.runInContext`, pass `importModuleDynamically`
*
* @default false
*/
Expand Down
8 changes: 6 additions & 2 deletions src/js_parser/parse/parse_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1059,8 +1059,12 @@ impl<'a> Parser<'a> {
// Note that top-level lowered "using" declarations disable tree-shaking
// because we only do tree-shaking on top-level statements and lowering
// a top-level "using" declaration moves all top-level statements into a
// nested scope.
if !p.options.tree_shaking || p.will_wrap_module_in_try_catch_for_using {
// nested scope. The REPL transform moves them into a function too, where
// an import runs as a statement: a class must not move above it.
Comment thread
robobun marked this conversation as resolved.
Resolved
if !p.options.tree_shaking
|| p.will_wrap_module_in_try_catch_for_using
|| p.options.repl_mode
{
// When tree shaking is disabled, everything comes in a single part
p.append_part(&mut parts, stmts)?;
} else {
Expand Down
Loading
Loading