@@ -1292,18 +1292,6 @@ func (p *printer) printDotThenSuffix() {
1292
1292
}
1293
1293
}
1294
1294
1295
- type printExprFlags uint8
1296
-
1297
- const (
1298
- forbidCall printExprFlags = 1 << iota
1299
- forbidIn
1300
- hasNonOptionalChainParent
1301
- exprResultIsUnused
1302
- didAlreadySimplifyUnusedExprs
1303
- isFollowedByOf
1304
- isInsideForAwait
1305
- )
1306
-
1307
1295
func (p * printer ) printUndefined (level js_ast.L ) {
1308
1296
if level >= js_ast .LPrefix {
1309
1297
p .print ("(void 0)" )
@@ -1373,12 +1361,19 @@ func (p *printer) simplifyUnusedExpr(expr js_ast.Expr) js_ast.Expr {
1373
1361
return expr
1374
1362
}
1375
1363
1376
- func (p * printer ) printExpr (expr js_ast.Expr , level js_ast.L , flags printExprFlags ) {
1377
- originalFlags := flags
1364
+ type printExprFlags uint8
1378
1365
1379
- // Turn these flags off so we don't unintentionally propagate them to child calls
1380
- flags &= ^ (isFollowedByOf | exprResultIsUnused | didAlreadySimplifyUnusedExprs )
1366
+ const (
1367
+ forbidCall printExprFlags = 1 << iota
1368
+ forbidIn
1369
+ hasNonOptionalChainParent
1370
+ exprResultIsUnused
1371
+ didAlreadySimplifyUnusedExprs
1372
+ isFollowedByOf
1373
+ isInsideForAwait
1374
+ )
1381
1375
1376
+ func (p * printer ) printExpr (expr js_ast.Expr , level js_ast.L , flags printExprFlags ) {
1382
1377
p .addSourceMapping (expr .Loc )
1383
1378
1384
1379
switch e := expr .Data .(type ) {
@@ -1560,20 +1555,20 @@ func (p *printer) printExpr(expr js_ast.Expr, level js_ast.L, flags printExprFla
1560
1555
for _ , arg := range e .Args {
1561
1556
replacement = js_ast .JoinWithComma (replacement , js_ast .SimplifyUnusedExpr (arg , p .isUnbound ))
1562
1557
}
1563
- if replacement .Data == nil || (originalFlags & exprResultIsUnused ) == 0 {
1558
+ if replacement .Data == nil || (flags & exprResultIsUnused ) == 0 {
1564
1559
replacement = js_ast .JoinWithComma (replacement , js_ast.Expr {Loc : expr .Loc , Data : js_ast .EUndefinedShared })
1565
1560
}
1566
- p .printExpr (replacement , level , originalFlags )
1561
+ p .printExpr (replacement , level , flags )
1567
1562
break
1568
1563
}
1569
1564
1570
1565
// Inline non-mutated identity functions at print time
1571
1566
if (symbolFlags & (js_ast .IsIdentityFunction | js_ast .CouldPotentiallyBeMutated )) == js_ast .IsIdentityFunction && len (e .Args ) == 1 {
1572
1567
arg := e .Args [0 ]
1573
- if (originalFlags & exprResultIsUnused ) != 0 {
1568
+ if (flags & exprResultIsUnused ) != 0 {
1574
1569
arg = js_ast .SimplifyUnusedExpr (arg , p .isUnbound )
1575
1570
}
1576
- p .printExpr (arg , level , originalFlags )
1571
+ p .printExpr (arg , level , flags )
1577
1572
break
1578
1573
}
1579
1574
}
@@ -1634,7 +1629,7 @@ func (p *printer) printExpr(expr js_ast.Expr, level js_ast.L, flags printExprFla
1634
1629
}
1635
1630
1636
1631
case * js_ast.ERequireString :
1637
- p .printRequireOrImportExpr (e .ImportRecordIndex , nil , level , originalFlags )
1632
+ p .printRequireOrImportExpr (e .ImportRecordIndex , nil , level , flags )
1638
1633
1639
1634
case * js_ast.ERequireResolveString :
1640
1635
wrap := level >= js_ast .LNew || (flags & forbidCall ) != 0
@@ -1654,7 +1649,7 @@ func (p *printer) printExpr(expr js_ast.Expr, level js_ast.L, flags printExprFla
1654
1649
if ! p .options .RemoveWhitespace {
1655
1650
leadingInteriorComments = e .LeadingInteriorComments
1656
1651
}
1657
- p .printRequireOrImportExpr (e .ImportRecordIndex , leadingInteriorComments , level , originalFlags )
1652
+ p .printRequireOrImportExpr (e .ImportRecordIndex , leadingInteriorComments , level , flags )
1658
1653
1659
1654
case * js_ast.EImportCall :
1660
1655
var leadingInteriorComments []js_ast.Comment
@@ -1724,7 +1719,7 @@ func (p *printer) printExpr(expr js_ast.Expr, level js_ast.L, flags printExprFla
1724
1719
}
1725
1720
flags &= ^ hasNonOptionalChainParent
1726
1721
}
1727
- p .printExpr (e .Target , js_ast .LPostfix , flags )
1722
+ p .printExpr (e .Target , js_ast .LPostfix , flags & ( forbidCall | hasNonOptionalChainParent ) )
1728
1723
if p .canPrintIdentifier (e .Name ) {
1729
1724
if e .OptionalChain != js_ast .OptionalChainStart && p .prevNumEnd == len (p .js ) {
1730
1725
// "1.toString" is a syntax error, so print "1 .toString" instead
@@ -1786,7 +1781,7 @@ func (p *printer) printExpr(expr js_ast.Expr, level js_ast.L, flags printExprFla
1786
1781
}
1787
1782
flags &= ^ hasNonOptionalChainParent
1788
1783
}
1789
- p .printExpr (e .Target , js_ast .LPostfix , flags )
1784
+ p .printExpr (e .Target , js_ast .LPostfix , flags & ( forbidCall | hasNonOptionalChainParent ) )
1790
1785
if e .OptionalChain == js_ast .OptionalChainStart {
1791
1786
p .print ("?." )
1792
1787
}
@@ -2072,7 +2067,7 @@ func (p *printer) printExpr(expr js_ast.Expr, level js_ast.L, flags printExprFla
2072
2067
case * js_ast.EIdentifier :
2073
2068
name := p .renamer .NameForSymbol (e .Ref )
2074
2069
wrap := len (p .js ) == p .forOfInitStart && (name == "let" ||
2075
- ((originalFlags & isFollowedByOf ) != 0 && (flags & isInsideForAwait ) == 0 && name == "async" ))
2070
+ ((flags & isFollowedByOf ) != 0 && (flags & isInsideForAwait ) == 0 && name == "async" ))
2076
2071
2077
2072
if wrap {
2078
2073
p .print ("(" )
@@ -2192,15 +2187,15 @@ func (p *printer) printExpr(expr js_ast.Expr, level js_ast.L, flags printExprFla
2192
2187
// should have already simplified unused expressions), or the result is used
2193
2188
// (and we can still simplify unused expressions inside the left operand)
2194
2189
if e .Op == js_ast .BinOpComma {
2195
- if (originalFlags & didAlreadySimplifyUnusedExprs ) == 0 {
2190
+ if (flags & didAlreadySimplifyUnusedExprs ) == 0 {
2196
2191
left := p .simplifyUnusedExpr (e .Left )
2197
2192
right := e .Right
2198
- if (originalFlags & exprResultIsUnused ) != 0 {
2193
+ if (flags & exprResultIsUnused ) != 0 {
2199
2194
right = p .simplifyUnusedExpr (right )
2200
2195
}
2201
2196
if left .Data != e .Left .Data || right .Data != e .Right .Data {
2202
2197
// Pass a flag so we don't needlessly re-simplify the same expression
2203
- p .printExpr (js_ast .JoinWithComma (left , e .Right ), level , originalFlags | didAlreadySimplifyUnusedExprs )
2198
+ p .printExpr (js_ast .JoinWithComma (left , e .Right ), level , flags | didAlreadySimplifyUnusedExprs )
2204
2199
break
2205
2200
}
2206
2201
} else {
@@ -2292,7 +2287,7 @@ func (p *printer) printExpr(expr js_ast.Expr, level js_ast.L, flags printExprFla
2292
2287
2293
2288
if e .Op == js_ast .BinOpComma {
2294
2289
// The result of the right operand of the comma operator is unused if the caller doesn't use it
2295
- p .printExpr (e .Right , rightLevel , (flags & forbidIn )| (originalFlags & exprResultIsUnused ))
2290
+ p .printExpr (e .Right , rightLevel , (flags & forbidIn )| (flags & exprResultIsUnused ))
2296
2291
} else {
2297
2292
p .printExpr (e .Right , rightLevel , flags & forbidIn )
2298
2293
}
0 commit comments