Merge pull request #25342 from ajafff/factory-leftmost-expression
getLeftmostExpression: handle AsExpression and NonNullExpression
This commit is contained in:
commit
e4145e3017
|
@ -4354,19 +4354,17 @@ namespace ts {
|
|||
case SyntaxKind.ConditionalExpression:
|
||||
node = (<ConditionalExpression>node).condition;
|
||||
continue;
|
||||
|
||||
case SyntaxKind.CallExpression:
|
||||
if (stopAtCallExpressions) {
|
||||
return node;
|
||||
}
|
||||
// falls through
|
||||
case SyntaxKind.AsExpression:
|
||||
case SyntaxKind.ElementAccessExpression:
|
||||
case SyntaxKind.PropertyAccessExpression:
|
||||
node = (<CallExpression | PropertyAccessExpression | ElementAccessExpression>node).expression;
|
||||
continue;
|
||||
|
||||
case SyntaxKind.NonNullExpression:
|
||||
case SyntaxKind.PartiallyEmittedExpression:
|
||||
node = (<PartiallyEmittedExpression>node).expression;
|
||||
node = (<CallExpression | PropertyAccessExpression | ElementAccessExpression | AsExpression | NonNullExpression | PartiallyEmittedExpression>node).expression;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -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",
|
||||
|
|
24
src/testRunner/unittests/factory.ts
Normal file
24
src/testRunner/unittests/factory.ts
Normal file
|
@ -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")));
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Reference in a new issue