(
node:
| TemplateChildNode
| IfBranchNode
| ExpressionNode
| CacheExpression
| undefined,
ids: TransformContext['identifiers'],
)
| 499 | |
| 500 | // Check if a node contains expressions that reference current context scope ids |
| 501 | export function hasScopeRef( |
| 502 | node: |
| 503 | | TemplateChildNode |
| 504 | | IfBranchNode |
| 505 | | ExpressionNode |
| 506 | | CacheExpression |
| 507 | | undefined, |
| 508 | ids: TransformContext['identifiers'], |
| 509 | ): boolean { |
| 510 | if (!node || Object.keys(ids).length === 0) { |
| 511 | return false |
| 512 | } |
| 513 | switch (node.type) { |
| 514 | case NodeTypes.ELEMENT: |
| 515 | for (let i = 0; i < node.props.length; i++) { |
| 516 | const p = node.props[i] |
| 517 | if ( |
| 518 | p.type === NodeTypes.DIRECTIVE && |
| 519 | (hasScopeRef(p.arg, ids) || hasScopeRef(p.exp, ids)) |
| 520 | ) { |
| 521 | return true |
| 522 | } |
| 523 | } |
| 524 | return node.children.some(c => hasScopeRef(c, ids)) |
| 525 | case NodeTypes.FOR: |
| 526 | if (hasScopeRef(node.source, ids)) { |
| 527 | return true |
| 528 | } |
| 529 | return node.children.some(c => hasScopeRef(c, ids)) |
| 530 | case NodeTypes.IF: |
| 531 | return node.branches.some(b => hasScopeRef(b, ids)) |
| 532 | case NodeTypes.IF_BRANCH: |
| 533 | if (hasScopeRef(node.condition, ids)) { |
| 534 | return true |
| 535 | } |
| 536 | return node.children.some(c => hasScopeRef(c, ids)) |
| 537 | case NodeTypes.SIMPLE_EXPRESSION: |
| 538 | return ( |
| 539 | !node.isStatic && |
| 540 | isSimpleIdentifier(node.content) && |
| 541 | !!ids[node.content] |
| 542 | ) |
| 543 | case NodeTypes.COMPOUND_EXPRESSION: |
| 544 | return node.children.some(c => isObject(c) && hasScopeRef(c, ids)) |
| 545 | case NodeTypes.INTERPOLATION: |
| 546 | case NodeTypes.TEXT_CALL: |
| 547 | return hasScopeRef(node.content, ids) |
| 548 | case NodeTypes.TEXT: |
| 549 | case NodeTypes.COMMENT: |
| 550 | case NodeTypes.JS_CACHE_EXPRESSION: |
| 551 | return false |
| 552 | default: |
| 553 | if (__DEV__) { |
| 554 | const exhaustiveCheck: never = node |
| 555 | exhaustiveCheck |
| 556 | } |
| 557 | return false |
| 558 | } |
no test coverage detected