(node, platform, parentOperator = null)
| 3377 | } |
| 3378 | let hasPreMatching |
| 3379 | function traverseTree(node, platform, parentOperator = null) { |
| 3380 | node.flags = { ...node.flags, ...flags } |
| 3381 | const features = platformFeatures[platform] |
| 3382 | if (!features) { |
| 3383 | throw new Error(`未知的平台:${platform}`) |
| 3384 | } |
| 3385 | |
| 3386 | if (!node || !node.type) { |
| 3387 | console.log('节点缺少 type 属性或节点为 null:', node) |
| 3388 | return '' |
| 3389 | } |
| 3390 | |
| 3391 | if (node.type === 'LOGICAL') { |
| 3392 | const operator = node.operator |
| 3393 | const arity = LOGICAL_OPERATORS_ARITY[operator] |
| 3394 | |
| 3395 | // 检查是否有 pre-matching 标志 |
| 3396 | // const hasPreMatching = node.flags && node.flags.preMatching; |
| 3397 | if (node.routingPolicy) { |
| 3398 | hasPreMatching = node.flags && node.flags.preMatching |
| 3399 | } |
| 3400 | if (hasPreMatching && node.routingPolicy) { |
| 3401 | // 验证 routingPolicy 是否符合 ^REJECT(-[A-Z]+)*$ 的格式 |
| 3402 | if (!features.rejectPolicyRegex.test(node.routingPolicy)) { |
| 3403 | console.log(`pre-matching 只能与 REJECT 系列策略一起使用,当前策略为:${node.routingPolicy}`) |
| 3404 | hasPreMatching = false |
| 3405 | } |
| 3406 | } |
| 3407 | |
| 3408 | if (hasPreMatching) { |
| 3409 | // 检查所有子规则是否属于支持 pre-matching 的类型 |
| 3410 | const notSupportedTypes = [] |
| 3411 | const allChildrenSupported = node.children.every(childArray => { |
| 3412 | return Array.isArray(childArray) |
| 3413 | ? childArray.every(child => { |
| 3414 | const isSupported = FLAG_SUPPORTED_TYPES.preMatching.includes(child.operator) |
| 3415 | if (!isSupported) { |
| 3416 | notSupportedTypes.push(child.operator) |
| 3417 | } |
| 3418 | return isSupported |
| 3419 | }) |
| 3420 | : true |
| 3421 | }) |
| 3422 | |
| 3423 | if (!allChildrenSupported) { |
| 3424 | console.log( |
| 3425 | `逻辑运算符 ${operator} 中的所有子规则必须是支持 pre-matching 的类型, 但 ${notSupportedTypes.join( |
| 3426 | ', ' |
| 3427 | )} 不支持` |
| 3428 | ) |
| 3429 | hasPreMatching = false |
| 3430 | } |
| 3431 | } |
| 3432 | |
| 3433 | let childrenOutputs = [] |
| 3434 | node.children.forEach(child => { |
| 3435 | flattenChildren(child).forEach(subChild => { |
| 3436 | const output = traverseTree(subChild, platform, operator) |
no test coverage detected