Skip to content

Commit e37b151

Browse files
committed
shave off a few bytes with forEach
1 parent d75ee62 commit e37b151

File tree

4 files changed

+11
-24
lines changed

4 files changed

+11
-24
lines changed

src/compiler.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,7 @@ function Compiler (vm, options) {
126126
compiler.compile(el, true)
127127

128128
// bind deferred directives (child components)
129-
for (var i = 0, l = compiler.deferred.length; i < l; i++) {
130-
compiler.bindDirective(compiler.deferred[i])
131-
}
129+
compiler.deferred.forEach(compiler.bindDirective, compiler)
132130

133131
// extract dependencies for computed properties
134132
compiler.parseDeps()
@@ -288,7 +286,7 @@ CompilerProto.compile = function (node, root) {
288286
}
289287

290288
// v-with has 2nd highest priority
291-
} else if (!root && ((withKey = utils.attr(node, 'with')) || componentCtor)) {
289+
} else if (root !== true && ((withKey = utils.attr(node, 'with')) || componentCtor)) {
292290

293291
directive = Directive.parse('with', withKey || '', compiler, node)
294292
if (directive) {
@@ -369,10 +367,7 @@ CompilerProto.compileNode = function (node) {
369367
}
370368
// recursively compile childNodes
371369
if (node.childNodes.length) {
372-
var nodes = slice.call(node.childNodes)
373-
for (i = 0, j = nodes.length; i < j; i++) {
374-
this.compile(nodes[i])
375-
}
370+
slice.call(node.childNodes).forEach(this.compile, this)
376371
}
377372
}
378373

@@ -387,7 +382,7 @@ CompilerProto.compileTextNode = function (node) {
387382

388383
for (var i = 0, l = tokens.length; i < l; i++) {
389384
token = tokens[i]
390-
directive = null
385+
directive = partialNodes = null
391386
if (token.key) { // a binding
392387
if (token.key.charAt(0) === '>') { // a partial
393388
partialId = token.key.slice(1).trim()
@@ -413,6 +408,8 @@ CompilerProto.compileTextNode = function (node) {
413408

414409
// insert node
415410
node.parentNode.insertBefore(el, node)
411+
412+
// bind directive
416413
if (directive) {
417414
this.bindDirective(directive)
418415
}
@@ -421,10 +418,7 @@ CompilerProto.compileTextNode = function (node) {
421418
// will change from the fragment to the correct parentNode.
422419
// This could affect directives that need access to its element's parentNode.
423420
if (partialNodes) {
424-
for (var j = 0, k = partialNodes.length; j < k; j++) {
425-
this.compile(partialNodes[j])
426-
}
427-
partialNodes = null
421+
partialNodes.forEach(this.compile, this)
428422
}
429423

430424
}

src/deps-parser.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ module.exports = {
3737
parse: function (bindings) {
3838
utils.log('\nparsing dependencies...')
3939
Observer.shouldGet = true
40-
var i = bindings.length
41-
while (i--) { catchDeps(bindings[i]) }
40+
bindings.forEach(catchDeps)
4241
Observer.shouldGet = false
4342
utils.log('\ndone.')
4443
}

src/directive.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ function Directive (definition, expression, rawKey, compiler, node) {
5858
var filterExps = this.expression.slice(rawKey.length).match(FILTERS_RE)
5959
if (filterExps) {
6060
this.filters = []
61-
var i = 0, l = filterExps.length, filter
62-
for (; i < l; i++) {
61+
for (var i = 0, l = filterExps.length, filter; i < l; i++) {
6362
filter = parseFilter(filterExps[i], this.compiler)
6463
if (filter) this.filters.push(filter)
6564
}

src/directives/repeat.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ var mutationHandlers = {
2525
},
2626

2727
unshift: function (m) {
28-
var i, l = m.args.length
29-
for (i = 0; i < l; i++) {
30-
this.buildItem(m.args[i], i)
31-
}
28+
m.args.forEach(this.buildItem, this)
3229
},
3330

3431
shift: function () {
@@ -144,9 +141,7 @@ module.exports = {
144141

145142
// create child-vms and append to DOM
146143
if (collection.length) {
147-
for (var i = 0, l = collection.length; i < l; i++) {
148-
this.buildItem(collection[i], i)
149-
}
144+
collection.forEach(this.buildItem, this)
150145
if (!init) this.changed()
151146
}
152147
},

0 commit comments

Comments
 (0)