From 3bb6b1e35308e6cfc9ccf077622e04d656c219af Mon Sep 17 00:00:00 2001 From: pjh456 <147148383@qq.com> Date: Sat, 26 Sep 2026 20:41:52 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=80=BB=E8=BE=91=E5=BF=AB=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E5=AE=89=E5=85=A8=E9=9B=86=E5=88=A0=E6=A0=87=E8=AF=86?= =?UTF-8?q?=E7=AC=A6=E8=87=82=EF=BC=8C=E6=81=A2=E5=A4=8D=20&&/||/=3F=3F=20?= =?UTF-8?q?=E7=9F=AD=E8=B7=AF=E8=AF=AD=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/oxide_emit/src/emit.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/oxide_emit/src/emit.rs b/crates/oxide_emit/src/emit.rs index bcfbfd85..17db1254 100644 --- a/crates/oxide_emit/src/emit.rs +++ b/crates/oxide_emit/src/emit.rs @@ -39,9 +39,10 @@ pub fn is_int_literal(value: f64) -> bool { value.fract() == 0.0 && value >= i32::MIN as f64 && value <= i32::MAX as f64 } -/// 判断表达式是否无副作用(字面量/标识符/纯二元运算等)。 -/// 用于可丢弃值的优化路径。 -/// 逻辑运算符快速路径的"无副作用"判定:仅字面量/标识符/this 读取安全。 +/// 判断表达式是否无副作用:仅字面量/this/RegExp 读取安全。 +/// 逻辑运算符快速路径的"无副作用"判定:左右两侧均安全时右值可急切发射 +/// (三操作数 AND/OR/NULLISH 指令)。标识符读可能抛 ReferenceError(未声明名/ +/// TDZ),不得判为无副作用,否则左值 falsy 时右值被求值破坏短路。 /// 算术表达式(`1 / a` 等)不得判为无副作用——对象操作数强转(ToNumber 触发 /// valueOf/toString/getter)可能在运行期抛错,急切求值会破坏 `||`/`&&` 短路。 pub fn is_side_effect_free(expr: &Expression) -> bool { @@ -52,7 +53,6 @@ pub fn is_side_effect_free(expr: &Expression) -> bool { | Expression::StringLiteral(_) | Expression::BooleanLiteral(_) | Expression::NullLiteral(_) - | Expression::Identifier(_) | Expression::RegExpLiteral(_) | Expression::ThisExpression(_) => {} Expression::ParenthesizedExpression(p) => stack.push(&p.expression),