From 7cc8302085f7b0add276670abcd214cb54fa9d27 Mon Sep 17 00:00:00 2001 From: Dan Freeman Date: Thu, 22 Jul 2021 16:31:45 +0200 Subject: [PATCH] Don't emit `parts: [undefined]` for `{{this}}` --- lib/helpers.js | 2 +- spec/ast.js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/helpers.js b/lib/helpers.js index c0f2865..323519c 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -86,7 +86,7 @@ export function preparePath(data, sexpr, parts, loc) { depth, head, tail, - parts: [head, ...tail], + parts: head ? [head, ...tail] : tail, original, loc }; diff --git a/spec/ast.js b/spec/ast.js index a89e687..0fe4903 100644 --- a/spec/ast.js +++ b/spec/ast.js @@ -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() {