From 4c6b3b79da5a901b42cf5c25106d31dd0844040f Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 10 Feb 2018 22:08:39 -0500 Subject: [PATCH] increase test coverage, handle immediately-closed blocks --- src/parse/state/mustache.ts | 2 +- .../samples/empty-block-dev/input.html | 4 +++- .../samples/empty-block-dev/warnings.json | 24 +++++++++++++------ .../samples/empty-block-prod/input.html | 4 +++- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/parse/state/mustache.ts b/src/parse/state/mustache.ts index 6e44f7c15e..0a255b1256 100644 --- a/src/parse/state/mustache.ts +++ b/src/parse/state/mustache.ts @@ -6,7 +6,7 @@ import { Parser } from '../index'; import { Node } from '../../interfaces'; function trimWhitespace(block: Node, trimBefore: boolean, trimAfter: boolean) { - if (!block.children) return; // AwaitBlock + if (!block.children || block.children.length === 0) return; // AwaitBlock const firstChild = block.children[0]; const lastChild = block.children[block.children.length - 1]; diff --git a/test/validator/samples/empty-block-dev/input.html b/test/validator/samples/empty-block-dev/input.html index 53e2ca8333..32b892d470 100644 --- a/test/validator/samples/empty-block-dev/input.html +++ b/test/validator/samples/empty-block-dev/input.html @@ -1,3 +1,5 @@ {{#each things as thing}} -{{/each}} \ No newline at end of file +{{/each}} + +{{#each things as thing}}{{/each}} \ No newline at end of file diff --git a/test/validator/samples/empty-block-dev/warnings.json b/test/validator/samples/empty-block-dev/warnings.json index 6cbc567ada..54584bf135 100644 --- a/test/validator/samples/empty-block-dev/warnings.json +++ b/test/validator/samples/empty-block-dev/warnings.json @@ -1,8 +1,18 @@ -[{ - "message": "Empty block", - "loc": { - "line": 1, - "column": 0 +[ + { + "message": "Empty block", + "loc": { + "line": 1, + "column": 0 + }, + "pos": 0 }, - "pos": 0 -}] \ No newline at end of file + { + "message": "Empty block", + "loc": { + "line": 5, + "column": 0 + }, + "pos": 38 + } +] \ No newline at end of file diff --git a/test/validator/samples/empty-block-prod/input.html b/test/validator/samples/empty-block-prod/input.html index 53e2ca8333..32b892d470 100644 --- a/test/validator/samples/empty-block-prod/input.html +++ b/test/validator/samples/empty-block-prod/input.html @@ -1,3 +1,5 @@ {{#each things as thing}} -{{/each}} \ No newline at end of file +{{/each}} + +{{#each things as thing}}{{/each}} \ No newline at end of file