@@ -114,25 +114,31 @@ namespace ts {
114
114
115
115
/* @internal */
116
116
namespace NativeCollections {
117
- declare const Map : MapConstructor | undefined ;
118
- declare const Set : SetConstructor | undefined ;
117
+ declare const self : any ;
118
+
119
+ const globals = typeof globalThis !== "undefined" ? globalThis :
120
+ typeof global !== "undefined" ? global :
121
+ typeof self !== "undefined" ? self :
122
+ undefined ;
119
123
120
124
/**
121
125
* Returns the native Map implementation if it is available and compatible (i.e. supports iteration).
122
126
*/
123
127
export function tryGetNativeMap ( ) : MapConstructor | undefined {
124
128
// Internet Explorer's Map doesn't support iteration, so don't use it.
129
+ const gMap = globals ?. Map ;
125
130
// eslint-disable-next-line no-in-operator
126
- return typeof Map !== "undefined" && "entries" in Map . prototype && new Map ( [ [ 0 , 0 ] ] ) . size === 1 ? Map : undefined ;
131
+ return typeof gMap !== "undefined" && "entries" in gMap . prototype && new gMap ( [ [ 0 , 0 ] ] ) . size === 1 ? gMap : undefined ;
127
132
}
128
133
129
134
/**
130
135
* Returns the native Set implementation if it is available and compatible (i.e. supports iteration).
131
136
*/
132
137
export function tryGetNativeSet ( ) : SetConstructor | undefined {
133
138
// Internet Explorer's Set doesn't support iteration, so don't use it.
139
+ const gSet = globals ?. Set ;
134
140
// eslint-disable-next-line no-in-operator
135
- return typeof Set !== "undefined" && "entries" in Set . prototype && new Set ( [ 0 ] ) . size === 1 ? Set : undefined ;
141
+ return typeof gSet !== "undefined" && "entries" in gSet . prototype && new gSet ( [ 0 ] ) . size === 1 ? gSet : undefined ;
136
142
}
137
143
}
138
144
0 commit comments