feat(facade): add support for `Date`
Also refactors the dart transpilar to expose the type mappings for future changes.
This commit is contained in:
parent
538b0879dc
commit
674848648a
|
@ -1,6 +1,6 @@
|
|||
library angular.core.facade.lang;
|
||||
|
||||
export 'dart:core' show Type, RegExp, print;
|
||||
export 'dart:core' show Type, RegExp, print, DateTime;
|
||||
import 'dart:math' as math;
|
||||
import 'dart:convert' as convert;
|
||||
|
||||
|
@ -183,3 +183,12 @@ class Json {
|
|||
static parse(String s) => convert.JSON.decode(s);
|
||||
static stringify(data) => convert.JSON.encode(data);
|
||||
}
|
||||
|
||||
class DateWrapper {
|
||||
static fromMillis(int ms) {
|
||||
return new DateTime.fromMillisecondsSinceEpoch(ms);
|
||||
}
|
||||
static now() {
|
||||
return new DateTime.now();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ export {_global as global};
|
|||
|
||||
export var Type = Function;
|
||||
export var Math = _global.Math;
|
||||
export var Date = _global.Date;
|
||||
|
||||
var assertionsEnabled_ = typeof assert !== 'undefined';
|
||||
|
||||
|
@ -250,3 +251,12 @@ export function print(obj) {
|
|||
|
||||
// Can't be all uppercase as our transpiler would think it is a special directive...
|
||||
export var Json = _global.JSON;
|
||||
|
||||
export class DateWrapper {
|
||||
static fromMillis(ms) {
|
||||
return new Date(ms);
|
||||
}
|
||||
static now() {
|
||||
return new Date();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ import {ParseTreeWriter as JavaScriptParseTreeWriter, ObjectLiteralExpression} f
|
|||
import {ImportedBinding, BindingIdentifier} from 'traceur/src/syntax/trees/ParseTrees';
|
||||
import {IdentifierToken} from 'traceur/src/syntax/IdentifierToken';
|
||||
import {EXPORT_STAR, NAMED_EXPORT} from 'traceur/src/syntax/trees/ParseTreeType';
|
||||
import {typeMapping} from '../type_mapping';
|
||||
|
||||
export class DartParseTreeWriter extends JavaScriptParseTreeWriter {
|
||||
constructor(moduleName, outputPath) {
|
||||
|
@ -221,14 +222,7 @@ export class DartParseTreeWriter extends JavaScriptParseTreeWriter {
|
|||
}
|
||||
|
||||
normalizeType_(typeName) {
|
||||
switch (typeName) {
|
||||
case 'number': return 'num';
|
||||
case 'boolean': return 'bool';
|
||||
case 'string': return 'String';
|
||||
case 'any': return 'dynamic';
|
||||
case 'Promise': return 'Future';
|
||||
default: return typeName;
|
||||
}
|
||||
return typeMapping[typeName] || typeName;
|
||||
}
|
||||
|
||||
// FUNCTION/METHOD ARGUMENTS
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
export var typeMapping = {
|
||||
'number': 'num',
|
||||
'boolean': 'bool',
|
||||
'string': 'String',
|
||||
'any': 'dynamic',
|
||||
'Promise': 'Future',
|
||||
'Date': 'DateTime'
|
||||
};
|
Loading…
Reference in New Issue