chore: remove obsolete files (#10240)
This commit is contained in:
@ -1,132 +0,0 @@
|
||||
library angular2.core.facade.async;
|
||||
|
||||
import 'dart:async';
|
||||
export 'dart:async' show Stream, StreamController, StreamSubscription;
|
||||
|
||||
export 'promise.dart';
|
||||
|
||||
class TimerWrapper {
|
||||
static Timer setTimeout(fn(), int millis) =>
|
||||
new Timer(new Duration(milliseconds: millis), fn);
|
||||
static void clearTimeout(Timer timer) {
|
||||
timer.cancel();
|
||||
}
|
||||
|
||||
static Timer setInterval(fn(), int millis) {
|
||||
var interval = new Duration(milliseconds: millis);
|
||||
return new Timer.periodic(interval, (Timer timer) {
|
||||
fn();
|
||||
});
|
||||
}
|
||||
|
||||
static void clearInterval(Timer timer) {
|
||||
timer.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
class ObservableWrapper {
|
||||
static StreamSubscription subscribe/*<T>*/(Stream s, onNext(/*=T*/ value),
|
||||
[onError, onComplete]) {
|
||||
return s.listen(onNext,
|
||||
onError: onError, onDone: onComplete, cancelOnError: true);
|
||||
}
|
||||
|
||||
static bool isObservable(obs) {
|
||||
return obs is Stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether `emitter` has any subscribers listening to events.
|
||||
*/
|
||||
static bool hasSubscribers(EventEmitter emitter) {
|
||||
return emitter._controller.hasListener;
|
||||
}
|
||||
|
||||
static void dispose(StreamSubscription s) {
|
||||
s.cancel();
|
||||
}
|
||||
|
||||
@Deprecated('Use callEmit() instead')
|
||||
static void callNext(EventEmitter emitter, value) {
|
||||
emitter.add(value);
|
||||
}
|
||||
|
||||
static void callEmit(EventEmitter emitter, value) {
|
||||
emitter.add(value);
|
||||
}
|
||||
|
||||
static void callError(EventEmitter emitter, error) {
|
||||
emitter.addError(error);
|
||||
}
|
||||
|
||||
static void callComplete(EventEmitter emitter) {
|
||||
emitter.close();
|
||||
}
|
||||
|
||||
static Stream fromPromise(Future f) {
|
||||
return new Stream.fromFuture(f);
|
||||
}
|
||||
|
||||
static Future toPromise(Stream s) {
|
||||
return s.single;
|
||||
}
|
||||
}
|
||||
|
||||
class EventEmitter<T> extends Stream<T> {
|
||||
StreamController<T> _controller;
|
||||
|
||||
/// Creates an instance of [EventEmitter], which depending on [isAsync],
|
||||
/// delivers events synchronously or asynchronously.
|
||||
EventEmitter([bool isAsync = true]) {
|
||||
_controller = new StreamController<T>.broadcast(sync: !isAsync);
|
||||
}
|
||||
|
||||
StreamSubscription<T> listen(void onData(T event),
|
||||
{Function onError, void onDone(), bool cancelOnError}) {
|
||||
return _controller.stream.listen(onData,
|
||||
onError: onError, onDone: onDone, cancelOnError: cancelOnError);
|
||||
}
|
||||
|
||||
void add(value) {
|
||||
_controller.add(value);
|
||||
}
|
||||
|
||||
void emit(value) {
|
||||
_controller.add(value);
|
||||
}
|
||||
|
||||
void addError(error) {
|
||||
_controller.addError(error);
|
||||
}
|
||||
|
||||
void close() {
|
||||
_controller.close();
|
||||
}
|
||||
}
|
||||
|
||||
//todo(robwormald): maybe fix in ts2dart?
|
||||
class Subject<T> extends Stream<T> {
|
||||
StreamController<T> _controller;
|
||||
|
||||
Subject([bool isAsync = true]) {
|
||||
_controller = new StreamController<T>.broadcast(sync: !isAsync);
|
||||
}
|
||||
|
||||
StreamSubscription<T> listen(void onData(T data),
|
||||
{Function onError, void onDone(), bool cancelOnError}) {
|
||||
return _controller.stream.listen(onData,
|
||||
onError: onError, onDone: onDone, cancelOnError: cancelOnError);
|
||||
}
|
||||
|
||||
void add(value) {
|
||||
_controller.add(value);
|
||||
}
|
||||
|
||||
void addError(error) {
|
||||
_controller.addError(error);
|
||||
}
|
||||
|
||||
void close() {
|
||||
_controller.close();
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
library angular.core.facade.base_wrapped_exception;
|
||||
|
||||
/**
|
||||
* A base class for the WrappedException that can be used to identify
|
||||
* a WrappedException from ExceptionHandler without adding circular
|
||||
* dependency.
|
||||
*/
|
||||
class BaseWrappedException extends Error {
|
||||
BaseWrappedException();
|
||||
|
||||
get originalException => null;
|
||||
get originalStack => null;
|
||||
|
||||
String get message => '';
|
||||
String get wrapperMessage => '';
|
||||
dynamic get context => null;
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
/**
|
||||
* Dart version of browser APIs. This library depends on 'dart:html' and
|
||||
* therefore can only run in the browser.
|
||||
*/
|
||||
library angular2.src.facade.browser;
|
||||
|
||||
import 'dart:js' show context;
|
||||
import 'dart:html' show Location, window;
|
||||
|
||||
export 'dart:html'
|
||||
show
|
||||
document,
|
||||
window,
|
||||
Element,
|
||||
Node,
|
||||
MouseEvent,
|
||||
KeyboardEvent,
|
||||
Event,
|
||||
EventTarget,
|
||||
History,
|
||||
Location,
|
||||
EventListener;
|
||||
|
||||
Location get location => window.location;
|
||||
|
||||
final _gc = context['gc'];
|
||||
|
||||
void gc() {
|
||||
if (_gc != null) {
|
||||
_gc.apply(const []);
|
||||
}
|
||||
}
|
@ -1,287 +0,0 @@
|
||||
library facade.collection;
|
||||
|
||||
import 'dart:collection' show IterableBase;
|
||||
import 'dart:convert' show JsonEncoder;
|
||||
export 'dart:core' show Iterator, Map, List, Set;
|
||||
import 'dart:math' show max, min;
|
||||
|
||||
var jsonEncoder = new JsonEncoder();
|
||||
|
||||
class MapIterator extends Iterator<List> {
|
||||
final Iterator _iterator;
|
||||
final Map _map;
|
||||
|
||||
MapIterator(Map map)
|
||||
: _map = map,
|
||||
_iterator = map.keys.iterator;
|
||||
|
||||
bool moveNext() => _iterator.moveNext();
|
||||
|
||||
List get current {
|
||||
return _iterator.current != null
|
||||
? [_iterator.current, _map[_iterator.current]]
|
||||
: null;
|
||||
}
|
||||
}
|
||||
|
||||
class IterableMap extends IterableBase<List> {
|
||||
final Map _map;
|
||||
|
||||
IterableMap(Map map) : _map = map;
|
||||
|
||||
Iterator<List> get iterator => new MapIterator(_map);
|
||||
}
|
||||
|
||||
class MapWrapper {
|
||||
static Map/*<K,V>*/ clone/*<K,V>*/(Map/*<K,V>*/ m) => new Map.from(m);
|
||||
|
||||
// in opposite to JS, Dart does not create a new map
|
||||
static Map/*<K,V>*/ createFromStringMap/*<K,V>*/(Map/*<K,V>*/ m) => m;
|
||||
|
||||
// in opposite to JS, Dart does not create a new map
|
||||
static Map/*<K,V>*/ toStringMap/*<K,V>*/(Map/*<K,V>*/ m) => m;
|
||||
|
||||
static Map/*<K,V>*/ createFromPairs/*<K,V>*/(List pairs) => pairs.fold(/*<K,V>*/{}, (m, p) {
|
||||
m[p[0]] = p[1];
|
||||
return m;
|
||||
});
|
||||
|
||||
static void clearValues(Map m) {
|
||||
for (var k in m.keys) {
|
||||
m[k] = null;
|
||||
}
|
||||
}
|
||||
|
||||
static Iterable/*<List<dynamic>>*/ iterable/*<K,V>*/(Map/*<K,V>*/ m) => new IterableMap(m);
|
||||
static List/*<K>*/ keys/*<K,V>*/(Map/*<K,V>*/ m) => m.keys.toList();
|
||||
static List/*<V>*/ values/*<K,V>*/(Map/*<K,V>*/ m) => m.values.toList();
|
||||
}
|
||||
|
||||
class StringMapWrapper {
|
||||
static Map/*<String,V>*/ create/*<V>*/() => {};
|
||||
static bool contains/*<V>*/(Map/*<String,V>*/ map, String key) => map.containsKey(key);
|
||||
static get/*<V>*/(Map/*<String,V>*/ map, String key) => map[key];
|
||||
static void set/*<V>*/(Map/*<String,V>*/ map, String key, /*=V*/value) {
|
||||
map[key] = value;
|
||||
}
|
||||
|
||||
static void delete/*<V>*/(Map/*<String,V>*/ m, String k) {
|
||||
m.remove(k);
|
||||
}
|
||||
|
||||
static void forEach/*<V>*/(Map/*<String,V>*/ m, fn(/*=V*/ v, String k)) {
|
||||
m.forEach((k, v) => fn(v, k));
|
||||
}
|
||||
|
||||
static Map/*<String,V>*/ merge/*<V>*/(Map/*<String,V>*/ a, Map/*<String,V>*/ b) {
|
||||
var m = new Map/*<String,V>*/.from(a);
|
||||
if (b != null) {
|
||||
b.forEach((k, v) => m[k] = v);
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
static List<String> keys(Map<String, dynamic> a) {
|
||||
return a.keys.toList();
|
||||
}
|
||||
|
||||
static List values(Map<String, dynamic> a) {
|
||||
return a.values.toList();
|
||||
}
|
||||
|
||||
static bool isEmpty(Map m) => m.isEmpty;
|
||||
static bool equals/*<V>*/(Map/*<String,V>*/ m1, Map/*<String,V>*/ m2) {
|
||||
if (m1.length != m2.length) {
|
||||
return false;
|
||||
}
|
||||
for (var key in m1.keys) {
|
||||
if (m1[key] != m2[key]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
typedef bool Predicate<T>(T item);
|
||||
|
||||
class ListWrapper {
|
||||
static List/*<T>*/ clone/*<T>*/(Iterable/*<T>*/ l) => new List.from(l);
|
||||
static List/*<T>*/ createFixedSize/*<T>*/(int size) => new List(size);
|
||||
static List/*<T>*/ createGrowableSize/*<T>*/(int size) =>
|
||||
new List.generate(size, (_) => null, growable: true);
|
||||
|
||||
static bool contains(List m, k) => m.contains(k);
|
||||
static int indexOf(List list, value, [int startIndex = 0]) =>
|
||||
list.indexOf(value, startIndex);
|
||||
static int lastIndexOf(List list, value, [int startIndex = null]) =>
|
||||
list.lastIndexOf(value, startIndex == null ? list.length : startIndex);
|
||||
|
||||
static void forEachWithIndex/*<T>*/(List/*<T>*/ list, fn(/*=T*/ item, int index)) {
|
||||
for (var i = 0; i < list.length; ++i) {
|
||||
fn(list[i], i);
|
||||
}
|
||||
}
|
||||
static /*=T*/ first/*<T>*/(List/*<T>*/ list) => list.isEmpty ? null : list.first;
|
||||
static /*=T*/ last/*<T>*/(List/*<T>*/ list) => list.isEmpty ? null : list.last;
|
||||
static List/*<T>*/ reversed/*<T>*/(List/*<T>*/ list) => list.reversed.toList();
|
||||
static List/*<T>*/ concat/*<T>*/(List/*<T>*/ a, List/*<T>*/ b) {
|
||||
return new List()
|
||||
..length = a.length + b.length
|
||||
..setRange(0, a.length, a)
|
||||
..setRange(a.length, a.length + b.length, b);
|
||||
}
|
||||
|
||||
static void insert/*<T>*/(List/*<T>*/ l, int index, /*=T*/ value) {
|
||||
l.insert(index, value);
|
||||
}
|
||||
|
||||
static removeAt(List l, int index) => l.removeAt(index);
|
||||
static void removeAll/*<T>*/(List/*<T>*/ list, List/*<T>*/ items) {
|
||||
for (var i = 0; i < items.length; ++i) {
|
||||
list.remove(items[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static bool remove/*<T>*/(List/*<T>*/ list, /*=T*/ item) => list.remove(item);
|
||||
static void clear(List l) {
|
||||
l.clear();
|
||||
}
|
||||
|
||||
static bool isEmpty(Iterable list) => list.isEmpty;
|
||||
static void fill/*<T>*/(List/*<T>*/ l, /*=T*/ value, [int start = 0, int end]) {
|
||||
l.fillRange(_startOffset(l, start), _endOffset(l, end), value);
|
||||
}
|
||||
|
||||
static bool equals/*<T>*/(List/*<T>*/ a, List/*<T>*/ b) {
|
||||
if (a.length != b.length) return false;
|
||||
for (var i = 0; i < a.length; ++i) {
|
||||
if (a[i] != b[i]) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static List/*<T>*/ slice/*<T>*/(List/*<T>*/ l, [int from = 0, int to]) {
|
||||
from = _startOffset(l, from);
|
||||
to = _endOffset(l, to);
|
||||
//in JS if from > to an empty array is returned
|
||||
if (to != null && from > to) {
|
||||
return [];
|
||||
}
|
||||
return l.sublist(from, to);
|
||||
}
|
||||
|
||||
static List/*<T>*/ splice/*<T>*/(List/*<T>*/ l, int from, int length) {
|
||||
from = _startOffset(l, from);
|
||||
var to = from + length;
|
||||
var sub = l.sublist(from, to);
|
||||
l.removeRange(from, to);
|
||||
return sub;
|
||||
}
|
||||
|
||||
static void sort/*<T>*/(List/*<T>*/ l, [int compareFn(/*=T*/a, /*=T*/b) = null]) {
|
||||
if (compareFn == null) {
|
||||
l.sort();
|
||||
} else {
|
||||
l.sort(compareFn);
|
||||
}
|
||||
}
|
||||
|
||||
static String toJSON(List l) {
|
||||
return jsonEncoder.convert(l);
|
||||
}
|
||||
|
||||
// JS splice, slice, fill functions can take start < 0 which indicates a position relative to
|
||||
// the end of the list
|
||||
static int _startOffset(List l, int start) {
|
||||
int len = l.length;
|
||||
return start < 0 ? max(len + start, 0) : min(start, len);
|
||||
}
|
||||
|
||||
// JS splice, slice, fill functions can take end < 0 which indicates a position relative to
|
||||
// the end of the list
|
||||
static int _endOffset(List l, int end) {
|
||||
int len = l.length;
|
||||
if (end == null) return len;
|
||||
return end < 0 ? max(len + end, 0) : min(end, len);
|
||||
}
|
||||
|
||||
static maximum(List l, fn(item)) {
|
||||
if (l.length == 0) {
|
||||
return null;
|
||||
}
|
||||
var solution = null;
|
||||
var maxValue = double.NEGATIVE_INFINITY;
|
||||
for (var index = 0; index < l.length; index++) {
|
||||
var candidate = l[index];
|
||||
if (candidate == null) {
|
||||
continue;
|
||||
}
|
||||
var candidateValue = fn(candidate);
|
||||
if (candidateValue > maxValue) {
|
||||
solution = candidate;
|
||||
maxValue = candidateValue;
|
||||
}
|
||||
}
|
||||
return solution;
|
||||
}
|
||||
|
||||
static List flatten(List l) {
|
||||
var target = [];
|
||||
_flattenArray(l, target);
|
||||
return target;
|
||||
}
|
||||
|
||||
static addAll(List l, List source) {
|
||||
l.addAll(source);
|
||||
}
|
||||
}
|
||||
|
||||
List _flattenArray(List source, List target) {
|
||||
if (source != null) {
|
||||
for (var i = 0; i < source.length; i++) {
|
||||
var item = source[i];
|
||||
if (item is List) {
|
||||
_flattenArray(item, target);
|
||||
} else {
|
||||
target.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
bool isListLikeIterable(obj) => obj is Iterable;
|
||||
|
||||
bool areIterablesEqual/*<T>*/(
|
||||
Iterable/*<T>*/ a,
|
||||
Iterable/*<T>*/ b,
|
||||
bool comparator(/*=T*/a, /*=T*/b))
|
||||
{
|
||||
var iterator1 = a.iterator;
|
||||
var iterator2 = b.iterator;
|
||||
|
||||
while (true) {
|
||||
var done1 = !iterator1.moveNext();
|
||||
var done2 = !iterator2.moveNext();
|
||||
if (done1 && done2) return true;
|
||||
if (done1 || done2) return false;
|
||||
if (!comparator(iterator1.current, iterator2.current)) return false;
|
||||
}
|
||||
}
|
||||
|
||||
void iterateListLike/*<T>*/(Iterable/*<T>*/ iter, fn(/*=T*/item)) {
|
||||
assert(iter is Iterable);
|
||||
for (var item in iter) {
|
||||
fn(item);
|
||||
}
|
||||
}
|
||||
|
||||
class SetWrapper {
|
||||
static Set/*<T>*/ createFromList/*<T>*/(List/*<T>*/ l) => new Set.from(l);
|
||||
static bool has/*<T>*/(Set/*<T>*/ s, /*=T*/key) => s.contains(key);
|
||||
static void delete/*<T>*/(Set/*<T>*/ m, /*=T*/k) {
|
||||
m.remove(k);
|
||||
}
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
library angular.core.facade.exceptions;
|
||||
|
||||
import 'base_wrapped_exception.dart';
|
||||
import 'exception_handler.dart';
|
||||
export 'exception_handler.dart';
|
||||
|
||||
class BaseException extends Error {
|
||||
final String _message;
|
||||
|
||||
BaseException([this._message]);
|
||||
|
||||
String get message => _message;
|
||||
|
||||
String toString() {
|
||||
return this.message;
|
||||
}
|
||||
}
|
||||
|
||||
class WrappedException extends BaseWrappedException {
|
||||
final dynamic _context;
|
||||
final String _wrapperMessage;
|
||||
final originalException;
|
||||
final originalStack;
|
||||
|
||||
WrappedException(
|
||||
[this._wrapperMessage,
|
||||
this.originalException,
|
||||
this.originalStack,
|
||||
this._context]);
|
||||
|
||||
String get message {
|
||||
return ExceptionHandler.exceptionToString(this);
|
||||
}
|
||||
|
||||
String toString() {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
dynamic get context => _context;
|
||||
|
||||
String get wrapperMessage => _wrapperMessage;
|
||||
}
|
||||
|
||||
Error makeTypeError([String message = ""]) {
|
||||
return new BaseException(message);
|
||||
}
|
||||
|
||||
dynamic unimplemented() {
|
||||
throw new BaseException('unimplemented');
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
library facade.intl;
|
||||
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
String _normalizeLocale(String locale) => locale.replaceAll('-', '_');
|
||||
|
||||
enum NumberFormatStyle { Decimal, Percent, Currency }
|
||||
|
||||
class NumberFormatter {
|
||||
static String format(num number, String locale, NumberFormatStyle style,
|
||||
{int minimumIntegerDigits: 1,
|
||||
int minimumFractionDigits: 0,
|
||||
int maximumFractionDigits: 3,
|
||||
String currency,
|
||||
bool currencyAsSymbol: false}) {
|
||||
locale = _normalizeLocale(locale);
|
||||
NumberFormat formatter;
|
||||
switch (style) {
|
||||
case NumberFormatStyle.Decimal:
|
||||
formatter = new NumberFormat.decimalPattern(locale);
|
||||
break;
|
||||
case NumberFormatStyle.Percent:
|
||||
formatter = new NumberFormat.percentPattern(locale);
|
||||
break;
|
||||
case NumberFormatStyle.Currency:
|
||||
if (currencyAsSymbol) {
|
||||
// See https://github.com/dart-lang/intl/issues/59.
|
||||
throw new Exception(
|
||||
'Displaying currency as symbol is not supported.');
|
||||
}
|
||||
formatter = new NumberFormat.currencyPattern(locale, currency);
|
||||
break;
|
||||
}
|
||||
formatter.minimumIntegerDigits = minimumIntegerDigits;
|
||||
formatter.minimumFractionDigits = minimumFractionDigits;
|
||||
formatter.maximumFractionDigits = maximumFractionDigits;
|
||||
return formatter.format(number);
|
||||
}
|
||||
}
|
||||
|
||||
class DateFormatter {
|
||||
static RegExp _multiPartRegExp = new RegExp(r'^([yMdE]+)([Hjms]+)$');
|
||||
|
||||
static String format(DateTime date, String locale, String pattern) {
|
||||
locale = _normalizeLocale(locale);
|
||||
var formatter = new DateFormat(null, locale);
|
||||
var matches = _multiPartRegExp.firstMatch(pattern);
|
||||
if (matches != null) {
|
||||
// Support for patterns which have known date and time components.
|
||||
formatter.addPattern(matches[1]);
|
||||
formatter.addPattern(matches[2], ', ');
|
||||
} else {
|
||||
formatter.addPattern(pattern);
|
||||
}
|
||||
return formatter.format(date);
|
||||
}
|
||||
}
|
@ -1,373 +0,0 @@
|
||||
library angular.core.facade.lang;
|
||||
|
||||
export 'dart:core' show Type, RegExp, print, DateTime, Uri;
|
||||
import 'dart:math' as math;
|
||||
import 'dart:convert' as convert;
|
||||
import 'dart:async' show Future, Zone;
|
||||
|
||||
String getTypeNameForDebugging(Object type) => type.toString();
|
||||
|
||||
class Math {
|
||||
static final _random = new math.Random();
|
||||
static int floor(num n) => n.floor();
|
||||
static double random() => _random.nextDouble();
|
||||
static num min(num a, num b) => math.min(a, b);
|
||||
}
|
||||
|
||||
const IS_DART = true;
|
||||
|
||||
scheduleMicroTask(Function fn) {
|
||||
Zone.current.scheduleMicrotask(fn);
|
||||
}
|
||||
|
||||
bool isPresent(Object obj) => obj != null;
|
||||
bool isBlank(Object obj) => obj == null;
|
||||
bool isString(Object obj) => obj is String;
|
||||
bool isFunction(Object obj) => obj is Function;
|
||||
bool isType(Object obj) => obj is Type;
|
||||
bool isStringMap(Object obj) => obj is Map;
|
||||
bool isStrictStringMap(Object obj) => obj is Map;
|
||||
bool isArray(Object obj) => obj is List;
|
||||
bool isPromise(Object obj) => obj is Future;
|
||||
bool isNumber(Object obj) => obj is num;
|
||||
bool isBoolean(Object obj) => obj is bool;
|
||||
bool isDate(Object obj) => obj is DateTime;
|
||||
|
||||
String stringify(obj) {
|
||||
final exp = new RegExp(r"from Function '(\w+)'");
|
||||
final str = obj.toString();
|
||||
if (exp.firstMatch(str) != null) {
|
||||
return exp.firstMatch(str).group(1);
|
||||
} else {
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
int serializeEnum(val) {
|
||||
return val.index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes an enum
|
||||
* val should be the indexed value of the enum (sa returned from @link{serializeEnum})
|
||||
* values should be a map from indexes to values for the enum that you want to deserialize.
|
||||
*/
|
||||
dynamic deserializeEnum(num val, Map<num, dynamic> values) {
|
||||
return values[val];
|
||||
}
|
||||
|
||||
String resolveEnumToken(enumValue, val) {
|
||||
// turn Enum.Token -> Token
|
||||
return val.toString().replaceFirst(new RegExp('^.+\\.'),'');
|
||||
}
|
||||
|
||||
class StringWrapper {
|
||||
static String fromCharCode(int code) {
|
||||
return new String.fromCharCode(code);
|
||||
}
|
||||
|
||||
static int charCodeAt(String s, int index) {
|
||||
return s.codeUnitAt(index);
|
||||
}
|
||||
|
||||
static List<String> split(String s, RegExp regExp) {
|
||||
var parts = <String>[];
|
||||
var lastEnd = 0;
|
||||
regExp.allMatches(s).forEach((match) {
|
||||
parts.add(s.substring(lastEnd, match.start));
|
||||
lastEnd = match.end;
|
||||
for (var i = 0; i < match.groupCount; i++) {
|
||||
parts.add(match.group(i + 1));
|
||||
}
|
||||
});
|
||||
parts.add(s.substring(lastEnd));
|
||||
return parts;
|
||||
}
|
||||
|
||||
static bool equals(String s, String s2) {
|
||||
return s == s2;
|
||||
}
|
||||
|
||||
static String stripLeft(String s, String charVal) {
|
||||
if (isPresent(s) && s.length > 0) {
|
||||
var pos = 0;
|
||||
for (var i = 0; i < s.length; i++) {
|
||||
if (s[i] != charVal) break;
|
||||
pos++;
|
||||
}
|
||||
s = s.substring(pos);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
static String stripRight(String s, String charVal) {
|
||||
if (isPresent(s) && s.length > 0) {
|
||||
var pos = s.length;
|
||||
for (var i = s.length - 1; i >= 0; i--) {
|
||||
if (s[i] != charVal) break;
|
||||
pos--;
|
||||
}
|
||||
s = s.substring(0, pos);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
static String replace(String s, Pattern from, String replace) {
|
||||
return s.replaceFirst(from, replace);
|
||||
}
|
||||
|
||||
static String replaceAll(String s, RegExp from, String replace) {
|
||||
return s.replaceAll(from, replace);
|
||||
}
|
||||
|
||||
static String slice(String s, [int start = 0, int end]) {
|
||||
start = _startOffset(s, start);
|
||||
end = _endOffset(s, end);
|
||||
//in JS if start > end an empty string is returned
|
||||
if (end != null && start > end) {
|
||||
return "";
|
||||
}
|
||||
return s.substring(start, end);
|
||||
}
|
||||
|
||||
static String replaceAllMapped(String s, RegExp from, Function cb) {
|
||||
return s.replaceAllMapped(from, cb);
|
||||
}
|
||||
|
||||
static bool contains(String s, String substr) {
|
||||
return s.contains(substr);
|
||||
}
|
||||
|
||||
static int compare(String a, String b) => a.compareTo(b);
|
||||
|
||||
// JS slice function can take start < 0 which indicates a position relative to
|
||||
// the end of the string
|
||||
static int _startOffset(String s, int start) {
|
||||
int len = s.length;
|
||||
return start < 0 ? math.max(len + start, 0) : math.min(start, len);
|
||||
}
|
||||
|
||||
// JS slice function can take end < 0 which indicates a position relative to
|
||||
// the end of the string
|
||||
static int _endOffset(String s, int end) {
|
||||
int len = s.length;
|
||||
if (end == null) return len;
|
||||
return end < 0 ? math.max(len + end, 0) : math.min(end, len);
|
||||
}
|
||||
}
|
||||
|
||||
class StringJoiner {
|
||||
final List<String> _parts = <String>[];
|
||||
|
||||
void add(String part) {
|
||||
_parts.add(part);
|
||||
}
|
||||
|
||||
String toString() => _parts.join("");
|
||||
}
|
||||
|
||||
class NumberWrapper {
|
||||
static String toFixed(num n, int fractionDigits) {
|
||||
return n.toStringAsFixed(fractionDigits);
|
||||
}
|
||||
|
||||
static bool equal(num a, num b) {
|
||||
return a == b;
|
||||
}
|
||||
|
||||
static int parseIntAutoRadix(String text) {
|
||||
return int.parse(text);
|
||||
}
|
||||
|
||||
static int parseInt(String text, int radix) {
|
||||
return int.parse(text, radix: radix);
|
||||
}
|
||||
|
||||
static double parseFloat(String text) {
|
||||
return double.parse(text);
|
||||
}
|
||||
|
||||
static double get NaN => double.NAN;
|
||||
|
||||
static bool isNumeric(value) {
|
||||
if(value == null) {
|
||||
return false;
|
||||
}
|
||||
return double.parse(value, (e) => null) != null;
|
||||
}
|
||||
|
||||
static bool isNaN(num value) => value.isNaN;
|
||||
|
||||
static bool isInteger(value) => value is int;
|
||||
}
|
||||
|
||||
class RegExpWrapper {
|
||||
static RegExp create(regExpStr, [String flags = '']) {
|
||||
bool multiLine = flags.contains('m');
|
||||
bool caseSensitive = !flags.contains('i');
|
||||
return new RegExp(regExpStr,
|
||||
multiLine: multiLine, caseSensitive: caseSensitive);
|
||||
}
|
||||
|
||||
static Match firstMatch(RegExp regExp, String input) {
|
||||
return regExp.firstMatch(input);
|
||||
}
|
||||
|
||||
static bool test(RegExp regExp, String input) {
|
||||
return regExp.hasMatch(input);
|
||||
}
|
||||
|
||||
static Iterator<Match> matcher(RegExp regExp, String input) {
|
||||
return regExp.allMatches(input).iterator;
|
||||
}
|
||||
|
||||
static String replaceAll(RegExp regExp, String input, Function replace) {
|
||||
final m = RegExpWrapper.matcher(regExp, input);
|
||||
var res = "";
|
||||
var prev = 0;
|
||||
while(m.moveNext()) {
|
||||
var c = m.current;
|
||||
res += input.substring(prev, c.start);
|
||||
res += replace(c);
|
||||
prev = c.start + c[0].length;
|
||||
}
|
||||
res += input.substring(prev);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
class RegExpMatcherWrapper {
|
||||
static _JSLikeMatch next(Iterator<Match> matcher) {
|
||||
if (matcher.moveNext()) {
|
||||
return new _JSLikeMatch(matcher.current);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class _JSLikeMatch {
|
||||
Match _m;
|
||||
|
||||
_JSLikeMatch(this._m);
|
||||
|
||||
String operator [](index) => _m[index];
|
||||
int get index => _m.start;
|
||||
int get length => _m.groupCount + 1;
|
||||
}
|
||||
|
||||
class FunctionWrapper {
|
||||
static apply(Function fn, posArgs) {
|
||||
return Function.apply(fn, posArgs);
|
||||
}
|
||||
|
||||
static Function bind(Function fn, dynamic scope) {
|
||||
return fn;
|
||||
}
|
||||
}
|
||||
|
||||
const _NAN_KEY = const Object();
|
||||
|
||||
// Dart VM implements `identical` as true reference identity. JavaScript does
|
||||
// not have this. The closest we have in JS is `===`. However, for strings JS
|
||||
// would actually compare the contents rather than references. `dart2js`
|
||||
// compiles `identical` to `===` and therefore there is a discrepancy between
|
||||
// Dart VM and `dart2js`. The implementation of `looseIdentical` attempts to
|
||||
// bridge the gap between the two while retaining good performance
|
||||
// characteristics. In JS we use simple `identical`, which compiles to `===`,
|
||||
// and in Dart VM we emulate the semantics of `===` by special-casing strings.
|
||||
// Note that the VM check is a compile-time constant. This allows `dart2js` to
|
||||
// evaluate the conditional during compilation and inline the entire function.
|
||||
//
|
||||
// See: dartbug.com/22496, dartbug.com/25270
|
||||
const _IS_DART_VM = !identical(1.0, 1); // a hack
|
||||
bool looseIdentical(a, b) => _IS_DART_VM
|
||||
? _looseIdentical(a, b)
|
||||
: identical(a, b);
|
||||
|
||||
// This function is intentionally separated from `looseIdentical` to keep the
|
||||
// number of AST nodes low enough for `dart2js` to inline the code.
|
||||
bool _looseIdentical(a, b) =>
|
||||
a is String && b is String ? a == b : identical(a, b);
|
||||
|
||||
// Dart compare map keys by equality and we can have NaN != NaN
|
||||
dynamic getMapKey(value) {
|
||||
if (value is! num) return value;
|
||||
return value.isNaN ? _NAN_KEY : value;
|
||||
}
|
||||
|
||||
// TODO: remove with https://github.com/angular/angular/issues/3055
|
||||
dynamic normalizeBlank(obj) => obj;
|
||||
|
||||
bool normalizeBool(bool obj) {
|
||||
return isBlank(obj) ? false : obj;
|
||||
}
|
||||
|
||||
bool isJsObject(o) {
|
||||
return false;
|
||||
}
|
||||
|
||||
warn(o) {
|
||||
print(o);
|
||||
}
|
||||
|
||||
// Can't be all uppercase as our transpiler would think it is a special directive...
|
||||
class Json {
|
||||
static parse(String s) => convert.JSON.decode(s);
|
||||
static String stringify(data) {
|
||||
var encoder = new convert.JsonEncoder.withIndent(" ");
|
||||
return encoder.convert(data);
|
||||
}
|
||||
}
|
||||
|
||||
class DateWrapper {
|
||||
static DateTime create(int year,
|
||||
[int month = 1,
|
||||
int day = 1,
|
||||
int hour = 0,
|
||||
int minutes = 0,
|
||||
int seconds = 0,
|
||||
int milliseconds = 0]) {
|
||||
return new DateTime(year, month, day, hour, minutes, seconds, milliseconds);
|
||||
}
|
||||
|
||||
static DateTime fromISOString(String str) {
|
||||
return DateTime.parse(str);
|
||||
}
|
||||
|
||||
static DateTime fromMillis(int ms) {
|
||||
return new DateTime.fromMillisecondsSinceEpoch(ms, isUtc: true);
|
||||
}
|
||||
|
||||
static int toMillis(DateTime date) {
|
||||
return date.millisecondsSinceEpoch;
|
||||
}
|
||||
|
||||
static DateTime now() {
|
||||
return new DateTime.now();
|
||||
}
|
||||
|
||||
static String toJson(DateTime date) {
|
||||
return date.toUtc().toIso8601String();
|
||||
}
|
||||
}
|
||||
|
||||
bool isPrimitive(Object obj) => obj is num || obj is bool || obj == null || obj is String;
|
||||
|
||||
// needed to match the exports from lang.js
|
||||
var global = null;
|
||||
|
||||
dynamic evalExpression(String sourceUrl, String expr, String declarations, Map<String, String> vars) {
|
||||
throw "Dart does not support evaluating expression during runtime!";
|
||||
}
|
||||
|
||||
bool hasConstructor(Object value, Type type) {
|
||||
return value.runtimeType == type;
|
||||
}
|
||||
|
||||
String escape(String s) {
|
||||
return Uri.encodeComponent(s);
|
||||
}
|
||||
|
||||
String escapeRegExp(String s) {
|
||||
return s.replaceAllMapped(new RegExp(r'([.*+?^=!:${}()|[\]\/\\])'), (Match m) => '\\${m[1]}');
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
library angular.core.facade.math;
|
||||
|
||||
import 'dart:core' show double, num;
|
||||
import 'dart:math' as math;
|
||||
|
||||
const NaN = double.NAN;
|
||||
|
||||
class Math {
|
||||
static num pow(num x, num exponent) {
|
||||
return math.pow(x, exponent);
|
||||
}
|
||||
|
||||
static num max(num a, num b) => math.max(a, b);
|
||||
|
||||
static num min(num a, num b) => math.min(a, b);
|
||||
|
||||
static num floor(num a) => a.floor();
|
||||
|
||||
static num ceil(num a) => a.ceil();
|
||||
|
||||
static num sqrt(num x) => math.sqrt(x);
|
||||
|
||||
static num round(num x) => x.round();
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
library angular2.core.facade.promise;
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:async' as async;
|
||||
|
||||
class PromiseWrapper {
|
||||
static Future/*<T>*/ resolve/*<T>*/(dynamic /*=T*/ obj) => new Future.value(obj);
|
||||
|
||||
static Future/*<T>*/ reject/*<T>*/(dynamic /*=T*/ obj, Object stackTrace) => new Future.error(obj,
|
||||
stackTrace != null ? stackTrace : obj is Error ? (obj as Error).stackTrace : null);
|
||||
|
||||
static Future<List/*<T>*/> all/*<T>*/(List<dynamic> promises) {
|
||||
return Future
|
||||
.wait(promises.map((p) => p is Future ? p as Future/*<T>*/ : new Future/*<T>*/.value(p)));
|
||||
}
|
||||
static Future/*<R>*/ then/*<T, R>*/(Future/*<T>*/ promise, dynamic /*=R*/ success(dynamic /*=T*/ value), [Function onError]) {
|
||||
if (success == null) return promise.catchError(onError);
|
||||
return promise.then(success, onError: onError);
|
||||
}
|
||||
|
||||
static Future/*<T>*/ wrap/*<T>*/(dynamic /*=T*/ fn()) {
|
||||
return new Future(fn);
|
||||
}
|
||||
|
||||
// Note: We can't rename this method to `catch`, as this is not a valid
|
||||
// method name in Dart.
|
||||
static Future catchError(Future promise, Function onError) {
|
||||
return promise.catchError(onError);
|
||||
}
|
||||
|
||||
static void scheduleMicrotask(fn) {
|
||||
async.scheduleMicrotask(fn);
|
||||
}
|
||||
|
||||
static bool isPromise(obj) {
|
||||
return obj is Future;
|
||||
}
|
||||
|
||||
static PromiseCompleter/*<T>*/ completer/*<T>*/() =>
|
||||
new PromiseCompleter();
|
||||
}
|
||||
|
||||
class PromiseCompleter<T> {
|
||||
final Completer<T> c = new Completer();
|
||||
|
||||
Future<T> get promise => c.future;
|
||||
|
||||
void resolve(v) {
|
||||
c.complete(v);
|
||||
}
|
||||
|
||||
void reject(error, stack) {
|
||||
if (stack == null && error is Error) {
|
||||
stack = error.stackTrace;
|
||||
}
|
||||
c.completeError(error, stack);
|
||||
}
|
||||
}
|
@ -1,106 +0,0 @@
|
||||
/// This file contains tests that make sense only in Dart
|
||||
library angular2.test.facade.async_dart_spec;
|
||||
|
||||
import 'dart:async';
|
||||
import 'package:angular2/testing_internal.dart';
|
||||
import 'package:angular2/src/facade/async.dart';
|
||||
|
||||
class MockException implements Error {
|
||||
var message;
|
||||
var stackTrace;
|
||||
}
|
||||
|
||||
class NonError {
|
||||
var message;
|
||||
}
|
||||
|
||||
void functionThatThrows() {
|
||||
try {
|
||||
throw new MockException();
|
||||
} catch (e, stack) {
|
||||
// If we lose the stack trace the message will no longer match
|
||||
// the first line in the stack
|
||||
e.message = stack.toString().split('\n')[0];
|
||||
e.stackTrace = stack;
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
void functionThatThrowsNonError() {
|
||||
try {
|
||||
throw new NonError();
|
||||
} catch (e, stack) {
|
||||
// If we lose the stack trace the message will no longer match
|
||||
// the first line in the stack
|
||||
e.message = stack.toString().split('\n')[0];
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
void expectFunctionThatThrowsWithStackTrace(
|
||||
Future future, AsyncTestCompleter async) {
|
||||
PromiseWrapper.catchError(future, (err, StackTrace stack) {
|
||||
expect(stack.toString().split('\n')[0]).toEqual(err.message);
|
||||
async.done();
|
||||
});
|
||||
}
|
||||
|
||||
main() {
|
||||
describe('async facade', () {
|
||||
describe('Completer', () {
|
||||
it(
|
||||
'should preserve Error stack traces',
|
||||
inject([AsyncTestCompleter], (async) {
|
||||
var c = PromiseWrapper.completer();
|
||||
|
||||
expectFunctionThatThrowsWithStackTrace(c.promise, async);
|
||||
|
||||
try {
|
||||
functionThatThrows();
|
||||
} catch (e) {
|
||||
c.reject(e, null);
|
||||
}
|
||||
}));
|
||||
|
||||
it(
|
||||
'should preserve error stack traces for non-Errors',
|
||||
inject([AsyncTestCompleter], (async) {
|
||||
var c = PromiseWrapper.completer();
|
||||
|
||||
expectFunctionThatThrowsWithStackTrace(c.promise, async);
|
||||
|
||||
try {
|
||||
functionThatThrowsNonError();
|
||||
} catch (e, s) {
|
||||
c.reject(e, s);
|
||||
}
|
||||
}));
|
||||
});
|
||||
|
||||
describe('PromiseWrapper', () {
|
||||
describe('reject', () {
|
||||
it(
|
||||
'should preserve Error stack traces',
|
||||
inject([AsyncTestCompleter], (async) {
|
||||
try {
|
||||
functionThatThrows();
|
||||
} catch (e) {
|
||||
var rejectedFuture = PromiseWrapper.reject(e, null);
|
||||
expectFunctionThatThrowsWithStackTrace(rejectedFuture, async);
|
||||
}
|
||||
}));
|
||||
|
||||
it(
|
||||
'should preserve stack traces for non-Errors',
|
||||
inject([AsyncTestCompleter], (async) {
|
||||
try {
|
||||
functionThatThrowsNonError();
|
||||
} catch (e, s) {
|
||||
var rejectedFuture = PromiseWrapper.reject(e, s);
|
||||
expectFunctionThatThrowsWithStackTrace(rejectedFuture, async);
|
||||
}
|
||||
}));
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user