Skip to content

Commit

Permalink
refactor(turbopack): Use ResolvedVc<T> for struct fields in `turbop…
Browse files Browse the repository at this point in the history
…ack-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 #

-->
  • Loading branch information
kdy1 authored Nov 29, 2024
1 parent 7f6bfe5 commit e06bb4b
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,25 +111,27 @@ impl ChunkableModule for NextServerComponentModule {
#[turbo_tasks::value_impl]
impl EcmascriptChunkPlaceable for NextServerComponentModule {
#[turbo_tasks::function]
fn get_exports(&self) -> Vc<EcmascriptExports> {
let module_reference = Vc::upcast(NextServerComponentModuleReference::new(Vc::upcast(
*self.module,
)));
async fn get_exports(&self) -> Result<Vc<EcmascriptExports>> {
let module_reference = ResolvedVc::upcast(
NextServerComponentModuleReference::new(Vc::upcast(*self.module))
.to_resolved()
.await?,
);

let mut exports = BTreeMap::new();
exports.insert(
"default".into(),
EsmExport::ImportedBinding(module_reference, "default".into(), false),
EsmExport::ImportedBinding(*module_reference, "default".into(), false),
);

EcmascriptExports::EsmExports(
Ok(EcmascriptExports::EsmExports(
EsmExports {
exports,
star_exports: vec![module_reference],
star_exports: vec![*module_reference],
}
.resolved_cell(),
)
.cell()
.cell())
}
}

Expand Down
7 changes: 6 additions & 1 deletion turbopack/crates/turbopack-core/src/source_map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use regex::Regex;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use sourcemap::{DecodedMap, SourceMap as RegularMap, SourceMapBuilder, SourceMapIndex};
use turbo_rcstr::RcStr;
use turbo_tasks::{TryJoinIterExt, ValueToString, Vc};
use turbo_tasks::{ResolvedVc, TryJoinIterExt, ValueToString, Vc};
use turbo_tasks_fs::{
rope::{Rope, RopeBuilder},
File, FileContent, FileSystem, FileSystemPath, VirtualFileSystem,
Expand Down Expand Up @@ -68,6 +68,11 @@ impl OptionSourceMap {
}
}

impl OptionSourceMap {
pub fn none_resolved() -> ResolvedVc<Self> {
ResolvedVc::cell(None)
}
}
#[turbo_tasks::value(transparent)]
#[derive(Clone, Debug)]
pub struct Tokens(Vec<Token>);
Expand Down
2 changes: 1 addition & 1 deletion turbopack/crates/turbopack-ecmascript/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ impl EcmascriptModuleContent {
references: Vc<ModuleReferences>,
code_generation: Vc<CodeGenerateables>,
async_module: Vc<OptionAsyncModule>,
source_map: Vc<OptionSourceMap>,
source_map: ResolvedVc<OptionSourceMap>,
exports: Vc<EcmascriptExports>,
async_module_info: Option<Vc<AsyncModuleInfo>>,
) -> Result<Vc<Self>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use swc_core::{
quote,
};
use turbo_tasks::{
trace::TraceRawVcs, FxIndexSet, ReadRef, TryFlatJoinIterExt, TryJoinIterExt, Vc,
trace::TraceRawVcs, FxIndexSet, ReadRef, ResolvedVc, TryFlatJoinIterExt, TryJoinIterExt, Vc,
};
use turbopack_core::{
chunk::{
Expand Down Expand Up @@ -51,7 +51,7 @@ pub struct AsyncModule {

/// Option<[AsyncModule]>.
#[turbo_tasks::value(transparent)]
pub struct OptionAsyncModule(Option<Vc<AsyncModule>>);
pub struct OptionAsyncModule(Option<ResolvedVc<AsyncModule>>);

#[turbo_tasks::value_impl]
impl OptionAsyncModule {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl EcmascriptChunkPlaceable for CachedExternalModule {
has_top_level_await: true,
import_externals: true,
}
.cell(),
.resolved_cell(),
)
} else {
None
Expand Down
4 changes: 2 additions & 2 deletions turbopack/crates/turbopack-ecmascript/src/references/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ impl AnalyzeEcmascriptModuleResultBuilder {
}

/// 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));
}

Expand Down Expand Up @@ -857,7 +857,7 @@ pub(crate) async fn analyse_ecmascript_module_internal(
has_top_level_await,
import_externals,
}
.cell();
.resolved_cell();
analysis.set_async_module(async_module);
} else if let Some(span) = top_level_await_span {
AnalyzeIssue {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ impl EcmascriptChunkPlaceable for EcmascriptModuleFacadeModule {
}

#[turbo_tasks::function]
fn get_async_module(self: Vc<Self>) -> Vc<OptionAsyncModule> {
Vc::cell(Some(self.async_module()))
async fn get_async_module(self: Vc<Self>) -> Result<Vc<OptionAsyncModule>> {
Ok(Vc::cell(Some(self.async_module().to_resolved().await?)))
}
}

Expand Down

0 comments on commit e06bb4b

Please sign in to comment.