Validate return value
This commit is contained in:
parent
7bac376599
commit
608fcb42be
|
@ -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,
|
||||||
|
|
Loading…
Reference in New Issue