Skip to content

Commit a0f122b

Browse files
authored
Merge pull request microsoft#30494 from Microsoft/fix29561
Prevent substitution of 'super' in async super helper
2 parents 5194264 + e19c7f1 commit a0f122b

File tree

5 files changed

+493
-6
lines changed

5 files changed

+493
-6
lines changed

src/compiler/transformers/es2017.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -690,9 +690,15 @@ namespace ts {
690690
/* parameters */ [],
691691
/* type */ undefined,
692692
/* equalsGreaterThanToken */ undefined,
693-
createPropertyAccess(
694-
createSuper(),
695-
name
693+
setEmitFlags(
694+
createPropertyAccess(
695+
setEmitFlags(
696+
createSuper(),
697+
EmitFlags.NoSubstitution
698+
),
699+
name
700+
),
701+
EmitFlags.NoSubstitution
696702
)
697703
)
698704
));
@@ -717,9 +723,16 @@ namespace ts {
717723
/* type */ undefined,
718724
/* equalsGreaterThanToken */ undefined,
719725
createAssignment(
720-
createPropertyAccess(
721-
createSuper(),
722-
name),
726+
setEmitFlags(
727+
createPropertyAccess(
728+
setEmitFlags(
729+
createSuper(),
730+
EmitFlags.NoSubstitution
731+
),
732+
name
733+
),
734+
EmitFlags.NoSubstitution
735+
),
723736
createIdentifier("v")
724737
)
725738
)

tests/baselines/reference/asyncMethodWithSuper_es6.js

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,66 @@ class B extends A {
124124
// element access (assign) in async arrow
125125
(async () => super["x"] = f);
126126
}
127+
128+
async * property_access_only_read_only_in_generator() {
129+
// call with property access
130+
super.x();
131+
132+
// property access (read)
133+
const a = super.x;
134+
135+
// property access in arrow
136+
(() => super.x());
137+
138+
// property access in async arrow
139+
(async () => super.x());
140+
}
141+
142+
async * property_access_only_write_only_in_generator() {
143+
const f = () => {};
144+
145+
// property access (assign)
146+
super.x = f;
147+
148+
// destructuring assign with property access
149+
({ f: super.x } = { f });
150+
151+
// property access (assign) in arrow
152+
(() => super.x = f);
153+
154+
// property access (assign) in async arrow
155+
(async () => super.x = f);
156+
}
157+
158+
async * element_access_only_read_only_in_generator() {
159+
// call with element access
160+
super["x"]();
161+
162+
// element access (read)
163+
const a = super["x"];
164+
165+
// element access in arrow
166+
(() => super["x"]());
167+
168+
// element access in async arrow
169+
(async () => super["x"]());
170+
}
171+
172+
async * element_access_only_write_only_in_generator() {
173+
const f = () => {};
174+
175+
// element access (assign)
176+
super["x"] = f;
177+
178+
// destructuring assign with element access
179+
({ f: super["x"] } = { f });
180+
181+
// element access (assign) in arrow
182+
(() => super["x"] = f);
183+
184+
// element access (assign) in async arrow
185+
(async () => super["x"] = f);
186+
}
127187
}
128188

129189

@@ -253,4 +313,67 @@ class B extends A {
253313
(() => __awaiter(this, void 0, void 0, function* () { return _superIndex("x").value = f; }));
254314
});
255315
}
316+
property_access_only_read_only_in_generator() {
317+
const _super = Object.create(null, {
318+
x: { get: () => super.x }
319+
});
320+
return __asyncGenerator(this, arguments, function* property_access_only_read_only_in_generator_1() {
321+
// call with property access
322+
_super.x.call(this);
323+
// property access (read)
324+
const a = _super.x;
325+
// property access in arrow
326+
(() => _super.x.call(this));
327+
// property access in async arrow
328+
(() => __awaiter(this, void 0, void 0, function* () { return _super.x.call(this); }));
329+
});
330+
}
331+
property_access_only_write_only_in_generator() {
332+
const _super = Object.create(null, {
333+
x: { get: () => super.x, set: v => super.x = v }
334+
});
335+
return __asyncGenerator(this, arguments, function* property_access_only_write_only_in_generator_1() {
336+
const f = () => { };
337+
// property access (assign)
338+
_super.x = f;
339+
// destructuring assign with property access
340+
({ f: _super.x } = { f });
341+
// property access (assign) in arrow
342+
(() => _super.x = f);
343+
// property access (assign) in async arrow
344+
(() => __awaiter(this, void 0, void 0, function* () { return _super.x = f; }));
345+
});
346+
}
347+
element_access_only_read_only_in_generator() {
348+
const _superIndex = name => super[name];
349+
const _super = Object.create(null, {});
350+
return __asyncGenerator(this, arguments, function* element_access_only_read_only_in_generator_1() {
351+
// call with element access
352+
_superIndex("x").call(this);
353+
// element access (read)
354+
const a = _superIndex("x");
355+
// element access in arrow
356+
(() => _superIndex("x").call(this));
357+
// element access in async arrow
358+
(() => __awaiter(this, void 0, void 0, function* () { return _superIndex("x").call(this); }));
359+
});
360+
}
361+
element_access_only_write_only_in_generator() {
362+
const _superIndex = (function (geti, seti) {
363+
const cache = Object.create(null);
364+
return name => cache[name] || (cache[name] = { get value() { return geti(name); }, set value(v) { seti(name, v); } });
365+
})(name => super[name], (name, value) => super[name] = value);
366+
const _super = Object.create(null, {});
367+
return __asyncGenerator(this, arguments, function* element_access_only_write_only_in_generator_1() {
368+
const f = () => { };
369+
// element access (assign)
370+
_superIndex("x").value = f;
371+
// destructuring assign with element access
372+
({ f: _superIndex("x").value } = { f });
373+
// element access (assign) in arrow
374+
(() => _superIndex("x").value = f);
375+
// element access (assign) in async arrow
376+
(() => __awaiter(this, void 0, void 0, function* () { return _superIndex("x").value = f; }));
377+
});
378+
}
256379
}

tests/baselines/reference/asyncMethodWithSuper_es6.symbols

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,5 +252,127 @@ class B extends A {
252252
>"x" : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9))
253253
>f : Symbol(f, Decl(asyncMethodWithSuper_es6.ts, 111, 13))
254254
}
255+
256+
async * property_access_only_read_only_in_generator() {
257+
>property_access_only_read_only_in_generator : Symbol(B.property_access_only_read_only_in_generator, Decl(asyncMethodWithSuper_es6.ts, 124, 5))
258+
259+
// call with property access
260+
super.x();
261+
>super.x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9))
262+
>super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0))
263+
>x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9))
264+
265+
// property access (read)
266+
const a = super.x;
267+
>a : Symbol(a, Decl(asyncMethodWithSuper_es6.ts, 131, 13))
268+
>super.x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9))
269+
>super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0))
270+
>x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9))
271+
272+
// property access in arrow
273+
(() => super.x());
274+
>super.x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9))
275+
>super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0))
276+
>x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9))
277+
278+
// property access in async arrow
279+
(async () => super.x());
280+
>super.x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9))
281+
>super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0))
282+
>x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9))
283+
}
284+
285+
async * property_access_only_write_only_in_generator() {
286+
>property_access_only_write_only_in_generator : Symbol(B.property_access_only_write_only_in_generator, Decl(asyncMethodWithSuper_es6.ts, 138, 5))
287+
288+
const f = () => {};
289+
>f : Symbol(f, Decl(asyncMethodWithSuper_es6.ts, 141, 13))
290+
291+
// property access (assign)
292+
super.x = f;
293+
>super.x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9))
294+
>super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0))
295+
>x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9))
296+
>f : Symbol(f, Decl(asyncMethodWithSuper_es6.ts, 141, 13))
297+
298+
// destructuring assign with property access
299+
({ f: super.x } = { f });
300+
>f : Symbol(f, Decl(asyncMethodWithSuper_es6.ts, 147, 10))
301+
>super.x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9))
302+
>super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0))
303+
>x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9))
304+
>f : Symbol(f, Decl(asyncMethodWithSuper_es6.ts, 147, 27))
305+
306+
// property access (assign) in arrow
307+
(() => super.x = f);
308+
>super.x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9))
309+
>super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0))
310+
>x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9))
311+
>f : Symbol(f, Decl(asyncMethodWithSuper_es6.ts, 141, 13))
312+
313+
// property access (assign) in async arrow
314+
(async () => super.x = f);
315+
>super.x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9))
316+
>super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0))
317+
>x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9))
318+
>f : Symbol(f, Decl(asyncMethodWithSuper_es6.ts, 141, 13))
319+
}
320+
321+
async * element_access_only_read_only_in_generator() {
322+
>element_access_only_read_only_in_generator : Symbol(B.element_access_only_read_only_in_generator, Decl(asyncMethodWithSuper_es6.ts, 154, 5))
323+
324+
// call with element access
325+
super["x"]();
326+
>super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0))
327+
>"x" : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9))
328+
329+
// element access (read)
330+
const a = super["x"];
331+
>a : Symbol(a, Decl(asyncMethodWithSuper_es6.ts, 161, 13))
332+
>super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0))
333+
>"x" : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9))
334+
335+
// element access in arrow
336+
(() => super["x"]());
337+
>super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0))
338+
>"x" : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9))
339+
340+
// element access in async arrow
341+
(async () => super["x"]());
342+
>super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0))
343+
>"x" : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9))
344+
}
345+
346+
async * element_access_only_write_only_in_generator() {
347+
>element_access_only_write_only_in_generator : Symbol(B.element_access_only_write_only_in_generator, Decl(asyncMethodWithSuper_es6.ts, 168, 5))
348+
349+
const f = () => {};
350+
>f : Symbol(f, Decl(asyncMethodWithSuper_es6.ts, 171, 13))
351+
352+
// element access (assign)
353+
super["x"] = f;
354+
>super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0))
355+
>"x" : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9))
356+
>f : Symbol(f, Decl(asyncMethodWithSuper_es6.ts, 171, 13))
357+
358+
// destructuring assign with element access
359+
({ f: super["x"] } = { f });
360+
>f : Symbol(f, Decl(asyncMethodWithSuper_es6.ts, 177, 10))
361+
>super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0))
362+
>"x" : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9))
363+
>f : Symbol(f, Decl(asyncMethodWithSuper_es6.ts, 177, 30))
364+
365+
// element access (assign) in arrow
366+
(() => super["x"] = f);
367+
>super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0))
368+
>"x" : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9))
369+
>f : Symbol(f, Decl(asyncMethodWithSuper_es6.ts, 171, 13))
370+
371+
// element access (assign) in async arrow
372+
(async () => super["x"] = f);
373+
>super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0))
374+
>"x" : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9))
375+
>f : Symbol(f, Decl(asyncMethodWithSuper_es6.ts, 171, 13))
376+
}
255377
}
256378

0 commit comments

Comments
 (0)