diff --git a/src/translator.ts b/src/translator.ts index 7f077a4..8202b63 100644 --- a/src/translator.ts +++ b/src/translator.ts @@ -407,11 +407,13 @@ export class JsonTemplateTranslator { code.push(JsonTemplateTranslator.generateAssignmentCode(result, ctx)); if (expr.object) { code.push(this.translateExpr(expr.object, result, ctx)); + code.push(`if(${JsonTemplateTranslator.returnIsNotEmpty(result)}){`); } - code.push(`if(${JsonTemplateTranslator.returnIsNotEmpty(result)}){`); const functionArgsStr = this.translateSpreadableExpressions(expr.args, result, code); code.push(result, '=', this.getFunctionName(expr, result), '(', functionArgsStr, ');'); - code.push('}'); + if (expr.object) { + code.push('}'); + } code.push(JsonTemplateTranslator.generateAssignmentCode(dest, result)); this.releaseVars(result); return code.join(''); diff --git a/test/scenarios/functions/data.ts b/test/scenarios/functions/data.ts index 6174146..8ec97ad 100644 --- a/test/scenarios/functions/data.ts +++ b/test/scenarios/functions/data.ts @@ -26,6 +26,16 @@ export const data: Scenario[] = [ templatePath: 'parent_scope_vars.jt', output: 90, }, + { + templatePath: 'promise.jt', + input: [1, 2], + output: [1, 2], + }, + { + templatePath: 'promise.jt', + input: { a: 1 }, + output: { a: 1 }, + }, { output: 80, }, diff --git a/test/scenarios/functions/promise.jt b/test/scenarios/functions/promise.jt new file mode 100644 index 0000000..eb81941 --- /dev/null +++ b/test/scenarios/functions/promise.jt @@ -0,0 +1,3 @@ +await new Promise(function(resolve) { + setTimeout(lambda resolve(^), 100) +}); \ No newline at end of file