aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-04-16 21:04:07 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-04-16 21:04:07 -0700
commit413ce0c7a5fffc3ed8c1112f22d2e1d9eb4428f1 (patch)
treeb9263202456652855e29bada84b2e3d54024ba2a
parentc916a55eadc6cc730084ae6851a57fcb8d9b85e6 (diff)
downloadbun-413ce0c7a5fffc3ed8c1112f22d2e1d9eb4428f1.tar.gz
bun-413ce0c7a5fffc3ed8c1112f22d2e1d9eb4428f1.tar.zst
bun-413ce0c7a5fffc3ed8c1112f22d2e1d9eb4428f1.zip
Add some comments
-rw-r--r--src/bundler/bundle_v2.zig26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/bundler/bundle_v2.zig b/src/bundler/bundle_v2.zig
index 5faa3c893..b91d23d4e 100644
--- a/src/bundler/bundle_v2.zig
+++ b/src/bundler/bundle_v2.zig
@@ -7064,13 +7064,35 @@ const LinkerContext = struct {
},
.dynamic_fallback_interop_default => {
+ // if the file was rewritten from CommonJS into ESM
+ // and the developer imported an export that doesn't exist
+ // We don't do a runtime error since that CJS would have returned undefined.
const named_import: js_ast.NamedImport = named_imports[prev_source_index].get(prev_import_ref).?;
+
+ // For code like this:
+ //
+ // import React from 'react';
+ //
+ // Normally, this would be rewritten to:
+ //
+ // const React = import_react().default;
+ //
+ // Instead, we rewrite to
+ //
+ // const React = import_react();
+ //
+ // But it means we now definitely need to wrap the module.
+ //
+ // We want to keep doing this transform though for each file
+ // so defer marking the export kind as esm_with_fallback until after
+ // we've visited every import.
to_mark_as_esm_with_dynamic_fallback.put(other_id, {}) catch unreachable;
- if (named_import.namespace_ref != null and named_import.namespace_ref.?.isValid()) {
- // If the file was rewritten to ESM from CJS, the "default" export should alias to the namespace export.
+ if (named_import.namespace_ref != null and named_import.namespace_ref.?.isValid()) {
if (strings.eqlComptime(named_import.alias orelse "", "default")) {
result.kind = .normal;
+ // Referencing the exports_ref directly feels wrong.
+ // TODO: revisit this.
result.ref = c.graph.ast.items(.exports_ref)[other_id];
result.name_loc = named_import.alias_loc orelse Logger.Loc.Empty;
} else {