mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 02:33:53 -06:00
Merge pull request #17919 from henrymercer/fix-empty-object-property-access
Fix property access on an object literal
This commit is contained in:
commit
d9951cbb8e
@ -3941,11 +3941,10 @@ namespace ts {
|
||||
return recreateOuterExpressions(expression, mutableCall, OuterExpressionKinds.PartiallyEmittedExpressions);
|
||||
}
|
||||
}
|
||||
else {
|
||||
const leftmostExpressionKind = getLeftmostExpression(emittedExpression).kind;
|
||||
if (leftmostExpressionKind === SyntaxKind.ObjectLiteralExpression || leftmostExpressionKind === SyntaxKind.FunctionExpression) {
|
||||
return setTextRange(createParen(expression), expression);
|
||||
}
|
||||
|
||||
const leftmostExpressionKind = getLeftmostExpression(emittedExpression).kind;
|
||||
if (leftmostExpressionKind === SyntaxKind.ObjectLiteralExpression || leftmostExpressionKind === SyntaxKind.FunctionExpression) {
|
||||
return setTextRange(createParen(expression), expression);
|
||||
}
|
||||
|
||||
return expression;
|
||||
|
||||
20
tests/baselines/reference/propertyAccessOnObjectLiteral.js
Normal file
20
tests/baselines/reference/propertyAccessOnObjectLiteral.js
Normal file
@ -0,0 +1,20 @@
|
||||
//// [propertyAccessOnObjectLiteral.ts]
|
||||
class A { }
|
||||
|
||||
(<A>{}).toString();
|
||||
|
||||
(() => {
|
||||
(<A>{}).toString();
|
||||
})();
|
||||
|
||||
|
||||
//// [propertyAccessOnObjectLiteral.js]
|
||||
var A = /** @class */ (function () {
|
||||
function A() {
|
||||
}
|
||||
return A;
|
||||
}());
|
||||
({}.toString());
|
||||
(function () {
|
||||
({}.toString());
|
||||
})();
|
||||
@ -0,0 +1,17 @@
|
||||
=== tests/cases/compiler/propertyAccessOnObjectLiteral.ts ===
|
||||
class A { }
|
||||
>A : Symbol(A, Decl(propertyAccessOnObjectLiteral.ts, 0, 0))
|
||||
|
||||
(<A>{}).toString();
|
||||
>(<A>{}).toString : Symbol(Object.toString, Decl(lib.d.ts, --, --))
|
||||
>A : Symbol(A, Decl(propertyAccessOnObjectLiteral.ts, 0, 0))
|
||||
>toString : Symbol(Object.toString, Decl(lib.d.ts, --, --))
|
||||
|
||||
(() => {
|
||||
(<A>{}).toString();
|
||||
>(<A>{}).toString : Symbol(Object.toString, Decl(lib.d.ts, --, --))
|
||||
>A : Symbol(A, Decl(propertyAccessOnObjectLiteral.ts, 0, 0))
|
||||
>toString : Symbol(Object.toString, Decl(lib.d.ts, --, --))
|
||||
|
||||
})();
|
||||
|
||||
@ -0,0 +1,29 @@
|
||||
=== tests/cases/compiler/propertyAccessOnObjectLiteral.ts ===
|
||||
class A { }
|
||||
>A : A
|
||||
|
||||
(<A>{}).toString();
|
||||
>(<A>{}).toString() : string
|
||||
>(<A>{}).toString : () => string
|
||||
>(<A>{}) : A
|
||||
><A>{} : A
|
||||
>A : A
|
||||
>{} : {}
|
||||
>toString : () => string
|
||||
|
||||
(() => {
|
||||
>(() => { (<A>{}).toString();})() : void
|
||||
>(() => { (<A>{}).toString();}) : () => void
|
||||
>() => { (<A>{}).toString();} : () => void
|
||||
|
||||
(<A>{}).toString();
|
||||
>(<A>{}).toString() : string
|
||||
>(<A>{}).toString : () => string
|
||||
>(<A>{}) : A
|
||||
><A>{} : A
|
||||
>A : A
|
||||
>{} : {}
|
||||
>toString : () => string
|
||||
|
||||
})();
|
||||
|
||||
7
tests/cases/compiler/propertyAccessOnObjectLiteral.ts
Normal file
7
tests/cases/compiler/propertyAccessOnObjectLiteral.ts
Normal file
@ -0,0 +1,7 @@
|
||||
class A { }
|
||||
|
||||
(<A>{}).toString();
|
||||
|
||||
(() => {
|
||||
(<A>{}).toString();
|
||||
})();
|
||||
Loading…
x
Reference in New Issue
Block a user