Skip to content

Commit

Permalink
Re-add spread attribute optimization and bail out when repeated @tags
Browse files Browse the repository at this point in the history
…present. Prevent dynamic tag from cloning non object attributes.
  • Loading branch information
DylanPiercey committed Nov 21, 2018
1 parent df26873 commit ac676d7
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 23 deletions.
6 changes: 4 additions & 2 deletions src/compiler/ast/CustomTag.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,10 @@ class CustomTag extends HtmlElement {
}

if (attr.spread) {
let isFirst = i === 0;
if (explicitAttrs || isFirst) {
let isFirstOfMany =
i === 0 &&
(this._hasDynamicNestedTags || this.attributes.length > 1);
if (explicitAttrs || isFirstOfMany) {
attrs.push(builder.objectExpression(explicitAttrs || {}));
}
attrs.push(attr.value);
Expand Down
11 changes: 7 additions & 4 deletions src/runtime/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,13 @@ var helpers = {
);
}
} else {
attrs = Object.keys(attrs).reduce(function(r, key) {
r[removeDashes(key)] = attrs[key];
return r;
}, {});
if (typeof attrs === "object") {
attrs = Object.keys(attrs).reduce(function(r, key) {
r[removeDashes(key)] = attrs[key];
return r;
}, {});
}

if (tag._ || tag.renderer || tag.render) {
var renderer = tag._ || tag.renderer || tag.render;
out.c(componentDef, key, customEvents);
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/html/helper-attrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = function attrs(arg) {
}
return out;
} else if (typeof arg === "string") {
return arg;
return attrHelper(arg, true);
}
return "";
};
Expand Down
36 changes: 20 additions & 16 deletions src/runtime/vdom/VElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,22 +206,26 @@ VElement.prototype = {
if (flags & FLAG_CUSTOM_ELEMENT) {
assign(el, attributes);
} else {
for (var attrName in attributes) {
var attrValue = attributes[attrName];

if (attrValue !== false && attrValue != null) {
var type = typeof attrValue;

if (type !== "string") {
// Special attributes aren't copied to the real DOM. They are only
// kept in the virtual attributes map
attrValue = convertAttrValue(type, attrValue);
}

if (attrName == ATTR_XLINK_HREF) {
setAttribute(el, NS_XLINK, ATTR_HREF, attrValue);
} else {
el.setAttribute(attrName, attrValue);
if (typeof attributes === "string") {
el.setAttribute(attributes, "");
} else {
for (var attrName in attributes) {
var attrValue = attributes[attrName];

if (attrValue !== false && attrValue != null) {
var type = typeof attrValue;

if (type !== "string") {
// Special attributes aren't copied to the real DOM. They are only
// kept in the virtual attributes map
attrValue = convertAttrValue(type, attrValue);
}

if (attrName == ATTR_XLINK_HREF) {
setAttribute(el, NS_XLINK, ATTR_HREF, attrValue);
} else {
el.setAttribute(attrName, attrValue);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<link test>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<link ..."test" />

0 comments on commit ac676d7

Please sign in to comment.