diff options
-rw-r--r-- | src/bundler/bundle_v2.zig | 4 | ||||
-rw-r--r-- | src/js_parser.zig | 25 |
2 files changed, 24 insertions, 5 deletions
diff --git a/src/bundler/bundle_v2.zig b/src/bundler/bundle_v2.zig index f534e4184..1fd77f5f2 100644 --- a/src/bundler/bundle_v2.zig +++ b/src/bundler/bundle_v2.zig @@ -2279,6 +2279,7 @@ pub const ParseTask = struct { known_target: ?options.Target = null, module_type: options.ModuleType = .unknown, ctx: *BundleV2, + package_version: string = "", /// Used by generated client components presolved_source_indices: []const Index.Int = &.{}, @@ -2299,6 +2300,7 @@ pub const ParseTask = struct { .jsx = resolve_result.jsx, .source_index = source_index orelse Index.invalid, .module_type = resolve_result.module_type, + .package_version = if (resolve_result.package_json) |package_json| package_json.version else "", }; } @@ -2591,6 +2593,8 @@ pub const ParseTask = struct { opts.warn_about_unbundled_modules = false; opts.macro_context = &this.data.macro_context; opts.bundle = true; + opts.package_version = task.package_version; + opts.features.top_level_await = true; opts.features.jsx_optimization_inline = target.isBun() and (bundler.options.jsx_optimization_inline orelse !task.jsx.development); opts.features.auto_import_jsx = task.jsx.parse and bundler.options.auto_import_jsx; diff --git a/src/js_parser.zig b/src/js_parser.zig index 5729efa39..6a2cc1228 100644 --- a/src/js_parser.zig +++ b/src/js_parser.zig @@ -2629,6 +2629,7 @@ pub const Parser = struct { tree_shaking: bool = false, bundle: bool = false, + package_version: string = "", macro_context: *MacroContextType() = undefined, @@ -21918,11 +21919,25 @@ fn NewParser_( // Only enable during bundling .commonjs_named_exports_deoptimized = !opts.bundle, - .unwrap_all_requires = opts.bundle and - if (source.path.packageName()) |pkg| - opts.features.shouldUnwrapRequire(pkg) - else - false, + }; + + this.unwrap_all_requires = brk: { + if (opts.bundle) { + if (source.path.packageName()) |pkg| { + if (opts.features.shouldUnwrapRequire(pkg)) { + if (strings.eqlComptime(pkg, "react") or strings.eqlComptime(pkg, "react-dom")) { + const version = opts.package_version; + if (version.len > 2 and (version[0] == '0' or (version[0] == '1' and version[1] < '8'))) { + break :brk false; + } + } + + break :brk true; + } + } + } + + break :brk false; }; this.symbols = std.ArrayList(Symbol).init(allocator); |