From 7c54d2daffd3c4a337e2de04c93aac87bcc4d93e Mon Sep 17 00:00:00 2001
From: "alexander.akait"
Date: Fri, 18 Nov 2022 04:30:43 +0300
Subject: [PATCH 1/5] ast: cdata
---
crates/swc_xml_ast/src/base.rs | 10 ++++++++++
crates/swc_xml_visit/src/lib.rs | 7 +++++++
2 files changed, 17 insertions(+)
diff --git a/crates/swc_xml_ast/src/base.rs b/crates/swc_xml_ast/src/base.rs
index 8bf054ad426d..f9edc7a83608 100644
--- a/crates/swc_xml_ast/src/base.rs
+++ b/crates/swc_xml_ast/src/base.rs
@@ -29,6 +29,8 @@ pub enum Child {
Element(Element),
#[tag("Text")]
Text(Text),
+ #[tag("CDATASection")]
+ CDATASection(CDATASection),
#[tag("Comment")]
Comment(Comment),
#[tag("ProcessingInstruction")]
@@ -90,6 +92,14 @@ pub struct Text {
pub raw: Option,
}
+#[ast_node("CDATASection")]
+#[derive(Eq, Hash, EqIgnoreSpan)]
+pub struct CDATASection {
+ pub span: Span,
+ pub data: JsWord,
+ pub raw: Option,
+}
+
#[ast_node("ProcessingInstruction")]
#[derive(Eq, Hash, EqIgnoreSpan)]
pub struct ProcessingInstruction {
diff --git a/crates/swc_xml_visit/src/lib.rs b/crates/swc_xml_visit/src/lib.rs
index 3519770cf8e9..3bd470839ea7 100644
--- a/crates/swc_xml_visit/src/lib.rs
+++ b/crates/swc_xml_visit/src/lib.rs
@@ -26,6 +26,7 @@ define!({
DocumentType(DocumentType),
Element(Element),
Text(Text),
+ CDATASection(CDATASection),
Comment(Comment),
ProcessingInstruction(ProcessingInstruction),
}
@@ -70,6 +71,12 @@ define!({
pub raw: Option,
}
+ pub struct CDATASection {
+ pub span: Span,
+ pub data: JsWord,
+ pub raw: Option,
+ }
+
pub struct ProcessingInstruction {
pub span: Span,
pub target: JsWord,
From 36cfb2ae758d89d4c52babe0ebcfa5fe765c6459 Mon Sep 17 00:00:00 2001
From: "alexander.akait"
Date: Mon, 28 Nov 2022 20:25:41 +0300
Subject: [PATCH 2/5] test: more
---
.../tests/fixture/cdata/dom.rust-debug | 42 +++
.../tests/fixture/cdata/input.xml | 12 +
.../tests/fixture/cdata/output.json | 330 +++++++++++++++++-
3 files changed, 379 insertions(+), 5 deletions(-)
diff --git a/crates/swc_xml_parser/tests/fixture/cdata/dom.rust-debug b/crates/swc_xml_parser/tests/fixture/cdata/dom.rust-debug
index 3ee42cec6b4a..fefd34b574a9 100644
--- a/crates/swc_xml_parser/tests/fixture/cdata/dom.rust-debug
+++ b/crates/swc_xml_parser/tests/fixture/cdata/dom.rust-debug
@@ -21,4 +21,46 @@
"
| "
+ "
+|
+| "Hello, world!"
+| "
+ "
+|
+| "content"
+| "
+ "
+|
+| "&ing"
+| "
+ "
+|
+| "&ing ]"
+| "
+ "
+|
+| "&ing]] "
+| "
+ "
+|
+| "text"
+| "
+ "
+|
+| ""
+| "
+ "
+|
+| "12"
+| "
+ "
+|
+| "
+ data "
+| "
+ "
+|
+| "bracket ]aafter"
+| "
+
"
diff --git a/crates/swc_xml_parser/tests/fixture/cdata/input.xml b/crates/swc_xml_parser/tests/fixture/cdata/input.xml
index d2fa2ce9f3ea..7535a16c7950 100644
--- a/crates/swc_xml_parser/tests/fixture/cdata/input.xml
+++ b/crates/swc_xml_parser/tests/fixture/cdata/input.xml
@@ -10,4 +10,16 @@
but my document is still well formed!
]]>
+
Hello, world!]]>
+
+
+
+
+ text]]>
+ ]]>
+
+
+
+
+
\ No newline at end of file
diff --git a/crates/swc_xml_parser/tests/fixture/cdata/output.json b/crates/swc_xml_parser/tests/fixture/cdata/output.json
index a8141533403e..84279148ae7d 100644
--- a/crates/swc_xml_parser/tests/fixture/cdata/output.json
+++ b/crates/swc_xml_parser/tests/fixture/cdata/output.json
@@ -2,7 +2,7 @@
"type": "Document",
"span": {
"start": 1,
- "end": 434,
+ "end": 859,
"ctxt": 0
},
"children": [
@@ -10,7 +10,7 @@
"type": "Element",
"span": {
"start": 1,
- "end": 434,
+ "end": 859,
"ctxt": 0
},
"tagName": "root",
@@ -124,11 +124,331 @@
"type": "Text",
"span": {
"start": 426,
- "end": 427,
+ "end": 431,
"ctxt": 0
},
- "data": "\n",
- "raw": "\n"
+ "data": "\n ",
+ "raw": "\n "
+ },
+ {
+ "type": "Element",
+ "span": {
+ "start": 431,
+ "end": 484,
+ "ctxt": 0
+ },
+ "tagName": "p",
+ "attributes": [],
+ "children": [
+ {
+ "type": "Text",
+ "span": {
+ "start": 434,
+ "end": 477,
+ "ctxt": 0
+ },
+ "data": "Hello, world!",
+ "raw": "Hello, world!"
+ }
+ ]
+ },
+ {
+ "type": "Text",
+ "span": {
+ "start": 484,
+ "end": 489,
+ "ctxt": 0
+ },
+ "data": "\n ",
+ "raw": "\n "
+ },
+ {
+ "type": "Element",
+ "span": {
+ "start": 489,
+ "end": 515,
+ "ctxt": 0
+ },
+ "tagName": "p",
+ "attributes": [],
+ "children": [
+ {
+ "type": "Text",
+ "span": {
+ "start": 492,
+ "end": 508,
+ "ctxt": 0
+ },
+ "data": "content",
+ "raw": "content"
+ }
+ ]
+ },
+ {
+ "type": "Text",
+ "span": {
+ "start": 515,
+ "end": 520,
+ "ctxt": 0
+ },
+ "data": "\n ",
+ "raw": "\n "
+ },
+ {
+ "type": "Element",
+ "span": {
+ "start": 520,
+ "end": 546,
+ "ctxt": 0
+ },
+ "tagName": "p",
+ "attributes": [],
+ "children": [
+ {
+ "type": "Text",
+ "span": {
+ "start": 523,
+ "end": 539,
+ "ctxt": 0
+ },
+ "data": "&ing",
+ "raw": "&ing"
+ }
+ ]
+ },
+ {
+ "type": "Text",
+ "span": {
+ "start": 546,
+ "end": 551,
+ "ctxt": 0
+ },
+ "data": "\n ",
+ "raw": "\n "
+ },
+ {
+ "type": "Element",
+ "span": {
+ "start": 551,
+ "end": 579,
+ "ctxt": 0
+ },
+ "tagName": "p",
+ "attributes": [],
+ "children": [
+ {
+ "type": "Text",
+ "span": {
+ "start": 554,
+ "end": 574,
+ "ctxt": 0
+ },
+ "data": "&ing ]",
+ "raw": "&ing ]"
+ }
+ ]
+ },
+ {
+ "type": "Text",
+ "span": {
+ "start": 579,
+ "end": 584,
+ "ctxt": 0
+ },
+ "data": "\n ",
+ "raw": "\n "
+ },
+ {
+ "type": "Element",
+ "span": {
+ "start": 584,
+ "end": 613,
+ "ctxt": 0
+ },
+ "tagName": "p",
+ "attributes": [],
+ "children": [
+ {
+ "type": "Text",
+ "span": {
+ "start": 587,
+ "end": 606,
+ "ctxt": 0
+ },
+ "data": "&ing]] ",
+ "raw": "&ing]] "
+ }
+ ]
+ },
+ {
+ "type": "Text",
+ "span": {
+ "start": 613,
+ "end": 618,
+ "ctxt": 0
+ },
+ "data": "\n ",
+ "raw": "\n "
+ },
+ {
+ "type": "Element",
+ "span": {
+ "start": 618,
+ "end": 660,
+ "ctxt": 0
+ },
+ "tagName": "p",
+ "attributes": [],
+ "children": [
+ {
+ "type": "Text",
+ "span": {
+ "start": 621,
+ "end": 653,
+ "ctxt": 0
+ },
+ "data": "text",
+ "raw": "text"
+ }
+ ]
+ },
+ {
+ "type": "Text",
+ "span": {
+ "start": 660,
+ "end": 665,
+ "ctxt": 0
+ },
+ "data": "\n ",
+ "raw": "\n "
+ },
+ {
+ "type": "Element",
+ "span": {
+ "start": 665,
+ "end": 735,
+ "ctxt": 0
+ },
+ "tagName": "p",
+ "attributes": [],
+ "children": [
+ {
+ "type": "Text",
+ "span": {
+ "start": 668,
+ "end": 728,
+ "ctxt": 0
+ },
+ "data": "",
+ "raw": ""
+ }
+ ]
+ },
+ {
+ "type": "Text",
+ "span": {
+ "start": 735,
+ "end": 740,
+ "ctxt": 0
+ },
+ "data": "\n ",
+ "raw": "\n "
+ },
+ {
+ "type": "Element",
+ "span": {
+ "start": 740,
+ "end": 773,
+ "ctxt": 0
+ },
+ "tagName": "p",
+ "attributes": [],
+ "children": [
+ {
+ "type": "Text",
+ "span": {
+ "start": 743,
+ "end": 766,
+ "ctxt": 0
+ },
+ "data": "12",
+ "raw": "12"
+ }
+ ]
+ },
+ {
+ "type": "Text",
+ "span": {
+ "start": 773,
+ "end": 778,
+ "ctxt": 0
+ },
+ "data": "\n ",
+ "raw": "\n "
+ },
+ {
+ "type": "Element",
+ "span": {
+ "start": 778,
+ "end": 812,
+ "ctxt": 0
+ },
+ "tagName": "p",
+ "attributes": [],
+ "children": [
+ {
+ "type": "Text",
+ "span": {
+ "start": 781,
+ "end": 808,
+ "ctxt": 0
+ },
+ "data": "\n data ",
+ "raw": "\n data "
+ }
+ ]
+ },
+ {
+ "type": "Text",
+ "span": {
+ "start": 812,
+ "end": 817,
+ "ctxt": 0
+ },
+ "data": "\n ",
+ "raw": "\n "
+ },
+ {
+ "type": "Element",
+ "span": {
+ "start": 817,
+ "end": 850,
+ "ctxt": 0
+ },
+ "tagName": "p",
+ "attributes": [],
+ "children": [
+ {
+ "type": "Text",
+ "span": {
+ "start": 820,
+ "end": 843,
+ "ctxt": 0
+ },
+ "data": "bracket ]aafter",
+ "raw": "bracket ]aafter"
+ }
+ ]
+ },
+ {
+ "type": "Text",
+ "span": {
+ "start": 850,
+ "end": 852,
+ "ctxt": 0
+ },
+ "data": "\n\n",
+ "raw": "\n\n"
}
]
}
From edbae157415d2e0f42c0f67b2363725e00152504 Mon Sep 17 00:00:00 2001
From: "alexander.akait"
Date: Mon, 28 Nov 2022 20:34:07 +0300
Subject: [PATCH 3/5] fix: bug in parsing
---
crates/swc_xml_ast/src/token.rs | 4 ++++
crates/swc_xml_parser/src/lexer/mod.rs | 2 +-
crates/swc_xml_parser/tests/fixture/cdata/dom.rust-debug | 2 +-
crates/swc_xml_parser/tests/fixture/cdata/output.json | 4 ++--
4 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/crates/swc_xml_ast/src/token.rs b/crates/swc_xml_ast/src/token.rs
index d3849968fb25..ba7b548bb020 100644
--- a/crates/swc_xml_ast/src/token.rs
+++ b/crates/swc_xml_ast/src/token.rs
@@ -60,5 +60,9 @@ pub enum Token {
target: JsWord,
data: JsWord,
},
+ CData {
+ data: JsWord,
+ raw: JsWord,
+ },
Eof,
}
diff --git a/crates/swc_xml_parser/src/lexer/mod.rs b/crates/swc_xml_parser/src/lexer/mod.rs
index 815867299ee6..eb087e545116 100644
--- a/crates/swc_xml_parser/src/lexer/mod.rs
+++ b/crates/swc_xml_parser/src/lexer/mod.rs
@@ -1762,7 +1762,7 @@ where
Some(c) => {
self.emit_character_token((']', ']'));
self.emit_character_token((c, c));
- self.reconsume_in_state(State::Cdata);
+ self.state = State::Cdata;
}
}
}
diff --git a/crates/swc_xml_parser/tests/fixture/cdata/dom.rust-debug b/crates/swc_xml_parser/tests/fixture/cdata/dom.rust-debug
index fefd34b574a9..e40c724c410a 100644
--- a/crates/swc_xml_parser/tests/fixture/cdata/dom.rust-debug
+++ b/crates/swc_xml_parser/tests/fixture/cdata/dom.rust-debug
@@ -60,7 +60,7 @@
| "
"
|
-| "bracket ]aafter"
+| "bracket ]after"
| "
"
diff --git a/crates/swc_xml_parser/tests/fixture/cdata/output.json b/crates/swc_xml_parser/tests/fixture/cdata/output.json
index 84279148ae7d..82c4490c4e24 100644
--- a/crates/swc_xml_parser/tests/fixture/cdata/output.json
+++ b/crates/swc_xml_parser/tests/fixture/cdata/output.json
@@ -435,8 +435,8 @@
"end": 843,
"ctxt": 0
},
- "data": "bracket ]aafter",
- "raw": "bracket ]aafter"
+ "data": "bracket ]after",
+ "raw": "bracket ]after"
}
]
},
From 26a701fa83ed9ba440cb64e7b21b3f6eec87d5b1 Mon Sep 17 00:00:00 2001
From: "alexander.akait"
Date: Mon, 28 Nov 2022 21:19:52 +0300
Subject: [PATCH 4/5] feat(xml/parser): CDataSection parsing
---
crates/swc_xml_ast/src/base.rs | 8 +-
crates/swc_xml_ast/src/token.rs | 2 +-
crates/swc_xml_codegen/src/lib.rs | 12 ++
.../tests/fixture/cdata_section/input.xml | 25 +++
.../fixture/cdata_section/output.min.xml | 25 +++
.../tests/fixture/cdata_section/output.xml | 25 +++
crates/swc_xml_parser/src/lexer/mod.rs | 79 ++++++---
crates/swc_xml_parser/src/parser/mod.rs | 45 +++++
crates/swc_xml_parser/src/parser/node.rs | 4 +
.../{cdata => cdata_section}/dom.rust-debug | 23 +--
.../{cdata => cdata_section}/input.xml | 4 +-
.../{cdata => cdata_section}/output.json | 156 +++++++++++++-----
.../{cdata => cdata_section}/span.rust-debug | 0
.../tests/recovery/cdata-after/dom.rust-debug | 7 +
.../tests/recovery/cdata-after/input.xml | 4 +
.../tests/recovery/cdata-after/output.json | 74 +++++++++
.../tests/recovery/cdata-after/output.stderr | 6 +
.../recovery/cdata-after/span.rust-debug | 78 +++++++++
.../recovery/cdata-before/dom.rust-debug | 7 +
.../tests/recovery/cdata-before/input.xml | 4 +
.../tests/recovery/cdata-before/output.json | 74 +++++++++
.../tests/recovery/cdata-before/output.stderr | 6 +
.../recovery/cdata-before/span.rust-debug | 78 +++++++++
crates/swc_xml_visit/src/lib.rs | 4 +-
24 files changed, 667 insertions(+), 83 deletions(-)
create mode 100644 crates/swc_xml_codegen/tests/fixture/cdata_section/input.xml
create mode 100644 crates/swc_xml_codegen/tests/fixture/cdata_section/output.min.xml
create mode 100644 crates/swc_xml_codegen/tests/fixture/cdata_section/output.xml
rename crates/swc_xml_parser/tests/fixture/{cdata => cdata_section}/dom.rust-debug (58%)
rename crates/swc_xml_parser/tests/fixture/{cdata => cdata_section}/input.xml (96%)
rename crates/swc_xml_parser/tests/fixture/{cdata => cdata_section}/output.json (72%)
rename crates/swc_xml_parser/tests/fixture/{cdata => cdata_section}/span.rust-debug (100%)
create mode 100644 crates/swc_xml_parser/tests/recovery/cdata-after/dom.rust-debug
create mode 100644 crates/swc_xml_parser/tests/recovery/cdata-after/input.xml
create mode 100644 crates/swc_xml_parser/tests/recovery/cdata-after/output.json
create mode 100644 crates/swc_xml_parser/tests/recovery/cdata-after/output.stderr
create mode 100644 crates/swc_xml_parser/tests/recovery/cdata-after/span.rust-debug
create mode 100644 crates/swc_xml_parser/tests/recovery/cdata-before/dom.rust-debug
create mode 100644 crates/swc_xml_parser/tests/recovery/cdata-before/input.xml
create mode 100644 crates/swc_xml_parser/tests/recovery/cdata-before/output.json
create mode 100644 crates/swc_xml_parser/tests/recovery/cdata-before/output.stderr
create mode 100644 crates/swc_xml_parser/tests/recovery/cdata-before/span.rust-debug
diff --git a/crates/swc_xml_ast/src/base.rs b/crates/swc_xml_ast/src/base.rs
index f9edc7a83608..ef01cac5777d 100644
--- a/crates/swc_xml_ast/src/base.rs
+++ b/crates/swc_xml_ast/src/base.rs
@@ -29,8 +29,8 @@ pub enum Child {
Element(Element),
#[tag("Text")]
Text(Text),
- #[tag("CDATASection")]
- CDATASection(CDATASection),
+ #[tag("CdataSection")]
+ CdataSection(CdataSection),
#[tag("Comment")]
Comment(Comment),
#[tag("ProcessingInstruction")]
@@ -92,9 +92,9 @@ pub struct Text {
pub raw: Option,
}
-#[ast_node("CDATASection")]
+#[ast_node("CdataSection")]
#[derive(Eq, Hash, EqIgnoreSpan)]
-pub struct CDATASection {
+pub struct CdataSection {
pub span: Span,
pub data: JsWord,
pub raw: Option,
diff --git a/crates/swc_xml_ast/src/token.rs b/crates/swc_xml_ast/src/token.rs
index ba7b548bb020..a7e61f60b7c0 100644
--- a/crates/swc_xml_ast/src/token.rs
+++ b/crates/swc_xml_ast/src/token.rs
@@ -60,7 +60,7 @@ pub enum Token {
target: JsWord,
data: JsWord,
},
- CData {
+ Cdata {
data: JsWord,
raw: JsWord,
},
diff --git a/crates/swc_xml_codegen/src/lib.rs b/crates/swc_xml_codegen/src/lib.rs
index 197bf1bde28a..391ccf275599 100644
--- a/crates/swc_xml_codegen/src/lib.rs
+++ b/crates/swc_xml_codegen/src/lib.rs
@@ -62,6 +62,7 @@ where
Child::Text(n) => emit!(self, n),
Child::Comment(n) => emit!(self, n),
Child::ProcessingInstruction(n) => emit!(self, n),
+ Child::CdataSection(n) => emit!(self, n),
}
}
@@ -287,6 +288,17 @@ where
write_multiline_raw!(self, n.span, &processing_instruction);
}
+ #[emitter]
+ fn emit_cdata_section(&mut self, n: &CdataSection) -> Result {
+ let mut cdata_section = String::with_capacity(n.data.len() + 12);
+
+ cdata_section.push_str("");
+
+ write_multiline_raw!(self, n.span, &cdata_section);
+ }
+
fn create_context_for_element(&self, n: &Element) -> Ctx {
let need_escape_text = match &*n.tag_name {
"noscript" => !self.config.scripting_enabled,
diff --git a/crates/swc_xml_codegen/tests/fixture/cdata_section/input.xml b/crates/swc_xml_codegen/tests/fixture/cdata_section/input.xml
new file mode 100644
index 000000000000..dc3a1779b945
--- /dev/null
+++ b/crates/swc_xml_codegen/tests/fixture/cdata_section/input.xml
@@ -0,0 +1,25 @@
+
+ An example of escaped CENDs
+
+
+
+
+
+ Hello, world!]]>
+
+
+
+
+ text]]>
+ ]]>
+
+
+
+
+
+
diff --git a/crates/swc_xml_codegen/tests/fixture/cdata_section/output.min.xml b/crates/swc_xml_codegen/tests/fixture/cdata_section/output.min.xml
new file mode 100644
index 000000000000..561ec0fcaba3
--- /dev/null
+++ b/crates/swc_xml_codegen/tests/fixture/cdata_section/output.min.xml
@@ -0,0 +1,25 @@
+
+ An example of escaped CENDs
+
+
+
+
+
+ Hello, world!]]>
+
+
+
+
+ text]]>
+ ]]>
+
+
+
+
+
+
\ No newline at end of file
diff --git a/crates/swc_xml_codegen/tests/fixture/cdata_section/output.xml b/crates/swc_xml_codegen/tests/fixture/cdata_section/output.xml
new file mode 100644
index 000000000000..561ec0fcaba3
--- /dev/null
+++ b/crates/swc_xml_codegen/tests/fixture/cdata_section/output.xml
@@ -0,0 +1,25 @@
+
+ An example of escaped CENDs
+
+
+
+
+
+ Hello, world!]]>
+
+
+
+
+ text]]>
+ ]]>
+
+
+
+
+
+
\ No newline at end of file
diff --git a/crates/swc_xml_parser/src/lexer/mod.rs b/crates/swc_xml_parser/src/lexer/mod.rs
index eb087e545116..3512c557ce98 100644
--- a/crates/swc_xml_parser/src/lexer/mod.rs
+++ b/crates/swc_xml_parser/src/lexer/mod.rs
@@ -111,6 +111,12 @@ struct ProcessingInstruction {
data: String,
}
+#[derive(PartialEq, Eq, Clone, Debug)]
+struct Cdata {
+ data: String,
+ raw: String,
+}
+
pub(crate) type LexResult = Result;
pub struct Lexer
@@ -128,11 +134,11 @@ where
additional_allowed_character: Option,
pending_tokens: VecDeque,
doctype_raw: Option,
- cdata_raw: Option,
current_doctype_token: Option,
current_comment_token: Option,
current_processing_instruction: Option,
current_tag_token: Option,
+ current_cdata_token: Option,
attribute_start_position: Option,
}
@@ -155,11 +161,11 @@ where
additional_allowed_character: None,
pending_tokens: VecDeque::new(),
doctype_raw: None,
- cdata_raw: None,
current_doctype_token: None,
current_comment_token: None,
current_processing_instruction: None,
current_tag_token: None,
+ current_cdata_token: None,
attribute_start_position: None,
};
@@ -864,6 +870,34 @@ where
});
}
+ fn create_cdata_token(&mut self) {
+ let data = String::new();
+ let raw = String::with_capacity(12);
+
+ self.current_cdata_token = Some(Cdata { data, raw });
+ }
+
+ fn append_to_cdata_token(&mut self, c: Option, raw_c: Option) {
+ if let Some(Cdata { data, raw }) = &mut self.current_cdata_token {
+ if let Some(c) = c {
+ data.push(c);
+ }
+
+ if let Some(raw_c) = raw_c {
+ raw.push(raw_c);
+ }
+ }
+ }
+
+ fn emit_cdata_token(&mut self) {
+ let cdata = self.current_cdata_token.take().unwrap();
+
+ self.emit_token(Token::Cdata {
+ data: cdata.data.into(),
+ raw: cdata.raw.into(),
+ });
+ }
+
fn handle_raw_and_emit_character_token(&mut self, c: char) {
let is_cr = c == '\r';
@@ -1400,17 +1434,16 @@ where
Some(t @ 'T') => match self.consume_next_char() {
Some(a2 @ 'A') => match self.consume_next_char() {
Some('[') => {
- let mut data = String::with_capacity(7);
-
- data.push('[');
- data.push(c);
- data.push(d);
- data.push(a1);
- data.push(t);
- data.push(a2);
- data.push('[');
-
- self.cdata_raw = Some(data);
+ self.create_cdata_token();
+ self.append_to_cdata_token(None, Some('<'));
+ self.append_to_cdata_token(None, Some('!'));
+ self.append_to_cdata_token(None, Some('['));
+ self.append_to_cdata_token(None, Some(c));
+ self.append_to_cdata_token(None, Some(d));
+ self.append_to_cdata_token(None, Some(a1));
+ self.append_to_cdata_token(None, Some(t));
+ self.append_to_cdata_token(None, Some(a2));
+ self.append_to_cdata_token(None, Some('['));
self.state = State::Cdata;
}
_ => {
@@ -1734,11 +1767,11 @@ where
self.reconsume_in_state(State::Data);
}
// Anything else
- // Emit the current input character as character token. Stay in the current
+ // Append the current input character to the cdata dta. Stay in the current
// state.
Some(c) => {
self.validate_input_stream_character(c);
- self.handle_raw_and_emit_character_token(c);
+ self.append_to_cdata_token(Some(c), Some(c));
}
}
}
@@ -1760,8 +1793,8 @@ where
// Emit a U+005D RIGHT SQUARE BRACKET character token. Reconsume in the
// CDATA section state.
Some(c) => {
- self.emit_character_token((']', ']'));
- self.emit_character_token((c, c));
+ self.append_to_cdata_token(Some(']'), Some(']'));
+ self.append_to_cdata_token(Some(c), Some(c));
self.state = State::Cdata;
}
}
@@ -1772,13 +1805,17 @@ where
// U+003E GREATER-THAN SIGN (>)
// Switch to the data state.
Some('>') => {
+ self.append_to_cdata_token(None, Some(']'));
+ self.append_to_cdata_token(None, Some(']'));
+ self.append_to_cdata_token(None, Some('>'));
+ self.emit_cdata_token();
self.state = State::Data;
}
// U+005D RIGHT SQUARE BRACKET (])
// Emit the current input character as character token. Stay in the current
// state.
Some(c @ ']') => {
- self.emit_character_token((c, c));
+ self.append_to_cdata_token(Some(c), Some(c));
}
// EOF
// Parse error. Reconsume the current input character in the data state.
@@ -1791,9 +1828,9 @@ where
// also emit the current input character as character token. Switch to the CDATA
// state.
Some(c) => {
- self.emit_character_token((']', ']'));
- self.emit_character_token((']', ']'));
- self.emit_character_token((c, c));
+ self.append_to_cdata_token(Some(']'), Some(']'));
+ self.append_to_cdata_token(Some(']'), Some(']'));
+ self.append_to_cdata_token(Some(c), Some(c));
self.state = State::Cdata;
}
}
diff --git a/crates/swc_xml_parser/src/parser/mod.rs b/crates/swc_xml_parser/src/parser/mod.rs
index 1021840e419c..bb76cf5c2fb3 100644
--- a/crates/swc_xml_parser/src/parser/mod.rs
+++ b/crates/swc_xml_parser/src/parser/mod.rs
@@ -188,6 +188,11 @@ where
data,
})
}
+ Data::CdataSection { data, raw } => Child::CdataSection(CdataSection {
+ span: start_span,
+ data,
+ raw,
+ }),
_ => {
unreachable!();
}
@@ -267,6 +272,14 @@ where
Token::ProcessingInstruction { .. } => {
self.append_processing_instruction_to_doc(token_and_info)?;
}
+ Token::Cdata { .. } => {
+ self.errors.push(Error::new(
+ token_and_info.span,
+ ErrorKind::UnexpectedTokenInStartPhase,
+ ));
+
+ self.append_cdata_to_doc(token_and_info)?;
+ }
Token::Character { value, .. } => {
if !is_whitespace(*value) {
self.errors.push(Error::new(
@@ -354,6 +367,11 @@ where
self.append_node(self.get_current_element(), processing_instruction);
}
+ Token::Cdata { .. } => {
+ let cdata = self.create_cdata_section(token_and_info);
+
+ self.append_node(self.get_current_element(), cdata);
+ }
Token::Eof => {
self.errors.push(Error::new(
token_and_info.span,
@@ -376,6 +394,14 @@ where
Token::ProcessingInstruction { .. } => {
self.append_processing_instruction_to_doc(token_and_info)?;
}
+ Token::Cdata { .. } => {
+ self.errors.push(Error::new(
+ token_and_info.span,
+ ErrorKind::UnexpectedTokenInEndPhase,
+ ));
+
+ self.append_cdata_to_doc(token_and_info)?;
+ }
Token::Character { value, .. } => {
if !is_whitespace(*value) {
self.errors.push(Error::new(
@@ -603,6 +629,25 @@ where
Ok(())
}
+ fn create_cdata_section(&self, token_and_info: &mut TokenAndInfo) -> RcNode {
+ let (data, raw) = match &token_and_info.token {
+ Token::Cdata { data, raw } => (data.clone(), Some(raw.clone())),
+ _ => {
+ unreachable!()
+ }
+ };
+
+ Node::new(Data::CdataSection { data, raw }, token_and_info.span)
+ }
+
+ fn append_cdata_to_doc(&mut self, token_and_info: &mut TokenAndInfo) -> PResult<()> {
+ let child = self.create_cdata_section(token_and_info);
+
+ self.append_node(self.document.as_ref().unwrap(), child);
+
+ Ok(())
+ }
+
fn update_end_tag_span(&self, node: Option<&RcNode>, span: Span) {
if let Some(node) = node {
if node.start_span.borrow().is_dummy() {
diff --git a/crates/swc_xml_parser/src/parser/node.rs b/crates/swc_xml_parser/src/parser/node.rs
index 90042d5b44b0..559676834de1 100644
--- a/crates/swc_xml_parser/src/parser/node.rs
+++ b/crates/swc_xml_parser/src/parser/node.rs
@@ -36,6 +36,10 @@ pub enum Data {
target: JsWord,
data: JsWord,
},
+ CdataSection {
+ data: JsWord,
+ raw: Option,
+ },
Comment {
data: JsWord,
raw: Option,
diff --git a/crates/swc_xml_parser/tests/fixture/cdata/dom.rust-debug b/crates/swc_xml_parser/tests/fixture/cdata_section/dom.rust-debug
similarity index 58%
rename from crates/swc_xml_parser/tests/fixture/cdata/dom.rust-debug
rename to crates/swc_xml_parser/tests/fixture/cdata_section/dom.rust-debug
index e40c724c410a..b3932f237ef5 100644
--- a/crates/swc_xml_parser/tests/fixture/cdata/dom.rust-debug
+++ b/crates/swc_xml_parser/tests/fixture/cdata_section/dom.rust-debug
@@ -14,53 +14,44 @@
"
|
| "
-
- Since this is a CDATA section
- I can use all sorts of reserved characters
- but my document is still well formed!
-
+ "
+| "
"
| "
"
|
-| "Hello, world!"
| "
"
|
-| "content"
| "
"
|
-| "&ing"
| "
"
|
-| "&ing ]"
| "
"
|
-| "&ing]] "
| "
"
|
-| "text"
| "
"
|
-| ""
| "
"
|
-| "12"
| "
"
|
| "
- data "
+ "
+| " "
+| "
+ "
+|
| "
"
|
-| "bracket ]after"
| "
-
"
diff --git a/crates/swc_xml_parser/tests/fixture/cdata/input.xml b/crates/swc_xml_parser/tests/fixture/cdata_section/input.xml
similarity index 96%
rename from crates/swc_xml_parser/tests/fixture/cdata/input.xml
rename to crates/swc_xml_parser/tests/fixture/cdata_section/input.xml
index 7535a16c7950..0a7a04578438 100644
--- a/crates/swc_xml_parser/tests/fixture/cdata/input.xml
+++ b/crates/swc_xml_parser/tests/fixture/cdata_section/input.xml
@@ -21,5 +21,5 @@
-
-
\ No newline at end of file
+
+
diff --git a/crates/swc_xml_parser/tests/fixture/cdata/output.json b/crates/swc_xml_parser/tests/fixture/cdata_section/output.json
similarity index 72%
rename from crates/swc_xml_parser/tests/fixture/cdata/output.json
rename to crates/swc_xml_parser/tests/fixture/cdata_section/output.json
index 82c4490c4e24..d33659fa05ba 100644
--- a/crates/swc_xml_parser/tests/fixture/cdata/output.json
+++ b/crates/swc_xml_parser/tests/fixture/cdata_section/output.json
@@ -2,7 +2,7 @@
"type": "Document",
"span": {
"start": 1,
- "end": 859,
+ "end": 883,
"ctxt": 0
},
"children": [
@@ -10,7 +10,7 @@
"type": "Element",
"span": {
"start": 1,
- "end": 859,
+ "end": 882,
"ctxt": 0
},
"tagName": "root",
@@ -112,11 +112,31 @@
"type": "Text",
"span": {
"start": 258,
+ "end": 263,
+ "ctxt": 0
+ },
+ "data": "\n ",
+ "raw": "\n "
+ },
+ {
+ "type": "CdataSection",
+ "span": {
+ "start": 263,
+ "end": 403,
+ "ctxt": 0
+ },
+ "data": "\n Since this is a CDATA section\n I can use all sorts of reserved characters\n but my document is still well formed!\n ",
+ "raw": ""
+ },
+ {
+ "type": "Text",
+ "span": {
+ "start": 403,
"end": 408,
"ctxt": 0
},
- "data": "\n \n Since this is a CDATA section\n I can use all sorts of reserved characters\n but my document is still well formed!\n \n ",
- "raw": "\n \n Since this is a CDATA section\n I can use all sorts of reserved characters\n but my document is still well formed!\n \n "
+ "data": "\n ",
+ "raw": "\n "
}
]
},
@@ -141,14 +161,14 @@
"attributes": [],
"children": [
{
- "type": "Text",
+ "type": "CdataSection",
"span": {
"start": 434,
- "end": 477,
+ "end": 480,
"ctxt": 0
},
"data": "Hello, world!",
- "raw": "Hello, world!"
+ "raw": "Hello, world!]]>"
}
]
},
@@ -173,14 +193,14 @@
"attributes": [],
"children": [
{
- "type": "Text",
+ "type": "CdataSection",
"span": {
"start": 492,
- "end": 508,
+ "end": 511,
"ctxt": 0
},
"data": "content",
- "raw": "content"
+ "raw": ""
}
]
},
@@ -205,14 +225,14 @@
"attributes": [],
"children": [
{
- "type": "Text",
+ "type": "CdataSection",
"span": {
"start": 523,
- "end": 539,
+ "end": 542,
"ctxt": 0
},
"data": "&ing",
- "raw": "&ing"
+ "raw": ""
}
]
},
@@ -237,14 +257,14 @@
"attributes": [],
"children": [
{
- "type": "Text",
+ "type": "CdataSection",
"span": {
"start": 554,
- "end": 574,
+ "end": 575,
"ctxt": 0
},
"data": "&ing ]",
- "raw": "&ing ]"
+ "raw": ""
}
]
},
@@ -269,14 +289,14 @@
"attributes": [],
"children": [
{
- "type": "Text",
+ "type": "CdataSection",
"span": {
"start": 587,
- "end": 606,
+ "end": 609,
"ctxt": 0
},
"data": "&ing]] ",
- "raw": "&ing]] "
+ "raw": ""
}
]
},
@@ -301,14 +321,14 @@
"attributes": [],
"children": [
{
- "type": "Text",
+ "type": "CdataSection",
"span": {
"start": 621,
- "end": 653,
+ "end": 656,
"ctxt": 0
},
"data": "text",
- "raw": "text"
+ "raw": "text]]>"
}
]
},
@@ -333,14 +353,14 @@
"attributes": [],
"children": [
{
- "type": "Text",
+ "type": "CdataSection",
"span": {
"start": 668,
- "end": 728,
+ "end": 731,
"ctxt": 0
},
"data": "",
- "raw": ""
+ "raw": "]]>"
}
]
},
@@ -365,14 +385,24 @@
"attributes": [],
"children": [
{
- "type": "Text",
+ "type": "CdataSection",
"span": {
"start": 743,
- "end": 766,
+ "end": 756,
+ "ctxt": 0
+ },
+ "data": "1",
+ "raw": ""
+ },
+ {
+ "type": "CdataSection",
+ "span": {
+ "start": 756,
+ "end": 769,
"ctxt": 0
},
- "data": "12",
- "raw": "12"
+ "data": "2",
+ "raw": ""
}
]
},
@@ -400,11 +430,31 @@
"type": "Text",
"span": {
"start": 781,
+ "end": 790,
+ "ctxt": 0
+ },
+ "data": "\n ",
+ "raw": "\n "
+ },
+ {
+ "type": "CdataSection",
+ "span": {
+ "start": 790,
+ "end": 806,
+ "ctxt": 0
+ },
+ "data": "data",
+ "raw": ""
+ },
+ {
+ "type": "Text",
+ "span": {
+ "start": 806,
"end": 808,
"ctxt": 0
},
- "data": "\n data ",
- "raw": "\n data "
+ "data": " ",
+ "raw": " "
}
]
},
@@ -429,14 +479,14 @@
"attributes": [],
"children": [
{
- "type": "Text",
+ "type": "CdataSection",
"span": {
"start": 820,
- "end": 843,
+ "end": 846,
"ctxt": 0
},
"data": "bracket ]after",
- "raw": "bracket ]after"
+ "raw": ""
}
]
},
@@ -444,11 +494,43 @@
"type": "Text",
"span": {
"start": 850,
- "end": 852,
+ "end": 855,
+ "ctxt": 0
+ },
+ "data": "\n ",
+ "raw": "\n "
+ },
+ {
+ "type": "Element",
+ "span": {
+ "start": 855,
+ "end": 874,
+ "ctxt": 0
+ },
+ "tagName": "p",
+ "attributes": [],
+ "children": [
+ {
+ "type": "CdataSection",
+ "span": {
+ "start": 858,
+ "end": 870,
+ "ctxt": 0
+ },
+ "data": "",
+ "raw": ""
+ }
+ ]
+ },
+ {
+ "type": "Text",
+ "span": {
+ "start": 874,
+ "end": 875,
"ctxt": 0
},
- "data": "\n\n",
- "raw": "\n\n"
+ "data": "\n",
+ "raw": "\n"
}
]
}
diff --git a/crates/swc_xml_parser/tests/fixture/cdata/span.rust-debug b/crates/swc_xml_parser/tests/fixture/cdata_section/span.rust-debug
similarity index 100%
rename from crates/swc_xml_parser/tests/fixture/cdata/span.rust-debug
rename to crates/swc_xml_parser/tests/fixture/cdata_section/span.rust-debug
diff --git a/crates/swc_xml_parser/tests/recovery/cdata-after/dom.rust-debug b/crates/swc_xml_parser/tests/recovery/cdata-after/dom.rust-debug
new file mode 100644
index 000000000000..e6ddfccb940d
--- /dev/null
+++ b/crates/swc_xml_parser/tests/recovery/cdata-after/dom.rust-debug
@@ -0,0 +1,7 @@
+|
+| "
+ "
+|
+| "Test"
+| "
+"
diff --git a/crates/swc_xml_parser/tests/recovery/cdata-after/input.xml b/crates/swc_xml_parser/tests/recovery/cdata-after/input.xml
new file mode 100644
index 000000000000..931c6206cb07
--- /dev/null
+++ b/crates/swc_xml_parser/tests/recovery/cdata-after/input.xml
@@ -0,0 +1,4 @@
+
+ Test
+
+
diff --git a/crates/swc_xml_parser/tests/recovery/cdata-after/output.json b/crates/swc_xml_parser/tests/recovery/cdata-after/output.json
new file mode 100644
index 000000000000..775c81e0f649
--- /dev/null
+++ b/crates/swc_xml_parser/tests/recovery/cdata-after/output.json
@@ -0,0 +1,74 @@
+{
+ "type": "Document",
+ "span": {
+ "start": 1,
+ "end": 52,
+ "ctxt": 0
+ },
+ "children": [
+ {
+ "type": "Element",
+ "span": {
+ "start": 1,
+ "end": 31,
+ "ctxt": 0
+ },
+ "tagName": "root",
+ "attributes": [],
+ "children": [
+ {
+ "type": "Text",
+ "span": {
+ "start": 7,
+ "end": 12,
+ "ctxt": 0
+ },
+ "data": "\n ",
+ "raw": "\n "
+ },
+ {
+ "type": "Element",
+ "span": {
+ "start": 12,
+ "end": 23,
+ "ctxt": 0
+ },
+ "tagName": "p",
+ "attributes": [],
+ "children": [
+ {
+ "type": "Text",
+ "span": {
+ "start": 15,
+ "end": 19,
+ "ctxt": 0
+ },
+ "data": "Test",
+ "raw": "Test"
+ }
+ ]
+ },
+ {
+ "type": "Text",
+ "span": {
+ "start": 23,
+ "end": 24,
+ "ctxt": 0
+ },
+ "data": "\n",
+ "raw": "\n"
+ }
+ ]
+ },
+ {
+ "type": "CdataSection",
+ "span": {
+ "start": 32,
+ "end": 51,
+ "ctxt": 0
+ },
+ "data": "content",
+ "raw": ""
+ }
+ ]
+}
diff --git a/crates/swc_xml_parser/tests/recovery/cdata-after/output.stderr b/crates/swc_xml_parser/tests/recovery/cdata-after/output.stderr
new file mode 100644
index 000000000000..0133832c7a57
--- /dev/null
+++ b/crates/swc_xml_parser/tests/recovery/cdata-after/output.stderr
@@ -0,0 +1,6 @@
+
+ x Unexpected token in end phase
+ ,-[$DIR/tests/recovery/cdata-after/input.xml:4:1]
+ 4 |
+ : ^^^^^^^^^^^^^^^^^^^
+ `----
diff --git a/crates/swc_xml_parser/tests/recovery/cdata-after/span.rust-debug b/crates/swc_xml_parser/tests/recovery/cdata-after/span.rust-debug
new file mode 100644
index 000000000000..198912cffdee
--- /dev/null
+++ b/crates/swc_xml_parser/tests/recovery/cdata-after/span.rust-debug
@@ -0,0 +1,78 @@
+
+ x Document
+ ,-[$DIR/tests/recovery/cdata-after/input.xml:1:1]
+ 1 | ,->
+ 2 | | Test
+ 3 | |
+ 4 | `->
+ `----
+
+ x Child
+ ,-[$DIR/tests/recovery/cdata-after/input.xml:1:1]
+ 1 | ,->
+ 2 | | Test
+ 3 | `->
+ `----
+
+ x Element
+ ,-[$DIR/tests/recovery/cdata-after/input.xml:1:1]
+ 1 | ,->
+ 2 | | Test
+ 3 | `->
+ `----
+
+ x Child
+ ,-[$DIR/tests/recovery/cdata-after/input.xml:1:1]
+ 1 | ,->
+ 2 | `-> Test
+ `----
+
+ x Text
+ ,-[$DIR/tests/recovery/cdata-after/input.xml:1:1]
+ 1 | ,->
+ 2 | `-> Test
+ `----
+
+ x Child
+ ,-[$DIR/tests/recovery/cdata-after/input.xml:2:5]
+ 2 | Test
+ : ^^^^^^^^^^^
+ `----
+
+ x Element
+ ,-[$DIR/tests/recovery/cdata-after/input.xml:2:5]
+ 2 | Test
+ : ^^^^^^^^^^^
+ `----
+
+ x Child
+ ,-[$DIR/tests/recovery/cdata-after/input.xml:2:5]
+ 2 | Test
+ : ^^^^
+ `----
+
+ x Text
+ ,-[$DIR/tests/recovery/cdata-after/input.xml:2:5]
+ 2 | Test
+ : ^^^^
+ `----
+
+ x Child
+ ,-[$DIR/tests/recovery/cdata-after/input.xml:2:5]
+ 2 | Test
+ : ^
+ 3 |
+ `----
+
+ x Text
+ ,-[$DIR/tests/recovery/cdata-after/input.xml:2:5]
+ 2 | Test
+ : ^
+ 3 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/recovery/cdata-after/input.xml:4:1]
+ 4 |
+ : ^^^^^^^^^^^^^^^^^^^
+ `----
diff --git a/crates/swc_xml_parser/tests/recovery/cdata-before/dom.rust-debug b/crates/swc_xml_parser/tests/recovery/cdata-before/dom.rust-debug
new file mode 100644
index 000000000000..e6ddfccb940d
--- /dev/null
+++ b/crates/swc_xml_parser/tests/recovery/cdata-before/dom.rust-debug
@@ -0,0 +1,7 @@
+|
+| "
+ "
+|
+| "Test"
+| "
+"
diff --git a/crates/swc_xml_parser/tests/recovery/cdata-before/input.xml b/crates/swc_xml_parser/tests/recovery/cdata-before/input.xml
new file mode 100644
index 000000000000..ab3b003f31d8
--- /dev/null
+++ b/crates/swc_xml_parser/tests/recovery/cdata-before/input.xml
@@ -0,0 +1,4 @@
+
+
+ Test
+
diff --git a/crates/swc_xml_parser/tests/recovery/cdata-before/output.json b/crates/swc_xml_parser/tests/recovery/cdata-before/output.json
new file mode 100644
index 000000000000..c07dab0fb495
--- /dev/null
+++ b/crates/swc_xml_parser/tests/recovery/cdata-before/output.json
@@ -0,0 +1,74 @@
+{
+ "type": "Document",
+ "span": {
+ "start": 1,
+ "end": 52,
+ "ctxt": 0
+ },
+ "children": [
+ {
+ "type": "CdataSection",
+ "span": {
+ "start": 1,
+ "end": 20,
+ "ctxt": 0
+ },
+ "data": "content",
+ "raw": ""
+ },
+ {
+ "type": "Element",
+ "span": {
+ "start": 21,
+ "end": 51,
+ "ctxt": 0
+ },
+ "tagName": "root",
+ "attributes": [],
+ "children": [
+ {
+ "type": "Text",
+ "span": {
+ "start": 27,
+ "end": 32,
+ "ctxt": 0
+ },
+ "data": "\n ",
+ "raw": "\n "
+ },
+ {
+ "type": "Element",
+ "span": {
+ "start": 32,
+ "end": 43,
+ "ctxt": 0
+ },
+ "tagName": "p",
+ "attributes": [],
+ "children": [
+ {
+ "type": "Text",
+ "span": {
+ "start": 35,
+ "end": 39,
+ "ctxt": 0
+ },
+ "data": "Test",
+ "raw": "Test"
+ }
+ ]
+ },
+ {
+ "type": "Text",
+ "span": {
+ "start": 43,
+ "end": 44,
+ "ctxt": 0
+ },
+ "data": "\n",
+ "raw": "\n"
+ }
+ ]
+ }
+ ]
+}
diff --git a/crates/swc_xml_parser/tests/recovery/cdata-before/output.stderr b/crates/swc_xml_parser/tests/recovery/cdata-before/output.stderr
new file mode 100644
index 000000000000..f941fa50ea8e
--- /dev/null
+++ b/crates/swc_xml_parser/tests/recovery/cdata-before/output.stderr
@@ -0,0 +1,6 @@
+
+ x Unexpected token in start phase
+ ,-[$DIR/tests/recovery/cdata-before/input.xml:1:1]
+ 1 |
+ : ^^^^^^^^^^^^^^^^^^^
+ `----
diff --git a/crates/swc_xml_parser/tests/recovery/cdata-before/span.rust-debug b/crates/swc_xml_parser/tests/recovery/cdata-before/span.rust-debug
new file mode 100644
index 000000000000..b94da22bc9cf
--- /dev/null
+++ b/crates/swc_xml_parser/tests/recovery/cdata-before/span.rust-debug
@@ -0,0 +1,78 @@
+
+ x Document
+ ,-[$DIR/tests/recovery/cdata-before/input.xml:1:1]
+ 1 | ,->
+ 2 | |
+ 3 | | Test
+ 4 | `->
+ `----
+
+ x Child
+ ,-[$DIR/tests/recovery/cdata-before/input.xml:1:1]
+ 1 |
+ : ^^^^^^^^^^^^^^^^^^^
+ `----
+
+ x Child
+ ,-[$DIR/tests/recovery/cdata-before/input.xml:2:1]
+ 2 | ,->
+ 3 | | Test
+ 4 | `->
+ `----
+
+ x Element
+ ,-[$DIR/tests/recovery/cdata-before/input.xml:2:1]
+ 2 | ,->
+ 3 | | Test
+ 4 | `->
+ `----
+
+ x Child
+ ,-[$DIR/tests/recovery/cdata-before/input.xml:2:1]
+ 2 | ,->
+ 3 | `-> Test
+ `----
+
+ x Text
+ ,-[$DIR/tests/recovery/cdata-before/input.xml:2:1]
+ 2 | ,->
+ 3 | `-> Test
+ `----
+
+ x Child
+ ,-[$DIR/tests/recovery/cdata-before/input.xml:3:5]
+ 3 | Test
+ : ^^^^^^^^^^^
+ `----
+
+ x Element
+ ,-[$DIR/tests/recovery/cdata-before/input.xml:3:5]
+ 3 | Test
+ : ^^^^^^^^^^^
+ `----
+
+ x Child
+ ,-[$DIR/tests/recovery/cdata-before/input.xml:3:5]
+ 3 | Test
+ : ^^^^
+ `----
+
+ x Text
+ ,-[$DIR/tests/recovery/cdata-before/input.xml:3:5]
+ 3 | Test
+ : ^^^^
+ `----
+
+ x Child
+ ,-[$DIR/tests/recovery/cdata-before/input.xml:3:5]
+ 3 | Test
+ : ^
+ 4 |
+ `----
+
+ x Text
+ ,-[$DIR/tests/recovery/cdata-before/input.xml:3:5]
+ 3 | Test
+ : ^
+ 4 |
+ `----
diff --git a/crates/swc_xml_visit/src/lib.rs b/crates/swc_xml_visit/src/lib.rs
index 3bd470839ea7..d54c5bf90216 100644
--- a/crates/swc_xml_visit/src/lib.rs
+++ b/crates/swc_xml_visit/src/lib.rs
@@ -26,7 +26,7 @@ define!({
DocumentType(DocumentType),
Element(Element),
Text(Text),
- CDATASection(CDATASection),
+ CdataSection(CdataSection),
Comment(Comment),
ProcessingInstruction(ProcessingInstruction),
}
@@ -71,7 +71,7 @@ define!({
pub raw: Option,
}
- pub struct CDATASection {
+ pub struct CdataSection {
pub span: Span,
pub data: JsWord,
pub raw: Option,
From 6ce296901e877e799378500c62851627444a245c Mon Sep 17 00:00:00 2001
From: "alexander.akait"
Date: Mon, 28 Nov 2022 21:37:36 +0300
Subject: [PATCH 5/5] test: fix rebase
---
.../fixture/cdata_section/span.rust-debug | 633 ++++++++++++++++--
.../tests/recovery/cdata-after/output.stderr | 3 +-
.../recovery/cdata-after/span.rust-debug | 55 +-
.../tests/recovery/cdata-before/output.stderr | 1 +
.../recovery/cdata-before/span.rust-debug | 61 +-
5 files changed, 661 insertions(+), 92 deletions(-)
diff --git a/crates/swc_xml_parser/tests/fixture/cdata_section/span.rust-debug b/crates/swc_xml_parser/tests/fixture/cdata_section/span.rust-debug
index dc5df295fc55..183e10f1b6c9 100644
--- a/crates/swc_xml_parser/tests/fixture/cdata_section/span.rust-debug
+++ b/crates/swc_xml_parser/tests/fixture/cdata_section/span.rust-debug
@@ -1,6 +1,6 @@
x Document
- ,-[$DIR/tests/fixture/cdata/input.xml:1:1]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:1:1]
1 | ,->
2 | | An example of escaped CENDs
3 | |
@@ -13,11 +13,23 @@
10 | | but my document is still well formed!
11 | | ]]>
12 | |
- 13 | `->
+ 13 | | Hello, world!]]>
+ 14 | |
+ 15 | |
+ 16 | |
+ 17 | |
+ 18 | | text]]>
+ 19 | | ]]>
+ 20 | |
+ 21 | |
+ 22 | |
+ 23 | |
+ 24 | |
+ 25 | `->
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:1:1]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:1:1]
1 | ,->
2 | | An example of escaped CENDs
3 | |
@@ -30,11 +42,23 @@
10 | | but my document is still well formed!
11 | | ]]>
12 | |
- 13 | `->
+ 13 | | Hello, world!]]>
+ 14 | |
+ 15 | |
+ 16 | |
+ 17 | |
+ 18 | | text]]>
+ 19 | | ]]>
+ 20 | |
+ 21 | |
+ 22 | |
+ 23 | |
+ 24 | |
+ 25 | `->
`----
x Element
- ,-[$DIR/tests/fixture/cdata/input.xml:1:1]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:1:1]
1 | ,->
2 | | An example of escaped CENDs
3 | |
@@ -47,25 +71,37 @@
10 | | but my document is still well formed!
11 | | ]]>
12 | |
- 13 | `->
+ 13 | | Hello, world!]]>
+ 14 | |
+ 15 | |
+ 16 | |
+ 17 | |
+ 18 | | text]]>
+ 19 | | ]]>
+ 20 | |
+ 21 | |
+ 22 | |
+ 23 | |
+ 24 | |
+ 25 | `->
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:1:1]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:1:1]
1 | ,->
2 | `-> An example of escaped CENDs
3 |
`----
x Text
- ,-[$DIR/tests/fixture/cdata/input.xml:1:1]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:1:1]
1 | ,->
2 | `-> An example of escaped CENDs
3 |
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:1:1]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:1:1]
1 |
2 | An example of escaped CENDs
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -73,7 +109,7 @@
`----
x Element
- ,-[$DIR/tests/fixture/cdata/input.xml:1:1]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:1:1]
1 |
2 | An example of escaped CENDs
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -81,7 +117,7 @@
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:1:1]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:1:1]
1 |
2 | An example of escaped CENDs
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -89,7 +125,7 @@
`----
x Text
- ,-[$DIR/tests/fixture/cdata/input.xml:1:1]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:1:1]
1 |
2 | An example of escaped CENDs
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -97,7 +133,7 @@
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:1:1]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:1:1]
1 |
2 | ,-> An example of escaped CENDs
3 | `->
@@ -105,7 +141,7 @@
`----
x Text
- ,-[$DIR/tests/fixture/cdata/input.xml:1:1]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:1:1]
1 |
2 | ,-> An example of escaped CENDs
3 | `->
@@ -113,7 +149,7 @@
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:2:1]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:2:1]
2 | An example of escaped CENDs
3 |
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -121,7 +157,7 @@
`----
x Comment
- ,-[$DIR/tests/fixture/cdata/input.xml:2:1]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:2:1]
2 | An example of escaped CENDs
3 |
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -129,7 +165,7 @@
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:2:1]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:2:1]
2 | An example of escaped CENDs
3 | ,->
4 | `->
4 | `->
4 | ,->
@@ -153,7 +189,7 @@
`----
x Comment
- ,-[$DIR/tests/fixture/cdata/input.xml:3:1]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:3:1]
3 |
4 | ,->
@@ -161,7 +197,7 @@
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:4:1]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:4:1]
4 |
6 | `->
@@ -169,7 +205,7 @@
`----
x Text
- ,-[$DIR/tests/fixture/cdata/input.xml:4:1]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:4:1]
4 |
6 | `->
@@ -177,7 +213,7 @@
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:5:1]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:5:1]
5 | and the > in the second CDATA block -->
6 | ,->
7 | |
12 | `->
- 13 |
+ 13 | Hello, world!]]>
`----
x Element
- ,-[$DIR/tests/fixture/cdata/input.xml:5:1]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:5:1]
5 | and the > in the second CDATA block -->
6 | ,->
7 | |
12 | `->
- 13 |
+ 13 | Hello, world!]]>
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:5:1]
- 5 | and the > in the second CDATA block -->
- 6 | ,->
- 7 | | in the second CDATA block -->
+ 6 | ,->
+ 7 | `-> in the second CDATA block -->
+ 6 | ,->
+ 7 | `->
+ 7 | ,->
+ 11 | `-> ]]>
+ 12 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:10:1]
+ 10 | but my document is still well formed!
+ 11 | ,-> ]]>
12 | `->
- 13 |
+ 13 | Hello, world!]]>
`----
x Text
- ,-[$DIR/tests/fixture/cdata/input.xml:5:1]
- 5 | and the > in the second CDATA block -->
- 6 | ,->
- 7 | |
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:10:1]
+ 10 | but my document is still well formed!
+ 11 | ,-> ]]>
12 | `->
- 13 |
+ 13 | Hello, world!]]>
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:11:1]
- 11 | ]]>
- 12 |
- : ^
- 13 |
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:11:1]
+ 11 | ]]>
+ 12 | ,->
+ 13 | `-> Hello, world!]]>
+ 14 |
`----
x Text
- ,-[$DIR/tests/fixture/cdata/input.xml:11:1]
- 11 | ]]>
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:11:1]
+ 11 | ]]>
+ 12 | ,->
+ 13 | `-> Hello, world!]]>
+ 14 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:12:1]
12 |
- : ^
- 13 |
+ 13 | Hello, world!]]>
+ : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ 14 |
+ `----
+
+ x Element
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:12:1]
+ 12 |
+ 13 | Hello, world!]]>
+ : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ 14 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:12:1]
+ 12 |
+ 13 | Hello, world!]]>
+ : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ 14 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:12:1]
+ 12 |
+ 13 | ,-> Hello, world!]]>
+ 14 | `->
+ 15 |
+ `----
+
+ x Text
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:12:1]
+ 12 |
+ 13 | ,-> Hello, world!]]>
+ 14 | `->
+ 15 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:13:1]
+ 13 | Hello, world!]]>
+ 14 |
+ : ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ 15 |
+ `----
+
+ x Element
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:13:1]
+ 13 | Hello, world!]]>
+ 14 |
+ : ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ 15 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:13:1]
+ 13 | Hello, world!]]>
+ 14 |
+ : ^^^^^^^^^^^^^^^^^^^
+ 15 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:13:1]
+ 13 | Hello, world!]]>
+ 14 | ,->
+ 15 | `->
+ 16 |
+ `----
+
+ x Text
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:13:1]
+ 13 | Hello, world!]]>
+ 14 | ,->
+ 15 | `->
+ 16 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:14:1]
+ 14 |
+ 15 |
+ : ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ 16 |
+ `----
+
+ x Element
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:14:1]
+ 14 |
+ 15 |
+ : ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ 16 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:14:1]
+ 14 |
+ 15 |
+ : ^^^^^^^^^^^^^^^^^^^
+ 16 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:14:1]
+ 14 |
+ 15 | ,->
+ 16 | `->
+ 17 |
+ `----
+
+ x Text
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:14:1]
+ 14 |
+ 15 | ,->
+ 16 | `->
+ 17 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:15:1]
+ 15 |
+ 16 |
+ : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ 17 |
+ `----
+
+ x Element
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:15:1]
+ 15 |
+ 16 |
+ : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ 17 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:15:1]
+ 15 |
+ 16 |
+ : ^^^^^^^^^^^^^^^^^^^^^
+ 17 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:15:1]
+ 15 |
+ 16 | ,->
+ 17 | `->
+ 18 | text]]>
+ `----
+
+ x Text
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:15:1]
+ 15 |
+ 16 | ,->
+ 17 | `->
+ 18 | text]]>
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:16:1]
+ 16 |
+ 17 |
+ : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ 18 | text]]>
+ `----
+
+ x Element
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:16:1]
+ 16 |
+ 17 |
+ : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ 18 | text]]>
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:16:1]
+ 16 |
+ 17 |
+ : ^^^^^^^^^^^^^^^^^^^^^^
+ 18 | text]]>
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:16:1]
+ 16 |
+ 17 | ,->
+ 18 | `-> text]]>
+ 19 | ]]>
+ `----
+
+ x Text
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:16:1]
+ 16 |
+ 17 | ,->
+ 18 | `-> text]]>
+ 19 | ]]>
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:17:1]
+ 17 |
+ 18 | text]]>
+ : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ 19 | ]]>
+ `----
+
+ x Element
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:17:1]
+ 17 |
+ 18 | text]]>
+ : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ 19 | ]]>
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:17:1]
+ 17 |
+ 18 | text]]>
+ : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ 19 | ]]>
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:17:1]
+ 17 |
+ 18 | ,-> text]]>
+ 19 | `-> ]]>
+ 20 |
+ `----
+
+ x Text
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:17:1]
+ 17 |
+ 18 | ,-> text]]>
+ 19 | `-> ]]>
+ 20 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:18:1]
+ 18 | text]]>
+ 19 | ]]>
+ : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ 20 |
+ `----
+
+ x Element
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:18:1]
+ 18 | text]]>
+ 19 | ]]>
+ : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ 20 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:18:1]
+ 18 | text]]>
+ 19 | ]]>
+ : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ 20 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:18:1]
+ 18 | text]]>
+ 19 | ,-> ]]>
+ 20 | `->
+ 21 |
+ `----
+
+ x Text
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:18:1]
+ 18 |
text]]>
+ 19 | ,-> ]]>
+ 20 | `->
+ 21 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:19:1]
+ 19 |
]]>
+ 20 |
+ : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ 21 |
+ `----
+
+ x Element
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:19:1]
+ 19 |
]]>
+ 20 |
+ : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ 21 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:19:1]
+ 19 |
]]>
+ 20 |
+ : ^^^^^^^^^^^^^
+ 21 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:19:1]
+ 19 |
]]>
+ 20 |
+ : ^^^^^^^^^^^^^
+ 21 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:19:1]
+ 19 |
]]>
+ 20 | ,->
+ 21 | `->
+ 22 |
+ `----
+
+ x Text
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:19:1]
+ 19 | ]]>
+ 20 | ,->
+ 21 | `->
+ 22 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:20:1]
+ 20 |
+ 21 | ,->
+ 22 | `->
+ 23 |
+ `----
+
+ x Element
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:20:1]
+ 20 |
+ 21 | ,->
+ 22 | `->
+ 23 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:20:1]
+ 20 |
+ 21 | ,->
+ 22 | `->
+ 23 |
+ `----
+
+ x Text
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:20:1]
+ 20 |
+ 21 | ,->
+ 22 | `->
+ 23 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:21:1]
+ 21 |
+ 22 |
+ : ^^^^^^^^^^^^^^^^
+ 23 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:21:1]
+ 21 |
+ 22 |
+ : ^^
+ 23 |
+ `----
+
+ x Text
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:21:1]
+ 21 |
+ 22 |
+ : ^^
+ 23 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:21:1]
+ 21 |
+ 22 | ,->
+ 23 | `->
+ 24 |
+ `----
+
+ x Text
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:21:1]
+ 21 |
+ 22 | ,->
+ 23 | `->
+ 24 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:22:1]
+ 22 |
+ 23 |
+ : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ 24 |
+ `----
+
+ x Element
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:22:1]
+ 22 |
+ 23 |
+ : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ 24 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:22:1]
+ 22 |
+ 23 |
+ : ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ 24 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:22:1]
+ 22 |
+ 23 | ,->
+ 24 | `->
+ 25 |
+ `----
+
+ x Text
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:22:1]
+ 22 |
+ 23 | ,->
+ 24 | `->
+ 25 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:23:1]
+ 23 |
+ 24 |
+ : ^^^^^^^^^^^^^^^^^^^
+ 25 |
+ `----
+
+ x Element
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:23:1]
+ 23 |
+ 24 |
+ : ^^^^^^^^^^^^^^^^^^^
+ 25 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:23:1]
+ 23 |
+ 24 |
+ : ^^^^^^^^^^^^
+ 25 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:23:1]
+ 23 |
+ 24 |
+ : ^
+ 25 |
+ `----
+
+ x Text
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:23:1]
+ 23 |
+ 24 |
+ : ^
+ 25 |
`----
diff --git a/crates/swc_xml_parser/tests/recovery/cdata-after/output.stderr b/crates/swc_xml_parser/tests/recovery/cdata-after/output.stderr
index 0133832c7a57..8c653e3e0fbe 100644
--- a/crates/swc_xml_parser/tests/recovery/cdata-after/output.stderr
+++ b/crates/swc_xml_parser/tests/recovery/cdata-after/output.stderr
@@ -1,6 +1,7 @@
x Unexpected token in end phase
- ,-[$DIR/tests/recovery/cdata-after/input.xml:4:1]
+ ,-[$DIR/tests/recovery/cdata-after/input.xml:3:1]
+ 3 |
4 |
: ^^^^^^^^^^^^^^^^^^^
`----
diff --git a/crates/swc_xml_parser/tests/recovery/cdata-after/span.rust-debug b/crates/swc_xml_parser/tests/recovery/cdata-after/span.rust-debug
index 198912cffdee..b364f3d4d5b9 100644
--- a/crates/swc_xml_parser/tests/recovery/cdata-after/span.rust-debug
+++ b/crates/swc_xml_parser/tests/recovery/cdata-after/span.rust-debug
@@ -12,6 +12,7 @@
1 | ,->
2 | | Test
3 | `->
+ 4 |
`----
x Element
@@ -19,60 +20,76 @@
1 | ,->
2 | | Test
3 | `->
+ 4 |
`----
x Child
,-[$DIR/tests/recovery/cdata-after/input.xml:1:1]
1 | ,->
2 | `-> Test
+ 3 |
`----
x Text
,-[$DIR/tests/recovery/cdata-after/input.xml:1:1]
1 | ,->
2 | `-> Test
+ 3 |
`----
x Child
- ,-[$DIR/tests/recovery/cdata-after/input.xml:2:5]
- 2 | Test
- : ^^^^^^^^^^^
+ ,-[$DIR/tests/recovery/cdata-after/input.xml:1:1]
+ 1 |
+ 2 | Test
+ : ^^^^^^^^^^^
+ 3 |
`----
x Element
- ,-[$DIR/tests/recovery/cdata-after/input.xml:2:5]
- 2 | Test
- : ^^^^^^^^^^^
+ ,-[$DIR/tests/recovery/cdata-after/input.xml:1:1]
+ 1 |
+ 2 | Test
+ : ^^^^^^^^^^^
+ 3 |
`----
x Child
- ,-[$DIR/tests/recovery/cdata-after/input.xml:2:5]
- 2 | Test
- : ^^^^
+ ,-[$DIR/tests/recovery/cdata-after/input.xml:1:1]
+ 1 |
+ 2 | Test
+ : ^^^^
+ 3 |
`----
x Text
- ,-[$DIR/tests/recovery/cdata-after/input.xml:2:5]
- 2 | Test
- : ^^^^
+ ,-[$DIR/tests/recovery/cdata-after/input.xml:1:1]
+ 1 |
+ 2 | Test
+ : ^^^^
+ 3 |
`----
x Child
- ,-[$DIR/tests/recovery/cdata-after/input.xml:2:5]
- 2 | Test
- : ^
+ ,-[$DIR/tests/recovery/cdata-after/input.xml:1:1]
+ 1 |
+ 2 | Test
+ : ^
3 |
+ 4 |
`----
x Text
- ,-[$DIR/tests/recovery/cdata-after/input.xml:2:5]
- 2 | Test
- : ^
+ ,-[$DIR/tests/recovery/cdata-after/input.xml:1:1]
+ 1 |
+ 2 | Test
+ : ^
3 |
+ 4 |
`----
x Child
- ,-[$DIR/tests/recovery/cdata-after/input.xml:4:1]
+ ,-[$DIR/tests/recovery/cdata-after/input.xml:3:1]
+ 3 |
4 |
: ^^^^^^^^^^^^^^^^^^^
`----
diff --git a/crates/swc_xml_parser/tests/recovery/cdata-before/output.stderr b/crates/swc_xml_parser/tests/recovery/cdata-before/output.stderr
index f941fa50ea8e..78ac267b3459 100644
--- a/crates/swc_xml_parser/tests/recovery/cdata-before/output.stderr
+++ b/crates/swc_xml_parser/tests/recovery/cdata-before/output.stderr
@@ -3,4 +3,5 @@
,-[$DIR/tests/recovery/cdata-before/input.xml:1:1]
1 |
: ^^^^^^^^^^^^^^^^^^^
+ 2 |
`----
diff --git a/crates/swc_xml_parser/tests/recovery/cdata-before/span.rust-debug b/crates/swc_xml_parser/tests/recovery/cdata-before/span.rust-debug
index b94da22bc9cf..575581c10722 100644
--- a/crates/swc_xml_parser/tests/recovery/cdata-before/span.rust-debug
+++ b/crates/swc_xml_parser/tests/recovery/cdata-before/span.rust-debug
@@ -11,68 +11,85 @@
,-[$DIR/tests/recovery/cdata-before/input.xml:1:1]
1 |
: ^^^^^^^^^^^^^^^^^^^
+ 2 |
`----
x Child
- ,-[$DIR/tests/recovery/cdata-before/input.xml:2:1]
+ ,-[$DIR/tests/recovery/cdata-before/input.xml:1:1]
+ 1 |
2 | ,->
3 | | Test
4 | `->
`----
x Element
- ,-[$DIR/tests/recovery/cdata-before/input.xml:2:1]
+ ,-[$DIR/tests/recovery/cdata-before/input.xml:1:1]
+ 1 |
2 | ,->
3 | | Test
4 | `->
`----
x Child
- ,-[$DIR/tests/recovery/cdata-before/input.xml:2:1]
+ ,-[$DIR/tests/recovery/cdata-before/input.xml:1:1]
+ 1 |
2 | ,->
3 | `-> Test
+ 4 |
`----
x Text
- ,-[$DIR/tests/recovery/cdata-before/input.xml:2:1]
+ ,-[$DIR/tests/recovery/cdata-before/input.xml:1:1]
+ 1 |
2 | ,->
3 | `-> Test
+ 4 |
`----
x Child
- ,-[$DIR/tests/recovery/cdata-before/input.xml:3:5]
- 3 | Test
- : ^^^^^^^^^^^
+ ,-[$DIR/tests/recovery/cdata-before/input.xml:2:1]
+ 2 |
+ 3 | Test
+ : ^^^^^^^^^^^
+ 4 |
`----
x Element
- ,-[$DIR/tests/recovery/cdata-before/input.xml:3:5]
- 3 | Test
- : ^^^^^^^^^^^
+ ,-[$DIR/tests/recovery/cdata-before/input.xml:2:1]
+ 2 |
+ 3 | Test
+ : ^^^^^^^^^^^
+ 4 |
`----
x Child
- ,-[$DIR/tests/recovery/cdata-before/input.xml:3:5]
- 3 | Test
- : ^^^^
+ ,-[$DIR/tests/recovery/cdata-before/input.xml:2:1]
+ 2 |
+ 3 | Test
+ : ^^^^
+ 4 |
`----
x Text
- ,-[$DIR/tests/recovery/cdata-before/input.xml:3:5]
- 3 | Test
- : ^^^^
+ ,-[$DIR/tests/recovery/cdata-before/input.xml:2:1]
+ 2 |
+ 3 | Test
+ : ^^^^
+ 4 |
`----
x Child
- ,-[$DIR/tests/recovery/cdata-before/input.xml:3:5]
- 3 | Test
- : ^
+ ,-[$DIR/tests/recovery/cdata-before/input.xml:2:1]
+ 2 |
+ 3 | Test
+ : ^
4 |
`----
x Text
- ,-[$DIR/tests/recovery/cdata-before/input.xml:3:5]
- 3 | Test
- : ^
+ ,-[$DIR/tests/recovery/cdata-before/input.xml:2:1]
+ 2 |
+ 3 | Test
+ : ^
4 |
`----