feat(transpiler): Transform for..of to Dart as for..in

fixes #53
This commit is contained in:
Tommy Odom
2014-11-09 18:24:28 -05:00
committed by Victor Berchet
parent bf71b94bde
commit f088e9ef15
8 changed files with 172 additions and 3 deletions

View File

@ -1,8 +1,35 @@
library facade.collection;
import 'dart:collection' show HashMap;
import 'dart:collection' show HashMap, IterableBase, Iterator;
export 'dart:core' show Map, List, Set;
class MapIterator extends Iterator<List> {
Iterator _iterator;
Map _map;
MapIterator(Map map) {
this._map = map;
this._iterator = map.keys.iterator;
}
bool moveNext() {
return this._iterator.moveNext();
}
List get current {
return this._iterator.current != null ?
[this._iterator.current, this._map[this._iterator.current]] :
null;
}
}
class IterableMap extends IterableBase<List> {
Map _map;
IterableMap(Map map) {
this._map = map;
}
Iterator<List> get iterator => new MapIterator(this._map);
}
class MapWrapper {
static HashMap create() => new HashMap();
static HashMap createFromStringMap(m) => m;
@ -21,6 +48,7 @@ class MapWrapper {
static int size(m) {return m.length;}
static void delete(m, k) { m.remove(k); }
static void clear(m) { m.clear(); }
static Iterable iterable(m) { return new IterableMap(m); }
}
// TODO: how to export StringMap=Map as a type?

View File

@ -23,6 +23,7 @@ export class MapWrapper {
static size(m) {return m.size;}
static delete(m, k) { m.delete(k); }
static clear(m) { m.clear(); }
static iterable(m) { return m; }
}
// TODO: cannot export StringMap as a type as Dart does not support renaming types...