Skip to content

Commit e96f462

Browse files
authored
Merge branch 'canary' into verify-cache-busting-param
2 parents 1b702ae + dcd5ed0 commit e96f462

File tree

3 files changed

+6
-29
lines changed

3 files changed

+6
-29
lines changed

turbopack/crates/turbopack-ecmascript/src/code_gen.rs

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use anyhow::Result;
22
use serde::{Deserialize, Serialize};
33
use swc_core::ecma::{
44
ast::{
5-
BlockStmt, CallExpr, Expr, Lit, MemberExpr, ModuleDecl, ModuleItem, Pass, Pat, Prop,
5+
BlockStmt, CallExpr, Expr, Lit, MemberExpr, ModuleDecl, ModuleItem, Pat, Program, Prop,
66
SimpleAssignTarget, Stmt, Str, SwitchCase,
77
},
88
visit::AstParentKind,
@@ -38,7 +38,6 @@ use crate::references::{
3838
#[derive(Default)]
3939
pub struct CodeGeneration {
4040
/// ast nodes matching the span will be visitor by the visitor
41-
pub root_visitors: Vec<Box<dyn PassFactory>>,
4241
pub visitors: Vec<(Vec<AstParentKind>, Box<dyn AstModifier>)>,
4342
pub hoisted_stmts: Vec<CodeGenerationHoistedStmt>,
4443
pub early_hoisted_stmts: Vec<CodeGenerationHoistedStmt>,
@@ -52,34 +51,18 @@ impl CodeGeneration {
5251
}
5352

5453
pub fn new(
55-
root_visitors: Vec<Box<dyn PassFactory>>,
5654
visitors: Vec<(Vec<AstParentKind>, Box<dyn AstModifier>)>,
5755
hoisted_stmts: Vec<CodeGenerationHoistedStmt>,
5856
early_hoisted_stmts: Vec<CodeGenerationHoistedStmt>,
5957
) -> Self {
6058
CodeGeneration {
61-
root_visitors,
6259
visitors,
6360
hoisted_stmts,
6461
early_hoisted_stmts,
6562
}
6663
}
6764

68-
pub fn root_visitors(root_visitors: Vec<Box<dyn PassFactory>>) -> Self {
69-
CodeGeneration {
70-
root_visitors,
71-
..Default::default()
72-
}
73-
}
74-
7565
pub fn visitors(visitors: Vec<(Vec<AstParentKind>, Box<dyn AstModifier>)>) -> Self {
76-
#[cfg(debug_assertions)]
77-
for (path, _) in visitors.iter() {
78-
if path.is_empty() {
79-
unreachable!("if the path is empty, the visitor should be a root visitor");
80-
}
81-
}
82-
8366
CodeGeneration {
8467
visitors,
8568
..Default::default()
@@ -113,10 +96,6 @@ impl CodeGenerationHoistedStmt {
11396
}
11497
}
11598

116-
pub trait PassFactory: Send + Sync {
117-
fn create<'a>(&'a self) -> Box<dyn Pass + Send + Sync + 'a>;
118-
}
119-
12099
macro_rules! method {
121100
($name:ident, $T:ty) => {
122101
fn $name(&self, _node: &mut $T) {}
@@ -137,6 +116,7 @@ pub trait AstModifier: Send + Sync {
137116
method!(visit_mut_str, Str);
138117
method!(visit_mut_block_stmt, BlockStmt);
139118
method!(visit_mut_switch_case, SwitchCase);
119+
method!(visit_mut_program, Program);
140120
}
141121

142122
pub trait ModifiableAst {
@@ -166,6 +146,7 @@ impl_modify!(visit_mut_lit, Lit);
166146
impl_modify!(visit_mut_str, Str);
167147
impl_modify!(visit_mut_block_stmt, BlockStmt);
168148
impl_modify!(visit_mut_switch_case, SwitchCase);
149+
impl_modify!(visit_mut_program, Program);
169150

170151
#[derive(PartialEq, Eq, Serialize, Deserialize, TraceRawVcs, ValueDebugFormat, NonLocalValue)]
171152
pub enum CodeGen {

turbopack/crates/turbopack-ecmascript/src/lib.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub use turbopack_resolve::ecmascript as resolve;
9494
use self::chunk::{EcmascriptChunkItemContent, EcmascriptChunkType, EcmascriptExports};
9595
use crate::{
9696
chunk::{EcmascriptChunkPlaceable, placeable::is_marked_as_side_effect_free},
97-
code_gen::CodeGens,
97+
code_gen::{CodeGens, ModifiableAst},
9898
parse::generate_js_source_map,
9999
references::{
100100
analyse_ecmascript_module, async_module::OptionAsyncModule, esm::base::EsmAssetReferences,
@@ -1172,13 +1172,10 @@ fn process_content_with_code_gens(
11721172
for CodeGenerationHoistedStmt { key, stmt } in code_gen.early_hoisted_stmts.drain(..) {
11731173
early_hoisted_stmts.insert(key.clone(), stmt);
11741174
}
1175-
for visitor in &code_gen.root_visitors {
1176-
root_visitors.push(visitor.create());
1177-
}
11781175

11791176
for (path, visitor) in &code_gen.visitors {
11801177
if path.is_empty() {
1181-
unreachable!("if the path is empty, the visitor should be a root visitor");
1178+
root_visitors.push(&**visitor);
11821179
} else {
11831180
visitors.push((path, &**visitor));
11841181
}
@@ -1193,7 +1190,7 @@ fn process_content_with_code_gens(
11931190
);
11941191
}
11951192
for pass in root_visitors {
1196-
program.mutate(pass);
1193+
program.modify(pass);
11971194
}
11981195
program.visit_mut_with(
11991196
&mut swc_core::ecma::transforms::base::hygiene::hygiene_with_config(

turbopack/crates/turbopack-ecmascript/src/references/esm/export.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,6 @@ impl EsmExports {
678678
};
679679

680680
Ok(CodeGeneration::new(
681-
vec![],
682681
vec![],
683682
[dynamic_stmt
684683
.map(|stmt| CodeGenerationHoistedStmt::new("__turbopack_dynamic__".into(), stmt))]

0 commit comments

Comments
 (0)