From c6ddf1c1dc76e09bb86da9c7523d26dd25599233 Mon Sep 17 00:00:00 2001 From: Yuichiro Yamashita Date: Sun, 1 May 2022 03:37:09 +0900 Subject: [PATCH] [fix] rendering void tag for `` (#7453) --- site/content/docs/02-template-syntax.md | 2 ++ src/compiler/compile/nodes/Element.ts | 2 +- .../render_dom/wrappers/Element/index.ts | 4 ++- .../compile/render_ssr/handlers/Element.ts | 36 +++++++++++++++---- src/compiler/parse/state/tag.ts | 2 +- src/compiler/utils/names.ts | 6 ---- src/runtime/internal/dev.ts | 10 +++++- src/runtime/internal/ssr.ts | 7 ++-- .../shared/boolean_attributes.ts | 0 src/shared/utils/names.ts | 5 +++ .../dynamic-element-void-tag/_config.js | 12 +++++++ .../dynamic-element-void-tag/main.svelte | 12 +++++++ .../_config.js | 9 +++++ .../main.svelte | 5 +++ .../_config.js | 9 +++++ .../main.svelte | 5 +++ .../Nested.svelte | 1 + .../_config.js | 9 +++++ .../main.svelte | 6 ++++ .../Nested.svelte | 1 + .../_config.js | 6 ++++ .../main.svelte | 6 ++++ 22 files changed, 135 insertions(+), 20 deletions(-) rename src/{compiler/compile/render_ssr/handlers => }/shared/boolean_attributes.ts (100%) create mode 100644 src/shared/utils/names.ts create mode 100644 test/runtime/samples/dynamic-element-void-tag/_config.js create mode 100644 test/runtime/samples/dynamic-element-void-tag/main.svelte create mode 100644 test/runtime/samples/dynamic-element-void-with-content-1/_config.js create mode 100644 test/runtime/samples/dynamic-element-void-with-content-1/main.svelte create mode 100644 test/runtime/samples/dynamic-element-void-with-content-2/_config.js create mode 100644 test/runtime/samples/dynamic-element-void-with-content-2/main.svelte create mode 100644 test/runtime/samples/dynamic-element-void-with-content-3/Nested.svelte create mode 100644 test/runtime/samples/dynamic-element-void-with-content-3/_config.js create mode 100644 test/runtime/samples/dynamic-element-void-with-content-3/main.svelte create mode 100644 test/runtime/samples/dynamic-element-void-with-content-4/Nested.svelte create mode 100644 test/runtime/samples/dynamic-element-void-with-content-4/_config.js create mode 100644 test/runtime/samples/dynamic-element-void-with-content-4/main.svelte diff --git a/site/content/docs/02-template-syntax.md b/site/content/docs/02-template-syntax.md index 456ea26418..a17314f27f 100644 --- a/site/content/docs/02-template-syntax.md +++ b/site/content/docs/02-template-syntax.md @@ -1641,6 +1641,8 @@ The only supported binding is `bind:this`, since the element type specific bindi If `this` has a nullish value, the element and its children will not be rendered. +If `this` is the name of a void tag (e.g., `br`) and `` has child elements, a runtime error will be thrown in development mode. + ```sv + +

+ + + + + diff --git a/test/runtime/samples/dynamic-element-void-with-content-1/_config.js b/test/runtime/samples/dynamic-element-void-with-content-1/_config.js new file mode 100644 index 0000000000..4016725e21 --- /dev/null +++ b/test/runtime/samples/dynamic-element-void-with-content-1/_config.js @@ -0,0 +1,9 @@ +export default { + compileOptions: { + dev: true + }, + props: { + tag: 'br' + }, + error: ' is self-closing and cannot have content.' +}; diff --git a/test/runtime/samples/dynamic-element-void-with-content-1/main.svelte b/test/runtime/samples/dynamic-element-void-with-content-1/main.svelte new file mode 100644 index 0000000000..bcf3fed2c3 --- /dev/null +++ b/test/runtime/samples/dynamic-element-void-with-content-1/main.svelte @@ -0,0 +1,5 @@ + + +foo diff --git a/test/runtime/samples/dynamic-element-void-with-content-2/_config.js b/test/runtime/samples/dynamic-element-void-with-content-2/_config.js new file mode 100644 index 0000000000..4016725e21 --- /dev/null +++ b/test/runtime/samples/dynamic-element-void-with-content-2/_config.js @@ -0,0 +1,9 @@ +export default { + compileOptions: { + dev: true + }, + props: { + tag: 'br' + }, + error: ' is self-closing and cannot have content.' +}; diff --git a/test/runtime/samples/dynamic-element-void-with-content-2/main.svelte b/test/runtime/samples/dynamic-element-void-with-content-2/main.svelte new file mode 100644 index 0000000000..0225654545 --- /dev/null +++ b/test/runtime/samples/dynamic-element-void-with-content-2/main.svelte @@ -0,0 +1,5 @@ + + +
bar
diff --git a/test/runtime/samples/dynamic-element-void-with-content-3/Nested.svelte b/test/runtime/samples/dynamic-element-void-with-content-3/Nested.svelte new file mode 100644 index 0000000000..e62294a135 --- /dev/null +++ b/test/runtime/samples/dynamic-element-void-with-content-3/Nested.svelte @@ -0,0 +1 @@ +
This is nested
diff --git a/test/runtime/samples/dynamic-element-void-with-content-3/_config.js b/test/runtime/samples/dynamic-element-void-with-content-3/_config.js new file mode 100644 index 0000000000..4016725e21 --- /dev/null +++ b/test/runtime/samples/dynamic-element-void-with-content-3/_config.js @@ -0,0 +1,9 @@ +export default { + compileOptions: { + dev: true + }, + props: { + tag: 'br' + }, + error: ' is self-closing and cannot have content.' +}; diff --git a/test/runtime/samples/dynamic-element-void-with-content-3/main.svelte b/test/runtime/samples/dynamic-element-void-with-content-3/main.svelte new file mode 100644 index 0000000000..97045e1766 --- /dev/null +++ b/test/runtime/samples/dynamic-element-void-with-content-3/main.svelte @@ -0,0 +1,6 @@ + + + diff --git a/test/runtime/samples/dynamic-element-void-with-content-4/Nested.svelte b/test/runtime/samples/dynamic-element-void-with-content-4/Nested.svelte new file mode 100644 index 0000000000..e62294a135 --- /dev/null +++ b/test/runtime/samples/dynamic-element-void-with-content-4/Nested.svelte @@ -0,0 +1 @@ +
This is nested
diff --git a/test/runtime/samples/dynamic-element-void-with-content-4/_config.js b/test/runtime/samples/dynamic-element-void-with-content-4/_config.js new file mode 100644 index 0000000000..4b2a279aaa --- /dev/null +++ b/test/runtime/samples/dynamic-element-void-with-content-4/_config.js @@ -0,0 +1,6 @@ +export default { + props: { + tag: 'br' + }, + html: '
' +}; diff --git a/test/runtime/samples/dynamic-element-void-with-content-4/main.svelte b/test/runtime/samples/dynamic-element-void-with-content-4/main.svelte new file mode 100644 index 0000000000..97045e1766 --- /dev/null +++ b/test/runtime/samples/dynamic-element-void-with-content-4/main.svelte @@ -0,0 +1,6 @@ + + +