* Validates that there are no event attribute bindings in the host bindings. * @param bindings - Map of host bindings for the component. * @param bindingParser - Binding parser used to create the binding expression. * @param sourceSpan - Source span where the host bindings were defined.
( bindings: ParsedHostBindings, bindingParser: BindingParser, sourceSpan: ParseSourceSpan, )
| 592 | * @param sourceSpan - Source span where the host bindings were defined. |
| 593 | */ |
| 594 | function validateNoEventBindings( |
| 595 | bindings: ParsedHostBindings, |
| 596 | bindingParser: BindingParser, |
| 597 | sourceSpan: ParseSourceSpan, |
| 598 | ): void { |
| 599 | for (const prop in bindings.properties) { |
| 600 | if (prop.startsWith('class.') || prop.startsWith('style.')) { |
| 601 | continue; |
| 602 | } |
| 603 | const isAttr = prop.startsWith('attr.'); |
| 604 | const boundName = isAttr ? prop.slice(5) : prop; |
| 605 | if (boundName.startsWith(':')) { |
| 606 | const type = isAttr ? 'attribute' : 'property'; |
| 607 | bindingParser.errors.push( |
| 608 | new ParseError( |
| 609 | sourceSpan, |
| 610 | `Invalid ${type} name '${boundName}'. ${type === 'attribute' ? 'Attribute' : 'Property'} names cannot start with a colon.`, |
| 611 | ), |
| 612 | ); |
| 613 | continue; |
| 614 | } |
| 615 | const colonIdx = boundName.lastIndexOf(':'); |
| 616 | const localName = colonIdx > -1 ? boundName.substring(colonIdx + 1) : boundName; |
| 617 | |
| 618 | if (localName.toLowerCase().startsWith('on')) { |
| 619 | const errorType = isAttr ? 'attribute' : 'property'; |
| 620 | const suggestion = `(${localName.slice(2)})=...`; |
| 621 | |
| 622 | let msg = `Binding to event ${errorType} '${boundName}' is disallowed for security reasons, please use ${suggestion}`; |
| 623 | if (!isAttr) { |
| 624 | msg += `\nIf '${prop}' is a directive input, make sure the directive is imported by the current module.`; |
| 625 | } |
| 626 | |
| 627 | bindingParser.errors.push(new ParseError(sourceSpan, msg)); |
| 628 | } |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | function compileStyles(styles: string[], selector: string, hostSelector: string): string[] { |
| 633 | const shadowCss = new ShadowCss(); |
no test coverage detected