Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(custom-transform): allow to assert empty program for rsc #61922

Merged
merged 2 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{collections::HashMap, path::PathBuf};

use regex::Regex;
use serde::Deserialize;
use swc_core::ecma::visit::VisitWith;
use swc_core::{common::util::take::Take, ecma::visit::VisitWith};
use turbopack_binding::swc::core::{
common::{
comments::{Comment, CommentKind, Comments},
Expand Down Expand Up @@ -576,6 +576,7 @@ impl ReactServerComponentValidator {
let is_error_file = Regex::new(r"[\\/]error\.(ts|js)x?$")
.unwrap()
.is_match(&self.filepath);

if is_error_file {
if let Some(app_dir) = &self.app_dir {
if let Some(app_dir) = app_dir.to_str() {
Expand Down Expand Up @@ -727,6 +728,14 @@ impl ReactServerComponentValidator {
impl Visit for ReactServerComponentValidator {
noop_visit_type!();

// coerce parsed script to run validation for the context, which is still
// required even if file is empty
fn visit_script(&mut self, script: &swc_core::ecma::ast::Script) {
if script.body.is_empty() {
self.visit_module(&Module::dummy());
}
}

fn visit_module(&mut self, module: &Module) {
let (is_client_entry, is_action_file, imports, export_names) =
collect_top_level_directives_and_imports(&self.app_dir, &self.filepath, module);
Expand Down
5 changes: 2 additions & 3 deletions test/turbopack-tests-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1162,11 +1162,10 @@
"Error overlay - RSC build errors should throw an error when error file is a server component",
"Error overlay - RSC build errors should throw an error when getServerSideProps is used",
"Error overlay - RSC build errors should throw an error when metadata export is used in client components",
"Error overlay - RSC build errors should throw an error when metadata exports are used together in server components"
],
"failed": [
"Error overlay - RSC build errors should throw an error when metadata exports are used together in server components",
"Error overlay - RSC build errors should throw an error when error file is a server component with empty error file"
],
"failed": [],
"pending": [
"Error overlay - RSC build errors should throw an error when getStaticProps is used"
],
Expand Down
Loading