* Returns the bound property and expression string within a given attribute, * if it exists. Otherwise, returns null. * @param {!Attr} attribute * @param {!Element} element * @return {?{property: string, expressionString: string}} * @private
(attribute, element)
| 985 | * @private |
| 986 | */ |
| 987 | boundPropertyInAttribute_(attribute, element) { |
| 988 | const tag = element.tagName; |
| 989 | const attr = attribute.name; |
| 990 | |
| 991 | let property; |
| 992 | if (attr.length > 2 && attr[0] === '[' && attr[attr.length - 1] === ']') { |
| 993 | property = attr.substr(1, attr.length - 2); |
| 994 | } else if (attr.startsWith('data-amp-bind-')) { |
| 995 | property = attr.substr(14); |
| 996 | // Ignore `data-amp-bind-foo` if `[foo]` already exists. |
| 997 | if (element.hasAttribute(`[${property}]`)) { |
| 998 | return null; |
| 999 | } |
| 1000 | } |
| 1001 | |
| 1002 | if (property) { |
| 1003 | if (this.validator_.canBind(tag, property)) { |
| 1004 | return {property, expressionString: attribute.value}; |
| 1005 | } else { |
| 1006 | const err = user().createError( |
| 1007 | '%s: Binding to [%s] on <%s> is not allowed.', |
| 1008 | TAG, |
| 1009 | property, |
| 1010 | tag |
| 1011 | ); |
| 1012 | this.reportError_(err, element); |
| 1013 | } |
| 1014 | } |
| 1015 | return null; |
| 1016 | } |
| 1017 | |
| 1018 | /** |
| 1019 | * Evaluates a single expression and returns its result. |
no test coverage detected