mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-16 15:51:35 -05:00
Add more check
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
/*@internal*/
|
||||
namespace ts {
|
||||
export function transformESNext(context: TransformationContext) {
|
||||
const {
|
||||
hoistVariableDeclaration
|
||||
} = context;
|
||||
return chainBundle(transformSourceFile);
|
||||
|
||||
function transformSourceFile(node: SourceFile) {
|
||||
@@ -31,15 +34,45 @@ namespace ts {
|
||||
const operator = binaryExpression.operatorToken;
|
||||
if (isCompoundAssignment(operator.kind) && isLogicalOrCoalescingAssignmentOperator(operator.kind)) {
|
||||
const nonAssignmentOperator = getNonAssignmentOperatorForCompoundAssignment(operator.kind);
|
||||
const left = visitNode(binaryExpression.left, visitor, isExpression);
|
||||
const right = visitNode(binaryExpression.right, visitor, isExpression);
|
||||
let left = skipParentheses(visitNode(binaryExpression.left, visitor, isLeftHandSideExpression));
|
||||
let assignmentTarget = left
|
||||
const right = skipParentheses(visitNode(binaryExpression.right, visitor, isExpression));
|
||||
if (isPropertyAccessExpression(left) || isElementAccessExpression(left)) {
|
||||
const tempVariable = createTempVariable(hoistVariableDeclaration)
|
||||
if (isPropertyAccessExpression(left)) {
|
||||
assignmentTarget = createPropertyAccess(
|
||||
tempVariable,
|
||||
left.name
|
||||
);
|
||||
left = createPropertyAccess(
|
||||
createAssignment(
|
||||
tempVariable,
|
||||
left.expression
|
||||
),
|
||||
left.name
|
||||
);
|
||||
}
|
||||
else {
|
||||
assignmentTarget = createElementAccess(
|
||||
tempVariable,
|
||||
left.argumentExpression
|
||||
);
|
||||
left = createElementAccess(
|
||||
createAssignment(
|
||||
tempVariable,
|
||||
left.expression
|
||||
),
|
||||
left.argumentExpression
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return createBinary(
|
||||
left,
|
||||
nonAssignmentOperator,
|
||||
createParen(
|
||||
createAssignment(
|
||||
left,
|
||||
assignmentTarget,
|
||||
right
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user