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

eco pollutes context objects #57

@osuushi

Description

@osuushi

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions