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
10 changes: 8 additions & 2 deletions crates/oxc_minifier/src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use oxc_span::format_atom;
use oxc_syntax::{
identifier::{is_identifier_part, is_identifier_start},
reference::ReferenceId,
scope::ScopeFlags,
};
use oxc_traverse::Ancestor;

Expand Down Expand Up @@ -196,9 +197,14 @@ impl<'a> Ctx<'a, '_> {
}
}

let scope_id = self.scoping.current_scope_id();
let scope_id = self.scoping().symbol_scope_id(symbol_id);
let scope_flags = self.scoping().scope_flags(scope_id);

let initialized_constant =
if scope_flags.contains(ScopeFlags::DirectEval) { None } else { constant };

let symbol_value = SymbolValue {
initialized_constant: constant,
initialized_constant,
exported,
read_references_count,
write_references_count,
Expand Down
11 changes: 11 additions & 0 deletions crates/oxc_minifier/tests/peephole/inline_single_use_variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ fn test_inline_single_use_variable() {
test_same("async function wrapper(arg0, arg1) { await using x = foo; return x}");
test_same("function wrapper(arg0) { eval('x'); var x = arg0; return x }");

test("{ let _; eval('_ = () => 1'); _() }", "{ let _; eval('_ = () => 1'), _() }");
test("{ let x = 1; eval('x = 2'); log(x) }", "{ let x = 1; eval('x = 2'), log(x) }");
test(
"function f() { let x; eval('x = 1'); return x }",
"function f() { let x; return eval('x = 1'), x }",
);
test(
"function f() { { let y; var x; } eval('x = 1'); return x }",
"function f() { { let y; var x; } return eval('x = 1'), x }",
);

test(
"
class Foo {
Expand Down
Loading