MCPcopy Index your code
hub / github.com/zenstackhq/zenstack / getFunctionExpressionContext

Function getFunctionExpressionContext

packages/language/src/utils.ts:416–430  ·  view source on GitHub ↗
(funcDecl: FunctionDecl)

Source from the content-addressed store, hash-verified

414 * Returns an empty array if no such attribute is found or if the attribute value cannot be determined.
415 */
416export function getFunctionExpressionContext(funcDecl: FunctionDecl) {
417 const funcAllowedContext: ExpressionContext[] = [];
418 const funcAttr = funcDecl.attributes.find((attr) => attr.decl.$refText === '@@@expressionContext');
419 if (funcAttr) {
420 const contextArg = funcAttr.args[0]?.value;
421 if (isArrayExpr(contextArg)) {
422 contextArg.items.forEach((item) => {
423 if (isEnumFieldReference(item)) {
424 funcAllowedContext.push(item.target.$refText as ExpressionContext);
425 }
426 });
427 }
428 }
429 return funcAllowedContext;
430}
431
432/**
433 * Gets the data field referenced by the given expression, if any. Returns `undefined` if the expression is not a reference to a data field.

Callers 1

validateMethod · 0.90

Calls 4

isArrayExprFunction · 0.90
isEnumFieldReferenceFunction · 0.85
findMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected