Skip to content

Commit

Permalink
Merge pull request #133 from Mido-sys/fix_if_condition_with_map_array…
Browse files Browse the repository at this point in the history
…_index

Fix if condition with map array index
  • Loading branch information
paganotoni authored Apr 15, 2021
2 parents e5e4fe3 + fe719ee commit ab79cdf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ast/index_expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ type IndexExpression struct {
Value Expression
}

func (ie *IndexExpression) validIfCondition() bool { return true }

func (ie *IndexExpression) expressionNode() {}

func (ie *IndexExpression) String() string {
Expand Down
9 changes: 9 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,15 @@ func Test_IfExpression_PrefixExpressions_InvalidCompar(t *testing.T) {

r.Error(err, "syntax error: invalid if condition, got x = 1")
}
func Test_IfExpression_With_Map_Array_Index(t *testing.T) {
r := require.New(t)
input := `<% if (flash["error"] ) { x } %>`

_, err := Parse(input)

r.NoError(err)
}

func Test_IfExpression_InfixExpressions_InvalidCompare(t *testing.T) {
r := require.New(t)
input := `<% if ( y == 1 && x = 1) { x } %>`
Expand Down

0 comments on commit ab79cdf

Please sign in to comment.