From cd9003895073ca8102fc048767781817269e6615 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Wed, 18 Feb 2015 09:04:02 -0800 Subject: [PATCH] fix(types): Add StringMap type --- modules/angular2/src/core/compiler/template_loader.js | 4 ++-- modules/angular2/src/facade/collection.dart | 1 - modules/angular2/src/facade/collection.es6 | 2 +- modules/angular2/src/forms/model.js | 6 +++--- modules/benchpress/src/measure_values.js | 5 +++-- modules/benchpress/src/metric.js | 5 +++-- modules/benchpress/src/metric/perflog_metric.js | 4 ++-- modules/benchpress/src/sample_description.js | 8 ++++---- modules/benchpress/src/sampler.js | 4 ++-- modules/benchpress/src/validator.js | 4 ++-- .../src/validator/regression_slope_validator.js | 4 ++-- modules/benchpress/src/validator/size_validator.js | 7 ++++--- tools/transpiler/src/type_mapping.js | 4 +++- 13 files changed, 31 insertions(+), 27 deletions(-) diff --git a/modules/angular2/src/core/compiler/template_loader.js b/modules/angular2/src/core/compiler/template_loader.js index dfdeba508d..32f5417885 100644 --- a/modules/angular2/src/core/compiler/template_loader.js +++ b/modules/angular2/src/core/compiler/template_loader.js @@ -1,6 +1,6 @@ import {isBlank, isPresent, BaseException, stringify} from 'angular2/src/facade/lang'; import {DOM, Element} from 'angular2/src/facade/dom'; -import {StringMapWrapper} from 'angular2/src/facade/collection'; +import {StringMapWrapper, StringMap} from 'angular2/src/facade/collection'; import {XHR} from './xhr/xhr'; @@ -11,7 +11,7 @@ import {Template} from 'angular2/src/core/annotations/template'; */ export class TemplateLoader { _xhr: XHR; - _cache; + _cache: StringMap; constructor(xhr: XHR) { this._xhr = xhr; diff --git a/modules/angular2/src/facade/collection.dart b/modules/angular2/src/facade/collection.dart index 9387ca27cb..928f8ea6e2 100644 --- a/modules/angular2/src/facade/collection.dart +++ b/modules/angular2/src/facade/collection.dart @@ -57,7 +57,6 @@ class MapWrapper { static Iterable values(Map m) => m.values; } -// TODO: how to export StringMap=Map as a type? class StringMapWrapper { static HashMap create() => new HashMap(); static bool contains(Map map, key) => map.containsKey(key); diff --git a/modules/angular2/src/facade/collection.es6 b/modules/angular2/src/facade/collection.es6 index d62dc87346..763335cf6c 100644 --- a/modules/angular2/src/facade/collection.es6 +++ b/modules/angular2/src/facade/collection.es6 @@ -3,6 +3,7 @@ import {int, isJsObject, global} from 'angular2/src/facade/lang'; export var List = global.Array; export var Map = global.Map; export var Set = global.Set; +export var StringMap = global.Object; export class MapWrapper { static create():Map { return new Map(); } @@ -29,7 +30,6 @@ export class MapWrapper { static values(m) { return m.values(); } } -// TODO: cannot export StringMap as a type as Dart does not support renaming types... /** * Wraps Javascript Objects */ diff --git a/modules/angular2/src/forms/model.js b/modules/angular2/src/forms/model.js index 22bc95369e..c654834c07 100644 --- a/modules/angular2/src/forms/model.js +++ b/modules/angular2/src/forms/model.js @@ -1,4 +1,4 @@ -import {StringMapWrapper} from 'angular2/src/facade/collection'; +import {StringMapWrapper, StringMap} from 'angular2/src/facade/collection'; export class Control { value:any; @@ -9,9 +9,9 @@ export class Control { } export class ControlGroup { - controls; + controls: StringMap; - constructor(controls) { + constructor(controls:StringMap) { this.controls = controls; } diff --git a/modules/benchpress/src/measure_values.js b/modules/benchpress/src/measure_values.js index 6e4c5a4ee1..cafae766c2 100644 --- a/modules/benchpress/src/measure_values.js +++ b/modules/benchpress/src/measure_values.js @@ -1,11 +1,12 @@ import { Date } from 'angular2/src/facade/lang'; +import { StringMap } from 'angular2/src/facade/collection'; export class MeasureValues { timeStamp:Date; runIndex:number; - values:any; + values:StringMap; - constructor(runIndex:number, timeStamp:Date, values:any) { + constructor(runIndex:number, timeStamp:Date, values:StringMap) { this.timeStamp = timeStamp; this.runIndex = runIndex; this.values = values; diff --git a/modules/benchpress/src/metric.js b/modules/benchpress/src/metric.js index 9d7bbcf21d..a9edcdb6ee 100644 --- a/modules/benchpress/src/metric.js +++ b/modules/benchpress/src/metric.js @@ -4,6 +4,7 @@ import { import { ABSTRACT, BaseException } from 'angular2/src/facade/lang'; +import { StringMap } from 'angular2/src/facade/collection'; /** * A metric is measures values @@ -22,7 +23,7 @@ export class Metric { * since the begin call. * @param restart: Whether to restart right after this. */ - endMeasure(restart:boolean):Promise { + endMeasure(restart:boolean):Promise { throw new BaseException('NYI'); } @@ -30,7 +31,7 @@ export class Metric { * Describes the metrics provided by this metric implementation. * (e.g. units, ...) */ - describe():any { + describe():StringMap { throw new BaseException('NYI'); } } diff --git a/modules/benchpress/src/metric/perflog_metric.js b/modules/benchpress/src/metric/perflog_metric.js index c8e983eff2..7fe1326124 100644 --- a/modules/benchpress/src/metric/perflog_metric.js +++ b/modules/benchpress/src/metric/perflog_metric.js @@ -1,6 +1,6 @@ import { PromiseWrapper, Promise } from 'angular2/src/facade/async'; import { isPresent, isBlank, int, BaseException, StringWrapper } from 'angular2/src/facade/lang'; -import { ListWrapper } from 'angular2/src/facade/collection'; +import { ListWrapper, StringMap } from 'angular2/src/facade/collection'; import { bind, OpaqueToken } from 'angular2/di'; import { WebDriverExtension } from '../web_driver_extension'; @@ -28,7 +28,7 @@ export class PerflogMetric extends Metric { this._setTimeout = setTimeout; } - describe() { + describe():StringMap { return { 'script': 'script execution time in ms', 'render': 'render time in ms', diff --git a/modules/benchpress/src/sample_description.js b/modules/benchpress/src/sample_description.js index eafda76494..98d95538e5 100644 --- a/modules/benchpress/src/sample_description.js +++ b/modules/benchpress/src/sample_description.js @@ -1,4 +1,4 @@ -import { StringMapWrapper, ListWrapper } from 'angular2/src/facade/collection'; +import { StringMapWrapper, ListWrapper, StringMap } from 'angular2/src/facade/collection'; import { bind, OpaqueToken } from 'angular2/di'; import { Sampler } from './sampler'; import { Validator } from './validator'; @@ -13,10 +13,10 @@ export class SampleDescription { static get BINDINGS() { return _BINDINGS; } id:string; - description:any; - metrics:any; + description:StringMap; + metrics:StringMap; - constructor(id, descriptions, metrics) { + constructor(id, descriptions:List, metrics:StringMap) { this.id = id; this.metrics = metrics; this.description = {}; diff --git a/modules/benchpress/src/sampler.js b/modules/benchpress/src/sampler.js index 8454e249bd..07be72e354 100644 --- a/modules/benchpress/src/sampler.js +++ b/modules/benchpress/src/sampler.js @@ -1,6 +1,6 @@ import { isPresent, isBlank, Date, DateWrapper } from 'angular2/src/facade/lang'; import { Promise, PromiseWrapper } from 'angular2/src/facade/async'; -import { StringMapWrapper, List, ListWrapper } from 'angular2/src/facade/collection'; +import { StringMapWrapper, StringMap, List, ListWrapper } from 'angular2/src/facade/collection'; import { bind, OpaqueToken } from 'angular2/di'; import { Metric } from './metric'; @@ -95,7 +95,7 @@ export class Sampler { .then( (measureValues) => this._report(lastState, measureValues) ); } - _report(state:SampleState, metricValues:any):Promise { + _report(state:SampleState, metricValues:StringMap):Promise { var measureValues = new MeasureValues(state.completeSample.length, this._time(), metricValues); var completeSample = ListWrapper.concat(state.completeSample, [measureValues]); var validSample = this._validator.validate(completeSample); diff --git a/modules/benchpress/src/validator.js b/modules/benchpress/src/validator.js index 1d0c2a313d..95311dcabd 100644 --- a/modules/benchpress/src/validator.js +++ b/modules/benchpress/src/validator.js @@ -1,4 +1,4 @@ -import { List } from 'angular2/src/facade/collection'; +import { List, StringMap } from 'angular2/src/facade/collection'; import { ABSTRACT, BaseException } from 'angular2/src/facade/lang'; @@ -23,7 +23,7 @@ export class Validator { * Returns a Map that describes the properties of the validator * (e.g. sample size, ...) */ - describe():any { + describe():StringMap { throw new BaseException('NYI'); } } \ No newline at end of file diff --git a/modules/benchpress/src/validator/regression_slope_validator.js b/modules/benchpress/src/validator/regression_slope_validator.js index 23bf7eca4c..94a49ea286 100644 --- a/modules/benchpress/src/validator/regression_slope_validator.js +++ b/modules/benchpress/src/validator/regression_slope_validator.js @@ -1,4 +1,4 @@ -import { List, ListWrapper } from 'angular2/src/facade/collection'; +import { List, ListWrapper, StringMap } from 'angular2/src/facade/collection'; import { bind, OpaqueToken } from 'angular2/di'; import { Validator } from '../validator'; @@ -26,7 +26,7 @@ export class RegressionSlopeValidator extends Validator { this._metric = metric; } - describe():any { + describe():StringMap { return { 'sampleSize': this._sampleSize, 'regressionSlopeMetric': this._metric diff --git a/modules/benchpress/src/validator/size_validator.js b/modules/benchpress/src/validator/size_validator.js index 33a1729a0d..652da00238 100644 --- a/modules/benchpress/src/validator/size_validator.js +++ b/modules/benchpress/src/validator/size_validator.js @@ -1,7 +1,8 @@ -import { List, ListWrapper } from 'angular2/src/facade/collection'; +import { List, ListWrapper, StringMap } from 'angular2/src/facade/collection'; import { bind, OpaqueToken } from 'angular2/di'; import { Validator } from '../validator'; +import { MeasureValues } from '../measure_values'; /** * A validator that waits for the sample to have a certain size. @@ -19,13 +20,13 @@ export class SizeValidator extends Validator { this._sampleSize = size; } - describe():any { + describe():StringMap { return { 'sampleSize': this._sampleSize }; } - validate(completeSample:List):List { + validate(completeSample:List):List { if (completeSample.length >= this._sampleSize) { return ListWrapper.slice(completeSample, completeSample.length - this._sampleSize, completeSample.length); } else { diff --git a/tools/transpiler/src/type_mapping.js b/tools/transpiler/src/type_mapping.js index 87c34dcbb4..cef5709784 100644 --- a/tools/transpiler/src/type_mapping.js +++ b/tools/transpiler/src/type_mapping.js @@ -1,8 +1,10 @@ +// JS -> Dart export var typeMapping = { 'number': 'num', 'boolean': 'bool', 'string': 'String', 'any': 'dynamic', 'Promise': 'Future', - 'Date': 'DateTime' + 'Date': 'DateTime', + 'StringMap': 'Map' };