Skip to content

Commit 94c4e5d

Browse files
authored
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 . ```
1 parent 1cb6faa commit 94c4e5d

File tree

42 files changed

+149
-233
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+149
-233
lines changed

crates/next-api/src/middleware.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,10 @@ impl MiddlewareEndpoint {
256256

257257
#[turbo_tasks::function]
258258
async fn userland_module(&self) -> Result<Vc<Box<dyn Module>>> {
259-
let this = self;
260-
261-
Ok(this
259+
Ok(self
262260
.asset_context
263261
.process(
264-
this.source,
262+
self.source,
265263
Value::new(ReferenceType::Entry(EntryReferenceSubType::Middleware)),
266264
)
267265
.module())

crates/next-api/src/pages.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -641,8 +641,7 @@ impl PageEndpoint {
641641

642642
#[turbo_tasks::function]
643643
async fn source(&self) -> Result<Vc<Box<dyn Source>>> {
644-
let this = self;
645-
Ok(Vc::upcast(FileSource::new(this.page.project_path())))
644+
Ok(Vc::upcast(FileSource::new(self.page.project_path())))
646645
}
647646

648647
#[turbo_tasks::function]
@@ -949,8 +948,7 @@ impl PageEndpoint {
949948
&self,
950949
entry_chunk: Vc<Box<dyn OutputAsset>>,
951950
) -> Result<Vc<Box<dyn OutputAsset>>> {
952-
let this = self;
953-
let node_root = this.pages_project.project().node_root();
951+
let node_root = self.pages_project.project().node_root();
954952
let chunk_path = entry_chunk.ident().path().await?;
955953

956954
let asset_path = node_root
@@ -960,11 +958,11 @@ impl PageEndpoint {
960958
.context("ssr chunk entry path must be inside the node root")?;
961959

962960
let pages_manifest = PagesManifest {
963-
pages: [(this.pathname.await?.clone_value(), asset_path.into())]
961+
pages: [(self.pathname.await?.clone_value(), asset_path.into())]
964962
.into_iter()
965963
.collect(),
966964
};
967-
let manifest_path_prefix = get_asset_prefix_from_pathname(&this.pathname.await?);
965+
let manifest_path_prefix = get_asset_prefix_from_pathname(&self.pathname.await?);
968966
Ok(Vc::upcast(VirtualOutputAsset::new(
969967
node_root
970968
.join(format!("server/pages{manifest_path_prefix}/pages-manifest.json",).into()),
@@ -994,13 +992,12 @@ impl PageEndpoint {
994992
&self,
995993
client_chunks: Vc<OutputAssets>,
996994
) -> Result<Vc<Box<dyn OutputAsset>>> {
997-
let this = self;
998-
let node_root = this.pages_project.project().node_root();
999-
let client_relative_path = this.pages_project.project().client_relative_path();
995+
let node_root = self.pages_project.project().node_root();
996+
let client_relative_path = self.pages_project.project().client_relative_path();
1000997
let client_relative_path_ref = client_relative_path.await?;
1001998
let build_manifest = BuildManifest {
1002999
pages: [(
1003-
this.pathname.await?.clone_value(),
1000+
self.pathname.await?.clone_value(),
10041001
client_chunks
10051002
.await?
10061003
.iter()
@@ -1022,7 +1019,7 @@ impl PageEndpoint {
10221019
.collect(),
10231020
..Default::default()
10241021
};
1025-
let manifest_path_prefix = get_asset_prefix_from_pathname(&this.pathname.await?);
1022+
let manifest_path_prefix = get_asset_prefix_from_pathname(&self.pathname.await?);
10261023
Ok(Vc::upcast(VirtualOutputAsset::new(
10271024
node_root
10281025
.join(format!("server/pages{manifest_path_prefix}/build-manifest.json",).into()),

crates/next-api/src/project.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,6 @@ impl ProjectContainer {
302302
impl ProjectContainer {
303303
#[turbo_tasks::function]
304304
pub async fn project(&self) -> Result<Vc<Project>> {
305-
let this = self;
306-
307305
let env_map: Vc<EnvMap>;
308306
let next_config;
309307
let define_env;
@@ -317,7 +315,7 @@ impl ProjectContainer {
317315
let preview_props;
318316
let browserslist_query;
319317
{
320-
let options = this.options_state.get();
318+
let options = self.options_state.get();
321319
let options = options
322320
.as_ref()
323321
.context("ProjectContainer need to be initialized with initialize()")?;
@@ -361,7 +359,7 @@ impl ProjectContainer {
361359
} else {
362360
NextMode::Build.cell()
363361
},
364-
versioned_content_map: this.versioned_content_map,
362+
versioned_content_map: self.versioned_content_map,
365363
build_id,
366364
encryption_key,
367365
preview_props,
@@ -518,13 +516,12 @@ impl Project {
518516

519517
#[turbo_tasks::function]
520518
async fn project_fs(&self) -> Result<Vc<DiskFileSystem>> {
521-
let this = self;
522519
let disk_fs = DiskFileSystem::new(
523520
PROJECT_FILESYSTEM_NAME.into(),
524-
this.root_path.clone(),
521+
self.root_path.clone(),
525522
vec![],
526523
);
527-
if this.watch {
524+
if self.watch {
528525
disk_fs.await?.start_watching_with_invalidation_reason()?;
529526
}
530527
Ok(disk_fs)
@@ -538,8 +535,7 @@ impl Project {
538535

539536
#[turbo_tasks::function]
540537
pub async fn output_fs(&self) -> Result<Vc<DiskFileSystem>> {
541-
let this = self;
542-
let disk_fs = DiskFileSystem::new("output".into(), this.project_path.clone(), vec![]);
538+
let disk_fs = DiskFileSystem::new("output".into(), self.project_path.clone(), vec![]);
543539
Ok(disk_fs)
544540
}
545541

crates/next-core/src/app_structure.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -733,8 +733,7 @@ struct DuplicateParallelRouteIssue {
733733
impl Issue for DuplicateParallelRouteIssue {
734734
#[turbo_tasks::function]
735735
async fn file_path(&self) -> Result<Vc<FileSystemPath>> {
736-
let this = self;
737-
Ok(this.app_dir.join(this.page.to_string().into()))
736+
Ok(self.app_dir.join(self.page.to_string().into()))
738737
}
739738

740739
#[turbo_tasks::function]

crates/next-core/src/next_config.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -847,8 +847,7 @@ impl NextConfig {
847847
&self,
848848
active_conditions: Vec<RcStr>,
849849
) -> Result<Vc<OptionWebpackRules>> {
850-
let this = self;
851-
let Some(turbo_rules) = this
850+
let Some(turbo_rules) = self
852851
.experimental
853852
.turbo
854853
.as_ref()
@@ -936,8 +935,7 @@ impl NextConfig {
936935

937936
#[turbo_tasks::function]
938937
pub async fn resolve_alias_options(&self) -> Result<Vc<ResolveAliasMap>> {
939-
let this = self;
940-
let Some(resolve_alias) = this
938+
let Some(resolve_alias) = self
941939
.experimental
942940
.turbo
943941
.as_ref()
@@ -951,8 +949,7 @@ impl NextConfig {
951949

952950
#[turbo_tasks::function]
953951
pub async fn resolve_extension(&self) -> Result<Vc<ResolveExtensions>> {
954-
let this = self;
955-
let Some(resolve_extensions) = this
952+
let Some(resolve_extensions) = self
956953
.experimental
957954
.turbo
958955
.as_ref()
@@ -1148,8 +1145,7 @@ impl NextConfig {
11481145

11491146
#[turbo_tasks::function]
11501147
pub async fn module_id_strategy_config(&self) -> Result<Vc<OptionModuleIdStrategy>> {
1151-
let this = self;
1152-
let Some(module_id_strategy) = this
1148+
let Some(module_id_strategy) = self
11531149
.experimental
11541150
.turbo
11551151
.as_ref()

crates/next-core/src/next_dynamic/dynamic_module.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ impl NextDynamicEntryModule {
3333
&self,
3434
client_chunking_context: Vc<Box<dyn ChunkingContext>>,
3535
) -> Result<Vc<OutputAssets>> {
36-
let this = self;
37-
3836
let Some(client_entry_module) =
39-
Vc::try_resolve_sidecast::<Box<dyn ChunkableModule>>(this.client_entry_module).await?
37+
Vc::try_resolve_sidecast::<Box<dyn ChunkableModule>>(self.client_entry_module).await?
4038
else {
4139
bail!("dynamic client asset must be chunkable");
4240
};

crates/next-core/src/next_server_component/server_component_module.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ impl NextServerComponentModule {
4747

4848
#[turbo_tasks::function]
4949
pub async fn server_path(&self) -> Result<Vc<FileSystemPath>> {
50-
let this = self;
51-
Ok(this.module.ident().path())
50+
Ok(self.module.ident().path())
5251
}
5352
}
5453

@@ -144,12 +143,11 @@ impl EcmascriptChunkItem for NextServerComponentChunkItem {
144143

145144
#[turbo_tasks::function]
146145
async fn content(&self) -> Result<Vc<EcmascriptChunkItemContent>> {
147-
let this = self;
148-
let inner = this.inner.await?;
146+
let inner = self.inner.await?;
149147

150148
let module_id = inner
151149
.module
152-
.as_chunk_item(Vc::upcast(this.chunking_context))
150+
.as_chunk_item(Vc::upcast(self.chunking_context))
153151
.id()
154152
.await?;
155153
Ok(EcmascriptChunkItemContent {

crates/next-core/src/page_loader.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ impl PageLoaderAsset {
9999
&self,
100100
rebase_prefix_path: Vc<FileSystemPathOption>,
101101
) -> Result<Vc<ChunksData>> {
102-
let this = self;
103-
let mut chunks = this.page_chunks;
102+
let mut chunks = self.page_chunks;
104103

105104
// If we are provided a prefix path, we need to rewrite our chunk paths to
106105
// remove that prefix.
@@ -119,7 +118,7 @@ impl PageLoaderAsset {
119118
chunks = Vc::cell(rebased);
120119
};
121120

122-
Ok(ChunkData::from_assets(this.server_root, chunks))
121+
Ok(ChunkData::from_assets(self.server_root, chunks))
123122
}
124123
}
125124

turbopack/crates/turbo-tasks-env/src/dotenv.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ impl DotenvProcessEnv {
2525

2626
#[turbo_tasks::function]
2727
pub async fn read_prior(&self) -> Result<Vc<EnvMap>> {
28-
let this = self;
29-
match this.prior {
28+
match self.prior {
3029
None => Ok(EnvMap::empty()),
3130
Some(p) => Ok(p.read_all()),
3231
}

turbopack/crates/turbo-tasks-fs/src/lib.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,10 +1171,9 @@ impl FileSystemPath {
11711171
/// None when the joined path would leave the filesystem root.
11721172
#[turbo_tasks::function]
11731173
pub async fn try_join(&self, path: RcStr) -> Result<Vc<FileSystemPathOption>> {
1174-
let this = self;
1175-
if let Some(path) = join_path(&this.path, &path) {
1174+
if let Some(path) = join_path(&self.path, &path) {
11761175
Ok(Vc::cell(Some(
1177-
Self::new_normalized(this.fs, path.into()).resolve().await?,
1176+
Self::new_normalized(self.fs, path.into()).resolve().await?,
11781177
)))
11791178
} else {
11801179
Ok(FileSystemPathOption::none())
@@ -1185,11 +1184,10 @@ impl FileSystemPath {
11851184
/// None when the joined path would leave the current path.
11861185
#[turbo_tasks::function]
11871186
pub async fn try_join_inside(&self, path: RcStr) -> Result<Vc<FileSystemPathOption>> {
1188-
let this = self;
1189-
if let Some(path) = join_path(&this.path, &path) {
1190-
if path.starts_with(&*this.path) {
1187+
if let Some(path) = join_path(&self.path, &path) {
1188+
if path.starts_with(&*self.path) {
11911189
return Ok(Vc::cell(Some(
1192-
Self::new_normalized(this.fs, path.into()).resolve().await?,
1190+
Self::new_normalized(self.fs, path.into()).resolve().await?,
11931191
)));
11941192
}
11951193
}
@@ -1217,8 +1215,7 @@ impl FileSystemPath {
12171215

12181216
#[turbo_tasks::function]
12191217
pub async fn extension(&self) -> Result<Vc<RcStr>> {
1220-
let this = self;
1221-
Ok(Vc::cell(this.extension_ref().unwrap_or("").into()))
1218+
Ok(Vc::cell(self.extension_ref().unwrap_or("").into()))
12221219
}
12231220

12241221
#[turbo_tasks::function]
@@ -1235,10 +1232,9 @@ impl FileSystemPath {
12351232
/// extension.
12361233
#[turbo_tasks::function]
12371234
pub async fn with_extension(&self, extension: RcStr) -> Result<Vc<FileSystemPath>> {
1238-
let this = self;
1239-
let (path_without_extension, _) = this.split_extension();
1235+
let (path_without_extension, _) = self.split_extension();
12401236
Ok(Self::new_normalized(
1241-
this.fs,
1237+
self.fs,
12421238
// Like `Path::with_extension` and `PathBuf::set_extension`, if the extension is empty,
12431239
// we remove the extension altogether.
12441240
match extension.is_empty() {
@@ -1258,8 +1254,7 @@ impl FileSystemPath {
12581254
/// * Otherwise, the portion of the file name before the final `.`
12591255
#[turbo_tasks::function]
12601256
pub async fn file_stem(&self) -> Result<Vc<Option<RcStr>>> {
1261-
let this = self;
1262-
let (_, file_stem, _) = this.split_file_stem_extension();
1257+
let (_, file_stem, _) = self.split_file_stem_extension();
12631258
if file_stem.is_empty() {
12641259
return Ok(Vc::cell(None));
12651260
}

0 commit comments

Comments
 (0)