Skip to content

Commit

Permalink
Workaround evanw/esbuild#1918
Browse files Browse the repository at this point in the history
  • Loading branch information
ascott18 committed Oct 31, 2022
1 parent 0fc630b commit 9d178e0
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/coalesce-vue/src/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,7 @@ export type ResponseCachingConfiguration = {
// Base class for ApiState that contains nothing but the logic for
// subclassing Function. Specifically, we do this to avoid a need to call
// `super()`, which triggers CSP unsafe-eval.
abstract class ApiStateBase<TArgs extends any[], TResult> extends Function {
abstract class ApiStateBase<TArgs extends any[], TResult> {
/** Invokes a call to this API endpoint. */
public readonly invoke!: this;

Expand All @@ -1052,7 +1052,6 @@ abstract class ApiStateBase<TArgs extends any[], TResult> extends Function {
callInvoker: () => any
): ApiResultPromise<TResult>;

// @ts-expect-error Don't call super() - it triggers CSP unsafe-eval (even though nothing is being eval'd)
constructor(
apiClient: ApiClient<any>,
invoker: ApiCallerInvoker<
Expand All @@ -1061,9 +1060,6 @@ abstract class ApiStateBase<TArgs extends any[], TResult> extends Function {
ApiClient<any>
>
) {
// Don't call super - this will trigger CSP unsafe-eval.
// super();

// Create our invoker function that will ultimately be our instance object.
const invokeFunc = function invokeFunc(this: any, ...args: TArgs) {
return invoke._invokeInternal(this, () => {
Expand All @@ -1086,6 +1082,14 @@ abstract class ApiStateBase<TArgs extends any[], TResult> extends Function {
}
}

// @ts-ignore Workaround for https://github.com/evanw/esbuild/issues/1918,
// an error that happens when esbuild transforms the class fields
// into incorrectly using `this` even though our actual constructor does not use `this`.
// Using `this` before a call to `super` (which we don't have or need either of these)
// when the class has a base class is invalid in JS. But we can prevent this by
// assigning the base class prototype directly, hiding the existence of a base class from JS.
ApiStateBase.prototype.__proto__ = Function;

export abstract class ApiState<
TArgs extends any[],
TResult
Expand Down

0 comments on commit 9d178e0

Please sign in to comment.