depyo 1.2.3 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1116,17 +1116,14 @@ function handleReturnValue() {
|
|
|
1116
1116
|
|
|
1117
1117
|
if (!this.currentCase && [AST.ASTBlock.BlockType.If, AST.ASTBlock.BlockType.Else].includes(this.curBlock.blockType)
|
|
1118
1118
|
&& (this.object.Reader.versionCompare(2, 6) >= 0)) {
|
|
1119
|
-
|
|
1119
|
+
// issue #3: do NOT fold `if cond: return x` into `return cond and x`.
|
|
1120
|
+
// The closing jump for a real if-return is POP_JUMP_IF_FALSE (non-sticky)
|
|
1121
|
+
// and the rewrite drops the `x` return path when x is falsy (e.g. 0, None, "").
|
|
1122
|
+
// Legitimate short-circuit `cond and x` is already handled via JUMP_IF_FALSE_OR_POP
|
|
1123
|
+
// in control_flow_jumps, so keeping the if-block here is always correct.
|
|
1124
|
+
const prev = this.curBlock;
|
|
1120
1125
|
this.blocks.pop();
|
|
1121
1126
|
this.curBlock = this.blocks.top();
|
|
1122
|
-
if (
|
|
1123
|
-
prev instanceof AST.ASTCondBlock &&
|
|
1124
|
-
prev.nodes.length == 1 &&
|
|
1125
|
-
prev.line == value.line
|
|
1126
|
-
) {
|
|
1127
|
-
prev = new AST.ASTReturn(new AST.ASTBinary(prev.condition, value, prev.negative ? AST.ASTBinary.BinOp.LogicalOr : AST.ASTBinary.BinOp.LogicalAnd));
|
|
1128
|
-
}
|
|
1129
|
-
|
|
1130
1127
|
this.curBlock.append(prev);
|
|
1131
1128
|
|
|
1132
1129
|
if ([this.OpCodes.JUMP_ABSOLUTE_A, this.OpCodes.JUMP_FORWARD_A].includes(this.code.Next?.OpCodeID)) {
|