mustache / spec

The Mustache spec.
MIT License
371 stars 71 forks source link

lambdas should use specified delimiters, NOT default delimiters #110

Closed jamesaspence closed 1 year ago

jamesaspence commented 5 years ago

As per https://github.com/mustache/spec/blob/master/specs/~lambdas.yml#L44, lambdas should use default delimiters when parsing return values. This ends up feeling very inconsistent - assume for example that we are passing a function like @{#myfunc}@@{otherVar}@@{/myfunc}@, we would need to change the inner section to {{otherVar}} to have it interpolate correctly.

pvande commented 3 years ago

IIRC, this behavior was specified because it's not possible for the called lambda to know what the current delimiters are, and using contextual delimiters limits how broadly the lambda can be reused.

Using Current Delimiters

const variable = 'value';
function lambda() {
  return "@{variable}@";
}
{{= @{ }@ =}}
This interpolates properly: @{lambda}@

{{= $ $ =}}
This does not: $lambda$

Using Default Delimiters

const variable = 'value';
function lambda() {
  return "{{variable}}";
}
{{= @{ }@ =}}
This interpolates properly: @{lambda}@

{{= $ $ =}}
So does this: $lambda$
jgonggrijp commented 1 year ago

Closing this as the question seems to have been adequately answered. Please feel welcome to comment anyway.