Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 9e795c4

Browse files
vicbmhevery
authored andcommitted
style: get ride of the for.length JS heritage
Closes #615
1 parent 8e1e69d commit 9e795c4

File tree

9 files changed

+25
-24
lines changed

9 files changed

+25
-24
lines changed

lib/core/interpolate.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Interpolation {
1111
String call(List parts, [_]) {
1212
if (parts == null) return seperators.join('');
1313
var str = [];
14-
for (var i = 0, ii = parts.length; i < ii; i++) {
14+
for (var i = 0; i < parts.length; i++) {
1515
str.add(seperators[i]);
1616
var value = parts[i];
1717
str.add(value == null ? '' : '$value');

lib/core/parser/eval.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Chain extends syntax.Chain {
1111
Chain(List<syntax.Expression> expressions) : super(expressions);
1212
eval(scope, [FilterMap filters]) {
1313
var result;
14-
for (int i = 0, length = expressions.length; i < length; i++) {
14+
for (int i = 0; i < expressions.length; i++) {
1515
var last = expressions[i].eval(scope, filters);
1616
if (last != null) result = last;
1717
}

lib/core_dom/block.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ class Block implements ElementWrapper {
7878
bool preventDefault = false;
7979

8080
Function removeDomElements = () {
81-
for (var j = 0, jj = elements.length; j < jj; j++) {
81+
for (var j = 0; j < elements.length; j++) {
8282
dom.Node current = elements[j];
83-
dom.Node next = j+1 < jj ? elements[j+1] : null;
83+
dom.Node next = j+1 < elements.length ? elements[j+1] : null;
8484

8585
while(next != null && current.nextNode != next) {
8686
current.nextNode.remove();

lib/core_dom/block_factory.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class BlockFactory {
5555
var preRenderedIndexOffset = 0;
5656
var directiveDefsByName = {};
5757

58-
for (int i = 0, ii = directivePositions.length; i < ii;) {
58+
for (int i = 0; i < directivePositions.length;) {
5959
int index = directivePositions[i++];
6060

6161
List<DirectiveRef> directiveRefs = directivePositions[i++];

lib/core_dom/compiler.dart

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Compiler {
2626

2727
cursorAlreadyAdvanced = false;
2828

29-
for (var j = 0, jj = declaredDirectiveRefs.length; j < jj; j++) {
29+
for (var j = 0; j < declaredDirectiveRefs.length; j++) {
3030
DirectiveRef directiveRef = declaredDirectiveRefs[j];
3131
NgAnnotation annotation = directiveRef.annotation;
3232
var blockFactory = null;
@@ -42,11 +42,11 @@ class Compiler {
4242
domCursor, templateCursor,
4343
directiveRef, remainingDirectives, directives);
4444

45-
j = jj; // stop processing further directives since they belong to transclusion;
46-
}
47-
if (usableDirectiveRefs == null) {
48-
usableDirectiveRefs = [];
45+
// stop processing further directives since they belong to
46+
// transclusion
47+
j = declaredDirectiveRefs.length;
4948
}
49+
if (usableDirectiveRefs == null) usableDirectiveRefs = [];
5050
directiveRef.blockFactory = blockFactory;
5151
createMappings(directiveRef);
5252
usableDirectiveRefs.add(directiveRef);

lib/core_dom/node_cursor.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class NodeCursor {
7575
remove() {
7676
var nodes = nodeList();
7777

78-
for (var i = 0, ii = nodes.length; i < ii; i++) {
78+
for (var i = 0; i < nodes.length; i++) {
7979
// NOTE(deboer): If elements is a list of child nodes on a node, then
8080
// calling Node.remove() may also remove it from the list. Thus, we
8181
// call elements.removeAt first so only one node is removed.

lib/directive/input_select.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ class _SelectMode {
140140

141141
get _options => select.querySelectorAll('option');
142142
_forEachOption(fn, [quiteOnReturn = false]) {
143-
for (var os = _options, i = 0, ii = os.length; i < ii; i++) {
144-
var retValue = fn(os[i], i);
143+
for (var i = 0; i < _options.length; i++) {
144+
var retValue = fn(_options[i], i);
145145
if (quiteOnReturn && retValue != null) return retValue;
146146
}
147147
return null;

lib/directive/ng_repeat.dart

+11-10
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class NgRepeatDirective extends AbstractNgRepeatDirective {
107107
* digest cycle and will not update on changes to the model.
108108
*
109109
*/
110+
@deprecated
110111
@NgDirective(
111112
children: NgAnnotation.TRANSCLUDE_CHILDREN,
112113
selector: '[ng-shallow-repeat]',
@@ -120,7 +121,7 @@ class NgShallowRepeatDirective extends AbstractNgRepeatDirective {
120121
AstParser astParser)
121122
: super(blockHole, boundBlockFactory, scope, parser, astParser)
122123
{
123-
print('DEPRICATED: [ng-shallow-repeat] use [ng-repeat]');
124+
print('DEPRECATED: [ng-shallow-repeat] use [ng-repeat]');
124125
}
125126
}
126127

@@ -218,7 +219,7 @@ abstract class AbstractNgRepeatDirective {
218219
}
219220
}
220221
// remove existing items
221-
_rows.forEach((key, row){
222+
_rows.forEach((key, row) {
222223
row.block.remove();
223224
row.scope.destroy();
224225
});
@@ -236,7 +237,7 @@ abstract class AbstractNgRepeatDirective {
236237

237238
List<_Row> newRowOrder = _computeNewRows(collection, trackById);
238239

239-
for (var index = 0, length = collection.length; index < length; index++) {
240+
for (var index = 0; index < collection.length; index++) {
240241
var value = collection.elementAt(index);
241242
_Row row = newRowOrder[index];
242243

@@ -263,14 +264,14 @@ abstract class AbstractNgRepeatDirective {
263264
childContext[_valueIdentifier] = value;
264265
}
265266
var first = (index == 0);
266-
var last = (index == (length - 1));
267+
var last = (index == collection.length - 1);
267268
childContext
268-
..[r'$index'] = index
269-
..[r'$first'] = (index == 0)
270-
..[r'$last'] = (index == (length - 1))
271-
..[r'$middle'] = !first && !last
272-
..[r'$odd'] = index & 1 == 1
273-
..[r'$even'] = index & 1 == 0;
269+
..[r'$index'] = index
270+
..[r'$first'] = first
271+
..[r'$last'] = last
272+
..[r'$middle'] = !first && !last
273+
..[r'$odd'] = index & 1 == 1
274+
..[r'$even'] = index & 1 == 0;
274275

275276
if (row.startNode == null) {
276277
var block = _boundBlockFactory(childScope);

test/jasmine_syntax.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
library jamine;
1+
library jasmine;
22

33
import 'package:unittest/unittest.dart' as unit;
44
import 'package:angular/utils.dart' as utils;

0 commit comments

Comments
 (0)