MCPcopy Create free account
hub / github.com/angular/dev-infra / transformExpressionToJs

Function transformExpressionToJs

ng-dev/pullapprove/condition_evaluator.ts:256–263  ·  view source on GitHub ↗

* Transforms a condition expression from PullApprove that is based on python * so that it can be run inside JavaScript. Current transformations: * * 1. `aExpr not in bExpr` --> `!bExpr.includes(aExpr)` * 2. `aExpr in bExpr` --> `bExpr.includes(aExpr`) * 3. `not expr` --> `!e

(expression: string)

Source from the content-addressed store, hash-verified

254 * 3. `not expr` --> `!expr`
255 */
256function transformExpressionToJs(expression: string): string {
257 return expression
258 .replace(/^(.+)\s+not in\s+(\[.+\])$/, '!$2.includes($1)')
259 .replace(/^(.+)\s+in\s+(.+)$/, '$2.some(x => $1.matchesAny || $1 == x)')
260 .replace(/^(.+)\s+not in\s+(.+)$/, '!$2.includes($1)')
261 .replace(/^(.+)\s+in\s+(.+)$/, '$2.includes($1)')
262 .replace(/not\s+/g, '!');
263}

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected