Skip to content
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
21 changes: 11 additions & 10 deletions crates/oxc_minifier/src/peephole/fold_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,12 +411,14 @@ impl<'a> PeepholeOptimizations {
.quasis
.first_mut()
.expect("template literal must have at least one quasi");
let new_raw = left_last_quasi.value.raw.to_string() + &right_first_quasi.value.raw;
left_last_quasi.value.raw = ctx.ast.atom(&new_raw);
left_last_quasi.value.raw = ctx.ast.atom_from_strs_array([
left_last_quasi.value.raw.as_str(),
right_first_quasi.value.raw.as_str(),
]);
let new_cooked = if let (Some(cooked1), Some(cooked2)) =
(left_last_quasi.value.cooked, right_first_quasi.value.cooked)
{
Some(ctx.ast.atom(&(cooked1.into_string() + cooked2.as_str())))
Some(ctx.ast.atom_from_strs_array([cooked1.as_str(), cooked2.as_str()]))
} else {
None
};
Expand Down Expand Up @@ -744,16 +746,15 @@ impl<'a> PeepholeOptimizations {
let idx = idx - i;
let next_quasi = (idx + 1 < t.quasis.len()).then(|| t.quasis.remove(idx + 1));
let quasi = &mut t.quasis[idx];
let new_raw = quasi.value.raw.into_string()
+ &Self::escape_string_for_template_literal(&str)
+ next_quasi.as_ref().map(|q| q.value.raw.as_str()).unwrap_or_default();
quasi.value.raw = ctx.ast.atom(&new_raw);
let escaped = Self::escape_string_for_template_literal(&str);
let next_raw = next_quasi.as_ref().map(|q| q.value.raw.as_str()).unwrap_or_default();
quasi.value.raw =
ctx.ast.atom_from_strs_array([quasi.value.raw.as_str(), &escaped, next_raw]);
let new_cooked = if let (Some(cooked1), Some(cooked2)) =
(quasi.value.cooked, next_quasi.as_ref().map(|q| q.value.cooked))
{
let v =
cooked1.into_string() + &str + cooked2.map(|c| c.as_str()).unwrap_or_default();
Some(ctx.ast.atom(&v))
let cooked2_str = cooked2.map(|c| c.as_str()).unwrap_or_default();
Some(ctx.ast.atom_from_strs_array([cooked1.as_str(), &str, cooked2_str]))
} else {
None
};
Expand Down
6 changes: 3 additions & 3 deletions tasks/track_memory_allocations/allocs_minifier.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ File | File size || Sys allocs | Sys reallocs |
-------------------------------------------------------------------------------------------------------------------------------------------
checker.ts | 2.92 MB || 329 | 37 || 152600 | 28244

cal.com.tsx | 1.06 MB || 20245 | 52 || 37141 | 4583
cal.com.tsx | 1.06 MB || 20239 | 46 || 37141 | 4583

RadixUIAdoptionSection.jsx | 2.52 kB || 34 | 6 || 30 | 6

pdf.mjs | 567.30 kB || 3995 | 417 || 47464 | 7734
pdf.mjs | 567.30 kB || 3993 | 417 || 47464 | 7734

antd.js | 6.69 MB || 7755 | 1661 || 331638 | 69344
antd.js | 6.69 MB || 7751 | 1657 || 331638 | 69344

binder.ts | 193.08 kB || 78 | 23 || 7075 | 824

Loading