From 58605cf350ce5bde64d9b278c857017ad5c06679 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Sun, 18 Sep 2016 15:39:26 -0700 Subject: [PATCH] refactor(facade): remove useless facades --- modules/@angular/benchpress/src/sampler.ts | 4 +- .../test/reporter/console_reporter_spec.ts | 4 +- .../@angular/benchpress/test/sampler_spec.ts | 2 +- .../regression_slope_validator_spec.ts | 2 +- .../test/validator/size_validator_spec.ts | 4 +- .../compiler/src/css_parser/css_lexer.ts | 6 +-- .../@angular/compiler/src/output/path_util.ts | 5 --- .../src/view_compiler/view_builder.ts | 17 +++---- .../@angular/core/src/application_tokens.ts | 2 +- .../@angular/core/src/reflection/reflector.ts | 4 +- .../@angular/core/testing/testing_internal.ts | 4 +- modules/@angular/facade/src/browser.ts | 10 ++--- modules/@angular/facade/src/collection.ts | 37 ++++----------- modules/@angular/facade/src/lang.ts | 30 ++----------- modules/@angular/facade/test/lang_spec.ts | 17 +------ modules/@angular/forms/src/form_builder.ts | 6 +-- modules/@angular/forms/src/model.ts | 2 +- modules/@angular/http/src/headers.ts | 3 -- modules/@angular/http/test/headers_spec.ts | 4 +- .../src/dom/events/key_events.ts | 14 +++--- .../test/browser_util_spec.ts | 22 ++++----- .../platform-server/src/parse5_adapter.ts | 45 +++++++++---------- .../shared/client_message_broker.ts | 2 +- .../src/web_workers/shared/serializer.ts | 4 +- 24 files changed, 91 insertions(+), 159 deletions(-) diff --git a/modules/@angular/benchpress/src/sampler.ts b/modules/@angular/benchpress/src/sampler.ts index 6576f0f7a1..f080827e68 100644 --- a/modules/@angular/benchpress/src/sampler.ts +++ b/modules/@angular/benchpress/src/sampler.ts @@ -6,10 +6,10 @@ * found in the LICENSE file at https://angular.io/license */ -import {Inject, Injectable, OpaqueToken} from '@angular/core'; +import {Inject, Injectable} from '@angular/core'; import {Options} from './common_options'; -import {Date, DateWrapper, isBlank, isPresent} from './facade/lang'; +import {isPresent} from './facade/lang'; import {MeasureValues} from './measure_values'; import {Metric} from './metric'; import {Reporter} from './reporter'; diff --git a/modules/@angular/benchpress/test/reporter/console_reporter_spec.ts b/modules/@angular/benchpress/test/reporter/console_reporter_spec.ts index f5bf67eac4..12ee9b7df9 100644 --- a/modules/@angular/benchpress/test/reporter/console_reporter_spec.ts +++ b/modules/@angular/benchpress/test/reporter/console_reporter_spec.ts @@ -9,8 +9,8 @@ import {Provider} from '@angular/core'; import {AsyncTestCompleter, afterEach, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; -import {ConsoleReporter, MeasureValues, ReflectiveInjector, Reporter, SampleDescription, SampleState} from '../../index'; -import {Date, DateWrapper, isBlank, isPresent} from '../../src/facade/lang'; +import {ConsoleReporter, MeasureValues, ReflectiveInjector, SampleDescription} from '../../index'; +import {DateWrapper, isBlank, isPresent} from '../../src/facade/lang'; export function main() { describe('console reporter', () => { diff --git a/modules/@angular/benchpress/test/sampler_spec.ts b/modules/@angular/benchpress/test/sampler_spec.ts index 5df862a3ba..c9653aed3f 100644 --- a/modules/@angular/benchpress/test/sampler_spec.ts +++ b/modules/@angular/benchpress/test/sampler_spec.ts @@ -9,7 +9,7 @@ import {AsyncTestCompleter, afterEach, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; import {MeasureValues, Metric, Options, ReflectiveInjector, Reporter, Sampler, Validator, WebDriverAdapter} from '../index'; -import {Date, DateWrapper, isBlank, isPresent, stringify} from '../src/facade/lang'; +import {DateWrapper, isBlank, isPresent} from '../src/facade/lang'; export function main() { var EMPTY_EXECUTE = () => {}; diff --git a/modules/@angular/benchpress/test/validator/regression_slope_validator_spec.ts b/modules/@angular/benchpress/test/validator/regression_slope_validator_spec.ts index c774597870..76305fb467 100644 --- a/modules/@angular/benchpress/test/validator/regression_slope_validator_spec.ts +++ b/modules/@angular/benchpress/test/validator/regression_slope_validator_spec.ts @@ -10,7 +10,7 @@ import {AsyncTestCompleter, afterEach, beforeEach, ddescribe, describe, expect, import {MeasureValues, ReflectiveInjector, RegressionSlopeValidator} from '../../index'; import {ListWrapper} from '../../src/facade/collection'; -import {Date, DateWrapper} from '../../src/facade/lang'; +import {DateWrapper} from '../../src/facade/lang'; export function main() { describe('regression slope validator', () => { diff --git a/modules/@angular/benchpress/test/validator/size_validator_spec.ts b/modules/@angular/benchpress/test/validator/size_validator_spec.ts index e9d0e4e144..bc8c35dc8e 100644 --- a/modules/@angular/benchpress/test/validator/size_validator_spec.ts +++ b/modules/@angular/benchpress/test/validator/size_validator_spec.ts @@ -8,9 +8,9 @@ import {AsyncTestCompleter, afterEach, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; -import {MeasureValues, ReflectiveInjector, SizeValidator, Validator} from '../../index'; +import {MeasureValues, ReflectiveInjector, SizeValidator} from '../../index'; import {ListWrapper} from '../../src/facade/collection'; -import {Date, DateWrapper} from '../../src/facade/lang'; +import {DateWrapper} from '../../src/facade/lang'; export function main() { describe('size validator', () => { diff --git a/modules/@angular/compiler/src/css_parser/css_lexer.ts b/modules/@angular/compiler/src/css_parser/css_lexer.ts index f616b85af8..3966f203ed 100644 --- a/modules/@angular/compiler/src/css_parser/css_lexer.ts +++ b/modules/@angular/compiler/src/css_parser/css_lexer.ts @@ -9,7 +9,7 @@ import * as chars from '../chars'; import {BaseError} from '../facade/errors'; -import {StringWrapper, isPresent, resolveEnumToken} from '../facade/lang'; +import {StringWrapper, isPresent} from '../facade/lang'; export enum CssTokenType { EOF, @@ -223,8 +223,8 @@ export class CssScanner { var error: CssScannerError = null; if (!isMatchingType || (isPresent(value) && value != next.strValue)) { - var errorMessage = resolveEnumToken(CssTokenType, next.type) + ' does not match expected ' + - resolveEnumToken(CssTokenType, type) + ' value'; + var errorMessage = + CssTokenType[next.type] + ' does not match expected ' + CssTokenType[type] + ' value'; if (isPresent(value)) { errorMessage += ' ("' + next.strValue + '" should match "' + value + '")'; diff --git a/modules/@angular/compiler/src/output/path_util.ts b/modules/@angular/compiler/src/output/path_util.ts index f9f762deb4..aebfb7bbab 100644 --- a/modules/@angular/compiler/src/output/path_util.ts +++ b/modules/@angular/compiler/src/output/path_util.ts @@ -6,11 +6,6 @@ * found in the LICENSE file at https://angular.io/license */ -import {Injectable} from '@angular/core'; - -import {Math, isBlank, isPresent} from '../facade/lang'; - - // asset:// var _ASSET_URL_RE = /asset:([^\/]+)\/([^\/]+)\/(.+)/; diff --git a/modules/@angular/compiler/src/view_compiler/view_builder.ts b/modules/@angular/compiler/src/view_compiler/view_builder.ts index 166b160252..8a8c5c8464 100644 --- a/modules/@angular/compiler/src/view_compiler/view_builder.ts +++ b/modules/@angular/compiler/src/view_compiler/view_builder.ts @@ -6,14 +6,15 @@ * found in the LICENSE file at https://angular.io/license */ -import {ChangeDetectionStrategy, ViewEncapsulation} from '@angular/core'; -import {CompileDirectiveMetadata, CompileIdentifierMetadata, CompileTokenMetadata, CompileTypeMetadata} from '../compile_metadata'; -import {ListWrapper, SetWrapper, StringMapWrapper} from '../facade/collection'; +import {ViewEncapsulation} from '@angular/core'; + +import {CompileDirectiveMetadata, CompileIdentifierMetadata, CompileTokenMetadata} from '../compile_metadata'; +import {ListWrapper, StringMapWrapper} from '../facade/collection'; import {StringWrapper, isPresent} from '../facade/lang'; -import {Identifiers, identifierToken, resolveIdentifier, resolveIdentifierToken} from '../identifiers'; +import {Identifiers, identifierToken, resolveIdentifier} from '../identifiers'; import * as o from '../output/output_ast'; import {ChangeDetectorStatus, ViewType, isDefaultChangeDetectionStrategy} from '../private_import_core'; -import {AttrAst, BoundDirectivePropertyAst, BoundElementPropertyAst, BoundEventAst, BoundTextAst, DirectiveAst, ElementAst, EmbeddedTemplateAst, NgContentAst, ProviderAst, ReferenceAst, TemplateAst, TemplateAstVisitor, TextAst, VariableAst, templateVisitAll} from '../template_parser/template_ast'; +import {AttrAst, BoundDirectivePropertyAst, BoundElementPropertyAst, BoundEventAst, BoundTextAst, DirectiveAst, ElementAst, EmbeddedTemplateAst, NgContentAst, ReferenceAst, TemplateAst, TemplateAstVisitor, TextAst, VariableAst, templateVisitAll} from '../template_parser/template_ast'; import {createDiTokenExpression} from '../util'; import {CompileElement, CompileNode} from './compile_element'; @@ -596,15 +597,15 @@ function generateDetectChangesMethod(view: CompileView): o.Statement[] { var varStmts: any[] = []; var readVars = o.findReadVarNames(stmts); - if (SetWrapper.has(readVars, DetectChangesVars.changed.name)) { + if (readVars.has(DetectChangesVars.changed.name)) { varStmts.push(DetectChangesVars.changed.set(o.literal(true)).toDeclStmt(o.BOOL_TYPE)); } - if (SetWrapper.has(readVars, DetectChangesVars.changes.name)) { + if (readVars.has(DetectChangesVars.changes.name)) { varStmts.push( DetectChangesVars.changes.set(o.NULL_EXPR) .toDeclStmt(new o.MapType(o.importType(resolveIdentifier(Identifiers.SimpleChange))))); } - if (SetWrapper.has(readVars, DetectChangesVars.valUnwrapper.name)) { + if (readVars.has(DetectChangesVars.valUnwrapper.name)) { varStmts.push( DetectChangesVars.valUnwrapper .set(o.importExpr(resolveIdentifier(Identifiers.ValueUnwrapper)).instantiate([])) diff --git a/modules/@angular/core/src/application_tokens.ts b/modules/@angular/core/src/application_tokens.ts index 12a7be59ce..f41ad681d6 100644 --- a/modules/@angular/core/src/application_tokens.ts +++ b/modules/@angular/core/src/application_tokens.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {Math, StringWrapper} from '../src/facade/lang'; +import {StringWrapper} from '../src/facade/lang'; import {OpaqueToken} from './di'; diff --git a/modules/@angular/core/src/reflection/reflector.ts b/modules/@angular/core/src/reflection/reflector.ts index 024c122236..ab045dcdd5 100644 --- a/modules/@angular/core/src/reflection/reflector.ts +++ b/modules/@angular/core/src/reflection/reflector.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {MapWrapper, SetWrapper, StringMapWrapper} from '../facade/collection'; +import {MapWrapper, StringMapWrapper} from '../facade/collection'; import {isPresent} from '../facade/lang'; import {Type} from '../type'; import {PlatformReflectionCapabilities} from './platform_reflection_capabilities'; @@ -64,7 +64,7 @@ export class Reflector extends ReflectorReader { throw new Error('Usage tracking is disabled'); } var allTypes = MapWrapper.keys(this._injectableInfo); - return allTypes.filter(key => !SetWrapper.has(this._usedKeys, key)); + return allTypes.filter(key => !this._usedKeys.has(key)); } registerFunction(func: Function, funcInfo: ReflectionInfo): void { diff --git a/modules/@angular/core/testing/testing_internal.ts b/modules/@angular/core/testing/testing_internal.ts index 27674f4da4..aa3c86ce70 100644 --- a/modules/@angular/core/testing/testing_internal.ts +++ b/modules/@angular/core/testing/testing_internal.ts @@ -8,9 +8,9 @@ import {AsyncTestCompleter} from './async_test_completer'; import {StringMapWrapper} from './facade/collection'; -import {Math, global} from './facade/lang'; +import {global} from './facade/lang'; import {isPromise} from './private_import_core'; -import {TestBed, getTestBed, inject} from './test_bed'; +import {getTestBed, inject} from './test_bed'; export {AsyncTestCompleter} from './async_test_completer'; export {MockAnimationPlayer} from './mock_animation_player'; diff --git a/modules/@angular/facade/src/browser.ts b/modules/@angular/facade/src/browser.ts index 8305b9ae44..c7fd16ee43 100644 --- a/modules/@angular/facade/src/browser.ts +++ b/modules/@angular/facade/src/browser.ts @@ -9,13 +9,13 @@ /** * JS version of browser APIs. This library can only run in the browser. */ -var win = typeof window !== 'undefined' && window || {}; +const win = typeof window !== 'undefined' && window || {}; export {win as window}; -export var document = win.document; -export var location = win.location; -export var gc = win['gc'] ? () => win['gc']() : (): any => null; -export var performance = win['performance'] ? win['performance'] : null; +export const document = win.document; +export const location = win.location; +export const gc = win['gc'] ? () => win['gc']() : (): any => null; +export const performance = win['performance'] ? win['performance'] : null; export const Event = win['Event']; export const MouseEvent = win['MouseEvent']; export const KeyboardEvent = win['KeyboardEvent']; diff --git a/modules/@angular/facade/src/collection.ts b/modules/@angular/facade/src/collection.ts index fa4a760706..6f73771f01 100644 --- a/modules/@angular/facade/src/collection.ts +++ b/modules/@angular/facade/src/collection.ts @@ -98,10 +98,15 @@ export class MapWrapper { * Wraps Javascript Objects */ export class StringMapWrapper { - static get(map: {[key: string]: V}, key: string): V { - return map.hasOwnProperty(key) ? map[key] : undefined; + static create(): {[k: /*any*/ string]: any} { + // Note: We are not using Object.create(null) here due to + // performance! + // http://jsperf.com/ng2-object-create-null + return {}; + } + static contains(map: {[key: string]: any}, key: string): boolean { + return map.hasOwnProperty(key); } - static set(map: {[key: string]: V}, key: string, value: V) { map[key] = value; } static keys(map: {[key: string]: any}): string[] { return Object.keys(map); } static values(map: {[key: string]: T}): T[] { @@ -312,28 +317,4 @@ export function iterateListLike(obj: any, fn: Function) { fn(item.value); } } -} - -// Safari and Internet Explorer do not support the iterable parameter to the -// Set constructor. We work around that by manually adding the items. -var createSetFromList: {(lst: any[]): Set} = (function() { - var test = new Set([1, 2, 3]); - if (test.size === 3) { - return function createSetFromList(lst: any[]): Set { return new Set(lst); }; - } else { - return function createSetAndPopulateFromList(lst: any[]): Set { - var res = new Set(lst); - if (res.size !== lst.length) { - for (var i = 0; i < lst.length; i++) { - res.add(lst[i]); - } - } - return res; - }; - } -})(); -export class SetWrapper { - static createFromList(lst: T[]): Set { return createSetFromList(lst); } - static has(s: Set, key: T): boolean { return s.has(key); } - static delete(m: Set, k: K) { m.delete(k); } -} +} \ No newline at end of file diff --git a/modules/@angular/facade/src/lang.ts b/modules/@angular/facade/src/lang.ts index 0d99a2a813..5cc46d0405 100644 --- a/modules/@angular/facade/src/lang.ts +++ b/modules/@angular/facade/src/lang.ts @@ -59,16 +59,9 @@ export {_global as global}; export function getTypeNameForDebugging(type: any): string { - if (type['name']) { - return type['name']; - } - return typeof type; + return type['name'] || typeof type; } - -export var Math = _global.Math; -export var Date = _global.Date; - // TODO: remove calls to assert in production environment // Note: Can't just export this and import in in other files // as `assert` is a reserved keyword in Dart @@ -139,24 +132,9 @@ export function stringify(token: any): string { return token.name; } - var res = token.toString(); - var newLineIndex = res.indexOf('\n'); - return (newLineIndex === -1) ? res : res.substring(0, newLineIndex); -} - -// serialize / deserialize enum exist only for consistency with dart API -// enums in typescript don't need to be serialized - -export function serializeEnum(val: any): number { - return val; -} - -export function deserializeEnum(val: any, values: Map): any { - return val; -} - -export function resolveEnumToken(enumValue: any, val: any): string { - return enumValue[val]; + const res = token.toString(); + const newLineIndex = res.indexOf('\n'); + return newLineIndex === -1 ? res : res.substring(0, newLineIndex); } export class StringWrapper { diff --git a/modules/@angular/facade/test/lang_spec.ts b/modules/@angular/facade/test/lang_spec.ts index 823cc9ed0b..3b5137ba48 100644 --- a/modules/@angular/facade/test/lang_spec.ts +++ b/modules/@angular/facade/test/lang_spec.ts @@ -6,12 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {NumberWrapper, StringWrapper, escapeRegExp, hasConstructor, isPresent, resolveEnumToken} from '../src/lang'; - -enum UsefulEnum { - MyToken, - MyOtherToken -} +import {NumberWrapper, StringWrapper, escapeRegExp, hasConstructor} from '../src/lang'; class MySuperclass {} class MySubclass extends MySuperclass {} @@ -135,16 +130,6 @@ export function main() { }); }); - describe('resolveEnumToken', () => { - it('should resolve a token given an enum and index values', () => { - var token = UsefulEnum.MyToken; - expect(resolveEnumToken(UsefulEnum, token)).toEqual('MyToken'); - - token = UsefulEnum.MyOtherToken; - expect(resolveEnumToken(UsefulEnum, token)).toEqual('MyOtherToken'); - }); - }); - describe('hasConstructor', () => { it('should be true when the type matches', () => { expect(hasConstructor(new MySuperclass(), MySuperclass)).toEqual(true); }); diff --git a/modules/@angular/forms/src/form_builder.ts b/modules/@angular/forms/src/form_builder.ts index 49ff12f56e..20015e3157 100644 --- a/modules/@angular/forms/src/form_builder.ts +++ b/modules/@angular/forms/src/form_builder.ts @@ -43,10 +43,8 @@ export class FormBuilder { */ group(controlsConfig: {[key: string]: any}, extra: {[key: string]: any} = null): FormGroup { const controls = this._reduceControls(controlsConfig); - const validator: ValidatorFn = - isPresent(extra) ? StringMapWrapper.get(extra, 'validator') : null; - const asyncValidator: AsyncValidatorFn = - isPresent(extra) ? StringMapWrapper.get(extra, 'asyncValidator') : null; + const validator: ValidatorFn = isPresent(extra) ? extra['validator'] : null; + const asyncValidator: AsyncValidatorFn = isPresent(extra) ? extra['asyncValidator'] : null; return new FormGroup(controls, validator, asyncValidator); } /** diff --git a/modules/@angular/forms/src/model.ts b/modules/@angular/forms/src/model.ts index 5a9ac3bd08..26c9c69531 100644 --- a/modules/@angular/forms/src/model.ts +++ b/modules/@angular/forms/src/model.ts @@ -492,7 +492,7 @@ export abstract class AbstractControl { getError(errorCode: string, path: string[] = null): any { var control = isPresent(path) && !ListWrapper.isEmpty(path) ? this.get(path) : this; if (isPresent(control) && isPresent(control._errors)) { - return StringMapWrapper.get(control._errors, errorCode); + return control._errors[errorCode]; } else { return null; } diff --git a/modules/@angular/http/src/headers.ts b/modules/@angular/http/src/headers.ts index 1bf2a0842e..b3c206038a 100644 --- a/modules/@angular/http/src/headers.ts +++ b/modules/@angular/http/src/headers.ts @@ -6,12 +6,9 @@ * found in the LICENSE file at https://angular.io/license */ - import {ListWrapper, MapWrapper, StringMapWrapper, isListLikeIterable, iterateListLike} from '../src/facade/collection'; import {isBlank} from '../src/facade/lang'; - - /** * Polyfill for [Headers](https://developer.mozilla.org/en-US/docs/Web/API/Headers/Headers), as * specified in the [Fetch Spec](https://fetch.spec.whatwg.org/#headers-class). diff --git a/modules/@angular/http/test/headers_spec.ts b/modules/@angular/http/test/headers_spec.ts index 72c415fec3..91c9b8fb19 100644 --- a/modules/@angular/http/test/headers_spec.ts +++ b/modules/@angular/http/test/headers_spec.ts @@ -35,7 +35,7 @@ export function main() { describe('initialization', () => { it('should merge values in provided dictionary', () => { - var headers = new Headers({'foo': 'bar'}); + const headers = new Headers({'foo': 'bar'}); expect(headers.get('foo')).toBe('bar'); expect(headers.getAll('foo')).toEqual(['bar']); }); @@ -52,7 +52,7 @@ export function main() { describe('.set()', () => { it('should clear all values and re-set for the provided key', () => { - var headers = new Headers({'foo': 'bar'}); + const headers = new Headers({'foo': 'bar'}); expect(headers.get('foo')).toBe('bar'); expect(headers.getAll('foo')).toEqual(['bar']); headers.set('foo', 'baz'); diff --git a/modules/@angular/platform-browser/src/dom/events/key_events.ts b/modules/@angular/platform-browser/src/dom/events/key_events.ts index d044539c30..54cff44bcf 100644 --- a/modules/@angular/platform-browser/src/dom/events/key_events.ts +++ b/modules/@angular/platform-browser/src/dom/events/key_events.ts @@ -39,11 +39,10 @@ export class KeyEventsPlugin extends EventManagerPlugin { var parsedEvent = KeyEventsPlugin.parseEventName(eventName); var outsideHandler = KeyEventsPlugin.eventCallback( - element, StringMapWrapper.get(parsedEvent, 'fullKey'), handler, this.manager.getZone()); + element, parsedEvent['fullKey'], handler, this.manager.getZone()); return this.manager.getZone().runOutsideAngular(() => { - return getDOM().onAndCancel( - element, StringMapWrapper.get(parsedEvent, 'domEventName'), outsideHandler); + return getDOM().onAndCancel(element, parsedEvent['domEventName'], outsideHandler); }); } @@ -72,9 +71,10 @@ export class KeyEventsPlugin extends EventManagerPlugin { // returning null instead of throwing to let another plugin process the event return null; } - var result = {}; - StringMapWrapper.set(result, 'domEventName', domEventName); - StringMapWrapper.set(result, 'fullKey', fullKey); + + var result: {[k: string]: string} = {}; + result['domEventName'] = domEventName; + result['fullKey'] = fullKey; return result; } @@ -89,7 +89,7 @@ export class KeyEventsPlugin extends EventManagerPlugin { } modifierKeys.forEach(modifierName => { if (modifierName != key) { - var modifierGetter = StringMapWrapper.get(modifierKeyGetters, modifierName); + var modifierGetter = modifierKeyGetters[modifierName]; if (modifierGetter(event)) { fullKey += modifierName + '.'; } diff --git a/modules/@angular/platform-browser/test/browser_util_spec.ts b/modules/@angular/platform-browser/test/browser_util_spec.ts index 893b6ffd35..e8e217921f 100644 --- a/modules/@angular/platform-browser/test/browser_util_spec.ts +++ b/modules/@angular/platform-browser/test/browser_util_spec.ts @@ -224,17 +224,17 @@ export function main() { ]; browsers.forEach((browser: {[key: string]: any}) => { - it(`should detect ${StringMapWrapper.get(browser, 'name')}`, () => { - var bd = new BrowserDetection(StringMapWrapper.get(browser, 'ua')); - expect(bd.isFirefox).toBe(StringMapWrapper.get(browser, 'isFirefox')); - expect(bd.isAndroid).toBe(StringMapWrapper.get(browser, 'isAndroid')); - expect(bd.isEdge).toBe(StringMapWrapper.get(browser, 'isEdge')); - expect(bd.isIE).toBe(StringMapWrapper.get(browser, 'isIE')); - expect(bd.isWebkit).toBe(StringMapWrapper.get(browser, 'isWebkit')); - expect(bd.isIOS7).toBe(StringMapWrapper.get(browser, 'isIOS7')); - expect(bd.isSlow).toBe(StringMapWrapper.get(browser, 'isSlow')); - expect(bd.isChromeDesktop).toBe(StringMapWrapper.get(browser, 'isChromeDesktop')); - expect(bd.isOldChrome).toBe(StringMapWrapper.get(browser, 'isOldChrome')); + it(`should detect ${browser[ 'name']}`, () => { + var bd = new BrowserDetection(browser['ua']); + expect(bd.isFirefox).toBe(browser['isFirefox']); + expect(bd.isAndroid).toBe(browser['isAndroid']); + expect(bd.isEdge).toBe(browser['isEdge']); + expect(bd.isIE).toBe(browser['isIE']); + expect(bd.isWebkit).toBe(browser['isWebkit']); + expect(bd.isIOS7).toBe(browser['isIOS7']); + expect(bd.isSlow).toBe(browser['isSlow']); + expect(bd.isChromeDesktop).toBe(browser['isChromeDesktop']); + expect(bd.isOldChrome).toBe(browser['isOldChrome']); }); }); }); diff --git a/modules/@angular/platform-server/src/parse5_adapter.ts b/modules/@angular/platform-server/src/parse5_adapter.ts index 59bed8e648..c3cad1fec8 100644 --- a/modules/@angular/platform-server/src/parse5_adapter.ts +++ b/modules/@angular/platform-server/src/parse5_adapter.ts @@ -146,16 +146,14 @@ export class Parse5DomAdapter extends DomAdapter { el: any /** TODO #9100 */, evt: any /** TODO #9100 */, listener: any /** TODO #9100 */): Function { this.on(el, evt, listener); - return () => { - ListWrapper.remove(StringMapWrapper.get(el._eventListenersMap, evt), listener); - }; + return () => { ListWrapper.remove((el._eventListenersMap[evt]), listener); }; } dispatchEvent(el: any /** TODO #9100 */, evt: any /** TODO #9100 */) { if (isBlank(evt.target)) { evt.target = el; } if (isPresent(el._eventListenersMap)) { - var listeners: any = StringMapWrapper.get(el._eventListenersMap, evt.type); + var listeners: any = el._eventListenersMap[evt.type]; if (isPresent(listeners)) { for (var i = 0; i < listeners.length; i++) { listeners[i](evt); @@ -499,9 +497,9 @@ export class Parse5DomAdapter extends DomAdapter { var body = treeAdapter.createElement('body', 'http://www.w3.org/1999/xhtml', []); this.appendChild(newDoc, head); this.appendChild(newDoc, body); - StringMapWrapper.set(newDoc, 'head', head); - StringMapWrapper.set(newDoc, 'body', body); - StringMapWrapper.set(newDoc, '_window', {}); + newDoc['head'] = head; + newDoc['body'] = body; + newDoc['_window'] = StringMapWrapper.create(); return newDoc; } defaultDoc(): Document { @@ -541,32 +539,31 @@ export class Parse5DomAdapter extends DomAdapter { for (var i = 0; i < parsedRules.length; i++) { var parsedRule = parsedRules[i]; var rule: {[key: string]: any} = {}; - StringMapWrapper.set(rule, 'cssText', css); - StringMapWrapper.set(rule, 'style', {content: '', cssText: ''}); + rule['cssText'] = css; + rule['style'] = {content: '', cssText: ''}; if (parsedRule.type == 'rule') { - StringMapWrapper.set(rule, 'type', 1); - StringMapWrapper.set( - rule, 'selectorText', parsedRule.selectors.join(', ') - .replace(/\s{2,}/g, ' ') - .replace(/\s*~\s*/g, ' ~ ') - .replace(/\s*\+\s*/g, ' + ') - .replace(/\s*>\s*/g, ' > ') - .replace(/\[(\w+)=(\w+)\]/g, '[$1="$2"]')); + rule['type'] = 1; + + rule['selectorText'] = + parsedRule.selectors.join(', '.replace(/\s{2,}/g, ' ') + .replace(/\s*~\s*/g, ' ~ ') + .replace(/\s*\+\s*/g, ' + ') + .replace(/\s*>\s*/g, ' > ') + .replace(/\[(\w+)=(\w+)\]/g, '[$1="$2"]')); if (isBlank(parsedRule.declarations)) { continue; } for (var j = 0; j < parsedRule.declarations.length; j++) { var declaration = parsedRule.declarations[j]; - StringMapWrapper.set( - StringMapWrapper.get(rule, 'style'), declaration.property, declaration.value); - StringMapWrapper.get(rule, 'style').cssText += - declaration.property + ': ' + declaration.value + ';'; + + rule['style'] = declaration.property[declaration.value]; + rule['style'].cssText += declaration.property + ': ' + declaration.value + ';'; } } else if (parsedRule.type == 'media') { - StringMapWrapper.set(rule, 'type', 4); - StringMapWrapper.set(rule, 'media', {mediaText: parsedRule.media}); + rule['type'] = 4; + rule['media'] = {mediaText: parsedRule.media}; if (parsedRule.rules) { - StringMapWrapper.set(rule, 'cssRules', this._buildRules(parsedRule.rules)); + rule['cssRules'] = this._buildRules(parsedRule.rules); } } rules.push(rule); diff --git a/modules/@angular/platform-webworker/src/web_workers/shared/client_message_broker.ts b/modules/@angular/platform-webworker/src/web_workers/shared/client_message_broker.ts index 361edf6716..6eaad1cfa3 100644 --- a/modules/@angular/platform-webworker/src/web_workers/shared/client_message_broker.ts +++ b/modules/@angular/platform-webworker/src/web_workers/shared/client_message_broker.ts @@ -150,7 +150,7 @@ class MessageData { id: string; constructor(data: {[key: string]: any}) { - this.type = StringMapWrapper.get(data, 'type'); + this.type = data['type']; this.id = this._getValueIfPresent(data, 'id'); this.value = this._getValueIfPresent(data, 'value'); } diff --git a/modules/@angular/platform-webworker/src/web_workers/shared/serializer.ts b/modules/@angular/platform-webworker/src/web_workers/shared/serializer.ts index 783cdc96b4..17c9ab2e00 100644 --- a/modules/@angular/platform-webworker/src/web_workers/shared/serializer.ts +++ b/modules/@angular/platform-webworker/src/web_workers/shared/serializer.ts @@ -8,7 +8,7 @@ import {Injectable, RenderComponentType, Type, ViewEncapsulation} from '@angular/core'; -import {isArray, isPresent, serializeEnum} from '../../facade/lang'; +import {isArray, isPresent} from '../../facade/lang'; import {VIEW_ENCAPSULATION_VALUES} from '../../private_import_core'; import {RenderStore} from './render_store'; @@ -42,7 +42,7 @@ export class Serializer { } else if (type === RenderComponentType) { return this._serializeRenderComponentType(obj); } else if (type === ViewEncapsulation) { - return serializeEnum(obj); + return obj; } else if (type === LocationType) { return this._serializeLocation(obj); } else {