Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: micro perf improve #835

Merged
merged 2 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion crates/mako/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,13 @@ fn transform_js(

// preset-env and other folders must be after plugin transform
// because plugin transform may inject some code that may need syntax transform
ast.body = folders.fold_module(ast.clone()).body;
let body = ast.body.take();
let module = Module {
span: ast.span,
shebang: ast.shebang.clone(),
body,
};
ast.body = folders.fold_module(module).body;

// inject helpers must after decorators
// since decorators will use helpers
Expand Down
8 changes: 4 additions & 4 deletions crates/mako/src/transform_in_generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,17 @@ pub fn transform_modules_in_thread(
insert_swc_helper_replace(&mut resolved_deps, &context);
let module = module_graph.get_module(&module_id).unwrap();
let info = module.info.as_ref().unwrap();
let ast = &mut info.ast.clone();
let ast = info.ast.clone();
let deps_to_replace = DependenciesToReplace {
resolved: resolved_deps,
missing: info.missing_deps.clone(),
ignored: info.ignored_deps.clone(),
};
if let ModuleAst::Script(ast) = ast {
if let ModuleAst::Script(mut ast) = ast {
let ret = transform_js_generate(TransformJsParam {
module_id: &module.id,
context: &context,
ast,
ast: &mut ast,
dep_map: &deps_to_replace,
async_deps: &async_deps,
wrap_async: info.is_async && info.external.is_none(),
Expand All @@ -143,7 +143,7 @@ pub fn transform_modules_in_thread(
} else {
Some(SwcHelpers::get_swc_helpers(&ast.ast, &context))
};
Ok((module_id, ModuleAst::Script(ast.clone()), swc_helpers))
Ok((module_id, ModuleAst::Script(ast), swc_helpers))
}
Err(e) => Err(e),
};
Expand Down