Skip to content

Commit 8cffccc

Browse files
committed
Get back to full test coverage.
See #272 for a discussion on our tests in GH.
1 parent c0994a1 commit 8cffccc

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

test/test-template-engine.js

+9
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ describe('html rendering', () => {
6161
assert(container.childNodes[0].textContent === 'This is HTML: "&ldquo;<div></div>&rdquo;"');
6262
});
6363

64+
it('renders void tags', () => {
65+
const container = document.createElement('div');
66+
render(container, html`<input><br><input>`);
67+
assert(container.childNodes.length === 3);
68+
assert(container.childNodes[0].localName === 'input');
69+
assert(container.childNodes[1].localName === 'br');
70+
assert(container.childNodes[2].localName === 'input');
71+
});
72+
6473
it('renders template elements', () => {
6574
// It’s important that the _content_ is populated here. Not the template.
6675
const container = document.createElement('div');

ts/x-parser.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export class XParser {
5555
static "__#1@#validateExit"(tagName: any): void;
5656
static "__#1@#sendInnerTextTokens"(onToken: any, string: any, index: any, start: any, end: any, plaintextType: any, referenceType: any): void;
5757
static "__#1@#validateTagName"(tagName: any): void;
58+
static "__#1@#validateNoDeclarativeShadowRoots"(tagName: any, attributeName: any): void;
5859
static "__#1@#sendBoundTextTokens"(onToken: any, stringsIndex: any, string: any, stringIndex: any, sloppyStartInterpolation: any): void;
5960
static "__#1@#sendBoundContentTokens"(onToken: any, stringsIndex: any, string: any, stringIndex: any): void;
6061
static "__#1@#sendTextTokens"(onToken: any, stringsIndex: any, string: any, stringIndex: any, nextStringIndex: any): void;

ts/x-parser.d.ts.map

+1-1
Original file line numberDiff line numberDiff line change

x-parser.js

+12-14
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,16 @@ export class XParser {
641641
}
642642
}
643643

644+
// This validates a specific case where we need to reject “template” elements
645+
// which have “declarative shadow roots” via a “shadowrootmode” attribute.
646+
static #validateNoDeclarativeShadowRoots(tagName, attributeName) {
647+
if (tagName === 'template' && attributeName === 'shadowrootmode') {
648+
const errorMessagesKey = XParser.#namedErrorsToErrorMessagesKey.get('declarative-shadow-root');
649+
const errorMessage = XParser.#errorMessages.get(errorMessagesKey);
650+
throw new Error(`[${errorMessagesKey}] ${errorMessage}`);
651+
}
652+
}
653+
644654
// This can only happen with a “textarea” element, currently. Note that the
645655
// subscriber is notified about this as a “text” binding not a “content”
646656
// binding so that it correctly bind _any_ interpolated value to the
@@ -715,13 +725,7 @@ export class XParser {
715725
static #sendBooleanTokens(onToken, tagName, stringsIndex, string, stringIndex, nextStringIndex) {
716726
// A boolean attribute in a start tag — “data-has-flag”
717727
const attributeName = string.slice(stringIndex, nextStringIndex);
718-
if (tagName === 'template') {
719-
if (attributeName === 'shadowrootmode') {
720-
const errorMessagesKey = XParser.#namedErrorsToErrorMessagesKey.get('declarative-shadow-root');
721-
const errorMessage = XParser.#errorMessages.get(errorMessagesKey);
722-
throw new Error(`[${errorMessagesKey}] ${errorMessage}`);
723-
}
724-
}
728+
XParser.#validateNoDeclarativeShadowRoots(tagName, attributeName);
725729
onToken(XParser.tokenTypes.booleanName, stringsIndex, stringIndex, nextStringIndex, attributeName);
726730
}
727731

@@ -731,13 +735,7 @@ export class XParser {
731735
// An attribute in a start tag — “data-foo="bar"”
732736
const equalsStart = string.indexOf('=', stringIndex);
733737
const attributeName = string.slice(stringIndex, equalsStart);
734-
if (tagName === 'template') {
735-
if (attributeName === 'shadowrootmode') {
736-
const errorMessagesKey = XParser.#namedErrorsToErrorMessagesKey.get('declarative-shadow-root');
737-
const errorMessage = XParser.#errorMessages.get(errorMessagesKey);
738-
throw new Error(`[${errorMessagesKey}] ${errorMessage}`);
739-
}
740-
}
738+
XParser.#validateNoDeclarativeShadowRoots(tagName, attributeName);
741739
const equalsEnd = equalsStart + 1;
742740
const valueStart = equalsEnd + 1;
743741
const valueEnd = nextStringIndex - 1;

0 commit comments

Comments
 (0)