Skip to content

Commit e4145e3

Browse files
Merge pull request microsoft#25342 from ajafff/factory-leftmost-expression
getLeftmostExpression: handle AsExpression and NonNullExpression
2 parents 204b70d + b8d7a2f commit e4145e3

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

src/compiler/factory.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4354,19 +4354,17 @@ namespace ts {
43544354
case SyntaxKind.ConditionalExpression:
43554355
node = (<ConditionalExpression>node).condition;
43564356
continue;
4357-
43584357
case SyntaxKind.CallExpression:
43594358
if (stopAtCallExpressions) {
43604359
return node;
43614360
}
43624361
// falls through
4362+
case SyntaxKind.AsExpression:
43634363
case SyntaxKind.ElementAccessExpression:
43644364
case SyntaxKind.PropertyAccessExpression:
4365-
node = (<CallExpression | PropertyAccessExpression | ElementAccessExpression>node).expression;
4366-
continue;
4367-
4365+
case SyntaxKind.NonNullExpression:
43684366
case SyntaxKind.PartiallyEmittedExpression:
4369-
node = (<PartiallyEmittedExpression>node).expression;
4367+
node = (<CallExpression | PropertyAccessExpression | ElementAccessExpression | AsExpression | NonNullExpression | PartiallyEmittedExpression>node).expression;
43704368
continue;
43714369
}
43724370

src/testRunner/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"unittests/extractTestHelpers.ts",
4040
"unittests/tsserverProjectSystem.ts",
4141
"unittests/typingsInstaller.ts",
42-
42+
4343
"unittests/asserts.ts",
4444
"unittests/base64.ts",
4545
"unittests/builder.ts",
@@ -54,6 +54,7 @@
5454
"unittests/extractConstants.ts",
5555
"unittests/extractFunctions.ts",
5656
"unittests/extractRanges.ts",
57+
"unittests/factory.ts",
5758
"unittests/hostNewLineSupport.ts",
5859
"unittests/incrementalParser.ts",
5960
"unittests/initializeTSConfig.ts",

src/testRunner/unittests/factory.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
namespace ts {
2+
describe("FactoryAPI", () => {
3+
describe("createArrowFunction", () => {
4+
it("parenthesizes concise body if necessary", () => {
5+
function checkBody(body: ConciseBody) {
6+
const node = createArrowFunction(
7+
/*modifiers*/ undefined,
8+
/*typeParameters*/ undefined,
9+
[],
10+
/*type*/ undefined,
11+
/*equalsGreaterThanToken*/ undefined,
12+
body,
13+
);
14+
assert.strictEqual(node.body.kind, SyntaxKind.ParenthesizedExpression);
15+
}
16+
17+
checkBody(createObjectLiteral());
18+
checkBody(createPropertyAccess(createObjectLiteral(), "prop"));
19+
checkBody(createAsExpression(createPropertyAccess(createObjectLiteral(), "prop"), createTypeReferenceNode("T", /*typeArguments*/ undefined)));
20+
checkBody(createNonNullExpression(createPropertyAccess(createObjectLiteral(), "prop")));
21+
});
22+
});
23+
});
24+
}

0 commit comments

Comments
 (0)