andrewplummer / Sugar

A Javascript library for working with native objects.
https://sugarjs.com/
MIT License
4.54k stars 305 forks source link

TypeError: Unmatched } in format string #587

Closed XadillaX closed 7 years ago

XadillaX commented 7 years ago

It's OK while I'm using 1.4 but broken under 2.

("{ name: '{name}' }").assign/format({ name: "Hi" });
andrewplummer commented 7 years ago

Hi... according to the docs "Literal braces in the string can be escaped by repeating them.". This hasn't changed since 1.4, so if this was ever working before it was definitely a bug. It seems that you're intending the outer braces to be unescaped so you should instead be using:

("{{ name: '{name}' }}").assign/format({ name: "Hi" });
andrewplummer commented 7 years ago

To be clear, without escaping you are nesting 2 meaningful braces, which isn't allowed, which explains the error message you're seeing.

andrewplummer commented 7 years ago

Going to close this one for now.