Skip to content

Commit 0bf5694

Browse files
committed
html: disallow content for imaginary-sibling
That means it's a throw, instead of silently dropping the content, when you pass it through html.metatag('imaginary-sibling').
1 parent d2eeb0c commit 0bf5694

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/util/html.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ export function metatag(identifier, ...args) {
329329
return new Tag(null, {[chunkwrap]: true, ...opts}, content);
330330

331331
case 'imaginary-sibling':
332-
return new Tag(null, {[imaginarySibling]: true});
332+
return new Tag(null, {[imaginarySibling]: true}, content);
333333

334334
default:
335335
throw new Error(`Unknown metatag "${identifier}"`);
@@ -413,6 +413,10 @@ export class Tag {
413413
throw new Error(`Tag <${this.tagName}> is self-closing but got content`);
414414
}
415415

416+
if (this.imaginarySibling && contentful) {
417+
throw new Error(`html.metatag('imaginary-sibling') can't have content`);
418+
}
419+
416420
const contentArray =
417421
(Array.isArray(value)
418422
? value.flat(Infinity).filter(Boolean)
@@ -572,6 +576,12 @@ export class Tag {
572576

573577
set imaginarySibling(value) {
574578
this.#setAttributeFlag(imaginarySibling, value);
579+
580+
try {
581+
this.content = this.content;
582+
} catch (error) {
583+
this.#setAttributeFlag(imaginarySibling, false);
584+
}
575585
}
576586

577587
get imaginarySibling() {

0 commit comments

Comments
 (0)