Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/html-self-closing-raw-text.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@solidjs/html": patch
---

Fix the tokenizer staying in raw text mode after a self-closing raw text element such as `<textarea />`, which swallowed the rest of the template as text.
1 change: 1 addition & 0 deletions packages/html/src/tokenize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export const tokenize = (
// ">"
if (
rawTextElements.has(lastTagName) &&
tokens[tokens.length - 1]?.type !== SLASH_TOKEN &&
tokens[tokens.length - 2]?.type !== SLASH_TOKEN
) {
state = STATE_RAW_TEXT;
Expand Down
16 changes: 16 additions & 0 deletions packages/html/test/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,22 @@ describe("Specialized Element AST", () => {
});
});

it("raw text elements: self-closing textarea inside an element", () => {
const ast = jsx`<div><textarea /></div>`;

expect(ast).toEqual({
type: ROOT_NODE,
children: [
{
type: ELEMENT_NODE,
name: "div",
props: [],
children: [{ type: ELEMENT_NODE, name: "textarea", props: [], children: [] }]
}
]
});
});

it("comments: braced comment ignored", () => {
const ast = jsx`<div>{/* a comment */}hello</div>`;

Expand Down
17 changes: 17 additions & 0 deletions packages/html/test/tokenize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,23 @@ describe("handling of raw text elements", () => {
{ type: TEXT_TOKEN, value: "Text" }
]);
});

it("should exit raw text mode after a self-closing raw text element", () => {
const tokens = tokenizeTemplate`<div><textarea /></div>`;
expect(tokens).toEqual([
{ type: OPEN_TAG_TOKEN },
{ type: IDENTIFIER_TOKEN, value: "div" },
{ type: CLOSE_TAG_TOKEN },
{ type: OPEN_TAG_TOKEN },
{ type: IDENTIFIER_TOKEN, value: "textarea" },
{ type: SLASH_TOKEN },
{ type: CLOSE_TAG_TOKEN },
{ type: OPEN_TAG_TOKEN },
{ type: SLASH_TOKEN },
{ type: IDENTIFIER_TOKEN, value: "div" },
{ type: CLOSE_TAG_TOKEN }
]);
});
});

describe("dynamic component tags", () => {
Expand Down
Loading