Skip to content

Commit

Permalink
fix block var names
Browse files Browse the repository at this point in the history
  • Loading branch information
camshaft committed Jul 1, 2015
1 parent 7746be0 commit 6e3f6a0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/etude/node.ex
Expand Up @@ -42,7 +42,7 @@ defimpl Etude.Node, for: Any do
|> List.keysort(0)
name(id, opts)
end
def name(node, opts) do
def name(node, _opts) do
"etude_#{:erlang.phash2(node)}"
|> String.to_atom
end
Expand Down
5 changes: 4 additions & 1 deletion lib/etude/node/block.ex
Expand Up @@ -6,7 +6,6 @@ defmodule Etude.Node.Block do
defimpl Etude.Node, for: Etude.Node.Block do
defdelegate name(node, opts), to: Etude.Node.Any
defdelegate prop(node, opts), to: Etude.Node.Any
defdelegate var(node, opts), to: Etude.Node.Any

def assign(node, opts) do
last(node) |> Etude.Node.assign(opts)
Expand All @@ -28,6 +27,10 @@ defmodule Etude.Node.Block do
Etude.Children.compile(node.children, opts)
end

def var(node, opts) do
last(node) |> Etude.Node.var(opts)
end

defp last(node) do
List.last(node.children)
end
Expand Down
27 changes: 27 additions & 0 deletions test/block_test.exs
Expand Up @@ -25,4 +25,31 @@ defmodule EtudeTest.Block do
}
]
], {:parent, :child}

etudetest "should use vars outside of blocks", [
render: [
%Assign{
expression: true, line: nil,
name: :action
},
%Cond{
arms: [
%Block{
children: [
%Var{
line: nil,
name: :action
}
],
line: nil, side_effects: true
},
],
expression: %Var{
line: nil,
name: :action
},
line: nil
}
]
], true
end

0 comments on commit 6e3f6a0

Please sign in to comment.