Skip to content

Commit b7f9c9c

Browse files
committed
always add raw property to text nodes
1 parent f089642 commit b7f9c9c

File tree

57 files changed

+150
-229
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+150
-229
lines changed

src/parse/state/tag.ts

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -476,35 +476,28 @@ function read_sequence(parser: Parser, done: () => boolean): Node[] {
476476
start: parser.index,
477477
end: null,
478478
type: 'Text',
479-
data: '',
479+
raw: '',
480+
data: null
480481
};
481482

483+
function flush() {
484+
if (current_chunk.raw) {
485+
current_chunk.data = decode_character_references(current_chunk.raw);
486+
current_chunk.end = parser.index;
487+
chunks.push(current_chunk);
488+
}
489+
}
490+
482491
const chunks: Node[] = [];
483492

484493
while (parser.index < parser.template.length) {
485494
const index = parser.index;
486495

487496
if (done()) {
488-
current_chunk.end = parser.index;
489-
490-
if (current_chunk.data) chunks.push(current_chunk);
491-
492-
chunks.forEach(chunk => {
493-
if (chunk.type === 'Text') {
494-
let decoded = decode_character_references(chunk.data);
495-
if (chunk.data != decoded) {
496-
chunk.raw = chunk.data;
497-
chunk.data = decoded;
498-
}
499-
}
500-
});
501-
497+
flush();
502498
return chunks;
503499
} else if (parser.eat('{')) {
504-
if (current_chunk.data) {
505-
current_chunk.end = index;
506-
chunks.push(current_chunk);
507-
}
500+
flush();
508501

509502
parser.allow_whitespace();
510503
const expression = read_expression(parser);
@@ -522,10 +515,11 @@ function read_sequence(parser: Parser, done: () => boolean): Node[] {
522515
start: parser.index,
523516
end: null,
524517
type: 'Text',
525-
data: '',
518+
raw: '',
519+
data: null
526520
};
527521
} else {
528-
current_chunk.data += parser.template[parser.index++];
522+
current_chunk.raw += parser.template[parser.index++];
529523
}
530524
}
531525

src/parse/state/text.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@ export default function text(parser: Parser) {
1818
start,
1919
end: parser.index,
2020
type: 'Text',
21+
raw: data,
2122
data: decode_character_references(data),
2223
};
2324

24-
if (node.data != data)
25-
node.raw = data;
26-
2725
parser.current().children.push(node);
2826
}

test/parser/samples/action-with-call/output.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,5 @@
4141
"children": []
4242
}
4343
]
44-
},
45-
"css": null,
46-
"instance": null,
47-
"module": null
44+
}
4845
}

test/parser/samples/action-with-identifier/output.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,5 @@
2727
"children": []
2828
}
2929
]
30-
},
31-
"css": null,
32-
"instance": null,
33-
"module": null
30+
}
3431
}

test/parser/samples/action-with-literal/output.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,5 @@
2828
"children": []
2929
}
3030
]
31-
},
32-
"css": null,
33-
"instance": null,
34-
"module": null
31+
}
3532
}

test/parser/samples/action/output.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,5 @@
2222
"children": []
2323
}
2424
]
25-
},
26-
"css": null,
27-
"instance": null,
28-
"module": null
25+
}
2926
}

test/parser/samples/animation/output.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"start": 51,
3636
"end": 56,
3737
"type": "Text",
38+
"raw": "flips",
3839
"data": "flips"
3940
}
4041
]
@@ -54,8 +55,5 @@
5455
}
5556
}
5657
]
57-
},
58-
"css": null,
59-
"instance": null,
60-
"module": null
58+
}
6159
}

test/parser/samples/attribute-containing-solidus/output.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"start": 8,
2121
"end": 30,
2222
"type": "Text",
23+
"raw": "https://www.google.com",
2324
"data": "https://www.google.com"
2425
}
2526
]
@@ -30,13 +31,11 @@
3031
"start": 31,
3132
"end": 37,
3233
"type": "Text",
34+
"raw": "Google",
3335
"data": "Google"
3436
}
3537
]
3638
}
3739
]
38-
},
39-
"css": null,
40-
"instance": null,
41-
"module": null
40+
}
4241
}

test/parser/samples/attribute-dynamic-boolean/output.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,5 @@
3333
"children": []
3434
}
3535
]
36-
},
37-
"css": null,
38-
"instance": null,
39-
"module": null
36+
}
4037
}

test/parser/samples/attribute-dynamic-reserved/output.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,5 @@
3333
"children": []
3434
}
3535
]
36-
},
37-
"css": null,
38-
"instance": null,
39-
"module": null
36+
}
4037
}

test/parser/samples/attribute-dynamic/output.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
"value": [
1919
{
2020
"start": 12,
21-
"end": 19,
21+
"end": 20,
2222
"type": "Text",
23+
"raw": "color: ",
2324
"data": "color: "
2425
},
2526
{
@@ -37,6 +38,7 @@
3738
"start": 26,
3839
"end": 27,
3940
"type": "Text",
41+
"raw": ";",
4042
"data": ";"
4143
}
4244
]
@@ -57,8 +59,5 @@
5759
]
5860
}
5961
]
60-
},
61-
"css": null,
62-
"instance": null,
63-
"module": null
62+
}
6463
}

test/parser/samples/attribute-escaped/output.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,14 @@
2020
"start": 15,
2121
"end": 33,
2222
"type": "Text",
23-
"data": "\"quoted\"",
24-
"raw": "&quot;quoted&quot;"
23+
"raw": "&quot;quoted&quot;",
24+
"data": "\"quoted\""
2525
}
2626
]
2727
}
2828
],
2929
"children": []
3030
}
3131
]
32-
},
33-
"css": null,
34-
"instance": null,
35-
"module": null
32+
}
3633
}

test/parser/samples/attribute-multiple/output.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"start": 9,
2121
"end": 10,
2222
"type": "Text",
23+
"raw": "x",
2324
"data": "x"
2425
}
2526
]
@@ -34,6 +35,7 @@
3435
"start": 19,
3536
"end": 20,
3637
"type": "Text",
38+
"raw": "y",
3739
"data": "y"
3840
}
3941
]
@@ -42,8 +44,5 @@
4244
"children": []
4345
}
4446
]
45-
},
46-
"css": null,
47-
"instance": null,
48-
"module": null
47+
}
4948
}

test/parser/samples/attribute-shorthand/output.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,5 @@
3333
"children": []
3434
}
3535
]
36-
},
37-
"css": null,
38-
"instance": null,
39-
"module": null
36+
}
4037
}

test/parser/samples/attribute-static-boolean/output.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,5 @@
2121
"children": []
2222
}
2323
]
24-
},
25-
"css": null,
26-
"instance": null,
27-
"module": null
24+
}
2825
}

test/parser/samples/attribute-static/output.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"start": 12,
2121
"end": 15,
2222
"type": "Text",
23+
"raw": "foo",
2324
"data": "foo"
2425
}
2526
]
@@ -28,8 +29,5 @@
2829
"children": []
2930
}
3031
]
31-
},
32-
"css": null,
33-
"instance": null,
34-
"module": null
32+
}
3533
}

test/parser/samples/attribute-unquoted/output.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"start": 11,
2121
"end": 14,
2222
"type": "Text",
23+
"raw": "foo",
2324
"data": "foo"
2425
}
2526
]
@@ -28,8 +29,5 @@
2829
"children": []
2930
}
3031
]
31-
},
32-
"css": null,
33-
"instance": null,
34-
"module": null
32+
}
3533
}

0 commit comments

Comments
 (0)