Skip to content

Incorrect evalution order #30

@irok

Description

@irok

The following code seems to be working properly.

jSmart = require('jsmart');
data = {
  array: [1, 2, 3],
  count: (array) => array.length
};

tmpl = new jSmart('{count($array)}');
console.log(tmpl.fetch(data));    // -> 3

tmpl = new jSmart('{if count($array)}OK{else}NG{/if}');
console.log(tmpl.fetch(data));    // -> OK

However, the following code does not work as expected.

tmpl = new jSmart('{if count($array) > 0}OK{else}NG{/if}');
console.log(tmpl.fetch(data));    // -> NG

Apparently, it seems that count modifier is working instead of my count method.

tmpl = new jSmart('{count($array)}');
console.log(tmpl.fetch({
  array: [1, 2, 3],
  count: (array) => 'My count method'
}));
// -> 3

Can I use my count method?

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