depyo 1.2.3 → 1.2.5
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.
- package/lib/ast/ast_node.js +22 -2
- package/lib/handlers/misc_other.js +6 -9
- package/package.json +1 -1
package/lib/ast/ast_node.js
CHANGED
|
@@ -1120,10 +1120,30 @@ class ASTStore extends ASTNode {
|
|
|
1120
1120
|
}
|
|
1121
1121
|
}
|
|
1122
1122
|
|
|
1123
|
-
let methodBody = codeObject.SourceCode.codeFragment();
|
|
1124
1123
|
if (inLambda) {
|
|
1125
|
-
|
|
1124
|
+
// issue #12: lambda body must render as an expression. Going
|
|
1125
|
+
// through ASTNodeList.codeFragment would emit "pass" for a single
|
|
1126
|
+
// `return None` (emptyBlock heuristic) and crash on a truly empty
|
|
1127
|
+
// body (3.12/3.13 RETURN_CONST None). Render the single ASTReturn
|
|
1128
|
+
// directly via its inLambda path; fall back to "None".
|
|
1129
|
+
const stmts = (codeObject.SourceCode?.list || []).filter(n => n);
|
|
1130
|
+
if (stmts.length === 1 && stmts[0] instanceof ASTReturn) {
|
|
1131
|
+
stmts[0].inLambda = true;
|
|
1132
|
+
const frag = stmts[0].codeFragment();
|
|
1133
|
+
const body = (frag && frag.toString().trim()) || "None";
|
|
1134
|
+
result.lastLineAppend(body);
|
|
1135
|
+
} else if (stmts.length > 0) {
|
|
1136
|
+
const methodBody = codeObject.SourceCode.codeFragment();
|
|
1137
|
+
if (methodBody && methodBody.toString().trim()) {
|
|
1138
|
+
result.lastLineAppend(methodBody);
|
|
1139
|
+
} else {
|
|
1140
|
+
result.lastLineAppend("None");
|
|
1141
|
+
}
|
|
1142
|
+
} else {
|
|
1143
|
+
result.lastLineAppend("None");
|
|
1144
|
+
}
|
|
1126
1145
|
} else {
|
|
1146
|
+
let methodBody = codeObject.SourceCode.codeFragment();
|
|
1127
1147
|
const bodyHasContent = methodBody && methodBody.toString().trim().length;
|
|
1128
1148
|
const hasGlobals = codeObject.Globals && codeObject.Globals.size > 0;
|
|
1129
1149
|
if (bodyHasContent) {
|
|
@@ -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)) {
|