Skip to content

Commit 27b95d5

Browse files
lbrooneyMoustaphaDev
authored andcommitted
fix: allow options to contain html elements
1 parent f1689ea commit 27b95d5

7 files changed

+231
-4
lines changed

internal/parser.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2358,6 +2358,8 @@ func inSelectIM(p *parser) bool {
23582358
p.resetInsertionMode()
23592359
case a.Template:
23602360
return inHeadIM(p)
2361+
default:
2362+
return inBodyIM(p)
23612363
}
23622364
case CommentToken:
23632365
p.addChild(&Node{
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
[TestPrinter/select_with_2_options_containing_element - 1]
3+
## Input
4+
5+
```
6+
<select><option><span>Lemon</span></option><option><span>Lime</span></option></select>
7+
```
8+
9+
## Output
10+
11+
```js
12+
import {
13+
Fragment,
14+
render as $$render,
15+
createAstro as $$createAstro,
16+
createComponent as $$createComponent,
17+
renderComponent as $$renderComponent,
18+
renderHead as $$renderHead,
19+
maybeRenderHead as $$maybeRenderHead,
20+
unescapeHTML as $$unescapeHTML,
21+
renderSlot as $$renderSlot,
22+
mergeSlots as $$mergeSlots,
23+
addAttribute as $$addAttribute,
24+
spreadAttributes as $$spreadAttributes,
25+
defineStyleVars as $$defineStyleVars,
26+
defineScriptVars as $$defineScriptVars,
27+
renderTransition as $$renderTransition,
28+
createTransitionScope as $$createTransitionScope,
29+
renderScript as $$renderScript,
30+
createMetadata as $$createMetadata
31+
} from "http://localhost:3000/";
32+
33+
export const $$metadata = $$createMetadata(import.meta.url, { modules: [], hydratedComponents: [], clientOnlyComponents: [], hydrationDirectives: new Set([]), hoisted: [] });
34+
35+
const $$Component = $$createComponent(($$result, $$props, $$slots) => {
36+
37+
return $$render`${$$maybeRenderHead($$result)}<select><option><span>Lemon</span></option><option><span>Lime</span></option></select>`;
38+
}, undefined, undefined);
39+
export default $$Component;
40+
```
41+
---
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
[TestPrinter/select_with_2_options_containing_element_with_div_sibling - 1]
3+
## Input
4+
5+
```
6+
<select><option><span>Lemon</span></option><option><span>Lime</span></option></select><div>Orange</div>
7+
```
8+
9+
## Output
10+
11+
```js
12+
import {
13+
Fragment,
14+
render as $$render,
15+
createAstro as $$createAstro,
16+
createComponent as $$createComponent,
17+
renderComponent as $$renderComponent,
18+
renderHead as $$renderHead,
19+
maybeRenderHead as $$maybeRenderHead,
20+
unescapeHTML as $$unescapeHTML,
21+
renderSlot as $$renderSlot,
22+
mergeSlots as $$mergeSlots,
23+
addAttribute as $$addAttribute,
24+
spreadAttributes as $$spreadAttributes,
25+
defineStyleVars as $$defineStyleVars,
26+
defineScriptVars as $$defineScriptVars,
27+
renderTransition as $$renderTransition,
28+
createTransitionScope as $$createTransitionScope,
29+
renderScript as $$renderScript,
30+
createMetadata as $$createMetadata
31+
} from "http://localhost:3000/";
32+
33+
export const $$metadata = $$createMetadata(import.meta.url, { modules: [], hydratedComponents: [], clientOnlyComponents: [], hydrationDirectives: new Set([]), hoisted: [] });
34+
35+
const $$Component = $$createComponent(($$result, $$props, $$slots) => {
36+
37+
return $$render`${$$maybeRenderHead($$result)}<select><option><span>Lemon</span></option><option><span>Lime</span></option></select><div>Orange</div>`;
38+
}, undefined, undefined);
39+
export default $$Component;
40+
```
41+
---
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
[TestPrinter/select_with_option_containing_element - 1]
3+
## Input
4+
5+
```
6+
<select><option><span>Lemon</span></option></select>
7+
```
8+
9+
## Output
10+
11+
```js
12+
import {
13+
Fragment,
14+
render as $$render,
15+
createAstro as $$createAstro,
16+
createComponent as $$createComponent,
17+
renderComponent as $$renderComponent,
18+
renderHead as $$renderHead,
19+
maybeRenderHead as $$maybeRenderHead,
20+
unescapeHTML as $$unescapeHTML,
21+
renderSlot as $$renderSlot,
22+
mergeSlots as $$mergeSlots,
23+
addAttribute as $$addAttribute,
24+
spreadAttributes as $$spreadAttributes,
25+
defineStyleVars as $$defineStyleVars,
26+
defineScriptVars as $$defineScriptVars,
27+
renderTransition as $$renderTransition,
28+
createTransitionScope as $$createTransitionScope,
29+
renderScript as $$renderScript,
30+
createMetadata as $$createMetadata
31+
} from "http://localhost:3000/";
32+
33+
export const $$metadata = $$createMetadata(import.meta.url, { modules: [], hydratedComponents: [], clientOnlyComponents: [], hydrationDirectives: new Set([]), hoisted: [] });
34+
35+
const $$Component = $$createComponent(($$result, $$props, $$slots) => {
36+
37+
return $$render`${$$maybeRenderHead($$result)}<select><option><span>Lemon</span></option></select>`;
38+
}, undefined, undefined);
39+
export default $$Component;
40+
```
41+
---
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
[TestPrinter/select_with_option_containing_element_and_button_containing_selected_content - 1]
3+
## Input
4+
5+
```
6+
<select><button><selectedcontent></selectedcontent></button><option><span>Lemon</span></option></select>
7+
```
8+
9+
## Output
10+
11+
```js
12+
import {
13+
Fragment,
14+
render as $$render,
15+
createAstro as $$createAstro,
16+
createComponent as $$createComponent,
17+
renderComponent as $$renderComponent,
18+
renderHead as $$renderHead,
19+
maybeRenderHead as $$maybeRenderHead,
20+
unescapeHTML as $$unescapeHTML,
21+
renderSlot as $$renderSlot,
22+
mergeSlots as $$mergeSlots,
23+
addAttribute as $$addAttribute,
24+
spreadAttributes as $$spreadAttributes,
25+
defineStyleVars as $$defineStyleVars,
26+
defineScriptVars as $$defineScriptVars,
27+
renderTransition as $$renderTransition,
28+
createTransitionScope as $$createTransitionScope,
29+
renderScript as $$renderScript,
30+
createMetadata as $$createMetadata
31+
} from "http://localhost:3000/";
32+
33+
export const $$metadata = $$createMetadata(import.meta.url, { modules: [], hydratedComponents: [], clientOnlyComponents: [], hydrationDirectives: new Set([]), hoisted: [] });
34+
35+
const $$Component = $$createComponent(($$result, $$props, $$slots) => {
36+
37+
return $$render`${$$maybeRenderHead($$result)}<select><button><selectedcontent></selectedcontent></button><option><span>Lemon</span></option></select>`;
38+
}, undefined, undefined);
39+
export default $$Component;
40+
```
41+
---
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
[TestPrinter/select_with_option_containing_element_with_div_sibling - 1]
3+
## Input
4+
5+
```
6+
<select><option><span>Lemon</span></option></select><div>Orange</div>
7+
```
8+
9+
## Output
10+
11+
```js
12+
import {
13+
Fragment,
14+
render as $$render,
15+
createAstro as $$createAstro,
16+
createComponent as $$createComponent,
17+
renderComponent as $$renderComponent,
18+
renderHead as $$renderHead,
19+
maybeRenderHead as $$maybeRenderHead,
20+
unescapeHTML as $$unescapeHTML,
21+
renderSlot as $$renderSlot,
22+
mergeSlots as $$mergeSlots,
23+
addAttribute as $$addAttribute,
24+
spreadAttributes as $$spreadAttributes,
25+
defineStyleVars as $$defineStyleVars,
26+
defineScriptVars as $$defineScriptVars,
27+
renderTransition as $$renderTransition,
28+
createTransitionScope as $$createTransitionScope,
29+
renderScript as $$renderScript,
30+
createMetadata as $$createMetadata
31+
} from "http://localhost:3000/";
32+
33+
export const $$metadata = $$createMetadata(import.meta.url, { modules: [], hydratedComponents: [], clientOnlyComponents: [], hydrationDirectives: new Set([]), hoisted: [] });
34+
35+
const $$Component = $$createComponent(($$result, $$props, $$slots) => {
36+
37+
return $$render`${$$maybeRenderHead($$result)}<select><option><span>Lemon</span></option></select><div>Orange</div>`;
38+
}, undefined, undefined);
39+
export default $$Component;
40+
```
41+
---

internal/printer/printer_test.go

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,19 +1554,19 @@ import { Container, Col, Row } from 'react-bootstrap';
15541554
source: `<body><Component><Fragment slot=named><div>Default</div><div>Named</div></Fragment></Component></body>`,
15551555
},
15561556
{
1557-
name: "Fragment with await",
1557+
name: "Fragment with await",
15581558
source: `<body><Fragment> { await Promise.resolve("Awaited") } </Fragment></body>`,
15591559
},
15601560
{
1561-
name: "Fragment shorthand with await",
1561+
name: "Fragment shorthand with await",
15621562
source: `<body><> { await Promise.resolve("Awaited") } </></body>`,
15631563
},
15641564
{
1565-
name: "Fragment wrapping link with awaited href",
1565+
name: "Fragment wrapping link with awaited href",
15661566
source: `<head><Fragment><link rel="preload" href={(await import('../fonts/some-font.woff2')).default} as="font" crossorigin /></Fragment></head>`,
15671567
},
15681568
{
1569-
name: "Component with await",
1569+
name: "Component with await",
15701570
source: `<body><Component> { await Promise.resolve("Awaited") } </Component></body>`,
15711571
},
15721572
{
@@ -2573,6 +2573,26 @@ const meta = { title: 'My App' };
25732573
name: "namespace is preserved when inside an expression",
25742574
source: `<svg>{<image />}</svg>`,
25752575
},
2576+
{
2577+
name: "select with option containing element",
2578+
source: `<select><option><span>Lemon</span></option></select>`,
2579+
},
2580+
{
2581+
name: "select with 2 options containing element",
2582+
source: `<select><option><span>Lemon</span></option><option><span>Lime</span></option></select>`,
2583+
},
2584+
{
2585+
name: "select with option containing element with div sibling",
2586+
source: `<select><option><span>Lemon</span></option></select><div>Orange</div>`,
2587+
},
2588+
{
2589+
name: "select with 2 options containing element with div sibling",
2590+
source: `<select><option><span>Lemon</span></option><option><span>Lime</span></option></select><div>Orange</div>`,
2591+
},
2592+
{
2593+
name: "select with option containing element and button containing selected content",
2594+
source: `<select><button><selectedcontent></selectedcontent></button><option><span>Lemon</span></option></select>`,
2595+
},
25762596
}
25772597
for _, tt := range tests {
25782598
if tt.only {

0 commit comments

Comments
 (0)