From b93aabfb662713831e73f1e3200c309a90084a46 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Thu, 15 Aug 2019 16:26:39 -0700 Subject: [PATCH] Allow using Map and Set internally Enables the ie11 safe api for Map and Set --- src/grammar.ts | 8 ++-- typings/lib.ie11_safe_es6.d.ts | 75 ++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 typings/lib.ie11_safe_es6.d.ts diff --git a/src/grammar.ts b/src/grammar.ts index 9beaa803..983115c6 100644 --- a/src/grammar.ts +++ b/src/grammar.ts @@ -170,7 +170,7 @@ class ScopeMetadataProvider { private readonly _initialLanguage: number; private readonly _themeProvider: IThemeProvider; - private _cache: { [scopeName: string]: ScopeMetadata; }; + private _cache: Map; private _defaultMetaData: ScopeMetadata; private readonly _embeddedLanguages: IEmbeddedLanguagesMap; private readonly _embeddedLanguagesRegex: RegExp; @@ -211,7 +211,7 @@ class ScopeMetadataProvider { } public onDidChangeTheme(): void { - this._cache = Object.create(null); + this._cache = new Map(); this._defaultMetaData = new ScopeMetadata( '', this._initialLanguage, @@ -236,12 +236,12 @@ class ScopeMetadataProvider { if (scopeName === null) { return ScopeMetadataProvider._NULL_SCOPE_METADATA; } - let value = this._cache[scopeName]; + let value = this._cache.get(scopeName); if (value) { return value; } value = this._doGetMetadataForScope(scopeName); - this._cache[scopeName] = value; + this._cache.set(scopeName, value); return value; } diff --git a/typings/lib.ie11_safe_es6.d.ts b/typings/lib.ie11_safe_es6.d.ts new file mode 100644 index 00000000..9516649c --- /dev/null +++ b/typings/lib.ie11_safe_es6.d.ts @@ -0,0 +1,75 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +// Defined a subset of ES6 built ins that run in IE11 +// CHECK WITH http://kangax.github.io/compat-table/es6/#ie11 + +interface Map { + clear(): void; + delete(key: K): boolean; + forEach(callbackfn: (value: V, index: K, map: Map) => void, thisArg?: any): void; + get(key: K): V | undefined; + has(key: K): boolean; + set(key: K, value?: V): Map; + readonly size: number; + + // not supported on IE11: + // entries(): IterableIterator<[K, V]>; + // keys(): IterableIterator; + // values(): IterableIterator; + // [Symbol.iterator]():IterableIterator<[K,V]>; + // [Symbol.toStringTag]: string; +} + +interface MapConstructor { + new (): Map; + + // not supported on IE11: + // new (iterable: Iterable<[K, V]>): Map; +} +declare var Map: MapConstructor; + + +interface Set { + add(value: T): Set; + clear(): void; + delete(value: T): boolean; + forEach(callbackfn: (value: T, index: T, set: Set) => void, thisArg?: any): void; + has(value: T): boolean; + readonly size: number; + + // not supported on IE11: + // entries(): IterableIterator<[T, T]>; + // keys(): IterableIterator; + // values(): IterableIterator; + // [Symbol.iterator]():IterableIterator; + // [Symbol.toStringTag]: string; +} + +interface SetConstructor { + new (): Set; + + // not supported on IE11: + // new (iterable: Iterable): Set; +} +declare var Set: SetConstructor; + + +interface WeakMap { + delete(key: K): boolean; + get(key: K): V | undefined; + has(key: K): boolean; + // IE11 doesn't return this + // set(key: K, value?: V): this; + set(key: K, value?: V): undefined; +} + +interface WeakMapConstructor { + new(): WeakMap; + new (): WeakMap; + // new (entries?: [K, V][]): WeakMap; + readonly prototype: WeakMap; +} +declare var WeakMap: WeakMapConstructor;