33// Promises implemented based on https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
44// and https://promisesaplus.com/
55
6- export enum __TS__PromiseState {
6+ export const enum PromiseState {
77 Pending ,
88 Fulfilled ,
99 Rejected ,
@@ -28,7 +28,7 @@ function isPromiseLike<T>(thing: unknown): thing is PromiseLike<T> {
2828}
2929
3030export class __TS__Promise < T > implements Promise < T > {
31- public state = __TS__PromiseState . Pending ;
31+ public state = PromiseState . Pending ;
3232 public value ?: T ;
3333 public rejectionReason ?: any ;
3434
@@ -42,7 +42,7 @@ export class __TS__Promise<T> implements Promise<T> {
4242 public static resolve < TData > ( this : void , data : TData ) : Promise < TData > {
4343 // Create and return a promise instance that is already resolved
4444 const promise = new __TS__Promise < TData > ( ( ) => { } ) ;
45- promise . state = __TS__PromiseState . Fulfilled ;
45+ promise . state = PromiseState . Fulfilled ;
4646 promise . value = data ;
4747 return promise ;
4848 }
@@ -51,7 +51,7 @@ export class __TS__Promise<T> implements Promise<T> {
5151 public static reject ( this : void , reason : any ) : Promise < never > {
5252 // Create and return a promise instance that is already rejected
5353 const promise = new __TS__Promise < never > ( ( ) => { } ) ;
54- promise . state = __TS__PromiseState . Rejected ;
54+ promise . state = PromiseState . Rejected ;
5555 promise . rejectionReason = reason ;
5656 return promise ;
5757 }
@@ -72,8 +72,8 @@ export class __TS__Promise<T> implements Promise<T> {
7272 ) : Promise < TResult1 | TResult2 > {
7373 const { promise, resolve, reject } = promiseDeferred < T | TResult1 | TResult2 > ( ) ;
7474
75- const isFulfilled = this . state === __TS__PromiseState . Fulfilled ;
76- const isRejected = this . state === __TS__PromiseState . Rejected ;
75+ const isFulfilled = this . state === PromiseState . Fulfilled ;
76+ const isRejected = this . state === PromiseState . Rejected ;
7777
7878 if ( onFulfilled ) {
7979 const internalCallback = this . createPromiseResolvingCallback ( onFulfilled , resolve , reject ) ;
@@ -121,7 +121,7 @@ export class __TS__Promise<T> implements Promise<T> {
121121 if ( onFinally ) {
122122 this . finallyCallbacks . push ( onFinally ) ;
123123
124- if ( this . state !== __TS__PromiseState . Pending ) {
124+ if ( this . state !== PromiseState . Pending ) {
125125 // If promise already resolved or rejected, immediately fire finally callback
126126 onFinally ( ) ;
127127 }
@@ -139,8 +139,8 @@ export class __TS__Promise<T> implements Promise<T> {
139139 }
140140
141141 // Resolve this promise, if it is still pending. This function is passed to the constructor function.
142- if ( this . state === __TS__PromiseState . Pending ) {
143- this . state = __TS__PromiseState . Fulfilled ;
142+ if ( this . state === PromiseState . Pending ) {
143+ this . state = PromiseState . Fulfilled ;
144144 this . value = data ;
145145
146146 for ( const callback of this . fulfilledCallbacks ) {
@@ -154,8 +154,8 @@ export class __TS__Promise<T> implements Promise<T> {
154154
155155 private reject ( reason : any ) : void {
156156 // Reject this promise, if it is still pending. This function is passed to the constructor function.
157- if ( this . state === __TS__PromiseState . Pending ) {
158- this . state = __TS__PromiseState . Rejected ;
157+ if ( this . state === PromiseState . Pending ) {
158+ this . state = PromiseState . Rejected ;
159159 this . rejectionReason = reason ;
160160
161161 for ( const callback of this . rejectedCallbacks ) {
@@ -189,11 +189,11 @@ export class __TS__Promise<T> implements Promise<T> {
189189 ) {
190190 if ( isPromiseLike < TResult > ( data ) ) {
191191 const nextpromise = data as __TS__Promise < TResult > ;
192- if ( nextpromise . state === __TS__PromiseState . Fulfilled ) {
192+ if ( nextpromise . state === PromiseState . Fulfilled ) {
193193 // If a handler function returns an already fulfilled promise,
194194 // the promise returned by then gets fulfilled with that promise's value
195195 resolve ( nextpromise . value ) ;
196- } else if ( nextpromise . state === __TS__PromiseState . Rejected ) {
196+ } else if ( nextpromise . state === PromiseState . Rejected ) {
197197 // If a handler function returns an already rejected promise,
198198 // the promise returned by then gets fulfilled with that promise's value
199199 reject ( nextpromise . rejectionReason ) ;
0 commit comments