aboutsummaryrefslogtreecommitdiff
path: root/src/linker.zig
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-06-25 04:41:20 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-06-25 04:41:20 -0700
commit8fbd92e37de61766a72fe0c4a1c98a5fb058c00c (patch)
treec8cbe1fa0b0d5251f0835057b9fdd3e3bc51651a /src/linker.zig
parent7bb75f55530e52447b9c68bc5b0908bf734ba184 (diff)
downloadbun-8fbd92e37de61766a72fe0c4a1c98a5fb058c00c.tar.gz
bun-8fbd92e37de61766a72fe0c4a1c98a5fb058c00c.tar.zst
bun-8fbd92e37de61766a72fe0c4a1c98a5fb058c00c.zip
Cleanup some of the require code
Diffstat (limited to 'src/linker.zig')
-rw-r--r--src/linker.zig34
1 files changed, 17 insertions, 17 deletions
diff --git a/src/linker.zig b/src/linker.zig
index 449367b00..e67339216 100644
--- a/src/linker.zig
+++ b/src/linker.zig
@@ -272,7 +272,7 @@ pub const Linker = struct {
if (JSC.DisabledModule.has(import_record.path.text)) {
import_record.path.is_disabled = true;
- import_record.wrap_with_to_module = true;
+ import_record.do_commonjs_transform_in_printer = true;
continue;
}
@@ -483,22 +483,22 @@ pub const Linker = struct {
import_path_format,
) catch continue;
- if (comptime !supports_dynamic_require) {
- // If we're importing a CommonJS module as ESM
- // We need to do the following transform:
- // import React from 'react';
- // =>
- // import {_require} from 'RUNTIME_IMPORTS';
- // import * as react_module from 'react';
- // var React = _require(react_module).default;
- // UNLESS it's a namespace import
- // If it's a namespace import, assume it's safe.
- // We can do this in the printer instead of creating a bunch of AST nodes here.
- // But we need to at least tell the printer that this needs to happen.
- if (loader != .napi and resolved_import.shouldAssumeCommonJS(import_record.kind)) {
- import_record.wrap_with_to_module = true;
- import_record.module_id = @truncate(u32, std.hash.Wyhash.hash(0, path.pretty));
-
+ // If we're importing a CommonJS module as ESM
+ // We need to do the following transform:
+ // import React from 'react';
+ // =>
+ // import {_require} from 'RUNTIME_IMPORTS';
+ // import * as react_module from 'react';
+ // var React = _require(react_module).default;
+ // UNLESS it's a namespace import
+ // If it's a namespace import, assume it's safe.
+ // We can do this in the printer instead of creating a bunch of AST nodes here.
+ // But we need to at least tell the printer that this needs to happen.
+ if (loader != .napi and resolved_import.shouldAssumeCommonJS(import_record.kind)) {
+ import_record.do_commonjs_transform_in_printer = true;
+ import_record.module_id = @truncate(u32, std.hash.Wyhash.hash(0, path.pretty));
+
+ if (comptime !supports_dynamic_require) {
result.ast.needs_runtime = true;
needs_require = true;
}