Skip to content

Commit

Permalink
Revert "syntax: simplify unset-or-null with null default to just unset"
Browse files Browse the repository at this point in the history
Per #970, even if the change is technically correct, it can easily lead
to confusion for users or unintentional bugs when they tweak the code
without noticing the subtlety between null (empty) and unset values.

This reverts commit e8ee47f.

Fixes #970.
  • Loading branch information
mvdan committed Mar 11, 2023
1 parent 450d401 commit d806889
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 9 deletions.
5 changes: 0 additions & 5 deletions syntax/simplify.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import "bytes"
// Remove redundant quotes [[ "$var" == str ]]
// Merge negations with unary operators [[ ! -n $var ]]
// Use single quotes to shorten literals "\$foo"
// Remove redundant param expansion colons ${foo:-}
func Simplify(n Node) bool {
s := simplifier{}
Walk(n, s.visit)
Expand All @@ -38,10 +37,6 @@ func (s *simplifier) visit(node Node) bool {
x.Index = s.removeParensArithm(x.Index)
// don't inline params - same as above.

if x.Exp != nil && x.Exp.Op == DefaultUnsetOrNull && x.Exp.Word == nil {
s.modified = true
x.Exp.Op = DefaultUnset
}
if x.Slice == nil {
break
}
Expand Down
4 changes: 0 additions & 4 deletions syntax/simplify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ var simplifyTests = [...]simplifyTest{
{"\"fo\\`o\"", "'fo`o'"},
noSimple(`fo"o"bar`),
noSimple(`foo""bar`),

// param expansions
{`${foo:-}`, `${foo-}`},
noSimple(`${foo:-bar}`),
}

func TestSimplify(t *testing.T) {
Expand Down

0 comments on commit d806889

Please sign in to comment.