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
}

0 commit comments

Comments
 (0)