Skip to content

Commit

Permalink
Merge pull request #6 from dfreeman/this-path-extra-element
Browse files Browse the repository at this point in the history
[bugfix] Don't emit `parts: [undefined]` for `{{this}}`
  • Loading branch information
pzuraq authored Jul 29, 2021
2 parents 5bf5493 + 7cc8302 commit 163b275
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function preparePath(data, sexpr, parts, loc) {
depth,
head,
tail,
parts: [head, ...tail],
parts: head ? [head, ...tail] : tail,
original,
loc
};
Expand Down
32 changes: 32 additions & 0 deletions spec/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,38 @@ describe('ast', function() {
});
});

describe('node details', function () {
describe('paths', function () {
it('{{this}}', function () {
let path = parse('{{this}}').body[0].path;
equals(path.original, 'this');
equals(path.head, undefined);
equals(path.tail.length, 0);
equals(path.parts.length, 0);
});

it('{{this.bar}}', function () {
let path = parse('{{this.bar}}').body[0].path;
equals(path.original, 'this.bar');
equals(path.head, 'bar');
equals(path.tail.length, 0);
equals(path.parts.length, 1);
equals(path.parts[0], 'bar');
});

it('{{foo.bar}}', function () {
let path = parse('{{foo.bar}}').body[0].path;
equals(path.original, 'foo.bar');
equals(path.head, 'foo');
equals(path.tail.length, 1);
equals(path.tail[0], 'bar')
equals(path.parts.length, 2);
equals(path.parts[0], 'foo');
equals(path.parts[1], 'bar');
});
});
});

describe('standalone flags', function() {
describe('mustache', function() {
it('does not mark mustaches as standalone', function() {
Expand Down

0 comments on commit 163b275

Please sign in to comment.