* Convert a LabelExpression AST node to a StepCondition. * Supports: LabelName, LabelOr, LabelAnd, LabelNot, LabelWildcard
(expr: LabelExpression)
| 1981 | * Supports: LabelName, LabelOr, LabelAnd, LabelNot, LabelWildcard |
| 1982 | */ |
| 1983 | function convertLabelExpression(expr: LabelExpression): StepCondition { |
| 1984 | switch (expr.type) { |
| 1985 | case "LabelName": |
| 1986 | return ["=", "@label", expr.name] as StepCondition; |
| 1987 | |
| 1988 | case "LabelOr": |
| 1989 | return [ |
| 1990 | "or", |
| 1991 | convertLabelExpression(expr.left), |
| 1992 | convertLabelExpression(expr.right), |
| 1993 | ] as StepCondition; |
| 1994 | |
| 1995 | case "LabelAnd": |
| 1996 | return [ |
| 1997 | "and", |
| 1998 | convertLabelExpression(expr.left), |
| 1999 | convertLabelExpression(expr.right), |
| 2000 | ] as StepCondition; |
| 2001 | |
| 2002 | case "LabelNot": |
| 2003 | return ["not", convertLabelExpression(expr.expression)] as StepCondition; |
| 2004 | |
| 2005 | case "LabelWildcard": |
| 2006 | // Wildcard matches any label - represented as "has a label" check |
| 2007 | return ["labelWildcard"] as StepCondition; |
| 2008 | |
| 2009 | default: { |
| 2010 | // Exhaustive check |
| 2011 | const _exhaustive: never = expr; |
| 2012 | throw new Error(`Unknown label expression type: ${(_exhaustive as any).type}`); |
| 2013 | } |
| 2014 | } |
| 2015 | } |
| 2016 | |
| 2017 | /** |
| 2018 | * Create a label condition from either simple labels or a label expression. |
no outgoing calls
no test coverage detected