Unverified Commit 3f09e569 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Turbopack: don't fail on export type in use server (#85054)

Allow `export type ... from "...";`
parent bf99e962
...@@ -1534,56 +1534,71 @@ impl<C: Comments> VisitMut for ServerActions<C> { ...@@ -1534,56 +1534,71 @@ impl<C: Comments> VisitMut for ServerActions<C> {
} }
} }
ModuleItem::ModuleDecl(ModuleDecl::ExportNamed(named)) => { ModuleItem::ModuleDecl(ModuleDecl::ExportNamed(named)) => {
if named.src.is_some() { if !named.type_only {
disallowed_export_span = named.span; if named.src.is_some() {
} else { if named.specifiers.iter().any(|s| match s {
for spec in &mut named.specifiers { ExportSpecifier::Namespace(_) | ExportSpecifier::Default(_) => {
if let ExportSpecifier::Named(ExportNamedSpecifier { true
orig: ModuleExportName::Ident(ident), }
exported, ExportSpecifier::Named(s) => !s.is_type_only,
.. }) {
}) = spec disallowed_export_span = named.span;
{ }
if let Some(export_name) = exported { } else {
if let ModuleExportName::Ident(Ident { sym, .. }) = for spec in &mut named.specifiers {
export_name if let ExportSpecifier::Named(ExportNamedSpecifier {
{ orig: ModuleExportName::Ident(ident),
// export { foo as bar } exported,
self.exported_idents.push(( is_type_only,
ident.clone(), ..
sym.clone(), }) = spec
self.generate_server_reference_id( {
sym.as_ref(), if !*is_type_only {
in_cache_file, if let Some(export_name) = exported {
None, if let ModuleExportName::Ident(Ident {
), sym, ..
)); }) = export_name
} else if let ModuleExportName::Str(str) = export_name { {
// export { foo as "bar" } // export { foo as bar }
self.exported_idents.push(( self.exported_idents.push((
ident.clone(), ident.clone(),
str.value.clone(), sym.clone(),
self.generate_server_reference_id( self.generate_server_reference_id(
str.value.as_ref(), sym.as_ref(),
in_cache_file, in_cache_file,
None, None,
), ),
)); ));
} else if let ModuleExportName::Str(str) =
export_name
{
// export { foo as "bar" }
self.exported_idents.push((
ident.clone(),
str.value.clone(),
self.generate_server_reference_id(
str.value.as_ref(),
in_cache_file,
None,
),
));
}
} else {
// export { foo }
self.exported_idents.push((
ident.clone(),
ident.sym.clone(),
self.generate_server_reference_id(
ident.sym.as_ref(),
in_cache_file,
None,
),
));
}
} }
} else { } else {
// export { foo } disallowed_export_span = named.span;
self.exported_idents.push((
ident.clone(),
ident.sym.clone(),
self.generate_server_reference_id(
ident.sym.as_ref(),
in_cache_file,
None,
),
));
} }
} else {
disallowed_export_span = named.span;
} }
} }
} }
...@@ -1591,7 +1606,6 @@ impl<C: Comments> VisitMut for ServerActions<C> { ...@@ -1591,7 +1606,6 @@ impl<C: Comments> VisitMut for ServerActions<C> {
ModuleItem::ModuleDecl(ModuleDecl::ExportDefaultDecl(ExportDefaultDecl { ModuleItem::ModuleDecl(ModuleDecl::ExportDefaultDecl(ExportDefaultDecl {
decl, decl,
span, span,
..
})) => match decl { })) => match decl {
DefaultDecl::Fn(f) => { DefaultDecl::Fn(f) => {
let (is_action_fn, is_cache_fn) = has_body_directive(&f.function.body); let (is_action_fn, is_cache_fn) = has_body_directive(&f.function.body);
...@@ -1760,8 +1774,14 @@ impl<C: Comments> VisitMut for ServerActions<C> { ...@@ -1760,8 +1774,14 @@ impl<C: Comments> VisitMut for ServerActions<C> {
} }
} }
} }
ModuleItem::ModuleDecl(ModuleDecl::ExportAll(ExportAll { span, .. })) => { ModuleItem::ModuleDecl(ModuleDecl::ExportAll(ExportAll {
disallowed_export_span = *span; span,
type_only,
..
})) => {
if !*type_only {
disallowed_export_span = *span;
}
} }
_ => {} _ => {}
} }
......
'use server'
export type X = string
// @ts-ignore -- that file does not exist
export { type A } from './a'
// @ts-ignore -- that file does not exist
export type { B } from './b'
// @ts-ignore -- that file does not exist
export type * from './c'
export async function actionA(): Promise<string> {
return 'hello from actionA'
}
/* __next_internal_action_entry_do_not_use__ {"0095ef8ede0a8a4c822fcbdb018cb264731cb15281":"actionA"} */ import { registerServerReference } from "private-next-rsc-server-reference";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
export type X = string;
// @ts-ignore -- that file does not exist
export { type A } from './a';
// @ts-ignore -- that file does not exist
export type { B } from './b';
// @ts-ignore -- that file does not exist
export type * from './c';
export async function actionA(): Promise<string> {
return 'hello from actionA';
}
import { ensureServerEntryExports } from "private-next-rsc-action-validate";
ensureServerEntryExports([
actionA
]);
registerServerReference(actionA, "0095ef8ede0a8a4c822fcbdb018cb264731cb15281", null);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment