Skip to content

Commit 987f46c

Browse files
committed
__turbopack_emit__ exports
1 parent e345b1c commit 987f46c

File tree

1 file changed

+25
-1
lines changed
  • turbopack/crates/turbopack-ecmascript/src/references

1 file changed

+25
-1
lines changed

turbopack/crates/turbopack-ecmascript/src/references/mod.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3041,6 +3041,7 @@ where
30413041
let mut data = None;
30423042
let mut emit_scope = None;
30433043
let mut with = None;
3044+
let mut exports = None;
30443045

30453046
for part in options {
30463047
if let ObjectPart::KeyValue(
@@ -3053,6 +3054,7 @@ where
30533054
"data" => data = Some(value.clone()),
30543055
"scope" => emit_scope = Some(value.clone()),
30553056
"with" => with = Some(value.clone()),
3057+
"exports" => exports = Some(value.clone()),
30563058
v => return invalid_args(v),
30573059
}
30583060
}
@@ -3078,6 +3080,28 @@ where
30783080
None => false,
30793081
_ => return invalid_args("scope"),
30803082
};
3083+
let exports = match exports {
3084+
Some(JsValue::Constant(JsConstantValue::Str(export))) => {
3085+
ExportUsage::Named(export.as_rcstr())
3086+
}
3087+
Some(JsValue::Array { items, .. }) => {
3088+
let mut result = vec![];
3089+
for item in items {
3090+
if let JsValue::Constant(JsConstantValue::Str(export)) = item {
3091+
result.push(export.as_rcstr());
3092+
} else {
3093+
return invalid_args("exports");
3094+
}
3095+
}
3096+
match result.len() {
3097+
0 => ExportUsage::All,
3098+
1 => ExportUsage::Named(result.into_iter().next().unwrap()),
3099+
_ => ExportUsage::PartialNamespaceObject(result.into()),
3100+
}
3101+
}
3102+
None => ExportUsage::All,
3103+
_ => return invalid_args("exports"),
3104+
};
30813105

30823106
analysis.add_reference_code_gen(
30833107
EmitReference::new(
@@ -3088,7 +3112,7 @@ where
30883112
issue_source(source, span),
30893113
annotations,
30903114
ResolveErrorMode::Error,
3091-
ExportUsage::All,
3115+
exports,
30923116
namespace.as_rcstr(),
30933117
match data {
30943118
Some(JsValue::Constant(JsConstantValue::Str(data))) => {

0 commit comments

Comments
 (0)