Skip to content

Commit f089642

Browse files
committed
Merge branch 'raw-entities' of https://github.com/RedHatter/svelte into RedHatter-raw-entities
2 parents 0d7f6fb + ef59c32 commit f089642

File tree

6 files changed

+22
-8
lines changed

6 files changed

+22
-8
lines changed

src/parse/state/tag.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,13 @@ function read_sequence(parser: Parser, done: () => boolean): Node[] {
490490
if (current_chunk.data) chunks.push(current_chunk);
491491

492492
chunks.forEach(chunk => {
493-
if (chunk.type === 'Text')
494-
chunk.data = decode_character_references(chunk.data);
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+
}
495500
});
496501

497502
return chunks;

src/parse/state/text.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,15 @@ export default function text(parser: Parser) {
1414
data += parser.template[parser.index++];
1515
}
1616

17-
parser.current().children.push({
17+
let node = {
1818
start,
1919
end: parser.index,
2020
type: 'Text',
2121
data: decode_character_references(data),
22-
});
22+
};
23+
24+
if (node.data != data)
25+
node.raw = data;
26+
27+
parser.current().children.push(node);
2328
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"start": 15,
2121
"end": 33,
2222
"type": "Text",
23-
"data": "\"quoted\""
23+
"data": "\"quoted\"",
24+
"raw": ""quoted""
2425
}
2526
]
2627
}

test/parser/samples/convert-entities-in-element/output.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"start": 3,
1616
"end": 20,
1717
"type": "Text",
18-
"data": "Hello & World"
18+
"data": "Hello & World",
19+
"raw": "Hello & World"
1920
}
2021
]
2122
}

test/parser/samples/convert-entities/output.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"start": 0,
99
"end": 17,
1010
"type": "Text",
11-
"data": "Hello & World"
11+
"data": "Hello & World",
12+
"raw": "Hello & World"
1213
}
1314
]
1415
},

test/parser/samples/nbsp/output.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"start": 6,
1616
"end": 12,
1717
"type": "Text",
18-
"data": " "
18+
"data": " ",
19+
"raw": " "
1920
}
2021
]
2122
}

0 commit comments

Comments
 (0)