Skip to content

Commit 50c62d1

Browse files
authoredMar 24, 2025··
feat(es/minifier): Allow disabling char frequency analysis (#10259)
**Description:** This is required for next.js
1 parent 28cc6f6 commit 50c62d1

File tree

6 files changed

+28
-6
lines changed

6 files changed

+28
-6
lines changed
 

‎.changeset/tasty-lies-notice.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
swc_ecma_minifier: major
3+
---
4+
5+
feat(es/minifier): Allow disabling char frequency analysis

‎crates/swc_ecma_minifier/src/lib.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,16 @@ pub fn optimize(
227227

228228
let preserved = idents_to_preserve(mangle, marks, &n);
229229

230-
let chars = CharFreq::compute(
231-
&n,
232-
&preserved,
233-
SyntaxContext::empty().apply_mark(marks.unresolved_mark),
234-
)
235-
.compile();
230+
let chars = if !mangle.disable_char_freq {
231+
CharFreq::compute(
232+
&n,
233+
&preserved,
234+
SyntaxContext::empty().apply_mark(marks.unresolved_mark),
235+
)
236+
.compile()
237+
} else {
238+
CharFreq::default().compile()
239+
};
236240

237241
mangle_names(
238242
&mut n,

‎crates/swc_ecma_minifier/src/option/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ pub struct MangleOptions {
9090
/// mangle names visible in scopes where eval or with are used
9191
#[serde(default)]
9292
pub eval: bool,
93+
94+
/// Disable char frequency analysis.
95+
#[serde(default)]
96+
pub disable_char_freq: bool,
9397
}
9498

9599
#[derive(Debug, Clone, Default, Serialize, Deserialize, Merge)]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
var foo;
3+
var bar = 2;
4+
var baz;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"disableCharFreq": true,
3+
"toplevel": true
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var a, b, c = 2;

0 commit comments

Comments
 (0)
Please sign in to comment.