From 8133132e49085ffed90decb9f9abbe29ecfd6dda Mon Sep 17 00:00:00 2001 From: Evan Wallace Date: Sun, 5 Jul 2020 17:22:07 -0700 Subject: [PATCH] rename "has pure comment" --- internal/ast/ast.go | 4 ++-- internal/parser/parser.go | 16 ++++++++-------- internal/parser/parser_lower.go | 16 ++++++++-------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/internal/ast/ast.go b/internal/ast/ast.go index 002b96c6dc9..6e3af445c9a 100644 --- a/internal/ast/ast.go +++ b/internal/ast/ast.go @@ -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{} @@ -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 { diff --git a/internal/parser/parser.go b/internal/parser/parser.go index 10dcbb11d38..4d53d981900 100644 --- a/internal/parser/parser.go +++ b/internal/parser/parser.go @@ -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 } } @@ -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{} } } @@ -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 @@ -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 @@ -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)) @@ -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)) diff --git a/internal/parser/parser_lower.go b/internal/parser/parser_lower.go index ab832855586..a5c77c45a5a 100644 --- a/internal/parser/parser_lower.go +++ b/internal/parser/parser_lower.go @@ -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 } @@ -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: