Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(773)

Unified Diff: sky/framework/sky-element/sky-binder.sky

Issue 845523004: console.error when using unknown attributes in templates. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/examples/widgets/index.sky ('k') | sky/framework/sky-element/sky-element.sky » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/framework/sky-element/sky-binder.sky
diff --git a/sky/framework/sky-element/sky-binder.sky b/sky/framework/sky-element/sky-binder.sky
index 7a7914c544f31c60905f44a1f147dafa001a3d11..8eff2f29875ce36f97e020b87109b42a2a05e766 100644
--- a/sky/framework/sky-element/sky-binder.sky
+++ b/sky/framework/sky-element/sky-binder.sky
@@ -26,6 +26,46 @@ class TemplateInstance {
var emptyInstance = new TemplateInstance();
var directiveCache = new WeakMap();
+// TODO(esprehn): It would be nice if these were exposed by the platform so
+// the framework didn't need to hard code a list.
+var defaultAttributesNames = new Set([
+ 'accesskey',
+ 'alt',
+ 'as',
+ 'async',
+ 'class',
+ 'contenteditable',
+ 'crossorigin',
+ 'dir',
+ 'height',
+ 'href',
+ 'id',
+ 'is',
+ 'lang',
+ 'media',
+ 'name',
+ 'rel',
+ 'select',
+ 'sizes',
+ 'spellcheck',
+ 'src',
+ 'srcset',
+ 'style',
+ 'tabindex',
+ 'title',
+ 'type',
+ 'width',
+]);
+var elementAttributeNames = new Map();
+
+function registerElement(name, options) {
+ elementAttributeNames.set(name, new Set(options.attributeNames));
+}
+
+registerElement('template', {
+ attributeNames: ['if', 'repeat'],
+});
+
function createInstance(template, model) {
var content = template.content;
if (!content.firstChild)
@@ -154,9 +194,21 @@ function parsePropertyDirective(value, property) {
return result;
}
+function checkAttribute(name, allowedAttributeNames) {
+ if (name.startsWith('data-'))
+ return true;
+ if (defaultAttributesNames.has(name))
+ return true;
+ if (allowedAttributeNames && allowedAttributeNames.has(name))
+ return true;
+ return false;
+}
+
function parseAttributeDirectives(element, directives) {
var attributes = element.getAttributes();
+ var allowedAttributeNames = elementAttributeNames.get(element.tagName);
+
for (var i = 0; i < attributes.length; i++) {
var attr = attributes[i];
var name = attr.name;
@@ -167,6 +219,11 @@ function parseAttributeDirectives(element, directives) {
continue;
}
+ if (!checkAttribute(name, allowedAttributeNames)) {
+ console.error('Element "'+ element.tagName +
+ '" has unknown attribute "' + name + '".');
+ }
+
var property = parsePropertyDirective(value, name);
if (!property)
continue;
@@ -467,5 +524,6 @@ class TemplateIterator {
module.exports = {
createInstance: createInstance,
+ registerElement: registerElement,
};
</script>
« no previous file with comments | « sky/examples/widgets/index.sky ('k') | sky/framework/sky-element/sky-element.sky » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698