Skip to content

Commit 086b1da

Browse files
committed
fix(transformer): Keep a bound-state regardless of declaration keys, since such keys may be cached and reused in parallel
A bound state is an indicator whether a new function instance is emitted, binding this in the current scope. The scope's constructor can then be referenced with `this.constructor` enabling a reference to the parent constructor.
1 parent 3f0bd8c commit 086b1da

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/transformer/genericDeclaration/genericDeclaration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ export function GenericDeclaration(scope: Scope): IGenericDeclaration {
167167
}
168168
}
169169

170-
if (!typeParameterDeclaration || scope.currentMockKey !== declarationKey) {
171-
genericValueDescriptor = GetDescriptor(genericNode, new Scope(declarationKey));
170+
if (!typeParameterDeclaration || !scope.isBound()) {
171+
genericValueDescriptor = GetDescriptor(genericNode, (new Scope(declarationKey)).bind());
172172
}
173173

174174
const genericParameter: GenericParameter = createGenericParameter(

src/transformer/scope/scope.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,32 @@ import * as ts from 'typescript';
33
export type InterfaceOrClassDeclaration = ts.InterfaceDeclaration | ts.ClassDeclaration;
44
export class Scope {
55
constructor(currentMockKey?: string) {
6+
this._bound = false;
67
this._currentMockKey = currentMockKey;
78
}
89

910
private readonly _currentMockKey: string | undefined;
11+
private _bound: boolean;
12+
13+
private _appendConstructorMarker(): string {
14+
return this._bound ? '_C' : '';
15+
}
16+
17+
public bind(): this {
18+
this._bound = true;
19+
20+
return this;
21+
}
22+
23+
public isBound(): boolean {
24+
return this._bound;
25+
}
1026

1127
public get currentMockKey(): string | undefined {
12-
return this._currentMockKey;
28+
if (this._currentMockKey === undefined) {
29+
return;
30+
}
31+
32+
return this._currentMockKey + this._appendConstructorMarker();
1333
}
1434
}

0 commit comments

Comments
 (0)