Merge pull request #17919 from henrymercer/fix-empty-object-property-access

Fix property access on an object literal
This commit is contained in:
Ron Buckton 2017-09-20 19:06:04 -07:00 committed by GitHub
commit d9951cbb8e
5 changed files with 77 additions and 5 deletions

View File

@ -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;

View 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());
})();

View File

@ -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, --, --))
})();

View File

@ -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
})();

View File

@ -0,0 +1,7 @@
class A { }
(<A>{}).toString();
(() => {
(<A>{}).toString();
})();