Fix single-line comment disrupting return w/optional chain (#42026)

This commit is contained in:
Ron Buckton 2020-12-17 18:55:09 -08:00 committed by GitHub
parent 052d7308e6
commit e789cb1356
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 6 deletions

View file

@ -77,7 +77,6 @@ namespace ts {
if (!isSimpleCopiableExpression(expression)) {
thisArg = factory.createTempVariable(hoistVariableDeclaration);
expression = factory.createAssignment(thisArg, expression);
// if (inParameterInitializer) tempVariableInParameter = true;
}
else {
thisArg = expression;
@ -117,7 +116,6 @@ namespace ts {
if (!isSimpleCopiableExpression(leftExpression)) {
capturedLeft = factory.createTempVariable(hoistVariableDeclaration);
leftExpression = factory.createAssignment(capturedLeft, leftExpression);
// if (inParameterInitializer) tempVariableInParameter = true;
}
let rightExpression = capturedLeft;
let thisArg: Expression | undefined;
@ -130,7 +128,6 @@ namespace ts {
if (!isSimpleCopiableExpression(rightExpression)) {
thisArg = factory.createTempVariable(hoistVariableDeclaration);
rightExpression = factory.createAssignment(thisArg, rightExpression);
// if (inParameterInitializer) tempVariableInParameter = true;
}
else {
thisArg = rightExpression;
@ -163,6 +160,7 @@ namespace ts {
const target = isDelete
? factory.createConditionalExpression(createNotNullCondition(leftExpression, capturedLeft, /*invert*/ true), /*questionToken*/ undefined, factory.createTrue(), /*colonToken*/ undefined, factory.createDeleteExpression(rightExpression))
: factory.createConditionalExpression(createNotNullCondition(leftExpression, capturedLeft, /*invert*/ true), /*questionToken*/ undefined, factory.createVoidZero(), /*colonToken*/ undefined, rightExpression);
setTextRange(target, node);
return thisArg ? factory.createSyntheticReferenceExpression(target, thisArg) : target;
}
@ -188,15 +186,14 @@ namespace ts {
if (!isSimpleCopiableExpression(left)) {
right = factory.createTempVariable(hoistVariableDeclaration);
left = factory.createAssignment(right, left);
// if (inParameterInitializer) tempVariableInParameter = true;
}
return factory.createConditionalExpression(
return setTextRange(factory.createConditionalExpression(
createNotNullCondition(left, right),
/*questionToken*/ undefined,
right,
/*colonToken*/ undefined,
visitNode(node.right, visitor, isExpression),
);
), node);
}
function visitDeleteExpression(node: DeleteExpression) {

View file

@ -0,0 +1,13 @@
//// [optionalChainingInArrow.ts]
// https://github.com/microsoft/TypeScript/issues/41814
const test = (names: string[]) =>
// single-line comment
names?.filter(x => x);
//// [optionalChainingInArrow.js]
// https://github.com/microsoft/TypeScript/issues/41814
var test = function (names) {
// single-line comment
return names === null || names === void 0 ? void 0 : names.filter(function (x) { return x; });
};

View file

@ -0,0 +1,6 @@
// @target: es5
// @noTypesAndSymbols: true
// https://github.com/microsoft/TypeScript/issues/41814
const test = (names: string[]) =>
// single-line comment
names?.filter(x => x);