Skip to content

Known issues

Alex Ewerlöf edited this page Aug 23, 2020 · 7 revisions

For the sake of speed and smaller code size, some edge cases are not addressed but you should be aware of:

Paths cannot be expressions

const scope = {
  arr: [10,20,30,40]
}

const template = `{{arr[1+1]}}`
// Gives a syntax error instead of `arr[2]`

However, you can process the paths (after using parse()) to support any syntax or DSL you desire.

Paths cannot include the ']' character

For example if you have an object like:

const a = {
  ']': 'close'
}

a[']'] will not give 'close' but rather throws a syntax error complaining that you have a mismatching quotation!

Paths cannot contain the open or close tags even when properly quoted

Examples:

  • Hello {{name["{{"]}}!
  • Hello {{name["}}"]}}!

Paths can start with a dot (.)

Hello {{.name}} is the same as Hello {{name}}

Paths don't require string delimiters:

Suppose you have this in Javascript:

const a = {
  'foo': 'bar'
}

If you want to get the value of the foo property, in Javascript you can say a['foo']. This works in micromustache too but you can also say a[foo] which is not valid Javascript strictly speaking but works without error.

This has a side effect that might be surprising:

const foo = 'baz'
const a = {
  foo: 'bar',
  baz: 'qux'
}
console.log(micromustache.render('{{a['foo']}}'))
// 'bar'
console.log(`${a['foo']}`)
// 'bar'
console.log(micromustache.render('{{a[foo]}}`)
// 'bar'
console.log(`${a[foo]}`)
// 'qux'

No support for comments

Unlike Mustache.js you cannot comment a path. You can of course work around this limitation by using your own resolve function.

No escape sequence

The templates cannot currently contain {{ and there's no way to escape it. One workaround is to literally pass '{{' as a value for a variable. Another workaround is to explicitly set the tags option to something other than ['{{', '}}'], for example ['<', '>'].

No nested paths

Currently there is no way to use a nested path:

const scope = {
  a: ['Java', 'Python', 'Ruby'],
  b: 1
}

micromustache.render(`My favorite language is not {{a[b]}}`)
// 'foo'

Will not give 'Python' because a[b] is treated as a['b'] or a.b. In other words instead of scope.a[scope.b] it gives the value of scope.a.b.

Clone this wiki locally