(host: {
[key: string]: string | o.Expression;
})
| 517 | } |
| 518 | |
| 519 | export function parseHostBindings(host: { |
| 520 | [key: string]: string | o.Expression; |
| 521 | }): ParsedHostBindings { |
| 522 | const attributes: Record<string, o.Expression> = {}; |
| 523 | const listeners: Record<string, string> = {}; |
| 524 | const properties: Record<string, string> = {}; |
| 525 | const specialAttributes: {styleAttr?: string; classAttr?: string} = {}; |
| 526 | |
| 527 | for (const key of Object.keys(host)) { |
| 528 | const value = host[key]; |
| 529 | |
| 530 | if (key.startsWith('(') && key.endsWith(')')) { |
| 531 | if (typeof value !== 'string') { |
| 532 | // TODO(alxhub): make this a diagnostic. |
| 533 | throw new Error(`Event binding must be string`); |
| 534 | } |
| 535 | listeners[key.slice(1, -1)] = value; |
| 536 | } else if (key.startsWith('[') && key.endsWith(']')) { |
| 537 | if (typeof value !== 'string') { |
| 538 | // TODO(alxhub): make this a diagnostic. |
| 539 | throw new Error(`Property binding must be string`); |
| 540 | } |
| 541 | // synthetic properties (the ones that have a `@` as a prefix) |
| 542 | // are still treated the same as regular properties. Therefore |
| 543 | // there is no point in storing them in a separate map. |
| 544 | properties[key.slice(1, -1)] = value; |
| 545 | } else { |
| 546 | switch (key) { |
| 547 | case 'class': |
| 548 | if (typeof value !== 'string') { |
| 549 | // TODO(alxhub): make this a diagnostic. |
| 550 | throw new Error(`Class binding must be string`); |
| 551 | } |
| 552 | specialAttributes.classAttr = value; |
| 553 | break; |
| 554 | case 'style': |
| 555 | if (typeof value !== 'string') { |
| 556 | // TODO(alxhub): make this a diagnostic. |
| 557 | throw new Error(`Style binding must be string`); |
| 558 | } |
| 559 | specialAttributes.styleAttr = value; |
| 560 | break; |
| 561 | default: |
| 562 | if (typeof value === 'string') { |
| 563 | attributes[key] = o.literal(value); |
| 564 | } else { |
| 565 | attributes[key] = value; |
| 566 | } |
| 567 | } |
| 568 | } |
| 569 | } |
| 570 | |
| 571 | return {attributes, listeners, properties, specialAttributes}; |
| 572 | } |
| 573 | |
| 574 | /** |
| 575 | * Verifies host bindings and returns the list of errors (if any). Empty array indicates that a |
no test coverage detected
searching dependent graphs…