Skip to content

Commit 28415a8

Browse files
committed
Removed private fields using new # syntax due to issues
1 parent 05d5962 commit 28415a8

File tree

5 files changed

+109
-108
lines changed

5 files changed

+109
-108
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4-
## [0.20.2] - 2022-02-25
4+
## [0.21.0] - 2022-04-06
55
### Fixed
66
- Return `undefined` to match `noImplicitReturns` rule
77
- Made `BaseHttpRequest` class abstract
8+
- Removed private fields using `#` inside `CancelablePromise`
89
- Filter out wrong enum values
910

1011
## [0.20.1] - 2022-02-25

src/openApi/v2/parser/getEnum.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const getEnum = (values?: (string | number)[]): Enum[] => {
2424
.replace(/^(\d+)/g, '_$1')
2525
.replace(/([a-z])([A-Z]+)/g, '$1_$2')
2626
.toUpperCase(),
27-
value: `'${value.replace(/'/g, '\\\'')}'`,
27+
value: `'${value.replace(/'/g, "\\'")}'`,
2828
type: 'string',
2929
description: null,
3030
};

src/openApi/v3/parser/getEnum.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const getEnum = (values?: (string | number)[]): Enum[] => {
2424
.replace(/^(\d+)/g, '_$1')
2525
.replace(/([a-z])([A-Z]+)/g, '$1_$2')
2626
.toUpperCase(),
27-
value: `'${value.replace(/'/g, '\\\'')}'`,
27+
value: `'${value.replace(/'/g, "\\'")}'`,
2828
type: 'string',
2929
description: null,
3030
};

src/templates/core/CancelablePromise.hbs

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ export interface OnCancel {
2323
export class CancelablePromise<T> implements Promise<T> {
2424
readonly [Symbol.toStringTag]: string;
2525

26-
#isResolved: boolean;
27-
#isRejected: boolean;
28-
#isCancelled: boolean;
29-
readonly #cancelHandlers: (() => void)[];
30-
readonly #promise: Promise<T>;
31-
#resolve?: (value: T | PromiseLike<T>) => void;
32-
#reject?: (reason?: any) => void;
26+
private _isResolved: boolean;
27+
private _isRejected: boolean;
28+
private _isCancelled: boolean;
29+
private readonly _cancelHandlers: (() => void)[];
30+
private readonly _promise: Promise<T>;
31+
private _resolve?: (value: T | PromiseLike<T>) => void;
32+
private _reject?: (reason?: any) => void;
3333

3434
constructor(
3535
executor: (
@@ -38,47 +38,47 @@ export class CancelablePromise<T> implements Promise<T> {
3838
onCancel: OnCancel
3939
) => void
4040
) {
41-
this.#isResolved = false;
42-
this.#isRejected = false;
43-
this.#isCancelled = false;
44-
this.#cancelHandlers = [];
45-
this.#promise = new Promise<T>((resolve, reject) => {
46-
this.#resolve = resolve;
47-
this.#reject = reject;
41+
this._isResolved = false;
42+
this._isRejected = false;
43+
this._isCancelled = false;
44+
this._cancelHandlers = [];
45+
this._promise = new Promise<T>((resolve, reject) => {
46+
this._resolve = resolve;
47+
this._reject = reject;
4848

4949
const onResolve = (value: T | PromiseLike<T>): void => {
50-
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
50+
if (this._isResolved || this._isRejected || this._isCancelled) {
5151
return;
5252
}
53-
this.#isResolved = true;
54-
this.#resolve?.(value);
53+
this._isResolved = true;
54+
this._resolve?.(value);
5555
};
5656

5757
const onReject = (reason?: any): void => {
58-
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
58+
if (this._isResolved || this._isRejected || this._isCancelled) {
5959
return;
6060
}
61-
this.#isRejected = true;
62-
this.#reject?.(reason);
61+
this._isRejected = true;
62+
this._reject?.(reason);
6363
};
6464

6565
const onCancel = (cancelHandler: () => void): void => {
66-
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
66+
if (this._isResolved || this._isRejected || this._isCancelled) {
6767
return;
6868
}
69-
this.#cancelHandlers.push(cancelHandler);
69+
this._cancelHandlers.push(cancelHandler);
7070
};
7171

7272
Object.defineProperty(onCancel, 'isResolved', {
73-
get: (): boolean => this.#isResolved,
73+
get: (): boolean => this._isResolved,
7474
});
7575

7676
Object.defineProperty(onCancel, 'isRejected', {
77-
get: (): boolean => this.#isRejected,
77+
get: (): boolean => this._isRejected,
7878
});
7979

8080
Object.defineProperty(onCancel, 'isCancelled', {
81-
get: (): boolean => this.#isCancelled,
81+
get: (): boolean => this._isCancelled,
8282
});
8383

8484
return executor(onResolve, onReject, onCancel as OnCancel);
@@ -89,39 +89,39 @@ export class CancelablePromise<T> implements Promise<T> {
8989
onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null,
9090
onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null
9191
): Promise<TResult1 | TResult2> {
92-
return this.#promise.then(onFulfilled, onRejected);
92+
return this._promise.then(onFulfilled, onRejected);
9393
}
9494

9595
public catch<TResult = never>(
9696
onRejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null
9797
): Promise<T | TResult> {
98-
return this.#promise.catch(onRejected);
98+
return this._promise.catch(onRejected);
9999
}
100100

101101
public finally(onFinally?: (() => void) | null): Promise<T> {
102-
return this.#promise.finally(onFinally);
102+
return this._promise.finally(onFinally);
103103
}
104104

105105
public cancel(): void {
106-
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
106+
if (this._isResolved || this._isRejected || this._isCancelled) {
107107
return;
108108
}
109-
this.#isCancelled = true;
110-
if (this.#cancelHandlers.length) {
109+
this._isCancelled = true;
110+
if (this._cancelHandlers.length) {
111111
try {
112-
for (const cancelHandler of this.#cancelHandlers) {
112+
for (const cancelHandler of this._cancelHandlers) {
113113
cancelHandler();
114114
}
115115
} catch (error) {
116116
console.warn('Cancellation threw an error', error);
117117
return;
118118
}
119119
}
120-
this.#cancelHandlers.length = 0;
121-
this.#reject?.(new CancelError('Request aborted'));
120+
this._cancelHandlers.length = 0;
121+
this._reject?.(new CancelError('Request aborted'));
122122
}
123123

124124
public get isCancelled(): boolean {
125-
return this.#isCancelled;
125+
return this._isCancelled;
126126
}
127127
}

0 commit comments

Comments
 (0)