Skip to content

Commit 05933b0

Browse files
committed
improve attribute extraction during transclusion (also fix compat with jsdom)
1 parent 067e174 commit 05933b0

File tree

2 files changed

+8
-37
lines changed

2 files changed

+8
-37
lines changed

src/compiler/compile.js

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ exports.compileAndLinkRoot = function (vm, el, options) {
180180
}
181181
} else {
182182
// non-component, just compile as a normal element.
183-
replacerLinkFn = compileDirectives(el, options)
183+
replacerLinkFn = compileDirectives(el.attributes, options)
184184
}
185185
}
186186

@@ -248,7 +248,7 @@ function compileElement (el, options) {
248248
}
249249
// normal directives
250250
if (!linkFn && hasAttrs) {
251-
linkFn = compileDirectives(el, options)
251+
linkFn = compileDirectives(el.attributes, options)
252252
}
253253
// if the element is a textarea, we need to interpolate
254254
// its content on initial render.
@@ -501,17 +501,12 @@ function makeTerminalNodeLinkFn (el, dirName, value, options, def) {
501501
/**
502502
* Compile the directives on an element and return a linker.
503503
*
504-
* @param {Element|Object} elOrAttrs
505-
* - could be an object of already-extracted
506-
* container attributes.
504+
* @param {Array|NamedNodeMap} attrs
507505
* @param {Object} options
508506
* @return {Function}
509507
*/
510508

511-
function compileDirectives (elOrAttrs, options) {
512-
var attrs = _.isPlainObject(elOrAttrs)
513-
? mapToList(elOrAttrs)
514-
: elOrAttrs.attributes
509+
function compileDirectives (attrs, options) {
515510
var i = attrs.length
516511
var dirs = []
517512
var attr, name, value, dir, dirName, dirDef
@@ -546,24 +541,6 @@ function compileDirectives (elOrAttrs, options) {
546541
}
547542
}
548543

549-
/**
550-
* Convert a map (Object) of attributes to an Array.
551-
*
552-
* @param {Object} map
553-
* @return {Array}
554-
*/
555-
556-
function mapToList (map) {
557-
var list = []
558-
for (var key in map) {
559-
list.push({
560-
name: key,
561-
value: map[key]
562-
})
563-
}
564-
return list
565-
}
566-
567544
/**
568545
* Build a link function for all directives on a single node.
569546
*

src/compiler/transclude.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,22 +106,16 @@ function transcludeTemplate (el, options) {
106106
}
107107

108108
/**
109-
* Helper to extract a component container's attribute names
110-
* into a map.
109+
* Helper to extract a component container's attributes
110+
* into a plain object array.
111111
*
112112
* @param {Element} el
113-
* @return {Object}
113+
* @return {Array}
114114
*/
115115

116116
function extractAttrs (el) {
117117
if (el.nodeType === 1 && el.hasAttributes()) {
118-
var attrs = el.attributes
119-
var res = {}
120-
var i = attrs.length
121-
while (i--) {
122-
res[attrs[i].name] = attrs[i].value
123-
}
124-
return res
118+
return _.toArray(el.attributes)
125119
}
126120
}
127121

0 commit comments

Comments
 (0)