Unverified Commit e06bb4b9 authored by Donny/강동윤's avatar Donny/강동윤 Committed by GitHub

refactor(turbopack): Use `ResolvedVc<T>` for struct fields in `turbopack-ecmascript` (#73302)

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the PR.
- Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. (A discussion must be opened, see https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to understand the PR)
- When linking to a Slack thread, you might want to share details of the conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->
parent 7f6bfe5a
...@@ -111,25 +111,27 @@ impl ChunkableModule for NextServerComponentModule { ...@@ -111,25 +111,27 @@ impl ChunkableModule for NextServerComponentModule {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl EcmascriptChunkPlaceable for NextServerComponentModule { impl EcmascriptChunkPlaceable for NextServerComponentModule {
#[turbo_tasks::function] #[turbo_tasks::function]
fn get_exports(&self) -> Vc<EcmascriptExports> { async fn get_exports(&self) -> Result<Vc<EcmascriptExports>> {
let module_reference = Vc::upcast(NextServerComponentModuleReference::new(Vc::upcast( let module_reference = ResolvedVc::upcast(
*self.module, NextServerComponentModuleReference::new(Vc::upcast(*self.module))
))); .to_resolved()
.await?,
);
let mut exports = BTreeMap::new(); let mut exports = BTreeMap::new();
exports.insert( exports.insert(
"default".into(), "default".into(),
EsmExport::ImportedBinding(module_reference, "default".into(), false), EsmExport::ImportedBinding(*module_reference, "default".into(), false),
); );
EcmascriptExports::EsmExports( Ok(EcmascriptExports::EsmExports(
EsmExports { EsmExports {
exports, exports,
star_exports: vec![module_reference], star_exports: vec![*module_reference],
} }
.resolved_cell(), .resolved_cell(),
) )
.cell() .cell())
} }
} }
......
...@@ -8,7 +8,7 @@ use regex::Regex; ...@@ -8,7 +8,7 @@ use regex::Regex;
use serde::{Deserialize, Deserializer, Serialize, Serializer}; use serde::{Deserialize, Deserializer, Serialize, Serializer};
use sourcemap::{DecodedMap, SourceMap as RegularMap, SourceMapBuilder, SourceMapIndex}; use sourcemap::{DecodedMap, SourceMap as RegularMap, SourceMapBuilder, SourceMapIndex};
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{TryJoinIterExt, ValueToString, Vc}; use turbo_tasks::{ResolvedVc, TryJoinIterExt, ValueToString, Vc};
use turbo_tasks_fs::{ use turbo_tasks_fs::{
rope::{Rope, RopeBuilder}, rope::{Rope, RopeBuilder},
File, FileContent, FileSystem, FileSystemPath, VirtualFileSystem, File, FileContent, FileSystem, FileSystemPath, VirtualFileSystem,
...@@ -68,6 +68,11 @@ impl OptionSourceMap { ...@@ -68,6 +68,11 @@ impl OptionSourceMap {
} }
} }
impl OptionSourceMap {
pub fn none_resolved() -> ResolvedVc<Self> {
ResolvedVc::cell(None)
}
}
#[turbo_tasks::value(transparent)] #[turbo_tasks::value(transparent)]
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Tokens(Vec<Token>); pub struct Tokens(Vec<Token>);
......
...@@ -721,7 +721,7 @@ impl EcmascriptModuleContent { ...@@ -721,7 +721,7 @@ impl EcmascriptModuleContent {
references: Vc<ModuleReferences>, references: Vc<ModuleReferences>,
code_generation: Vc<CodeGenerateables>, code_generation: Vc<CodeGenerateables>,
async_module: Vc<OptionAsyncModule>, async_module: Vc<OptionAsyncModule>,
source_map: Vc<OptionSourceMap>, source_map: ResolvedVc<OptionSourceMap>,
exports: Vc<EcmascriptExports>, exports: Vc<EcmascriptExports>,
async_module_info: Option<Vc<AsyncModuleInfo>>, async_module_info: Option<Vc<AsyncModuleInfo>>,
) -> Result<Vc<Self>> { ) -> Result<Vc<Self>> {
......
...@@ -6,7 +6,7 @@ use swc_core::{ ...@@ -6,7 +6,7 @@ use swc_core::{
quote, quote,
}; };
use turbo_tasks::{ use turbo_tasks::{
trace::TraceRawVcs, FxIndexSet, ReadRef, TryFlatJoinIterExt, TryJoinIterExt, Vc, trace::TraceRawVcs, FxIndexSet, ReadRef, ResolvedVc, TryFlatJoinIterExt, TryJoinIterExt, Vc,
}; };
use turbopack_core::{ use turbopack_core::{
chunk::{ chunk::{
...@@ -51,7 +51,7 @@ pub struct AsyncModule { ...@@ -51,7 +51,7 @@ pub struct AsyncModule {
/// Option<[AsyncModule]>. /// Option<[AsyncModule]>.
#[turbo_tasks::value(transparent)] #[turbo_tasks::value(transparent)]
pub struct OptionAsyncModule(Option<Vc<AsyncModule>>); pub struct OptionAsyncModule(Option<ResolvedVc<AsyncModule>>);
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl OptionAsyncModule { impl OptionAsyncModule {
......
...@@ -164,7 +164,7 @@ impl EcmascriptChunkPlaceable for CachedExternalModule { ...@@ -164,7 +164,7 @@ impl EcmascriptChunkPlaceable for CachedExternalModule {
has_top_level_await: true, has_top_level_await: true,
import_externals: true, import_externals: true,
} }
.cell(), .resolved_cell(),
) )
} else { } else {
None None
......
...@@ -265,7 +265,7 @@ impl AnalyzeEcmascriptModuleResultBuilder { ...@@ -265,7 +265,7 @@ impl AnalyzeEcmascriptModuleResultBuilder {
} }
/// Sets the analysis result ES export. /// Sets the analysis result ES export.
pub fn set_async_module(&mut self, async_module: Vc<AsyncModule>) { pub fn set_async_module(&mut self, async_module: ResolvedVc<AsyncModule>) {
self.async_module = ResolvedVc::cell(Some(async_module)); self.async_module = ResolvedVc::cell(Some(async_module));
} }
...@@ -857,7 +857,7 @@ pub(crate) async fn analyse_ecmascript_module_internal( ...@@ -857,7 +857,7 @@ pub(crate) async fn analyse_ecmascript_module_internal(
has_top_level_await, has_top_level_await,
import_externals, import_externals,
} }
.cell(); .resolved_cell();
analysis.set_async_module(async_module); analysis.set_async_module(async_module);
} else if let Some(span) = top_level_await_span { } else if let Some(span) = top_level_await_span {
AnalyzeIssue { AnalyzeIssue {
......
...@@ -278,8 +278,8 @@ impl EcmascriptChunkPlaceable for EcmascriptModuleFacadeModule { ...@@ -278,8 +278,8 @@ impl EcmascriptChunkPlaceable for EcmascriptModuleFacadeModule {
} }
#[turbo_tasks::function] #[turbo_tasks::function]
fn get_async_module(self: Vc<Self>) -> Vc<OptionAsyncModule> { async fn get_async_module(self: Vc<Self>) -> Result<Vc<OptionAsyncModule>> {
Vc::cell(Some(self.async_module())) Ok(Vc::cell(Some(self.async_module().to_resolved().await?)))
} }
} }
......
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