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,19 +1534,30 @@ impl<C: Comments> VisitMut for ServerActions<C> { ...@@ -1534,19 +1534,30 @@ impl<C: Comments> VisitMut for ServerActions<C> {
} }
} }
ModuleItem::ModuleDecl(ModuleDecl::ExportNamed(named)) => { ModuleItem::ModuleDecl(ModuleDecl::ExportNamed(named)) => {
if !named.type_only {
if named.src.is_some() { if named.src.is_some() {
if named.specifiers.iter().any(|s| match s {
ExportSpecifier::Namespace(_) | ExportSpecifier::Default(_) => {
true
}
ExportSpecifier::Named(s) => !s.is_type_only,
}) {
disallowed_export_span = named.span; disallowed_export_span = named.span;
}
} else { } else {
for spec in &mut named.specifiers { for spec in &mut named.specifiers {
if let ExportSpecifier::Named(ExportNamedSpecifier { if let ExportSpecifier::Named(ExportNamedSpecifier {
orig: ModuleExportName::Ident(ident), orig: ModuleExportName::Ident(ident),
exported, exported,
is_type_only,
.. ..
}) = spec }) = spec
{ {
if !*is_type_only {
if let Some(export_name) = exported { if let Some(export_name) = exported {
if let ModuleExportName::Ident(Ident { sym, .. }) = if let ModuleExportName::Ident(Ident {
export_name sym, ..
}) = export_name
{ {
// export { foo as bar } // export { foo as bar }
self.exported_idents.push(( self.exported_idents.push((
...@@ -1558,7 +1569,9 @@ impl<C: Comments> VisitMut for ServerActions<C> { ...@@ -1558,7 +1569,9 @@ impl<C: Comments> VisitMut for ServerActions<C> {
None, None,
), ),
)); ));
} else if let ModuleExportName::Str(str) = 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(),
...@@ -1582,16 +1595,17 @@ impl<C: Comments> VisitMut for ServerActions<C> { ...@@ -1582,16 +1595,17 @@ impl<C: Comments> VisitMut for ServerActions<C> {
), ),
)); ));
} }
}
} else { } else {
disallowed_export_span = named.span; disallowed_export_span = named.span;
} }
} }
} }
} }
}
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,9 +1774,15 @@ impl<C: Comments> VisitMut for ServerActions<C> { ...@@ -1760,9 +1774,15 @@ impl<C: Comments> VisitMut for ServerActions<C> {
} }
} }
} }
ModuleItem::ModuleDecl(ModuleDecl::ExportAll(ExportAll { span, .. })) => { ModuleItem::ModuleDecl(ModuleDecl::ExportAll(ExportAll {
span,
type_only,
..
})) => {
if !*type_only {
disallowed_export_span = *span; 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