Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using Map and Set internally #107

Merged
merged 1 commit into from
Aug 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class ScopeMetadataProvider {

private readonly _initialLanguage: number;
private readonly _themeProvider: IThemeProvider;
private _cache: { [scopeName: string]: ScopeMetadata; };
private _cache: Map<string, ScopeMetadata>;
private _defaultMetaData: ScopeMetadata;
private readonly _embeddedLanguages: IEmbeddedLanguagesMap;
private readonly _embeddedLanguagesRegex: RegExp;
Expand Down Expand Up @@ -211,7 +211,7 @@ class ScopeMetadataProvider {
}

public onDidChangeTheme(): void {
this._cache = Object.create(null);
this._cache = new Map();
this._defaultMetaData = new ScopeMetadata(
'',
this._initialLanguage,
Expand All @@ -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;
}

Expand Down
75 changes: 75 additions & 0 deletions typings/lib.ie11_safe_es6.d.ts
Original file line number Diff line number Diff line change
@@ -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<K, V> {
clear(): void;
delete(key: K): boolean;
forEach(callbackfn: (value: V, index: K, map: Map<K, V>) => void, thisArg?: any): void;
get(key: K): V | undefined;
has(key: K): boolean;
set(key: K, value?: V): Map<K, V>;
readonly size: number;

// not supported on IE11:
// entries(): IterableIterator<[K, V]>;
// keys(): IterableIterator<K>;
// values(): IterableIterator<V>;
// [Symbol.iterator]():IterableIterator<[K,V]>;
// [Symbol.toStringTag]: string;
}

interface MapConstructor {
new <K, V>(): Map<K, V>;

// not supported on IE11:
// new <K, V>(iterable: Iterable<[K, V]>): Map<K, V>;
}
declare var Map: MapConstructor;


interface Set<T> {
add(value: T): Set<T>;
clear(): void;
delete(value: T): boolean;
forEach(callbackfn: (value: T, index: T, set: Set<T>) => void, thisArg?: any): void;
has(value: T): boolean;
readonly size: number;

// not supported on IE11:
// entries(): IterableIterator<[T, T]>;
// keys(): IterableIterator<T>;
// values(): IterableIterator<T>;
// [Symbol.iterator]():IterableIterator<T>;
// [Symbol.toStringTag]: string;
}

interface SetConstructor {
new <T>(): Set<T>;

// not supported on IE11:
// new <T>(iterable: Iterable<T>): Set<T>;
}
declare var Set: SetConstructor;


interface WeakMap<K extends object, V> {
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<any, any>;
new <K extends object, V>(): WeakMap<K, V>;
// new <K, V>(entries?: [K, V][]): WeakMap<K, V>;
readonly prototype: WeakMap<object, any>;
}
declare var WeakMap: WeakMapConstructor;