Skip to content

Commit b8c6dc3

Browse files
committed
* Optimizing new Element(expression), aligning the behavior to the new specs. It may needs some benchmarks and further optimization.
1 parent fe7237a commit b8c6dc3

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

Source/Element/Element.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,20 @@ var Element = function(tag, props){
2121

2222
if (!props) props = {};
2323

24-
var parsed = Slick.parse(tag).expressions[0][0];
25-
tag = parsed.tag || 'div';
26-
if (parsed.id) props.id = parsed.id;
27-
28-
var classes = [];
29-
parsed.parts.each(function(part){
30-
switch (part.type){
31-
case 'class': classes.push(part.value); break;
32-
case 'attribute': if (part.value && part.operator == '=') props[part.key] = part.value;
24+
if (!tag.test(/^\w+$/)){
25+
var parsed = Slick.parse(tag).expressions[0][0];
26+
tag = (parsed.tag == '*') ? 'div' : parsed.tag;
27+
if (parsed.id && props.id == null) props.id = parsed.id;
28+
29+
for (var i = 0, l = parsed.parts.length; i < l; i++){
30+
var part = parsed.parts[i];
31+
if (part.type == 'attribute' && part.value && part.operator == '=' && props[part.key] == null)
32+
props[part.key] = part.value;
3333
}
34-
});
35-
36-
if (classes.length) props['class'] = classes.join(' ');
34+
35+
var classList = props['class'];
36+
if (parsed.classes) props['class'] = (classList ? classList + ' ' : '') + parsed.classes.join(' ');
37+
}
3738

3839
return document.newElement(tag, props);
3940
};

0 commit comments

Comments
 (0)