Skip to content

Commit d9951cb

Browse files
authored
Merge pull request #17919 from henrymercer/fix-empty-object-property-access
Fix property access on an object literal
2 parents f00c78c + a881092 commit d9951cb

File tree

5 files changed

+77
-5
lines changed

5 files changed

+77
-5
lines changed

src/compiler/factory.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3941,11 +3941,10 @@ namespace ts {
39413941
return recreateOuterExpressions(expression, mutableCall, OuterExpressionKinds.PartiallyEmittedExpressions);
39423942
}
39433943
}
3944-
else {
3945-
const leftmostExpressionKind = getLeftmostExpression(emittedExpression).kind;
3946-
if (leftmostExpressionKind === SyntaxKind.ObjectLiteralExpression || leftmostExpressionKind === SyntaxKind.FunctionExpression) {
3947-
return setTextRange(createParen(expression), expression);
3948-
}
3944+
3945+
const leftmostExpressionKind = getLeftmostExpression(emittedExpression).kind;
3946+
if (leftmostExpressionKind === SyntaxKind.ObjectLiteralExpression || leftmostExpressionKind === SyntaxKind.FunctionExpression) {
3947+
return setTextRange(createParen(expression), expression);
39493948
}
39503949

39513950
return expression;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//// [propertyAccessOnObjectLiteral.ts]
2+
class A { }
3+
4+
(<A>{}).toString();
5+
6+
(() => {
7+
(<A>{}).toString();
8+
})();
9+
10+
11+
//// [propertyAccessOnObjectLiteral.js]
12+
var A = /** @class */ (function () {
13+
function A() {
14+
}
15+
return A;
16+
}());
17+
({}.toString());
18+
(function () {
19+
({}.toString());
20+
})();
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
=== tests/cases/compiler/propertyAccessOnObjectLiteral.ts ===
2+
class A { }
3+
>A : Symbol(A, Decl(propertyAccessOnObjectLiteral.ts, 0, 0))
4+
5+
(<A>{}).toString();
6+
>(<A>{}).toString : Symbol(Object.toString, Decl(lib.d.ts, --, --))
7+
>A : Symbol(A, Decl(propertyAccessOnObjectLiteral.ts, 0, 0))
8+
>toString : Symbol(Object.toString, Decl(lib.d.ts, --, --))
9+
10+
(() => {
11+
(<A>{}).toString();
12+
>(<A>{}).toString : Symbol(Object.toString, Decl(lib.d.ts, --, --))
13+
>A : Symbol(A, Decl(propertyAccessOnObjectLiteral.ts, 0, 0))
14+
>toString : Symbol(Object.toString, Decl(lib.d.ts, --, --))
15+
16+
})();
17+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
=== tests/cases/compiler/propertyAccessOnObjectLiteral.ts ===
2+
class A { }
3+
>A : A
4+
5+
(<A>{}).toString();
6+
>(<A>{}).toString() : string
7+
>(<A>{}).toString : () => string
8+
>(<A>{}) : A
9+
><A>{} : A
10+
>A : A
11+
>{} : {}
12+
>toString : () => string
13+
14+
(() => {
15+
>(() => { (<A>{}).toString();})() : void
16+
>(() => { (<A>{}).toString();}) : () => void
17+
>() => { (<A>{}).toString();} : () => void
18+
19+
(<A>{}).toString();
20+
>(<A>{}).toString() : string
21+
>(<A>{}).toString : () => string
22+
>(<A>{}) : A
23+
><A>{} : A
24+
>A : A
25+
>{} : {}
26+
>toString : () => string
27+
28+
})();
29+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class A { }
2+
3+
(<A>{}).toString();
4+
5+
(() => {
6+
(<A>{}).toString();
7+
})();

0 commit comments

Comments
 (0)