diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index b8b77193ed067..ed04a6dc6f032 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -4354,19 +4354,17 @@ namespace ts { case SyntaxKind.ConditionalExpression: node = (node).condition; continue; - case SyntaxKind.CallExpression: if (stopAtCallExpressions) { return node; } // falls through + case SyntaxKind.AsExpression: case SyntaxKind.ElementAccessExpression: case SyntaxKind.PropertyAccessExpression: - node = (node).expression; - continue; - + case SyntaxKind.NonNullExpression: case SyntaxKind.PartiallyEmittedExpression: - node = (node).expression; + node = (node).expression; continue; } diff --git a/src/testRunner/tsconfig.json b/src/testRunner/tsconfig.json index 3943d4f4f85ca..b02f1a6c17532 100644 --- a/src/testRunner/tsconfig.json +++ b/src/testRunner/tsconfig.json @@ -39,7 +39,7 @@ "unittests/extractTestHelpers.ts", "unittests/tsserverProjectSystem.ts", "unittests/typingsInstaller.ts", - + "unittests/asserts.ts", "unittests/base64.ts", "unittests/builder.ts", @@ -54,6 +54,7 @@ "unittests/extractConstants.ts", "unittests/extractFunctions.ts", "unittests/extractRanges.ts", + "unittests/factory.ts", "unittests/hostNewLineSupport.ts", "unittests/incrementalParser.ts", "unittests/initializeTSConfig.ts", diff --git a/src/testRunner/unittests/factory.ts b/src/testRunner/unittests/factory.ts new file mode 100644 index 0000000000000..1651da64d43c4 --- /dev/null +++ b/src/testRunner/unittests/factory.ts @@ -0,0 +1,24 @@ +namespace ts { + describe("FactoryAPI", () => { + describe("createArrowFunction", () => { + it("parenthesizes concise body if necessary", () => { + function checkBody(body: ConciseBody) { + const node = createArrowFunction( + /*modifiers*/ undefined, + /*typeParameters*/ undefined, + [], + /*type*/ undefined, + /*equalsGreaterThanToken*/ undefined, + body, + ); + assert.strictEqual(node.body.kind, SyntaxKind.ParenthesizedExpression); + } + + checkBody(createObjectLiteral()); + checkBody(createPropertyAccess(createObjectLiteral(), "prop")); + checkBody(createAsExpression(createPropertyAccess(createObjectLiteral(), "prop"), createTypeReferenceNode("T", /*typeArguments*/ undefined))); + checkBody(createNonNullExpression(createPropertyAccess(createObjectLiteral(), "prop"))); + }); + }); + }); +}