Skip to content

Commit 365b256

Browse files
authored
Fix and validate post-increment/decrement in module emit (microsoft#44968)
1 parent 476054e commit 365b256

File tree

13 files changed

+819
-272
lines changed

13 files changed

+819
-272
lines changed

src/compiler/factory/nodeFactory.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2724,6 +2724,14 @@ namespace ts {
27242724
node.operator = operator;
27252725
node.operand = parenthesizerRules().parenthesizeOperandOfPrefixUnary(operand);
27262726
node.transformFlags |= propagateChildFlags(node.operand);
2727+
// Only set this flag for non-generated identifiers and non-"local" names. See the
2728+
// comment in `visitPreOrPostfixUnaryExpression` in module.ts
2729+
if ((operator === SyntaxKind.PlusPlusToken || operator === SyntaxKind.MinusMinusToken) &&
2730+
isIdentifier(node.operand) &&
2731+
!isGeneratedIdentifier(node.operand) &&
2732+
!isLocalName(node.operand)) {
2733+
node.transformFlags |= TransformFlags.ContainsUpdateExpressionForIdentifier;
2734+
}
27272735
return node;
27282736
}
27292737

@@ -2739,7 +2747,14 @@ namespace ts {
27392747
const node = createBaseExpression<PostfixUnaryExpression>(SyntaxKind.PostfixUnaryExpression);
27402748
node.operator = operator;
27412749
node.operand = parenthesizerRules().parenthesizeOperandOfPostfixUnary(operand);
2742-
node.transformFlags = propagateChildFlags(node.operand);
2750+
node.transformFlags |= propagateChildFlags(node.operand);
2751+
// Only set this flag for non-generated identifiers and non-"local" names. See the
2752+
// comment in `visitPreOrPostfixUnaryExpression` in module.ts
2753+
if (isIdentifier(node.operand) &&
2754+
!isGeneratedIdentifier(node.operand) &&
2755+
!isLocalName(node.operand)) {
2756+
node.transformFlags |= TransformFlags.ContainsUpdateExpressionForIdentifier;
2757+
}
27432758
return node;
27442759
}
27452760

src/compiler/transformers/module/module.ts

Lines changed: 136 additions & 92 deletions
Large diffs are not rendered by default.

src/compiler/transformers/module/system.ts

Lines changed: 148 additions & 114 deletions
Large diffs are not rendered by default.

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6640,6 +6640,7 @@ namespace ts {
66406640
ContainsClassFields = 1 << 23,
66416641
ContainsPossibleTopLevelAwait = 1 << 24,
66426642
ContainsLexicalSuper = 1 << 25,
6643+
ContainsUpdateExpressionForIdentifier = 1 << 26,
66436644
// Please leave this as 1 << 29.
66446645
// It is the maximum bit we can set before we outgrow the size of a v8 small integer (SMI) on an x86 system.
66456646
// It is a good reminder of how much room we have left

0 commit comments

Comments
 (0)