Validate return value

This commit is contained in:
Adria Navarro 2025-02-19 12:24:19 +01:00
parent 7bac376599
commit 608fcb42be
1 changed files with 13 additions and 0 deletions

View File

@ -25,7 +25,11 @@ export function validateJsTemplate(
offset += line.length + 1 // +1 for newline character offset += line.length + 1 // +1 for newline character
} }
let hasReturnStatement = false
walk(ast, { walk(ast, {
ReturnStatement(node) {
hasReturnStatement = !!node.argument
},
CallExpression(node) { CallExpression(node) {
const callee: any = node.callee const callee: any = node.callee
if ( if (
@ -67,6 +71,15 @@ export function validateJsTemplate(
} }
}, },
}) })
if (!hasReturnStatement) {
diagnostics.push({
from: 0,
to: code.length,
severity: "error",
message: "Your code must return a value.",
})
}
} catch (e: any) { } catch (e: any) {
diagnostics.push({ diagnostics.push({
from: 0, from: 0,