fix(coding-agent): 等待最终 Promise 表达式

This commit is contained in:
jiwangyihao
2026-05-13 02:24:10 +02:00
committed by can1357
parent 3af9369536
commit efbf6b3833
2 changed files with 16 additions and 1 deletions
@@ -29,6 +29,7 @@ type BabelExpressionStatement = {
type: "ExpressionStatement";
start: number;
end: number;
expression?: { type?: string };
};
type BabelProgramNode = BabelImportDeclaration | BabelLexicalDecl | BabelExpressionStatement | { type: string };
@@ -186,7 +187,10 @@ function returnFinalExpression(code: string): { source: string; returned: boolea
const suffix = code.slice(expression.end);
const semicolonMatch = statement.match(/;\s*$/);
const trimmedStatement = semicolonMatch ? statement.slice(0, semicolonMatch.index) : statement;
return { source: `${prefix}__omp_display__(${trimmedStatement});${suffix}`, returned: true };
const needsAwait =
expression.expression?.type === "AwaitExpression" || expression.expression?.type === "CallExpression";
const displayExpression = needsAwait ? `await (${trimmedStatement})` : trimmedStatement;
return { source: `${prefix}__omp_display__(${displayExpression});${suffix}`, returned: true };
}
/**