Skip to content

Commit bb544ba

Browse files
authoredNov 15, 2022
fix(es/minifier): Fix code for dropping unreachable statements (#6429)
**Related issue:** - Closes #6405.
1 parent e117bc4 commit bb544ba

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed
 

‎crates/swc_ecma_minifier/src/compress/pure/dead_code.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -269,15 +269,7 @@ impl Pure<'_> {
269269
);
270270
}
271271

272-
match stmts[idx].as_stmt() {
273-
Some(Stmt::Return(ReturnStmt { arg: None, .. })) => {
274-
// Exclude return
275-
new_stmts.extend(stmts.drain(..idx));
276-
}
277-
_ => {
278-
new_stmts.extend(stmts.drain(..=idx));
279-
}
280-
}
272+
new_stmts.extend(stmts.drain(..=idx));
281273

282274
new_stmts.extend(hoisted_fns);
283275

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export const fn = () => {
2+
let val;
3+
4+
if (!val) {
5+
return undefined;
6+
// works as expected if comment out below line
7+
throw new Error('first');
8+
}
9+
10+
if (val.a?.b !== true) { // Uncaught TypeError: Cannot read properties of undefined (reading 'a')
11+
throw new Error('second');
12+
}
13+
return val;
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const fn = ()=>{
2+
let val;
3+
if (!!val) {
4+
if (val.a?.b !== !0) throw Error('second');
5+
return val;
6+
}
7+
};

0 commit comments

Comments
 (0)