is_tag_valid_with_parent() — svelte Function Reference
Architecture documentation for the is_tag_valid_with_parent() function in html-tree-validation.js from the svelte codebase.
Entity Profile
Dependency Diagram
graph TD b52e7925_73b5_1187_beab_fb7eb59cc45d["is_tag_valid_with_parent()"] 302f84f3_ec7c_fd57_5b8e_e2f3ec2953b7["html-tree-validation.js"] b52e7925_73b5_1187_beab_fb7eb59cc45d -->|defined in| 302f84f3_ec7c_fd57_5b8e_e2f3ec2953b7 db90bc4d_679e_5ec7_8a25_9fc20869c6fb["ExpressionTag()"] db90bc4d_679e_5ec7_8a25_9fc20869c6fb -->|calls| b52e7925_73b5_1187_beab_fb7eb59cc45d 874d992f_5e60_ebce_f4ce_ea5fed014bc4["RegularElement()"] 874d992f_5e60_ebce_f4ce_ea5fed014bc4 -->|calls| b52e7925_73b5_1187_beab_fb7eb59cc45d e511a3c6_68c7_d02e_710d_edc19c11b9e3["Text()"] e511a3c6_68c7_d02e_710d_edc19c11b9e3 -->|calls| b52e7925_73b5_1187_beab_fb7eb59cc45d 5e189954_74f0_0aa0_89f7_83b3ae199b34["push_element()"] 5e189954_74f0_0aa0_89f7_83b3ae199b34 -->|calls| b52e7925_73b5_1187_beab_fb7eb59cc45d style b52e7925_73b5_1187_beab_fb7eb59cc45d fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/svelte/src/html-tree-validation.js lines 184–238
export function is_tag_valid_with_parent(child_tag, parent_tag, child_loc, parent_loc) {
if (child_tag.includes('-') || parent_tag?.includes('-')) return null; // custom elements can be anything
if (parent_tag === 'template') return null; // no errors or warning should be thrown in immediate children of template tags
const disallowed = disallowed_children[parent_tag];
const child = child_loc ? `\`<${child_tag}>\` (${child_loc})` : `\`<${child_tag}>\``;
const parent = parent_loc ? `\`<${parent_tag}>\` (${parent_loc})` : `\`<${parent_tag}>\``;
if (disallowed) {
if ('direct' in disallowed && disallowed.direct.includes(child_tag)) {
return `${child} cannot be a direct child of ${parent}`;
}
if ('descendant' in disallowed && disallowed.descendant.includes(child_tag)) {
return `${child} cannot be a child of ${parent}`;
}
if ('only' in disallowed && disallowed.only) {
if (disallowed.only.includes(child_tag)) {
return null;
} else {
return `${child} cannot be a child of ${parent}. \`<${parent_tag}>\` only allows these children: ${disallowed.only.map((d) => `\`<${d}>\``).join(', ')}`;
}
}
}
// These tags are only valid with a few parents that have special child
// parsing rules - if we're down here, then none of those matched and
// so we allow it only if we don't know what the parent is, as all other
// cases are invalid (and we only get into this function if we know the parent).
switch (child_tag) {
case 'body':
case 'caption':
case 'col':
case 'colgroup':
case 'frameset':
case 'frame':
case 'head':
case 'html':
return `${child} cannot be a child of ${parent}`;
case 'thead':
case 'tbody':
case 'tfoot':
return `${child} must be the child of a \`<table>\`, not a ${parent}`;
case 'td':
case 'th':
return `${child} must be the child of a \`<tr>\`, not a ${parent}`;
case 'tr':
return `\`<tr>\` must be the child of a \`<thead>\`, \`<tbody>\`, or \`<tfoot>\`, not a ${parent}`;
}
return null;
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does is_tag_valid_with_parent() do?
is_tag_valid_with_parent() is a function in the svelte codebase, defined in packages/svelte/src/html-tree-validation.js.
Where is is_tag_valid_with_parent() defined?
is_tag_valid_with_parent() is defined in packages/svelte/src/html-tree-validation.js at line 184.
What calls is_tag_valid_with_parent()?
is_tag_valid_with_parent() is called by 4 function(s): ExpressionTag, RegularElement, Text, push_element.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free