Skip to content
This repository has been archived by the owner on Jun 10, 2018. It is now read-only.

eco pollutes context objects #57

Open
osuushi opened this issue Oct 5, 2012 · 0 comments
Open

eco pollutes context objects #57

osuushi opened this issue Oct 5, 2012 · 0 comments

Comments

@osuushi
Copy link

osuushi commented Oct 5, 2012

In order to support the @safe and @escape helpers, eco adds these to the context object, which can make for confusing bugs.

Here's a very simplified version of where I ran into the problem:

sales = ({price: i, shipping:i, tax:i} for i in [0..10])

tpl = eco.compile "Price: <%= @price %>; Shipping: <%= @shipping %>; Tax: <%= @tax %><br>"

totals =
    price: 0
    shipping: 0
    tax: 0


for s in sales
    console.log tpl s
    totals[k] += v for k,v of s 

console.log tpl totals

The problem is calling tpl pollutes s with the escape property, which then gets concatenated repeatedly onto totals.escape. As a result, we end up with a garbled function string that begins "undefinedfunction (value)...". Then when we call tpl totals, this eco tries to call that garbled string as a function, and we get an error which was rather confusing to pin down.

For now, I'm working around this by shallow copying my inputs. But this is really not how a template library should be treating its inputs. Any changes made on the context object should be reversed before returning.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant