From d7ab08ef3c3107dd98b41326f458a6513867518b Mon Sep 17 00:00:00 2001 From: Tim van der Lippe Date: Tue, 25 May 2021 12:38:47 +0100 Subject: [PATCH] Add test for nested template literals Initially I thought this package wouldn't work for nested template literals (which ChromeDevTools used). I wanted to do TDD and add the test first (since there was no test for it yet) and I discovered this use case is already covered. That's because the `template.tag` for MemberExpressions already includes the whole line, and thus it matches on `lihtml.html`, which indeed includes `html`. So let's add the test to make sure this use case remains covers, but no actual code changes are required :tada: --- test/minifyHTMLLiterals.spec.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/minifyHTMLLiterals.spec.ts b/test/minifyHTMLLiterals.spec.ts index 48eab94..3453302 100644 --- a/test/minifyHTMLLiterals.spec.ts +++ b/test/minifyHTMLLiterals.spec.ts @@ -214,6 +214,21 @@ describe('minifyHTMLLiterals()', () => { } `; + const NESTED_TEMPLATE_SOURCE = ` + function nested() { + return LitHtml.html\`
+ Some content here +
+ \`; + } + `; + + const NESTED_TEMPLATE_SOURCE_MIN = ` + function nested() { + return LitHtml.html\`
Some content here
\`; + } + `; + it('should minify "html" and "css" tagged templates', () => { const result = minifyHTMLLiterals(SOURCE, { fileName: 'test.js' }); expect(result).to.be.an('object'); @@ -232,6 +247,14 @@ describe('minifyHTMLLiterals()', () => { expect(result!.code).to.equal(COMMENT_SOURCE_MIN); }); + it('should minify html tagged with a member expression ending in html', () => { + const result = minifyHTMLLiterals(NESTED_TEMPLATE_SOURCE, { + fileName: 'test.js' + }); + expect(result).to.be.an('object'); + expect(result!.code).to.equal(NESTED_TEMPLATE_SOURCE_MIN); + }); + it('should minify multiline svg elements', () => { const result = minifyHTMLLiterals(SVG_MULTILINE_SOURCE, { fileName: 'test.js'