2323
2424const dbEnum = require ( '../../src-shared/db-enum' )
2525
26- const OPERAND_REGEX = / [ A - Z a - z ] [ A - Z a - z 0 - 9 _ ] * / g
26+ const OPERAND_REGEX = / [ A - Z a - z ] \w * / g
2727
2828/**
2929 * Evaluate the value of a boolean conformance expression that includes operands and operators.
@@ -75,7 +75,7 @@ function evaluateConformanceExpression(expression, elementMap) {
7575 // if any operand is desc, the conformance is too complex to parse
7676 for ( let part of parts ) {
7777 let operands = getOperandsFromExpression ( part )
78- if ( operands && operands . includes ( dbEnum . conformanceTag . described ) ) {
78+ if ( operands . includes ( dbEnum . conformanceTag . described ) ) {
7979 return dbEnum . conformanceTag . described
8080 }
8181 }
@@ -141,7 +141,7 @@ function checkMissingOperands(expression, elementMap) {
141141 */
142142function checkIfExpressionHasOperand ( expression , operand ) {
143143 let operands = getOperandsFromExpression ( expression )
144- return operands && operands . includes ( operand )
144+ return operands . includes ( operand )
145145}
146146
147147/**
@@ -152,8 +152,8 @@ function checkIfExpressionHasOperand(expression, operand) {
152152 */
153153function getOperandsFromExpression ( expression ) {
154154 if ( ! expression ) return [ ]
155- let operands = expression . match ( OPERAND_REGEX )
156- return operands ? operands : [ ]
155+ let operands = expression . match ( OPERAND_REGEX ) || [ ]
156+ return operands
157157}
158158
159159/**
@@ -262,12 +262,11 @@ function translateConformanceTag(expression) {
262262 */
263263function translateBooleanExpr ( expr ) {
264264 // match operands and operators
265- let tokens = expr . match ( / [ A - Z a - z 0 - 9 _ ] + | [ ! & | ( ) ] / g) || [ ]
265+ let tokens = expr . match ( / \w + | [ ! & | ( ) ] / g) || [ ]
266266 let output = [ ]
267-
268- for ( let i = 0 ; i < tokens . length ; i ++ ) {
267+ let i = 0
268+ while ( i < tokens . length ) {
269269 let token = tokens [ i ]
270-
271270 if ( token === '&' ) {
272271 output . push ( dbEnum . logicalOperators . and )
273272 } else if ( token === '|' ) {
@@ -288,8 +287,8 @@ function translateBooleanExpr(expr) {
288287 // if none of the above is matched, it is an element operand
289288 output . push ( `${ token } is enabled` )
290289 }
290+ i ++
291291 }
292-
293292 return output . join ( ' ' )
294293}
295294
@@ -321,7 +320,7 @@ function translateConformanceExpression(expression) {
321320 if ( conformanceTag ) return conformanceTag
322321
323322 // handle optional expressions surrounded by '[]'
324- let optionalMatch = part . match ( / ^ \[ ( .* ) \] $ / )
323+ let optionalMatch = / ^ \[ ( .* ) \] $ / . exec ( part )
325324 if ( optionalMatch ) {
326325 // optionalMatch[1] is the expression inside '[]'
327326 let optionalText = translateBooleanExpr ( optionalMatch [ 1 ] )
0 commit comments