Unverified Commit 94c4e5da authored by Benjamin Woodruff's avatar Benjamin Woodruff Committed by GitHub

codemod(turbopack): Inline trivial uses of `let this = self` (#70431)

A follow-up to the #70431 codemod diff, which leave behind a lot of
trivial `let this = self;` statements.

Using the following ast-grep rule config:

```yaml
language: rust
id: inline_trivial_this

utils:
  block-with-this:
    all:
    - pattern: $BLOCK
    - kind: block
    - has:
        all:
          - pattern: let this = $SELF;
          - any:
            - pattern: let this = self;
            - pattern: let this = &self.0;

rule:
  matches: block-with-this

rewriters:
  - id: remove-let-this
    rule:
      pattern: let this = $SELF;
    fix: ""
  - id: inline-this-auto-deref
    rule:
      pattern: this
      inside:
        kind: field_expression
    transform:
      SELF_AUTO_DEREF:
        replace:
          source: $SELF
          replace: "&?(?<INNER>.*)"
          by: "$INNER"
    fix: $SELF_AUTO_DEREF
  - id: inline-this
    rule:
      pattern: this
    fix: $SELF

transform:
  NEW_BLOCK:
    rewrite:
      source: $BLOCK
      rewriters:
        - remove-let-this
        - inline-this-auto-deref
        - inline-this

fix:
  $NEW_BLOCK
```

Applied with

```
sg scan -U -r ../codemod_inline_trivial_this.yml .
```
parent 1cb6faae
...@@ -256,12 +256,10 @@ impl MiddlewareEndpoint { ...@@ -256,12 +256,10 @@ impl MiddlewareEndpoint {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn userland_module(&self) -> Result<Vc<Box<dyn Module>>> { async fn userland_module(&self) -> Result<Vc<Box<dyn Module>>> {
let this = self; Ok(self
Ok(this
.asset_context .asset_context
.process( .process(
this.source, self.source,
Value::new(ReferenceType::Entry(EntryReferenceSubType::Middleware)), Value::new(ReferenceType::Entry(EntryReferenceSubType::Middleware)),
) )
.module()) .module())
......
...@@ -641,8 +641,7 @@ impl PageEndpoint { ...@@ -641,8 +641,7 @@ impl PageEndpoint {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn source(&self) -> Result<Vc<Box<dyn Source>>> { async fn source(&self) -> Result<Vc<Box<dyn Source>>> {
let this = self; Ok(Vc::upcast(FileSource::new(self.page.project_path())))
Ok(Vc::upcast(FileSource::new(this.page.project_path())))
} }
#[turbo_tasks::function] #[turbo_tasks::function]
...@@ -949,8 +948,7 @@ impl PageEndpoint { ...@@ -949,8 +948,7 @@ impl PageEndpoint {
&self, &self,
entry_chunk: Vc<Box<dyn OutputAsset>>, entry_chunk: Vc<Box<dyn OutputAsset>>,
) -> Result<Vc<Box<dyn OutputAsset>>> { ) -> Result<Vc<Box<dyn OutputAsset>>> {
let this = self; let node_root = self.pages_project.project().node_root();
let node_root = this.pages_project.project().node_root();
let chunk_path = entry_chunk.ident().path().await?; let chunk_path = entry_chunk.ident().path().await?;
let asset_path = node_root let asset_path = node_root
...@@ -960,11 +958,11 @@ impl PageEndpoint { ...@@ -960,11 +958,11 @@ impl PageEndpoint {
.context("ssr chunk entry path must be inside the node root")?; .context("ssr chunk entry path must be inside the node root")?;
let pages_manifest = PagesManifest { let pages_manifest = PagesManifest {
pages: [(this.pathname.await?.clone_value(), asset_path.into())] pages: [(self.pathname.await?.clone_value(), asset_path.into())]
.into_iter() .into_iter()
.collect(), .collect(),
}; };
let manifest_path_prefix = get_asset_prefix_from_pathname(&this.pathname.await?); let manifest_path_prefix = get_asset_prefix_from_pathname(&self.pathname.await?);
Ok(Vc::upcast(VirtualOutputAsset::new( Ok(Vc::upcast(VirtualOutputAsset::new(
node_root node_root
.join(format!("server/pages{manifest_path_prefix}/pages-manifest.json",).into()), .join(format!("server/pages{manifest_path_prefix}/pages-manifest.json",).into()),
...@@ -994,13 +992,12 @@ impl PageEndpoint { ...@@ -994,13 +992,12 @@ impl PageEndpoint {
&self, &self,
client_chunks: Vc<OutputAssets>, client_chunks: Vc<OutputAssets>,
) -> Result<Vc<Box<dyn OutputAsset>>> { ) -> Result<Vc<Box<dyn OutputAsset>>> {
let this = self; let node_root = self.pages_project.project().node_root();
let node_root = this.pages_project.project().node_root(); let client_relative_path = self.pages_project.project().client_relative_path();
let client_relative_path = this.pages_project.project().client_relative_path();
let client_relative_path_ref = client_relative_path.await?; let client_relative_path_ref = client_relative_path.await?;
let build_manifest = BuildManifest { let build_manifest = BuildManifest {
pages: [( pages: [(
this.pathname.await?.clone_value(), self.pathname.await?.clone_value(),
client_chunks client_chunks
.await? .await?
.iter() .iter()
...@@ -1022,7 +1019,7 @@ impl PageEndpoint { ...@@ -1022,7 +1019,7 @@ impl PageEndpoint {
.collect(), .collect(),
..Default::default() ..Default::default()
}; };
let manifest_path_prefix = get_asset_prefix_from_pathname(&this.pathname.await?); let manifest_path_prefix = get_asset_prefix_from_pathname(&self.pathname.await?);
Ok(Vc::upcast(VirtualOutputAsset::new( Ok(Vc::upcast(VirtualOutputAsset::new(
node_root node_root
.join(format!("server/pages{manifest_path_prefix}/build-manifest.json",).into()), .join(format!("server/pages{manifest_path_prefix}/build-manifest.json",).into()),
......
...@@ -302,8 +302,6 @@ impl ProjectContainer { ...@@ -302,8 +302,6 @@ impl ProjectContainer {
impl ProjectContainer { impl ProjectContainer {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn project(&self) -> Result<Vc<Project>> { pub async fn project(&self) -> Result<Vc<Project>> {
let this = self;
let env_map: Vc<EnvMap>; let env_map: Vc<EnvMap>;
let next_config; let next_config;
let define_env; let define_env;
...@@ -317,7 +315,7 @@ impl ProjectContainer { ...@@ -317,7 +315,7 @@ impl ProjectContainer {
let preview_props; let preview_props;
let browserslist_query; let browserslist_query;
{ {
let options = this.options_state.get(); let options = self.options_state.get();
let options = options let options = options
.as_ref() .as_ref()
.context("ProjectContainer need to be initialized with initialize()")?; .context("ProjectContainer need to be initialized with initialize()")?;
...@@ -361,7 +359,7 @@ impl ProjectContainer { ...@@ -361,7 +359,7 @@ impl ProjectContainer {
} else { } else {
NextMode::Build.cell() NextMode::Build.cell()
}, },
versioned_content_map: this.versioned_content_map, versioned_content_map: self.versioned_content_map,
build_id, build_id,
encryption_key, encryption_key,
preview_props, preview_props,
...@@ -518,13 +516,12 @@ impl Project { ...@@ -518,13 +516,12 @@ impl Project {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn project_fs(&self) -> Result<Vc<DiskFileSystem>> { async fn project_fs(&self) -> Result<Vc<DiskFileSystem>> {
let this = self;
let disk_fs = DiskFileSystem::new( let disk_fs = DiskFileSystem::new(
PROJECT_FILESYSTEM_NAME.into(), PROJECT_FILESYSTEM_NAME.into(),
this.root_path.clone(), self.root_path.clone(),
vec![], vec![],
); );
if this.watch { if self.watch {
disk_fs.await?.start_watching_with_invalidation_reason()?; disk_fs.await?.start_watching_with_invalidation_reason()?;
} }
Ok(disk_fs) Ok(disk_fs)
...@@ -538,8 +535,7 @@ impl Project { ...@@ -538,8 +535,7 @@ impl Project {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn output_fs(&self) -> Result<Vc<DiskFileSystem>> { pub async fn output_fs(&self) -> Result<Vc<DiskFileSystem>> {
let this = self; let disk_fs = DiskFileSystem::new("output".into(), self.project_path.clone(), vec![]);
let disk_fs = DiskFileSystem::new("output".into(), this.project_path.clone(), vec![]);
Ok(disk_fs) Ok(disk_fs)
} }
......
...@@ -733,8 +733,7 @@ struct DuplicateParallelRouteIssue { ...@@ -733,8 +733,7 @@ struct DuplicateParallelRouteIssue {
impl Issue for DuplicateParallelRouteIssue { impl Issue for DuplicateParallelRouteIssue {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn file_path(&self) -> Result<Vc<FileSystemPath>> { async fn file_path(&self) -> Result<Vc<FileSystemPath>> {
let this = self; Ok(self.app_dir.join(self.page.to_string().into()))
Ok(this.app_dir.join(this.page.to_string().into()))
} }
#[turbo_tasks::function] #[turbo_tasks::function]
......
...@@ -847,8 +847,7 @@ impl NextConfig { ...@@ -847,8 +847,7 @@ impl NextConfig {
&self, &self,
active_conditions: Vec<RcStr>, active_conditions: Vec<RcStr>,
) -> Result<Vc<OptionWebpackRules>> { ) -> Result<Vc<OptionWebpackRules>> {
let this = self; let Some(turbo_rules) = self
let Some(turbo_rules) = this
.experimental .experimental
.turbo .turbo
.as_ref() .as_ref()
...@@ -936,8 +935,7 @@ impl NextConfig { ...@@ -936,8 +935,7 @@ impl NextConfig {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn resolve_alias_options(&self) -> Result<Vc<ResolveAliasMap>> { pub async fn resolve_alias_options(&self) -> Result<Vc<ResolveAliasMap>> {
let this = self; let Some(resolve_alias) = self
let Some(resolve_alias) = this
.experimental .experimental
.turbo .turbo
.as_ref() .as_ref()
...@@ -951,8 +949,7 @@ impl NextConfig { ...@@ -951,8 +949,7 @@ impl NextConfig {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn resolve_extension(&self) -> Result<Vc<ResolveExtensions>> { pub async fn resolve_extension(&self) -> Result<Vc<ResolveExtensions>> {
let this = self; let Some(resolve_extensions) = self
let Some(resolve_extensions) = this
.experimental .experimental
.turbo .turbo
.as_ref() .as_ref()
...@@ -1148,8 +1145,7 @@ impl NextConfig { ...@@ -1148,8 +1145,7 @@ impl NextConfig {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn module_id_strategy_config(&self) -> Result<Vc<OptionModuleIdStrategy>> { pub async fn module_id_strategy_config(&self) -> Result<Vc<OptionModuleIdStrategy>> {
let this = self; let Some(module_id_strategy) = self
let Some(module_id_strategy) = this
.experimental .experimental
.turbo .turbo
.as_ref() .as_ref()
......
...@@ -33,10 +33,8 @@ impl NextDynamicEntryModule { ...@@ -33,10 +33,8 @@ impl NextDynamicEntryModule {
&self, &self,
client_chunking_context: Vc<Box<dyn ChunkingContext>>, client_chunking_context: Vc<Box<dyn ChunkingContext>>,
) -> Result<Vc<OutputAssets>> { ) -> Result<Vc<OutputAssets>> {
let this = self;
let Some(client_entry_module) = let Some(client_entry_module) =
Vc::try_resolve_sidecast::<Box<dyn ChunkableModule>>(this.client_entry_module).await? Vc::try_resolve_sidecast::<Box<dyn ChunkableModule>>(self.client_entry_module).await?
else { else {
bail!("dynamic client asset must be chunkable"); bail!("dynamic client asset must be chunkable");
}; };
......
...@@ -47,8 +47,7 @@ impl NextServerComponentModule { ...@@ -47,8 +47,7 @@ impl NextServerComponentModule {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn server_path(&self) -> Result<Vc<FileSystemPath>> { pub async fn server_path(&self) -> Result<Vc<FileSystemPath>> {
let this = self; Ok(self.module.ident().path())
Ok(this.module.ident().path())
} }
} }
...@@ -144,12 +143,11 @@ impl EcmascriptChunkItem for NextServerComponentChunkItem { ...@@ -144,12 +143,11 @@ impl EcmascriptChunkItem for NextServerComponentChunkItem {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn content(&self) -> Result<Vc<EcmascriptChunkItemContent>> { async fn content(&self) -> Result<Vc<EcmascriptChunkItemContent>> {
let this = self; let inner = self.inner.await?;
let inner = this.inner.await?;
let module_id = inner let module_id = inner
.module .module
.as_chunk_item(Vc::upcast(this.chunking_context)) .as_chunk_item(Vc::upcast(self.chunking_context))
.id() .id()
.await?; .await?;
Ok(EcmascriptChunkItemContent { Ok(EcmascriptChunkItemContent {
......
...@@ -99,8 +99,7 @@ impl PageLoaderAsset { ...@@ -99,8 +99,7 @@ impl PageLoaderAsset {
&self, &self,
rebase_prefix_path: Vc<FileSystemPathOption>, rebase_prefix_path: Vc<FileSystemPathOption>,
) -> Result<Vc<ChunksData>> { ) -> Result<Vc<ChunksData>> {
let this = self; let mut chunks = self.page_chunks;
let mut chunks = this.page_chunks;
// If we are provided a prefix path, we need to rewrite our chunk paths to // If we are provided a prefix path, we need to rewrite our chunk paths to
// remove that prefix. // remove that prefix.
...@@ -119,7 +118,7 @@ impl PageLoaderAsset { ...@@ -119,7 +118,7 @@ impl PageLoaderAsset {
chunks = Vc::cell(rebased); chunks = Vc::cell(rebased);
}; };
Ok(ChunkData::from_assets(this.server_root, chunks)) Ok(ChunkData::from_assets(self.server_root, chunks))
} }
} }
......
...@@ -25,8 +25,7 @@ impl DotenvProcessEnv { ...@@ -25,8 +25,7 @@ impl DotenvProcessEnv {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn read_prior(&self) -> Result<Vc<EnvMap>> { pub async fn read_prior(&self) -> Result<Vc<EnvMap>> {
let this = self; match self.prior {
match this.prior {
None => Ok(EnvMap::empty()), None => Ok(EnvMap::empty()),
Some(p) => Ok(p.read_all()), Some(p) => Ok(p.read_all()),
} }
......
...@@ -1171,10 +1171,9 @@ impl FileSystemPath { ...@@ -1171,10 +1171,9 @@ impl FileSystemPath {
/// None when the joined path would leave the filesystem root. /// None when the joined path would leave the filesystem root.
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn try_join(&self, path: RcStr) -> Result<Vc<FileSystemPathOption>> { pub async fn try_join(&self, path: RcStr) -> Result<Vc<FileSystemPathOption>> {
let this = self; if let Some(path) = join_path(&self.path, &path) {
if let Some(path) = join_path(&this.path, &path) {
Ok(Vc::cell(Some( Ok(Vc::cell(Some(
Self::new_normalized(this.fs, path.into()).resolve().await?, Self::new_normalized(self.fs, path.into()).resolve().await?,
))) )))
} else { } else {
Ok(FileSystemPathOption::none()) Ok(FileSystemPathOption::none())
...@@ -1185,11 +1184,10 @@ impl FileSystemPath { ...@@ -1185,11 +1184,10 @@ impl FileSystemPath {
/// None when the joined path would leave the current path. /// None when the joined path would leave the current path.
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn try_join_inside(&self, path: RcStr) -> Result<Vc<FileSystemPathOption>> { pub async fn try_join_inside(&self, path: RcStr) -> Result<Vc<FileSystemPathOption>> {
let this = self; if let Some(path) = join_path(&self.path, &path) {
if let Some(path) = join_path(&this.path, &path) { if path.starts_with(&*self.path) {
if path.starts_with(&*this.path) {
return Ok(Vc::cell(Some( return Ok(Vc::cell(Some(
Self::new_normalized(this.fs, path.into()).resolve().await?, Self::new_normalized(self.fs, path.into()).resolve().await?,
))); )));
} }
} }
...@@ -1217,8 +1215,7 @@ impl FileSystemPath { ...@@ -1217,8 +1215,7 @@ impl FileSystemPath {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn extension(&self) -> Result<Vc<RcStr>> { pub async fn extension(&self) -> Result<Vc<RcStr>> {
let this = self; Ok(Vc::cell(self.extension_ref().unwrap_or("").into()))
Ok(Vc::cell(this.extension_ref().unwrap_or("").into()))
} }
#[turbo_tasks::function] #[turbo_tasks::function]
...@@ -1235,10 +1232,9 @@ impl FileSystemPath { ...@@ -1235,10 +1232,9 @@ impl FileSystemPath {
/// extension. /// extension.
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn with_extension(&self, extension: RcStr) -> Result<Vc<FileSystemPath>> { pub async fn with_extension(&self, extension: RcStr) -> Result<Vc<FileSystemPath>> {
let this = self; let (path_without_extension, _) = self.split_extension();
let (path_without_extension, _) = this.split_extension();
Ok(Self::new_normalized( Ok(Self::new_normalized(
this.fs, self.fs,
// Like `Path::with_extension` and `PathBuf::set_extension`, if the extension is empty, // Like `Path::with_extension` and `PathBuf::set_extension`, if the extension is empty,
// we remove the extension altogether. // we remove the extension altogether.
match extension.is_empty() { match extension.is_empty() {
...@@ -1258,8 +1254,7 @@ impl FileSystemPath { ...@@ -1258,8 +1254,7 @@ impl FileSystemPath {
/// * Otherwise, the portion of the file name before the final `.` /// * Otherwise, the portion of the file name before the final `.`
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn file_stem(&self) -> Result<Vc<Option<RcStr>>> { pub async fn file_stem(&self) -> Result<Vc<Option<RcStr>>> {
let this = self; let (_, file_stem, _) = self.split_file_stem_extension();
let (_, file_stem, _) = this.split_file_stem_extension();
if file_stem.is_empty() { if file_stem.is_empty() {
return Ok(Vc::cell(None)); return Ok(Vc::cell(None));
} }
......
...@@ -87,9 +87,8 @@ impl Bools { ...@@ -87,9 +87,8 @@ impl Bools {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn into_bools(&self) -> Result<Vc<Vec<bool>>> { async fn into_bools(&self) -> Result<Vc<Vec<bool>>> {
let this = &self.0; let bools = self
.0
let bools = this
.iter() .iter()
.map(|b| b.into_future().map_ok(|b| *b)) .map(|b| b.into_future().map_ok(|b| *b))
.try_join() .try_join()
......
...@@ -56,11 +56,10 @@ impl EcmascriptDevChunkContent { ...@@ -56,11 +56,10 @@ impl EcmascriptDevChunkContent {
impl EcmascriptDevChunkContent { impl EcmascriptDevChunkContent {
#[turbo_tasks::function] #[turbo_tasks::function]
pub(crate) async fn own_version(&self) -> Result<Vc<EcmascriptDevChunkVersion>> { pub(crate) async fn own_version(&self) -> Result<Vc<EcmascriptDevChunkVersion>> {
let this = self;
Ok(EcmascriptDevChunkVersion::new( Ok(EcmascriptDevChunkVersion::new(
this.chunking_context.output_root(), self.chunking_context.output_root(),
this.chunk.ident().path(), self.chunk.ident().path(),
this.entries, self.entries,
)) ))
} }
......
...@@ -58,10 +58,9 @@ impl EcmascriptDevEvaluateChunk { ...@@ -58,10 +58,9 @@ impl EcmascriptDevEvaluateChunk {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn chunks_data(&self) -> Result<Vc<ChunksData>> { async fn chunks_data(&self) -> Result<Vc<ChunksData>> {
let this = self;
Ok(ChunkData::from_assets( Ok(ChunkData::from_assets(
this.chunking_context.output_root(), self.chunking_context.output_root(),
this.other_chunks, self.other_chunks,
)) ))
} }
......
...@@ -71,12 +71,10 @@ impl EcmascriptDevChunkListContent { ...@@ -71,12 +71,10 @@ impl EcmascriptDevChunkListContent {
/// Computes the version of this content. /// Computes the version of this content.
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn version(&self) -> Result<Vc<EcmascriptDevChunkListVersion>> { pub async fn version(&self) -> Result<Vc<EcmascriptDevChunkListVersion>> {
let this = self;
let mut by_merger = IndexMap::<_, Vec<_>>::new(); let mut by_merger = IndexMap::<_, Vec<_>>::new();
let mut by_path = IndexMap::<_, _>::new(); let mut by_path = IndexMap::<_, _>::new();
for (chunk_path, chunk_content) in &this.chunks_contents { for (chunk_path, chunk_content) in &self.chunks_contents {
if let Some(mergeable) = if let Some(mergeable) =
Vc::try_resolve_sidecast::<Box<dyn MergeableVersionedContent>>(*chunk_content) Vc::try_resolve_sidecast::<Box<dyn MergeableVersionedContent>>(*chunk_content)
.await? .await?
......
...@@ -66,14 +66,13 @@ impl AvailableChunkItems { ...@@ -66,14 +66,13 @@ impl AvailableChunkItems {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn hash(&self) -> Result<Vc<u64>> { pub async fn hash(&self) -> Result<Vc<u64>> {
let this = self;
let mut hasher = Xxh3Hash64Hasher::new(); let mut hasher = Xxh3Hash64Hasher::new();
if let Some(parent) = this.parent { if let Some(parent) = self.parent {
hasher.write_value(parent.hash().await?); hasher.write_value(parent.hash().await?);
} else { } else {
hasher.write_value(0u64); hasher.write_value(0u64);
} }
let item_idents = this let item_idents = self
.chunk_items .chunk_items
.await? .await?
.iter() .iter()
...@@ -91,11 +90,10 @@ impl AvailableChunkItems { ...@@ -91,11 +90,10 @@ impl AvailableChunkItems {
&self, &self,
chunk_item: Vc<Box<dyn ChunkItem>>, chunk_item: Vc<Box<dyn ChunkItem>>,
) -> Result<Vc<OptionAvailableChunkItemInfo>> { ) -> Result<Vc<OptionAvailableChunkItemInfo>> {
let this = self; if let Some(&info) = self.chunk_items.await?.get(&chunk_item) {
if let Some(&info) = this.chunk_items.await?.get(&chunk_item) {
return Ok(Vc::cell(Some(info))); return Ok(Vc::cell(Some(info)));
}; };
if let Some(parent) = this.parent { if let Some(parent) = self.parent {
return Ok(parent.get(chunk_item)); return Ok(parent.get(chunk_item));
} }
Ok(Vc::cell(None)) Ok(Vc::cell(None))
......
...@@ -67,8 +67,7 @@ pub enum ExecutionEnvironment { ...@@ -67,8 +67,7 @@ pub enum ExecutionEnvironment {
impl Environment { impl Environment {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn compile_target(&self) -> Result<Vc<CompileTarget>> { pub async fn compile_target(&self) -> Result<Vc<CompileTarget>> {
let this = self; Ok(match self.execution {
Ok(match this.execution {
ExecutionEnvironment::NodeJsBuildTime(node_env, ..) ExecutionEnvironment::NodeJsBuildTime(node_env, ..)
| ExecutionEnvironment::NodeJsLambda(node_env) => node_env.await?.compile_target, | ExecutionEnvironment::NodeJsLambda(node_env) => node_env.await?.compile_target,
ExecutionEnvironment::Browser(_) => CompileTarget::unknown(), ExecutionEnvironment::Browser(_) => CompileTarget::unknown(),
...@@ -79,8 +78,7 @@ impl Environment { ...@@ -79,8 +78,7 @@ impl Environment {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn runtime_versions(&self) -> Result<Vc<RuntimeVersions>> { pub async fn runtime_versions(&self) -> Result<Vc<RuntimeVersions>> {
let this = self; Ok(match self.execution {
Ok(match this.execution {
ExecutionEnvironment::NodeJsBuildTime(node_env, ..) ExecutionEnvironment::NodeJsBuildTime(node_env, ..)
| ExecutionEnvironment::NodeJsLambda(node_env) => node_env.runtime_versions(), | ExecutionEnvironment::NodeJsLambda(node_env) => node_env.runtime_versions(),
ExecutionEnvironment::Browser(browser_env) => { ExecutionEnvironment::Browser(browser_env) => {
...@@ -96,8 +94,7 @@ impl Environment { ...@@ -96,8 +94,7 @@ impl Environment {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn node_externals(&self) -> Result<Vc<bool>> { pub async fn node_externals(&self) -> Result<Vc<bool>> {
let this = self; Ok(match self.execution {
Ok(match this.execution {
ExecutionEnvironment::NodeJsBuildTime(..) | ExecutionEnvironment::NodeJsLambda(_) => { ExecutionEnvironment::NodeJsBuildTime(..) | ExecutionEnvironment::NodeJsLambda(_) => {
Vc::cell(true) Vc::cell(true)
} }
...@@ -109,8 +106,7 @@ impl Environment { ...@@ -109,8 +106,7 @@ impl Environment {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn supports_esm_externals(&self) -> Result<Vc<bool>> { pub async fn supports_esm_externals(&self) -> Result<Vc<bool>> {
let this = self; Ok(match self.execution {
Ok(match this.execution {
ExecutionEnvironment::NodeJsBuildTime(..) | ExecutionEnvironment::NodeJsLambda(_) => { ExecutionEnvironment::NodeJsBuildTime(..) | ExecutionEnvironment::NodeJsLambda(_) => {
Vc::cell(true) Vc::cell(true)
} }
...@@ -122,8 +118,7 @@ impl Environment { ...@@ -122,8 +118,7 @@ impl Environment {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn supports_commonjs_externals(&self) -> Result<Vc<bool>> { pub async fn supports_commonjs_externals(&self) -> Result<Vc<bool>> {
let this = self; Ok(match self.execution {
Ok(match this.execution {
ExecutionEnvironment::NodeJsBuildTime(..) | ExecutionEnvironment::NodeJsLambda(_) => { ExecutionEnvironment::NodeJsBuildTime(..) | ExecutionEnvironment::NodeJsLambda(_) => {
Vc::cell(true) Vc::cell(true)
} }
...@@ -135,8 +130,7 @@ impl Environment { ...@@ -135,8 +130,7 @@ impl Environment {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn supports_wasm(&self) -> Result<Vc<bool>> { pub async fn supports_wasm(&self) -> Result<Vc<bool>> {
let this = self; Ok(match self.execution {
Ok(match this.execution {
ExecutionEnvironment::NodeJsBuildTime(..) | ExecutionEnvironment::NodeJsLambda(_) => { ExecutionEnvironment::NodeJsBuildTime(..) | ExecutionEnvironment::NodeJsLambda(_) => {
Vc::cell(true) Vc::cell(true)
} }
......
...@@ -224,14 +224,13 @@ impl ValueToString for IssueProcessingPathItem { ...@@ -224,14 +224,13 @@ impl ValueToString for IssueProcessingPathItem {
impl IssueProcessingPathItem { impl IssueProcessingPathItem {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn into_plain(&self) -> Result<Vc<PlainIssueProcessingPathItem>> { pub async fn into_plain(&self) -> Result<Vc<PlainIssueProcessingPathItem>> {
let this = self;
Ok(PlainIssueProcessingPathItem { Ok(PlainIssueProcessingPathItem {
file_path: if let Some(context) = this.file_path { file_path: if let Some(context) = self.file_path {
Some(context.to_string().await?) Some(context.to_string().await?)
} else { } else {
None None
}, },
description: this.description.await?, description: self.description.await?,
} }
.cell()) .cell())
} }
...@@ -778,15 +777,14 @@ pub struct PlainIssueSource { ...@@ -778,15 +777,14 @@ pub struct PlainIssueSource {
impl IssueSource { impl IssueSource {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn into_plain(&self) -> Result<Vc<PlainIssueSource>> { pub async fn into_plain(&self) -> Result<Vc<PlainIssueSource>> {
let this = self;
Ok(PlainIssueSource { Ok(PlainIssueSource {
asset: PlainSource::from_source(this.source).await?, asset: PlainSource::from_source(self.source).await?,
range: match this.range { range: match self.range {
Some(range) => match &*range.await? { Some(range) => match &*range.await? {
SourceRange::LineColumn(start, end) => Some((*start, *end)), SourceRange::LineColumn(start, end) => Some((*start, *end)),
SourceRange::ByteOffset(start, end) => { SourceRange::ByteOffset(start, end) => {
if let FileLinesContent::Lines(lines) = if let FileLinesContent::Lines(lines) =
&*this.source.content().lines().await? &*self.source.content().lines().await?
{ {
let start = find_line_and_column(lines.as_ref(), *start); let start = find_line_and_column(lines.as_ref(), *start);
let end = find_line_and_column(lines.as_ref(), *end); let end = find_line_and_column(lines.as_ref(), *end);
......
...@@ -320,14 +320,12 @@ impl ModuleResolveResult { ...@@ -320,14 +320,12 @@ impl ModuleResolveResult {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn is_unresolveable(&self) -> Result<Vc<bool>> { pub async fn is_unresolveable(&self) -> Result<Vc<bool>> {
let this = self; Ok(Vc::cell(self.is_unresolveable_ref()))
Ok(Vc::cell(this.is_unresolveable_ref()))
} }
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn first_module(&self) -> Result<Vc<OptionModule>> { pub async fn first_module(&self) -> Result<Vc<OptionModule>> {
let this = self; Ok(Vc::cell(self.primary.iter().find_map(
Ok(Vc::cell(this.primary.iter().find_map(
|(_, item)| match item { |(_, item)| match item {
&ModuleResolveResultItem::Module(a) => Some(a), &ModuleResolveResultItem::Module(a) => Some(a),
_ => None, _ => None,
...@@ -339,8 +337,7 @@ impl ModuleResolveResult { ...@@ -339,8 +337,7 @@ impl ModuleResolveResult {
/// modules are already resolved Vc. /// modules are already resolved Vc.
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn primary_modules(&self) -> Result<Vc<Modules>> { pub async fn primary_modules(&self) -> Result<Vc<Modules>> {
let this = self; let mut iter = self.primary_modules_iter();
let mut iter = this.primary_modules_iter();
let Some(first) = iter.next() else { let Some(first) = iter.next() else {
return Ok(Vc::cell(vec![])); return Ok(Vc::cell(vec![]));
}; };
...@@ -353,7 +350,7 @@ impl ModuleResolveResult { ...@@ -353,7 +350,7 @@ impl ModuleResolveResult {
// We have at least two items, so we need to deduplicate them // We have at least two items, so we need to deduplicate them
let mut set = IndexSet::from([first, second]); let mut set = IndexSet::from([first, second]);
for module in this.primary_modules_iter() { for module in self.primary_modules_iter() {
set.insert(module.resolve().await?); set.insert(module.resolve().await?);
} }
Ok(Vc::cell(set.into_iter().collect())) Ok(Vc::cell(set.into_iter().collect()))
...@@ -361,9 +358,8 @@ impl ModuleResolveResult { ...@@ -361,9 +358,8 @@ impl ModuleResolveResult {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn primary_output_assets(&self) -> Result<Vc<OutputAssets>> { pub async fn primary_output_assets(&self) -> Result<Vc<OutputAssets>> {
let this = self;
Ok(Vc::cell( Ok(Vc::cell(
this.primary self.primary
.iter() .iter()
.filter_map(|(_, item)| match item { .filter_map(|(_, item)| match item {
&ModuleResolveResultItem::OutputAsset(a) => Some(a), &ModuleResolveResultItem::OutputAsset(a) => Some(a),
...@@ -852,14 +848,12 @@ impl ResolveResult { ...@@ -852,14 +848,12 @@ impl ResolveResult {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn is_unresolveable(&self) -> Result<Vc<bool>> { pub async fn is_unresolveable(&self) -> Result<Vc<bool>> {
let this = self; Ok(Vc::cell(self.is_unresolveable_ref()))
Ok(Vc::cell(this.is_unresolveable_ref()))
} }
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn first_source(&self) -> Result<Vc<OptionSource>> { pub async fn first_source(&self) -> Result<Vc<OptionSource>> {
let this = self; Ok(Vc::cell(self.primary.iter().find_map(|(_, item)| {
Ok(Vc::cell(this.primary.iter().find_map(|(_, item)| {
if let &ResolveResultItem::Source(a) = item { if let &ResolveResultItem::Source(a) = item {
Some(a) Some(a)
} else { } else {
...@@ -870,9 +864,8 @@ impl ResolveResult { ...@@ -870,9 +864,8 @@ impl ResolveResult {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn primary_sources(&self) -> Result<Vc<Sources>> { pub async fn primary_sources(&self) -> Result<Vc<Sources>> {
let this = self;
Ok(Vc::cell( Ok(Vc::cell(
this.primary self.primary
.iter() .iter()
.filter_map(|(_, item)| { .filter_map(|(_, item)| {
if let &ResolveResultItem::Source(a) = item { if let &ResolveResultItem::Source(a) = item {
...@@ -895,9 +888,8 @@ impl ResolveResult { ...@@ -895,9 +888,8 @@ impl ResolveResult {
old_request_key: RcStr, old_request_key: RcStr,
request_key: Value<RequestKey>, request_key: Value<RequestKey>,
) -> Result<Vc<Self>> { ) -> Result<Vc<Self>> {
let this = self;
let request_key = request_key.into_value(); let request_key = request_key.into_value();
let new_primary = this let new_primary = self
.primary .primary
.iter() .iter()
.filter_map(|(k, v)| { .filter_map(|(k, v)| {
...@@ -916,7 +908,7 @@ impl ResolveResult { ...@@ -916,7 +908,7 @@ impl ResolveResult {
.collect(); .collect();
Ok(ResolveResult { Ok(ResolveResult {
primary: new_primary, primary: new_primary,
affecting_sources: this.affecting_sources.clone(), affecting_sources: self.affecting_sources.clone(),
} }
.into()) .into())
} }
...@@ -933,8 +925,8 @@ impl ResolveResult { ...@@ -933,8 +925,8 @@ impl ResolveResult {
) -> Result<Vc<Self>> { ) -> Result<Vc<Self>> {
let old_request_key = &*old_request_key.await?; let old_request_key = &*old_request_key.await?;
let request_key = &*request_key.await?; let request_key = &*request_key.await?;
let this = self;
let new_primary = this let new_primary = self
.primary .primary
.iter() .iter()
.map(|(k, v)| { .map(|(k, v)| {
...@@ -953,7 +945,7 @@ impl ResolveResult { ...@@ -953,7 +945,7 @@ impl ResolveResult {
.collect(); .collect();
Ok(ResolveResult { Ok(ResolveResult {
primary: new_primary, primary: new_primary,
affecting_sources: this.affecting_sources.clone(), affecting_sources: self.affecting_sources.clone(),
} }
.into()) .into())
} }
...@@ -962,8 +954,7 @@ impl ResolveResult { ...@@ -962,8 +954,7 @@ impl ResolveResult {
/// passed `request`. /// passed `request`.
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn with_request(&self, request: RcStr) -> Result<Vc<Self>> { pub async fn with_request(&self, request: RcStr) -> Result<Vc<Self>> {
let this = self; let new_primary = self
let new_primary = this
.primary .primary
.iter() .iter()
.map(|(k, v)| { .map(|(k, v)| {
...@@ -978,7 +969,7 @@ impl ResolveResult { ...@@ -978,7 +969,7 @@ impl ResolveResult {
.collect(); .collect();
Ok(ResolveResult { Ok(ResolveResult {
primary: new_primary, primary: new_primary,
affecting_sources: this.affecting_sources.clone(), affecting_sources: self.affecting_sources.clone(),
} }
.into()) .into())
} }
......
...@@ -449,9 +449,8 @@ impl ResolvedMap { ...@@ -449,9 +449,8 @@ impl ResolvedMap {
lookup_path: Vc<FileSystemPath>, lookup_path: Vc<FileSystemPath>,
request: Vc<Request>, request: Vc<Request>,
) -> Result<Vc<ImportMapResult>> { ) -> Result<Vc<ImportMapResult>> {
let this = self;
let resolved = resolved.await?; let resolved = resolved.await?;
for (root, glob, mapping) in this.by_glob.iter() { for (root, glob, mapping) in self.by_glob.iter() {
let root = root.await?; let root = root.await?;
if let Some(path) = root.get_path_to(&resolved) { if let Some(path) = root.get_path_to(&resolved) {
if glob.await?.execute(path) { if glob.await?.execute(path) {
......
...@@ -23,9 +23,8 @@ impl AfterResolvePluginCondition { ...@@ -23,9 +23,8 @@ impl AfterResolvePluginCondition {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn matches(&self, fs_path: Vc<FileSystemPath>) -> Result<Vc<bool>> { pub async fn matches(&self, fs_path: Vc<FileSystemPath>) -> Result<Vc<bool>> {
let this = self; let root = self.root.await?;
let root = this.root.await?; let glob = self.glob.await?;
let glob = this.glob.await?;
let path = fs_path.await?; let path = fs_path.await?;
......
...@@ -251,8 +251,7 @@ pub struct VersionState { ...@@ -251,8 +251,7 @@ pub struct VersionState {
impl VersionState { impl VersionState {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn get(&self) -> Result<Vc<Box<dyn Version>>> { pub async fn get(&self) -> Result<Vc<Box<dyn Version>>> {
let this = self; let version = TraitRef::cell(self.version.get().clone());
let version = TraitRef::cell(this.version.get().clone());
Ok(version) Ok(version)
} }
} }
......
...@@ -233,11 +233,9 @@ fn chunk_item_key() -> Vc<RcStr> { ...@@ -233,11 +233,9 @@ fn chunk_item_key() -> Vc<RcStr> {
impl OutputAsset for CssChunk { impl OutputAsset for CssChunk {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn ident(&self) -> Result<Vc<AssetIdent>> { async fn ident(&self) -> Result<Vc<AssetIdent>> {
let this = self;
let mut assets = Vec::new(); let mut assets = Vec::new();
let CssChunkContent { chunk_items, .. } = &*this.content.await?; let CssChunkContent { chunk_items, .. } = &*self.content.await?;
let mut common_path = if let Some(chunk_item) = chunk_items.first() { let mut common_path = if let Some(chunk_item) = chunk_items.first() {
let path = chunk_item.asset_ident().path().resolve().await?; let path = chunk_item.asset_ident().path().resolve().await?;
Some((path, path.await?)) Some((path, path.await?))
...@@ -283,7 +281,7 @@ impl OutputAsset for CssChunk { ...@@ -283,7 +281,7 @@ impl OutputAsset for CssChunk {
layer: None, layer: None,
}; };
Ok(AssetIdent::from_path(this.chunking_context.chunk_path( Ok(AssetIdent::from_path(self.chunking_context.chunk_path(
AssetIdent::new(Value::new(ident)), AssetIdent::new(Value::new(ident)),
".css".into(), ".css".into(),
))) )))
......
...@@ -153,9 +153,8 @@ struct ModuleCssClasses(IndexMap<String, Vec<ModuleCssClass>>); ...@@ -153,9 +153,8 @@ struct ModuleCssClasses(IndexMap<String, Vec<ModuleCssClass>>);
impl ModuleCssAsset { impl ModuleCssAsset {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn inner(&self) -> Result<Vc<ProcessResult>> { async fn inner(&self) -> Result<Vc<ProcessResult>> {
let this = self; Ok(self.asset_context.process(
Ok(this.asset_context.process( self.source,
this.source,
Value::new(ReferenceType::Css(CssReferenceSubType::Internal)), Value::new(ReferenceType::Css(CssReferenceSubType::Internal)),
)) ))
} }
......
...@@ -127,9 +127,7 @@ impl DevHtmlAsset { ...@@ -127,9 +127,7 @@ impl DevHtmlAsset {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn chunks(&self) -> Result<Vc<OutputAssets>> { async fn chunks(&self) -> Result<Vc<OutputAssets>> {
let this = self; let all_assets = self
let all_assets = this
.entries .entries
.iter() .iter()
.map(|entry| async move { .map(|entry| async move {
...@@ -181,12 +179,10 @@ impl DevHtmlAssetContent { ...@@ -181,12 +179,10 @@ impl DevHtmlAssetContent {
impl DevHtmlAssetContent { impl DevHtmlAssetContent {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn content(&self) -> Result<Vc<AssetContent>> { async fn content(&self) -> Result<Vc<AssetContent>> {
let this = self;
let mut scripts = Vec::new(); let mut scripts = Vec::new();
let mut stylesheets = Vec::new(); let mut stylesheets = Vec::new();
for relative_path in &*this.chunk_paths { for relative_path in &*self.chunk_paths {
if relative_path.ends_with(".js") { if relative_path.ends_with(".js") {
scripts.push(format!("<script src=\"{}\"></script>", relative_path)); scripts.push(format!("<script src=\"{}\"></script>", relative_path));
} else if relative_path.ends_with(".css") { } else if relative_path.ends_with(".css") {
...@@ -199,7 +195,7 @@ impl DevHtmlAssetContent { ...@@ -199,7 +195,7 @@ impl DevHtmlAssetContent {
} }
} }
let body = match &this.body { let body = match &self.body {
Some(body) => body.as_str(), Some(body) => body.as_str(),
None => "", None => "",
}; };
......
...@@ -89,12 +89,11 @@ impl AssetGraphContentSource { ...@@ -89,12 +89,11 @@ impl AssetGraphContentSource {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn all_assets_map(&self) -> Result<Vc<OutputAssetsMap>> { async fn all_assets_map(&self) -> Result<Vc<OutputAssetsMap>> {
let this = self;
Ok(Vc::cell( Ok(Vc::cell(
expand( expand(
&*this.root_assets.await?, &*self.root_assets.await?,
&*this.root_path.await?, &*self.root_path.await?,
this.expanded.as_ref(), self.expanded.as_ref(),
) )
.await?, .await?,
)) ))
......
...@@ -31,14 +31,13 @@ pub struct AsyncLoaderChunkItem { ...@@ -31,14 +31,13 @@ pub struct AsyncLoaderChunkItem {
impl AsyncLoaderChunkItem { impl AsyncLoaderChunkItem {
#[turbo_tasks::function] #[turbo_tasks::function]
pub(super) async fn chunks(&self) -> Result<Vc<OutputAssets>> { pub(super) async fn chunks(&self) -> Result<Vc<OutputAssets>> {
let this = self; let module = self.module.await?;
let module = this.module.await?;
if let Some(chunk_items) = module.availability_info.available_chunk_items() { if let Some(chunk_items) = module.availability_info.available_chunk_items() {
if chunk_items if chunk_items
.get( .get(
module module
.inner .inner
.as_chunk_item(Vc::upcast(this.chunking_context)) .as_chunk_item(Vc::upcast(self.chunking_context))
.resolve() .resolve()
.await?, .await?,
) )
...@@ -48,7 +47,7 @@ impl AsyncLoaderChunkItem { ...@@ -48,7 +47,7 @@ impl AsyncLoaderChunkItem {
return Ok(Vc::cell(vec![])); return Ok(Vc::cell(vec![]));
} }
} }
Ok(this.chunking_context.chunk_group_assets( Ok(self.chunking_context.chunk_group_assets(
Vc::upcast(module.inner), Vc::upcast(module.inner),
Value::new(module.availability_info), Value::new(module.availability_info),
)) ))
......
...@@ -79,7 +79,6 @@ impl EcmascriptChunkItemContent { ...@@ -79,7 +79,6 @@ impl EcmascriptChunkItemContent {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn module_factory(&self) -> Result<Vc<Code>> { pub async fn module_factory(&self) -> Result<Vc<Code>> {
let this = self;
let mut args = vec![ let mut args = vec![
"r: __turbopack_require__", "r: __turbopack_require__",
"f: __turbopack_module_context__", "f: __turbopack_module_context__",
...@@ -99,55 +98,55 @@ impl EcmascriptChunkItemContent { ...@@ -99,55 +98,55 @@ impl EcmascriptChunkItemContent {
// HACK // HACK
"__dirname", "__dirname",
]; ];
if this.options.async_module.is_some() { if self.options.async_module.is_some() {
args.push("a: __turbopack_async_module__"); args.push("a: __turbopack_async_module__");
} }
if this.options.externals { if self.options.externals {
args.push("x: __turbopack_external_require__"); args.push("x: __turbopack_external_require__");
args.push("y: __turbopack_external_import__"); args.push("y: __turbopack_external_import__");
} }
if this.options.refresh { if self.options.refresh {
args.push("k: __turbopack_refresh__"); args.push("k: __turbopack_refresh__");
} }
if this.options.module || this.options.refresh { if self.options.module || self.options.refresh {
args.push("m: module"); args.push("m: module");
} }
if this.options.exports { if self.options.exports {
args.push("e: exports"); args.push("e: exports");
} }
if this.options.stub_require { if self.options.stub_require {
args.push("z: require"); args.push("z: require");
} else { } else {
args.push("t: require"); args.push("t: require");
} }
if this.options.wasm { if self.options.wasm {
args.push("w: __turbopack_wasm__"); args.push("w: __turbopack_wasm__");
args.push("u: __turbopack_wasm_module__"); args.push("u: __turbopack_wasm_module__");
} }
let mut code = CodeBuilder::default(); let mut code = CodeBuilder::default();
let args = FormatIter(|| args.iter().copied().intersperse(", ")); let args = FormatIter(|| args.iter().copied().intersperse(", "));
if this.options.this { if self.options.this {
code += "(function(__turbopack_context__) {\n"; code += "(function(__turbopack_context__) {\n";
} else { } else {
code += "((__turbopack_context__) => {\n"; code += "((__turbopack_context__) => {\n";
} }
if this.options.strict { if self.options.strict {
code += "\"use strict\";\n\n"; code += "\"use strict\";\n\n";
} else { } else {
code += "\n"; code += "\n";
} }
writeln!(code, "var {{ {} }} = __turbopack_context__;", args)?; writeln!(code, "var {{ {} }} = __turbopack_context__;", args)?;
if this.options.async_module.is_some() { if self.options.async_module.is_some() {
code += "__turbopack_async_module__(async (__turbopack_handle_async_dependencies__, \ code += "__turbopack_async_module__(async (__turbopack_handle_async_dependencies__, \
__turbopack_async_result__) => { try {\n"; __turbopack_async_result__) => { try {\n";
} else { } else {
code += "{\n"; code += "{\n";
} }
code.push_source(&this.inner_code, this.source_map); code.push_source(&self.inner_code, self.source_map);
if let Some(opts) = &this.options.async_module { if let Some(opts) = &self.options.async_module {
write!( write!(
code, code,
"__turbopack_async_result__();\n}} catch(e) {{ __turbopack_async_result__(e); }} \ "__turbopack_async_result__();\n}} catch(e) {{ __turbopack_async_result__(e); }} \
......
...@@ -77,11 +77,9 @@ fn availability_root_key() -> Vc<RcStr> { ...@@ -77,11 +77,9 @@ fn availability_root_key() -> Vc<RcStr> {
impl Chunk for EcmascriptChunk { impl Chunk for EcmascriptChunk {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn ident(&self) -> Result<Vc<AssetIdent>> { async fn ident(&self) -> Result<Vc<AssetIdent>> {
let this = self;
let mut assets = Vec::new(); let mut assets = Vec::new();
let EcmascriptChunkContent { chunk_items, .. } = &*this.content.await?; let EcmascriptChunkContent { chunk_items, .. } = &*self.content.await?;
let mut common_path = if let Some((chunk_item, _)) = chunk_items.first() { let mut common_path = if let Some((chunk_item, _)) = chunk_items.first() {
let path = chunk_item.asset_ident().path().resolve().await?; let path = chunk_item.asset_ident().path().resolve().await?;
Some((path, path.await?)) Some((path, path.await?))
...@@ -136,8 +134,7 @@ impl Chunk for EcmascriptChunk { ...@@ -136,8 +134,7 @@ impl Chunk for EcmascriptChunk {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn references(&self) -> Result<Vc<OutputAssets>> { async fn references(&self) -> Result<Vc<OutputAssets>> {
let this = self; let content = self.content.await?;
let content = this.content.await?;
Ok(Vc::cell(content.referenced_output_assets.clone())) Ok(Vc::cell(content.referenced_output_assets.clone()))
} }
} }
......
...@@ -125,8 +125,7 @@ struct ChunkGroupFilesChunkItem { ...@@ -125,8 +125,7 @@ struct ChunkGroupFilesChunkItem {
impl ChunkGroupFilesChunkItem { impl ChunkGroupFilesChunkItem {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn chunks(&self) -> Result<Vc<OutputAssets>> { async fn chunks(&self) -> Result<Vc<OutputAssets>> {
let this = self; let inner = self.inner.await?;
let inner = this.inner.await?;
let chunks = if let Some(ecma) = let chunks = if let Some(ecma) =
Vc::try_resolve_sidecast::<Box<dyn EvaluatableAsset>>(inner.module).await? Vc::try_resolve_sidecast::<Box<dyn EvaluatableAsset>>(inner.module).await?
{ {
......
...@@ -53,10 +53,9 @@ impl ManifestAsyncModule { ...@@ -53,10 +53,9 @@ impl ManifestAsyncModule {
#[turbo_tasks::function] #[turbo_tasks::function]
pub(super) async fn chunks(&self) -> Result<Vc<OutputAssets>> { pub(super) async fn chunks(&self) -> Result<Vc<OutputAssets>> {
let this = self; Ok(self
Ok(this
.chunking_context .chunking_context
.chunk_group_assets(Vc::upcast(this.inner), Value::new(this.availability_info))) .chunk_group_assets(Vc::upcast(self.inner), Value::new(self.availability_info)))
} }
#[turbo_tasks::function] #[turbo_tasks::function]
......
...@@ -30,10 +30,9 @@ pub(super) struct ManifestChunkItem { ...@@ -30,10 +30,9 @@ pub(super) struct ManifestChunkItem {
impl ManifestChunkItem { impl ManifestChunkItem {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn chunks_data(&self) -> Result<Vc<ChunksData>> { async fn chunks_data(&self) -> Result<Vc<ChunksData>> {
let this = self;
Ok(ChunkData::from_assets( Ok(ChunkData::from_assets(
this.chunking_context.output_root(), self.chunking_context.output_root(),
this.manifest.chunks(), self.manifest.chunks(),
)) ))
} }
} }
......
...@@ -59,10 +59,9 @@ impl ManifestLoaderChunkItem { ...@@ -59,10 +59,9 @@ impl ManifestLoaderChunkItem {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn chunks_data(&self) -> Result<Vc<ChunksData>> { pub async fn chunks_data(&self) -> Result<Vc<ChunksData>> {
let this = self; let chunks = self.manifest.manifest_chunks();
let chunks = this.manifest.manifest_chunks();
Ok(ChunkData::from_assets( Ok(ChunkData::from_assets(
this.chunking_context.output_root(), self.chunking_context.output_root(),
chunks, chunks,
)) ))
} }
......
...@@ -154,9 +154,8 @@ impl CodeGenerateable for EsmBindings { ...@@ -154,9 +154,8 @@ impl CodeGenerateable for EsmBindings {
&self, &self,
_context: Vc<Box<dyn ChunkingContext>>, _context: Vc<Box<dyn ChunkingContext>>,
) -> Result<Vc<CodeGeneration>> { ) -> Result<Vc<CodeGeneration>> {
let this = self;
let mut visitors = Vec::new(); let mut visitors = Vec::new();
let bindings = this.bindings.clone(); let bindings = self.bindings.clone();
for item in bindings.into_iter() { for item in bindings.into_iter() {
item.to_visitors(&mut visitors).await?; item.to_visitors(&mut visitors).await?;
......
...@@ -48,8 +48,7 @@ impl StaticEcmascriptCode { ...@@ -48,8 +48,7 @@ impl StaticEcmascriptCode {
/// the code builder, including the source map if available. /// the code builder, including the source map if available.
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn code(&self) -> Result<Vc<Code>> { pub async fn code(&self) -> Result<Vc<Code>> {
let this = self; let runtime_base_content = self.asset.module_content_without_analysis().await?;
let runtime_base_content = this.asset.module_content_without_analysis().await?;
let mut code = CodeBuilder::default(); let mut code = CodeBuilder::default();
code.push_source( code.push_source(
&runtime_base_content.inner_code, &runtime_base_content.inner_code,
......
...@@ -34,16 +34,14 @@ pub struct EcmascriptModulePartAsset { ...@@ -34,16 +34,14 @@ pub struct EcmascriptModulePartAsset {
impl EcmascriptParsable for EcmascriptModulePartAsset { impl EcmascriptParsable for EcmascriptModulePartAsset {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn failsafe_parse(&self) -> Result<Vc<ParseResult>> { async fn failsafe_parse(&self) -> Result<Vc<ParseResult>> {
let this = self; let parsed = self.full_module.failsafe_parse();
let parsed = this.full_module.failsafe_parse();
let split_data = split( let split_data = split(
this.full_module.ident(), self.full_module.ident(),
this.full_module.source(), self.full_module.source(),
parsed, parsed,
this.full_module.options().await?.special_exports, self.full_module.options().await?.special_exports,
); );
Ok(part_of_module(split_data, this.part)) Ok(part_of_module(split_data, self.part))
} }
#[turbo_tasks::function] #[turbo_tasks::function]
fn parse_original(&self) -> Result<Vc<ParseResult>> { fn parse_original(&self) -> Result<Vc<ParseResult>> {
...@@ -60,9 +58,8 @@ impl EcmascriptParsable for EcmascriptModulePartAsset { ...@@ -60,9 +58,8 @@ impl EcmascriptParsable for EcmascriptModulePartAsset {
impl EcmascriptAnalyzable for EcmascriptModulePartAsset { impl EcmascriptAnalyzable for EcmascriptModulePartAsset {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn analyze(&self) -> Result<Vc<AnalyzeEcmascriptModuleResult>> { async fn analyze(&self) -> Result<Vc<AnalyzeEcmascriptModuleResult>> {
let this = self; let part = self.part;
let part = this.part; Ok(analyse_ecmascript_module(self.full_module, Some(part)))
Ok(analyse_ecmascript_module(this.full_module, Some(part)))
} }
#[turbo_tasks::function] #[turbo_tasks::function]
...@@ -225,9 +222,7 @@ impl ChunkableModule for EcmascriptModulePartAsset { ...@@ -225,9 +222,7 @@ impl ChunkableModule for EcmascriptModulePartAsset {
impl EcmascriptModulePartAsset { impl EcmascriptModulePartAsset {
#[turbo_tasks::function] #[turbo_tasks::function]
pub(super) async fn analyze(&self) -> Result<Vc<AnalyzeEcmascriptModuleResult>> { pub(super) async fn analyze(&self) -> Result<Vc<AnalyzeEcmascriptModuleResult>> {
let this = self; Ok(analyze(self.full_module, self.part))
Ok(analyze(this.full_module, this.part))
} }
} }
......
...@@ -35,13 +35,12 @@ impl EcmascriptChunkItem for EcmascriptModulePartChunkItem { ...@@ -35,13 +35,12 @@ impl EcmascriptChunkItem for EcmascriptModulePartChunkItem {
&self, &self,
async_module_info: Option<Vc<AsyncModuleInfo>>, async_module_info: Option<Vc<AsyncModuleInfo>>,
) -> Result<Vc<EcmascriptChunkItemContent>> { ) -> Result<Vc<EcmascriptChunkItemContent>> {
let this = self; let module = self.module.await?;
let module = this.module.await?;
let split_data = split_module(module.full_module); let split_data = split_module(module.full_module);
let parsed = part_of_module(split_data, module.part); let parsed = part_of_module(split_data, module.part);
let analyze = this.module.analyze().await?; let analyze = self.module.analyze().await?;
let async_module_options = analyze.async_module.module_options(async_module_info); let async_module_options = analyze.async_module.module_options(async_module_info);
let module_type_result = *module.full_module.determine_module_type().await?; let module_type_result = *module.full_module.determine_module_type().await?;
...@@ -50,7 +49,7 @@ impl EcmascriptChunkItem for EcmascriptModulePartChunkItem { ...@@ -50,7 +49,7 @@ impl EcmascriptChunkItem for EcmascriptModulePartChunkItem {
parsed, parsed,
module.full_module.ident(), module.full_module.ident(),
module_type_result.module_type, module_type_result.module_type,
this.chunking_context, self.chunking_context,
analyze.references, analyze.references,
analyze.code_generation, analyze.code_generation,
analyze.async_module, analyze.async_module,
...@@ -61,7 +60,7 @@ impl EcmascriptChunkItem for EcmascriptModulePartChunkItem { ...@@ -61,7 +60,7 @@ impl EcmascriptChunkItem for EcmascriptModulePartChunkItem {
Ok(EcmascriptChunkItemContent::new( Ok(EcmascriptChunkItemContent::new(
content, content,
this.chunking_context, self.chunking_context,
module.full_module.await?.options, module.full_module.await?.options,
async_module_options, async_module_options,
)) ))
......
...@@ -36,8 +36,7 @@ pub fn worker_modifier() -> Vc<RcStr> { ...@@ -36,8 +36,7 @@ pub fn worker_modifier() -> Vc<RcStr> {
impl WorkerLoaderChunkItem { impl WorkerLoaderChunkItem {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn chunks(&self) -> Result<Vc<OutputAssets>> { async fn chunks(&self) -> Result<Vc<OutputAssets>> {
let this = self; let module = self.module.await?;
let module = this.module.await?;
let Some(evaluatable) = let Some(evaluatable) =
Vc::try_resolve_downcast::<Box<dyn EvaluatableAsset>>(module.inner).await? Vc::try_resolve_downcast::<Box<dyn EvaluatableAsset>>(module.inner).await?
...@@ -48,9 +47,9 @@ impl WorkerLoaderChunkItem { ...@@ -48,9 +47,9 @@ impl WorkerLoaderChunkItem {
); );
}; };
Ok(this.chunking_context.evaluated_chunk_group_assets( Ok(self.chunking_context.evaluated_chunk_group_assets(
AssetIdent::from_path( AssetIdent::from_path(
this.chunking_context self.chunking_context
.chunk_path(module.inner.ident(), ".js".into()), .chunk_path(module.inner.ident(), ".js".into()),
) )
.with_modifier(worker_modifier()), .with_modifier(worker_modifier()),
......
...@@ -135,9 +135,8 @@ impl Asset for MdxTransformedAsset { ...@@ -135,9 +135,8 @@ impl Asset for MdxTransformedAsset {
impl MdxTransformedAsset { impl MdxTransformedAsset {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn process(&self) -> Result<Vc<MdxTransformResult>> { async fn process(&self) -> Result<Vc<MdxTransformResult>> {
let this = self; let content = self.source.content().await?;
let content = this.source.content().await?; let transform_options = self.options.await?;
let transform_options = this.options.await?;
let AssetContent::File(file) = &*content else { let AssetContent::File(file) = &*content else {
anyhow::bail!("Unexpected mdx asset content"); anyhow::bail!("Unexpected mdx asset content");
...@@ -175,7 +174,7 @@ impl MdxTransformedAsset { ...@@ -175,7 +174,7 @@ impl MdxTransformedAsset {
.jsx_import_source .jsx_import_source
.clone() .clone()
.map(RcStr::into_owned), .map(RcStr::into_owned),
filepath: Some(this.source.ident().path().await?.to_string()), filepath: Some(self.source.ident().path().await?.to_string()),
..Default::default() ..Default::default()
}; };
...@@ -210,11 +209,11 @@ impl MdxTransformedAsset { ...@@ -210,11 +209,11 @@ impl MdxTransformedAsset {
} }
}; };
IssueSource::from_line_col(this.source, start, end) IssueSource::from_line_col(self.source, start, end)
}); });
MdxIssue { MdxIssue {
path: this.source.ident().path(), path: self.source.ident().path(),
loc, loc,
reason: err.reason, reason: err.reason,
mdx_rule_id: *err.rule_id, mdx_rule_id: *err.rule_id,
......
...@@ -129,11 +129,9 @@ impl SourceMapTrace { ...@@ -129,11 +129,9 @@ impl SourceMapTrace {
/// serialization. /// serialization.
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn trace(&self) -> Result<Vc<TraceResult>> { pub async fn trace(&self) -> Result<Vc<TraceResult>> {
let this = self; let token = self
let token = this
.map .map
.lookup_token(this.line.saturating_sub(1), this.column.saturating_sub(1)) .lookup_token(self.line.saturating_sub(1), self.column.saturating_sub(1))
.await?; .await?;
let result = match &*token { let result = match &*token {
Token::Original(t) => TraceResult::Found(StackFrame { Token::Original(t) => TraceResult::Found(StackFrame {
...@@ -143,7 +141,7 @@ impl SourceMapTrace { ...@@ -143,7 +141,7 @@ impl SourceMapTrace {
name: t name: t
.name .name
.clone() .clone()
.or_else(|| this.name.clone()) .or_else(|| self.name.clone())
.map(|v| v.into_owned()) .map(|v| v.into_owned())
.map(Cow::Owned), .map(Cow::Owned),
}), }),
......
...@@ -425,12 +425,11 @@ impl GenerateSourceMap for PostCssTransformedAsset { ...@@ -425,12 +425,11 @@ impl GenerateSourceMap for PostCssTransformedAsset {
impl PostCssTransformedAsset { impl PostCssTransformedAsset {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn process(&self) -> Result<Vc<ProcessPostCssResult>> { async fn process(&self) -> Result<Vc<ProcessPostCssResult>> {
let this = self;
let ExecutionContext { let ExecutionContext {
project_path, project_path,
chunking_context, chunking_context,
env, env,
} = *this.execution_context.await?; } = *self.execution_context.await?;
// For this postcss transform, there is no gaurantee that looking up for the // For this postcss transform, there is no gaurantee that looking up for the
// source path will arrives specific project config for the postcss. // source path will arrives specific project config for the postcss.
...@@ -444,16 +443,16 @@ impl PostCssTransformedAsset { ...@@ -444,16 +443,16 @@ impl PostCssTransformedAsset {
// //
// We look for the config in the project path first, then the source path // We look for the config in the project path first, then the source path
let Some(config_path) = let Some(config_path) =
find_config_in_location(project_path, this.config_location, this.source).await? find_config_in_location(project_path, self.config_location, self.source).await?
else { else {
return Ok(ProcessPostCssResult { return Ok(ProcessPostCssResult {
content: this.source.content(), content: self.source.content(),
assets: Vec::new(), assets: Vec::new(),
} }
.cell()); .cell());
}; };
let source_content = this.source.content(); let source_content = self.source.content();
let AssetContent::File(file) = *source_content.await? else { let AssetContent::File(file) = *source_content.await? else {
bail!("PostCSS transform only support transforming files"); bail!("PostCSS transform only support transforming files");
}; };
...@@ -465,14 +464,14 @@ impl PostCssTransformedAsset { ...@@ -465,14 +464,14 @@ impl PostCssTransformedAsset {
.cell()); .cell());
}; };
let content = content.content().to_str()?; let content = content.content().to_str()?;
let evaluate_context = this.evaluate_context; let evaluate_context = self.evaluate_context;
// This invalidates the transform when the config changes. // This invalidates the transform when the config changes.
let config_changed = config_changed(evaluate_context, config_path); let config_changed = config_changed(evaluate_context, config_path);
let postcss_executor = let postcss_executor =
postcss_executor(evaluate_context, project_path, config_path).module(); postcss_executor(evaluate_context, project_path, config_path).module();
let css_fs_path = this.source.ident().path(); let css_fs_path = self.source.ident().path();
// We need to get a path relative to the project because the postcss loader // We need to get a path relative to the project because the postcss loader
// runs with the project as the current working directory. // runs with the project as the current working directory.
...@@ -490,7 +489,7 @@ impl PostCssTransformedAsset { ...@@ -490,7 +489,7 @@ impl PostCssTransformedAsset {
module_asset: postcss_executor, module_asset: postcss_executor,
cwd: project_path, cwd: project_path,
env, env,
context_ident_for_issue: this.source.ident(), context_ident_for_issue: self.source.ident(),
asset_context: evaluate_context, asset_context: evaluate_context,
chunking_context, chunking_context,
resolve_options_context: None, resolve_options_context: None,
......
...@@ -110,12 +110,11 @@ impl EcmascriptBuildNodeChunkContent { ...@@ -110,12 +110,11 @@ impl EcmascriptBuildNodeChunkContent {
#[turbo_tasks::function] #[turbo_tasks::function]
pub(crate) async fn own_version(&self) -> Result<Vc<EcmascriptBuildNodeChunkVersion>> { pub(crate) async fn own_version(&self) -> Result<Vc<EcmascriptBuildNodeChunkVersion>> {
let this = self;
Ok(EcmascriptBuildNodeChunkVersion::new( Ok(EcmascriptBuildNodeChunkVersion::new(
this.chunking_context.output_root(), self.chunking_context.output_root(),
this.chunk.ident().path(), self.chunk.ident().path(),
this.content, self.content,
this.chunking_context.await?.minify_type(), self.chunking_context.await?.minify_type(),
)) ))
} }
} }
......
...@@ -145,8 +145,7 @@ impl EcmascriptBuildNodeEntryChunk { ...@@ -145,8 +145,7 @@ impl EcmascriptBuildNodeEntryChunk {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn runtime_chunk(&self) -> Result<Vc<EcmascriptBuildNodeRuntimeChunk>> { async fn runtime_chunk(&self) -> Result<Vc<EcmascriptBuildNodeRuntimeChunk>> {
let this = self; Ok(EcmascriptBuildNodeRuntimeChunk::new(self.chunking_context))
Ok(EcmascriptBuildNodeRuntimeChunk::new(this.chunking_context))
} }
} }
......
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