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 d503f301274a..de777230b4ad 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),
}
}
@@ -289,6 +290,17 @@ where
newline!(self);
}
+ #[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 6549b937a942..a8f9159ecd5d 100644
--- a/crates/swc_xml_parser/src/lexer/mod.rs
+++ b/crates/swc_xml_parser/src/lexer/mod.rs
@@ -110,6 +110,12 @@ struct ProcessingInstruction {
data: String,
}
+#[derive(PartialEq, Eq, Clone, Debug)]
+struct Cdata {
+ data: String,
+ raw: String,
+}
+
pub(crate) type LexResult = Result;
pub struct Lexer
@@ -127,11 +133,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,
}
@@ -154,11 +160,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,
};
@@ -863,6 +869,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';
@@ -1364,17 +1398,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;
}
_ => {
@@ -1697,11 +1730,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));
}
}
}
@@ -1723,8 +1756,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;
}
}
@@ -1735,13 +1768,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.
@@ -1754,9 +1791,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 66%
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
index d7993ed0942b..629ccec2214b 100644
--- a/crates/swc_xml_parser/tests/fixture/cdata/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 | |
@@ -24,12 +24,12 @@
21 | |
22 | |
23 | |
- 24 | |
+ 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 | |
@@ -53,12 +53,12 @@
21 | |
22 | |
23 | |
- 24 | |
+ 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 | |
@@ -82,108 +82,108 @@
21 | |
22 | |
23 | |
- 24 | |
+ 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
`----
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
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:2:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:2:5]
2 | An example of escaped CENDs
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
x Element
- ,-[$DIR/tests/fixture/cdata/input.xml:2:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:2:5]
2 | An example of escaped CENDs
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:2:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:2:5]
2 | An example of escaped CENDs
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
x Text
- ,-[$DIR/tests/fixture/cdata/input.xml:2:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:2:5]
2 | An example of escaped CENDs
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:2:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:2:5]
2 | ,-> An example of escaped CENDs
3 | `->
`----
x Text
- ,-[$DIR/tests/fixture/cdata/input.xml:2:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:2:5]
2 | ,-> An example of escaped CENDs
3 | `->
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:3:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:3:5]
3 |
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
x Comment
- ,-[$DIR/tests/fixture/cdata/input.xml:3:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:3:5]
3 |
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:3:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:3:5]
3 | ,->
4 | `->
4 | `->
`----
x Comment
- ,-[$DIR/tests/fixture/cdata/input.xml:4:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:4:5]
4 | ,->
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:5:10]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:5:10]
5 | ,-> and the > in the second CDATA block -->
6 | `->
`----
x Text
- ,-[$DIR/tests/fixture/cdata/input.xml:5:10]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:5:10]
5 | ,-> and the > in the second CDATA block -->
6 | `->
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:6:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:6:5]
6 | ,->
7 | |
7 | |
- 7 | |
+ 7 | `->
+ 7 | `->
+ 11 | `-> ]]>
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:11:5]
+ 11 | ,-> ]]>
12 | `->
`----
x Text
- ,-[$DIR/tests/fixture/cdata/input.xml:6:5]
- 6 | ,->
- 7 | |
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:11:5]
+ 11 | ,-> ]]>
12 | `->
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:12:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:12:5]
12 | ,->
13 | `-> Hello, world!]]>
`----
x Text
- ,-[$DIR/tests/fixture/cdata/input.xml:12:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:12:5]
12 | ,->
13 | `-> Hello, world!]]>
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:13:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:13:5]
13 | Hello, world!]]>
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
x Element
- ,-[$DIR/tests/fixture/cdata/input.xml:13:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:13:5]
13 | Hello, world!]]>
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:13:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:13:5]
13 | Hello, world!]]>
- : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- `----
-
- x Text
- ,-[$DIR/tests/fixture/cdata/input.xml:13:5]
- 13 | Hello, world!]]>
- : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:13:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:13:5]
13 | ,-> Hello, world!]]>
14 | `->
`----
x Text
- ,-[$DIR/tests/fixture/cdata/input.xml:13:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:13:5]
13 | ,-> Hello, world!]]>
14 | `->
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:14:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:14:5]
14 |
: ^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
x Element
- ,-[$DIR/tests/fixture/cdata/input.xml:14:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:14:5]
14 |
: ^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:14:5]
- 14 |
- : ^^^^^^^^^^^^^^^^
- `----
-
- x Text
- ,-[$DIR/tests/fixture/cdata/input.xml:14:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:14:5]
14 |
- : ^^^^^^^^^^^^^^^^
+ : ^^^^^^^^^^^^^^^^^^^
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:14:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:14:5]
14 | ,->
15 | `->
`----
x Text
- ,-[$DIR/tests/fixture/cdata/input.xml:14:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:14:5]
14 | ,->
15 | `->
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:15:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:15:5]
15 |
: ^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
x Element
- ,-[$DIR/tests/fixture/cdata/input.xml:15:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:15:5]
15 |
: ^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:15:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:15:5]
15 |
- : ^^^^^^^^^^^^^^^^
- `----
-
- x Text
- ,-[$DIR/tests/fixture/cdata/input.xml:15:5]
- 15 |
- : ^^^^^^^^^^^^^^^^
+ : ^^^^^^^^^^^^^^^^^^^
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:15:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:15:5]
15 | ,->
16 | `->
`----
x Text
- ,-[$DIR/tests/fixture/cdata/input.xml:15:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:15:5]
15 | ,->
16 | `->
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:16:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:16:5]
16 |
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
x Element
- ,-[$DIR/tests/fixture/cdata/input.xml:16:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:16:5]
16 |
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:16:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:16:5]
16 |
- : ^^^^^^^^^^^^^^^^^^^^
- `----
-
- x Text
- ,-[$DIR/tests/fixture/cdata/input.xml:16:5]
- 16 |
- : ^^^^^^^^^^^^^^^^^^^^
+ : ^^^^^^^^^^^^^^^^^^^^^
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:16:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:16:5]
16 | ,->
17 | `->
`----
x Text
- ,-[$DIR/tests/fixture/cdata/input.xml:16:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:16:5]
16 | ,->
17 | `->
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:17:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:17:5]
17 |
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
x Element
- ,-[$DIR/tests/fixture/cdata/input.xml:17:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:17:5]
17 |
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:17:5]
- 17 |
- : ^^^^^^^^^^^^^^^^^^^
- `----
-
- x Text
- ,-[$DIR/tests/fixture/cdata/input.xml:17:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:17:5]
17 |
- : ^^^^^^^^^^^^^^^^^^^
+ : ^^^^^^^^^^^^^^^^^^^^^^
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:17:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:17:5]
17 | ,->
18 | `-> text]]>
`----
x Text
- ,-[$DIR/tests/fixture/cdata/input.xml:17:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:17:5]
17 | ,->
18 | `-> text]]>
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:18:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:18:5]
18 | text]]>
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
x Element
- ,-[$DIR/tests/fixture/cdata/input.xml:18:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:18:5]
18 | text]]>
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:18:5]
- 18 | text]]>
- : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- `----
-
- x Text
- ,-[$DIR/tests/fixture/cdata/input.xml:18:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:18:5]
18 | text]]>
- : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:18:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:18:5]
18 | ,-> text]]>
19 | `-> ]]>
`----
x Text
- ,-[$DIR/tests/fixture/cdata/input.xml:18:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:18:5]
18 | ,-> text]]>
19 | `-> ]]>
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:19:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:19:5]
19 | ]]>
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
x Element
- ,-[$DIR/tests/fixture/cdata/input.xml:19:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:19:5]
19 | ]]>
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:19:5]
- 19 | ]]>
- : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- `----
-
- x Text
- ,-[$DIR/tests/fixture/cdata/input.xml:19:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:19:5]
19 | ]]>
- : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:19:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:19:5]
19 | ,-> ]]>
20 | `->
`----
x Text
- ,-[$DIR/tests/fixture/cdata/input.xml:19:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:19:5]
19 | ,-> ]]>
20 | `->
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:20:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:20:5]
20 |
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
x Element
- ,-[$DIR/tests/fixture/cdata/input.xml:20:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:20:5]
20 |
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:20:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:20:5]
20 |
- : ^^^^^^^^^^^^^^^^^^^^^^^
+ : ^^^^^^^^^^^^^
`----
- x Text
- ,-[$DIR/tests/fixture/cdata/input.xml:20:5]
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:20:5]
20 |
- : ^^^^^^^^^^^^^^^^^^^^^^^
+ : ^^^^^^^^^^^^^
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:20:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:20:5]
20 | ,->
21 | `->
`----
x Text
- ,-[$DIR/tests/fixture/cdata/input.xml:20:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:20:5]
20 | ,->
21 | `->
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:21:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:21:5]
21 | ,->
22 | `->
`----
x Element
- ,-[$DIR/tests/fixture/cdata/input.xml:21:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:21:5]
21 | ,->
22 | `->
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:21:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:21:5]
21 | ,->
22 | `->
`----
x Text
- ,-[$DIR/tests/fixture/cdata/input.xml:21:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:21:5]
21 | ,->
22 | `->
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:22:9]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:22:9]
+ 22 |
+ : ^^^^^^^^^^^^^^^^
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:22:9]
+ 22 |
+ : ^^
+ `----
+
+ x Text
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:22:9]
+ 22 |
+ : ^^
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:22:9]
22 | ,->
23 | `->
`----
x Text
- ,-[$DIR/tests/fixture/cdata/input.xml:22:9]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:22:9]
22 | ,->
23 | `->
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:23:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:23:5]
23 |
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
x Element
- ,-[$DIR/tests/fixture/cdata/input.xml:23:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:23:5]
23 |
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:23:5]
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:23:5]
23 |
- : ^^^^^^^^^^^^^^^^^^^^^^^
+ : ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:23:5]
+ 23 | ,->
+ 24 | `->
`----
x Text
- ,-[$DIR/tests/fixture/cdata/input.xml:23:5]
- 23 |
- : ^^^^^^^^^^^^^^^^^^^^^^^
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:23:5]
+ 23 | ,->
+ 24 | `->
`----
x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:23:5]
- 23 | ,->
- 24 | `->
- 25 |
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:24:5]
+ 24 |
+ : ^^^^^^^^^^^^^^^^^^^
+ `----
+
+ x Element
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:24:5]
+ 24 |
+ : ^^^^^^^^^^^^^^^^^^^
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:24:5]
+ 24 |
+ : ^^^^^^^^^^^^
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:24:5]
+ 24 |
+ : ^
+ 25 |
`----
x Text
- ,-[$DIR/tests/fixture/cdata/input.xml:23:5]
- 23 | ,->
- 24 | `->
- 25 |
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:24:5]
+ 24 |
+ : ^
+ 25 |
`----
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,