@@ -150,19 +150,30 @@ interface SlotsToTypes {
150
150
151
151
type SlotKey = keyof SlotsToTypes ;
152
152
153
- const globalTemporalSlotMapKey = Symbol . for ( '@@Temporal__slots__private_do_not_use' ) ;
153
+ const globalSlots = new WeakMap ( ) ;
154
154
155
- ( globalThis as any ) [ globalTemporalSlotMapKey ] ||= new WeakMap ( ) ;
155
+ function _GetSlots ( container : Slots [ SlotKey ] [ 'usedBy' ] ) {
156
+ return globalSlots . get ( container ) ;
157
+ }
156
158
157
- const slots = ( globalThis as any ) [ globalTemporalSlotMapKey ] ;
159
+ const GetSlotsSymbol = Symbol . for ( '@@Temporal__GetSlots' ) ;
158
160
159
- export function CreateSlots ( container : AnyTemporalType ) : void {
160
- slots . set ( container , Object . create ( null ) ) ;
161
- }
161
+ // expose GetSlots to avoid dual package hazards
162
+ ( globalThis as any ) [ GetSlotsSymbol ] ||= _GetSlots ;
163
+
164
+ const GetSlots = ( globalThis as any ) [ GetSlotsSymbol ] ;
162
165
163
- function GetSlots < T extends AnyTemporalType > ( container : T ) {
164
- return slots . get ( container ) ;
166
+ function _CreateSlots ( container : Slots [ SlotKey ] [ 'usedBy' ] ) : void {
167
+ globalSlots . set ( container , Object . create ( null ) ) ;
165
168
}
169
+
170
+ const CreateSlotsSymbol = Symbol . for ( '@@Temporal__CreateSlots' ) ;
171
+
172
+ // expose CreateSlots to avoid dual package hazards
173
+ ( globalThis as any ) [ CreateSlotsSymbol ] ||= _CreateSlots ;
174
+
175
+ export const CreateSlots = ( globalThis as any ) [ CreateSlotsSymbol ] ;
176
+
166
177
// TODO: is there a better way than 9 overloads to make HasSlot into a type
167
178
// guard that takes a variable number of parameters?
168
179
export function HasSlot < ID1 extends SlotKey > ( container : unknown , id1 : ID1 ) : container is Slots [ ID1 ] [ 'usedBy' ] ;
@@ -292,5 +303,11 @@ export function SetSlot<KeyT extends SlotKey>(
292
303
id : KeyT ,
293
304
value : Slots [ KeyT ] [ 'value' ]
294
305
) : void {
295
- GetSlots ( container ) [ id ] = value ;
306
+ const slot = GetSlots ( container ) ;
307
+
308
+ if ( id in slot ) {
309
+ throw new TypeError ( `${ id } already has set` ) ;
310
+ }
311
+
312
+ slot [ id ] = value ;
296
313
}
0 commit comments