Skip to content

Commit d8fe76f

Browse files
committed
fix for empty text and add quote tests
1 parent 2ab32e3 commit d8fe76f

File tree

4 files changed

+52
-20
lines changed

4 files changed

+52
-20
lines changed

src/parser/converts/element.ts

+3
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ export function* convertChildren(
7878
continue;
7979
}
8080
if (child.type === "Text") {
81+
if (!child.data && child.start === child.end) {
82+
continue;
83+
}
8184
yield convertText(child, parent, ctx);
8285
continue;
8386
}

tests/fixtures/parser/ast/script-tag-output.json

+1-20
Original file line numberDiff line numberDiff line change
@@ -250,26 +250,7 @@
250250
}
251251
}
252252
},
253-
"children": [
254-
{
255-
"type": "SvelteText",
256-
"value": "",
257-
"range": [
258-
70,
259-
70
260-
],
261-
"loc": {
262-
"start": {
263-
"line": 2,
264-
"column": 63
265-
},
266-
"end": {
267-
"line": 2,
268-
"column": 63
269-
}
270-
}
271-
}
272-
],
253+
"children": [],
273254
"endTag": {
274255
"type": "SvelteEndTag",
275256
"range": [

tests/src/parser/__snapshots__/html.ts.snap

+42
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,45 @@ Object {
185185
"index": 10,
186186
}
187187
`;
188+
189+
exports[`parseAttributes quote="'" 1`] = `
190+
Object {
191+
"attributes": Array [
192+
Object {
193+
"key": Object {
194+
"end": 5,
195+
"name": "quote",
196+
"start": 0,
197+
},
198+
"value": Object {
199+
"end": 9,
200+
"quote": "\\"",
201+
"start": 6,
202+
"value": "'",
203+
},
204+
},
205+
],
206+
"index": 11,
207+
}
208+
`;
209+
210+
exports[`parseAttributes quote='"' 1`] = `
211+
Object {
212+
"attributes": Array [
213+
Object {
214+
"key": Object {
215+
"end": 5,
216+
"name": "quote",
217+
"start": 0,
218+
},
219+
"value": Object {
220+
"end": 9,
221+
"quote": "'",
222+
"start": 6,
223+
"value": "\\"",
224+
},
225+
},
226+
],
227+
"index": 11,
228+
}
229+
`;

tests/src/parser/html.ts

+6
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ describe("parseAttributes", () => {
3939
{
4040
input: `empty='' `,
4141
},
42+
{
43+
input: `quote="'" `,
44+
},
45+
{
46+
input: `quote='"' `,
47+
},
4248
];
4349
for (const { input, index } of testCases) {
4450
it(input, () => {

0 commit comments

Comments
 (0)