Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions test/test-template-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ describe('html rendering', () => {
assert(container.childNodes[0].textContent === 'This is HTML: "&ldquo;<div></div>&rdquo;"');
});

it('renders void tags', () => {
const container = document.createElement('div');
render(container, html`<input><br><input>`);
assert(container.childNodes.length === 3);
assert(container.childNodes[0].localName === 'input');
assert(container.childNodes[1].localName === 'br');
assert(container.childNodes[2].localName === 'input');
});

it('renders template elements', () => {
// It’s important that the _content_ is populated here. Not the template.
const container = document.createElement('div');
Expand Down
1 change: 1 addition & 0 deletions ts/x-parser.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export class XParser {
static "__#1@#validateExit"(tagName: any): void;
static "__#1@#sendInnerTextTokens"(onToken: any, string: any, index: any, start: any, end: any, plaintextType: any, referenceType: any): void;
static "__#1@#validateTagName"(tagName: any): void;
static "__#1@#validateNoDeclarativeShadowRoots"(tagName: any, attributeName: any): void;
static "__#1@#sendBoundTextTokens"(onToken: any, stringsIndex: any, string: any, stringIndex: any, sloppyStartInterpolation: any): void;
static "__#1@#sendBoundContentTokens"(onToken: any, stringsIndex: any, string: any, stringIndex: any): void;
static "__#1@#sendTextTokens"(onToken: any, stringsIndex: any, string: any, stringIndex: any, nextStringIndex: any): void;
Expand Down
2 changes: 1 addition & 1 deletion ts/x-parser.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 12 additions & 14 deletions x-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,16 @@ export class XParser {
}
}

// This validates a specific case where we need to reject “template” elements
// which have “declarative shadow roots” via a “shadowrootmode” attribute.
static #validateNoDeclarativeShadowRoots(tagName, attributeName) {
if (tagName === 'template' && attributeName === 'shadowrootmode') {
const errorMessagesKey = XParser.#namedErrorsToErrorMessagesKey.get('declarative-shadow-root');
const errorMessage = XParser.#errorMessages.get(errorMessagesKey);
throw new Error(`[${errorMessagesKey}] ${errorMessage}`);
}
}

// This can only happen with a “textarea” element, currently. Note that the
// subscriber is notified about this as a “text” binding not a “content”
// binding so that it correctly bind _any_ interpolated value to the
Expand Down Expand Up @@ -715,13 +725,7 @@ export class XParser {
static #sendBooleanTokens(onToken, tagName, stringsIndex, string, stringIndex, nextStringIndex) {
// A boolean attribute in a start tag — “data-has-flag”
const attributeName = string.slice(stringIndex, nextStringIndex);
if (tagName === 'template') {
if (attributeName === 'shadowrootmode') {
const errorMessagesKey = XParser.#namedErrorsToErrorMessagesKey.get('declarative-shadow-root');
const errorMessage = XParser.#errorMessages.get(errorMessagesKey);
throw new Error(`[${errorMessagesKey}] ${errorMessage}`);
}
}
XParser.#validateNoDeclarativeShadowRoots(tagName, attributeName);
onToken(XParser.tokenTypes.booleanName, stringsIndex, stringIndex, nextStringIndex, attributeName);
}

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