Skip to content

Commit

Permalink
rename "has pure comment"
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Jul 6, 2020
1 parent eddb21d commit 8133132
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions internal/ast/ast.go
Expand Up @@ -400,7 +400,7 @@ type ENew struct {

// True if there is a comment containing "@__PURE__" or "#__PURE__" preceding
// this call expression. See the comment inside ECall for more details.
HasPureComment bool
CanBeUnwrappedIfUnused bool
}

type ENewTarget struct{}
Expand Down Expand Up @@ -435,7 +435,7 @@ type ECall struct {
// Note that the arguments are not considered to be part of the call. If the
// call itself is removed due to this annotation, the arguments must remain
// if they have side effects.
HasPureComment bool
CanBeUnwrappedIfUnused bool
}

type EDot struct {
Expand Down
16 changes: 8 additions & 8 deletions internal/parser/parser.go
Expand Up @@ -2203,9 +2203,9 @@ func (p *parser) parseExprCommon(level ast.L, errors *deferredErrors, flags expr
expr = p.parseSuffix(expr, ast.LCall-1, errors, flags)
switch e := expr.Data.(type) {
case *ast.ECall:
e.HasPureComment = true
e.CanBeUnwrappedIfUnused = true
case *ast.ENew:
e.HasPureComment = true
e.CanBeUnwrappedIfUnused = true
}
}

Expand Down Expand Up @@ -7394,8 +7394,8 @@ func (p *parser) visitExprInOut(expr ast.Expr, in exprIn) (ast.Expr, exprOut) {
Name: "call",
NameLoc: target.Loc,
}},
Args: append([]ast.Expr{targetFunc()}, e.Args...),
HasPureComment: e.HasPureComment,
Args: append([]ast.Expr{targetFunc()}, e.Args...),
CanBeUnwrappedIfUnused: e.CanBeUnwrappedIfUnused,
}}), exprOut{}
}
}
Expand Down Expand Up @@ -8014,7 +8014,7 @@ func (p *parser) exprCanBeRemovedIfUnused(expr ast.Expr) bool {
case *ast.ECall:
// A call that has been marked "__PURE__" can be removed if all arguments
// can be removed. The annotation causes us to ignore the target.
if e.HasPureComment {
if e.CanBeUnwrappedIfUnused {
for _, arg := range e.Args {
if !p.exprCanBeRemovedIfUnused(arg) {
return false
Expand All @@ -8026,7 +8026,7 @@ func (p *parser) exprCanBeRemovedIfUnused(expr ast.Expr) bool {
case *ast.ENew:
// A constructor call that has been marked "__PURE__" can be removed if all
// arguments can be removed. The annotation causes us to ignore the target.
if e.HasPureComment {
if e.CanBeUnwrappedIfUnused {
for _, arg := range e.Args {
if !p.exprCanBeRemovedIfUnused(arg) {
return false
Expand Down Expand Up @@ -8072,7 +8072,7 @@ func (p *parser) simplifyUnusedExpr(expr ast.Expr) ast.Expr {
case *ast.ECall:
// A call that has been marked "__PURE__" can be removed if all arguments
// can be removed. The annotation causes us to ignore the target.
if e.HasPureComment {
if e.CanBeUnwrappedIfUnused {
expr = ast.Expr{}
for _, arg := range e.Args {
expr = maybeJoinWithComma(expr, p.simplifyUnusedExpr(arg))
Expand All @@ -8082,7 +8082,7 @@ func (p *parser) simplifyUnusedExpr(expr ast.Expr) ast.Expr {
case *ast.ENew:
// A constructor call that has been marked "__PURE__" can be removed if all
// arguments can be removed. The annotation causes us to ignore the target.
if e.HasPureComment {
if e.CanBeUnwrappedIfUnused {
expr = ast.Expr{}
for _, arg := range e.Args {
expr = maybeJoinWithComma(expr, p.simplifyUnusedExpr(arg))
Expand Down
16 changes: 8 additions & 8 deletions internal/parser/parser_lower.go
Expand Up @@ -354,8 +354,8 @@ flatten:
Name: "call",
NameLoc: loc,
}},
Args: append([]ast.Expr{thisArg}, e.Args...),
HasPureComment: e.HasPureComment,
Args: append([]ast.Expr{thisArg}, e.Args...),
CanBeUnwrappedIfUnused: e.CanBeUnwrappedIfUnused,
}}
break
}
Expand All @@ -371,18 +371,18 @@ flatten:
Name: "call",
NameLoc: loc,
}},
Args: append([]ast.Expr{privateThisFunc()}, e.Args...),
HasPureComment: e.HasPureComment,
Args: append([]ast.Expr{privateThisFunc()}, e.Args...),
CanBeUnwrappedIfUnused: e.CanBeUnwrappedIfUnused,
}})
privateThisFunc = nil
break
}

result = ast.Expr{Loc: loc, Data: &ast.ECall{
Target: result,
Args: e.Args,
IsDirectEval: e.IsDirectEval,
HasPureComment: e.HasPureComment,
Target: result,
Args: e.Args,
IsDirectEval: e.IsDirectEval,
CanBeUnwrappedIfUnused: e.CanBeUnwrappedIfUnused,
}}

case *ast.EUnary:
Expand Down

0 comments on commit 8133132

Please sign in to comment.