diff --git a/crates/swc_xml_ast/src/base.rs b/crates/swc_xml_ast/src/base.rs
index 8bf054ad426d..ef01cac5777d 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_ast/src/token.rs b/crates/swc_xml_ast/src/token.rs
index d3849968fb25..a7e61f60b7c0 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_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 815867299ee6..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,9 +1793,9 @@ 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.reconsume_in_state(State::Cdata);
+ 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/input.xml b/crates/swc_xml_parser/tests/fixture/cdata/input.xml
deleted file mode 100644
index d2fa2ce9f3ea..000000000000
--- a/crates/swc_xml_parser/tests/fixture/cdata/input.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-
- An example of escaped CENDs
-
-
-
-
-
-
\ 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
deleted file mode 100644
index a8141533403e..000000000000
--- a/crates/swc_xml_parser/tests/fixture/cdata/output.json
+++ /dev/null
@@ -1,136 +0,0 @@
-{
- "type": "Document",
- "span": {
- "start": 1,
- "end": 434,
- "ctxt": 0
- },
- "children": [
- {
- "type": "Element",
- "span": {
- "start": 1,
- "end": 434,
- "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": 66,
- "ctxt": 0
- },
- "tagName": "description",
- "attributes": [],
- "children": [
- {
- "type": "Text",
- "span": {
- "start": 25,
- "end": 52,
- "ctxt": 0
- },
- "data": "An example of escaped CENDs",
- "raw": "An example of escaped CENDs"
- }
- ]
- },
- {
- "type": "Text",
- "span": {
- "start": 66,
- "end": 71,
- "ctxt": 0
- },
- "data": "\n ",
- "raw": "\n "
- },
- {
- "type": "Comment",
- "span": {
- "start": 71,
- "end": 109,
- "ctxt": 0
- },
- "data": " This text contains a CEND ]]> ",
- "raw": ""
- },
- {
- "type": "Text",
- "span": {
- "start": 109,
- "end": 114,
- "ctxt": 0
- },
- "data": "\n ",
- "raw": "\n "
- },
- {
- "type": "Comment",
- "span": {
- "start": 114,
- "end": 236,
- "ctxt": 0
- },
- "data": " In this first case we put the ]] at the end of the first CDATA block\n and the > in the second CDATA block ",
- "raw": ""
- },
- {
- "type": "Text",
- "span": {
- "start": 236,
- "end": 241,
- "ctxt": 0
- },
- "data": "\n ",
- "raw": "\n "
- },
- {
- "type": "Element",
- "span": {
- "start": 241,
- "end": 426,
- "ctxt": 0
- },
- "tagName": "exampleOfACDATA",
- "attributes": [],
- "children": [
- {
- "type": "Text",
- "span": {
- "start": 258,
- "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 "
- }
- ]
- },
- {
- "type": "Text",
- "span": {
- "start": 426,
- "end": 427,
- "ctxt": 0
- },
- "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/span.rust-debug
deleted file mode 100644
index dc5df295fc55..000000000000
--- a/crates/swc_xml_parser/tests/fixture/cdata/span.rust-debug
+++ /dev/null
@@ -1,245 +0,0 @@
-
- x Document
- ,-[$DIR/tests/fixture/cdata/input.xml:1:1]
- 1 | ,->
- 2 | | An example of escaped CENDs
- 3 | |
- 4 | |
- 6 | |
- 7 | |
- 12 | |
- 13 | `->
- `----
-
- x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:1:1]
- 1 | ,->
- 2 | | An example of escaped CENDs
- 3 | |
- 4 | |
- 6 | |
- 7 | |
- 12 | |
- 13 | `->
- `----
-
- x Element
- ,-[$DIR/tests/fixture/cdata/input.xml:1:1]
- 1 | ,->
- 2 | | An example of escaped CENDs
- 3 | |
- 4 | |
- 6 | |
- 7 | |
- 12 | |
- 13 | `->
- `----
-
- x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:1:1]
- 1 | ,->
- 2 | `-> An example of escaped CENDs
- 3 |
- `----
-
- x Text
- ,-[$DIR/tests/fixture/cdata/input.xml:1:1]
- 1 | ,->
- 2 | `-> An example of escaped CENDs
- 3 |
- `----
-
- x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:1:1]
- 1 |
- 2 | An example of escaped CENDs
- : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- 3 |
- `----
-
- x Element
- ,-[$DIR/tests/fixture/cdata/input.xml:1:1]
- 1 |
- 2 | An example of escaped CENDs
- : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- 3 |
- `----
-
- x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:1:1]
- 1 |
- 2 | An example of escaped CENDs
- : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
- 3 |
- `----
-
- x Text
- ,-[$DIR/tests/fixture/cdata/input.xml:1:1]
- 1 |
- 2 | An example of escaped CENDs
- : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
- 3 |
- `----
-
- x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:1:1]
- 1 |
- 2 | ,-> An example of escaped CENDs
- 3 | `->
- 4 |
- 4 |
- : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- 4 |
- : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- 4 |
- 4 | `->
- `----
-
- x Text
- ,-[$DIR/tests/fixture/cdata/input.xml:2:1]
- 2 | An example of escaped CENDs
- 3 | ,->
- 4 | `->
- `----
-
- x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:3:1]
- 3 |
- 4 | ,->
- 6 |
- `----
-
- x Comment
- ,-[$DIR/tests/fixture/cdata/input.xml:3:1]
- 3 |
- 4 | ,->
- 6 |
- `----
-
- x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:4:1]
- 4 |
- 6 | `->
- 7 | and the > in the second CDATA block -->
- 6 | `->
- 7 | in the second CDATA block -->
- 6 | ,->
- 7 | |
- 12 | `->
- 13 |
- `----
-
- x Element
- ,-[$DIR/tests/fixture/cdata/input.xml:5:1]
- 5 | and the > in the second CDATA block -->
- 6 | ,->
- 7 | |
- 12 | `->
- 13 |
- `----
-
- x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:5:1]
- 5 | and the > in the second CDATA block -->
- 6 | ,->
- 7 | |
- 12 | `->
- 13 |
- `----
-
- x Text
- ,-[$DIR/tests/fixture/cdata/input.xml:5:1]
- 5 | and the > in the second CDATA block -->
- 6 | ,->
- 7 | |
- 12 | `->
- 13 |
- `----
-
- x Child
- ,-[$DIR/tests/fixture/cdata/input.xml:11:1]
- 11 | ]]>
- 12 |
- : ^
- 13 |
- `----
-
- x Text
- ,-[$DIR/tests/fixture/cdata/input.xml:11:1]
- 11 | ]]>
- 12 |
- : ^
- 13 |
- `----
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 55%
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 3ee42cec6b4a..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,11 +14,44 @@
"
|
| "
-
- Since this is a CDATA section
- I can use all sorts of reserved characters
- but my document is still well formed!
-
"
+| "
+ "
+| "
+ "
+|
+| "
+ "
+|
+| "
+ "
+|
+| "
+ "
+|
+| "
+ "
+|
+| "
+ "
+|
+| "
+ "
+|
+| "
+ "
+|
+| "
+ "
+|
+| "
+ "
+| " "
+| "
+ "
+|
+| "
+ "
+|
| "
"
diff --git a/crates/swc_xml_parser/tests/fixture/cdata_section/input.xml b/crates/swc_xml_parser/tests/fixture/cdata_section/input.xml
new file mode 100644
index 000000000000..0a7a04578438
--- /dev/null
+++ b/crates/swc_xml_parser/tests/fixture/cdata_section/input.xml
@@ -0,0 +1,25 @@
+
+ An example of escaped CENDs
+
+
+
+
+
+ Hello, world!]]>
+
+
+
+
+ text]]>
+ ]]>
+
+
+
+
+
+
diff --git a/crates/swc_xml_parser/tests/fixture/cdata_section/output.json b/crates/swc_xml_parser/tests/fixture/cdata_section/output.json
new file mode 100644
index 000000000000..d33659fa05ba
--- /dev/null
+++ b/crates/swc_xml_parser/tests/fixture/cdata_section/output.json
@@ -0,0 +1,538 @@
+{
+ "type": "Document",
+ "span": {
+ "start": 1,
+ "end": 883,
+ "ctxt": 0
+ },
+ "children": [
+ {
+ "type": "Element",
+ "span": {
+ "start": 1,
+ "end": 882,
+ "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": 66,
+ "ctxt": 0
+ },
+ "tagName": "description",
+ "attributes": [],
+ "children": [
+ {
+ "type": "Text",
+ "span": {
+ "start": 25,
+ "end": 52,
+ "ctxt": 0
+ },
+ "data": "An example of escaped CENDs",
+ "raw": "An example of escaped CENDs"
+ }
+ ]
+ },
+ {
+ "type": "Text",
+ "span": {
+ "start": 66,
+ "end": 71,
+ "ctxt": 0
+ },
+ "data": "\n ",
+ "raw": "\n "
+ },
+ {
+ "type": "Comment",
+ "span": {
+ "start": 71,
+ "end": 109,
+ "ctxt": 0
+ },
+ "data": " This text contains a CEND ]]> ",
+ "raw": ""
+ },
+ {
+ "type": "Text",
+ "span": {
+ "start": 109,
+ "end": 114,
+ "ctxt": 0
+ },
+ "data": "\n ",
+ "raw": "\n "
+ },
+ {
+ "type": "Comment",
+ "span": {
+ "start": 114,
+ "end": 236,
+ "ctxt": 0
+ },
+ "data": " In this first case we put the ]] at the end of the first CDATA block\n and the > in the second CDATA block ",
+ "raw": ""
+ },
+ {
+ "type": "Text",
+ "span": {
+ "start": 236,
+ "end": 241,
+ "ctxt": 0
+ },
+ "data": "\n ",
+ "raw": "\n "
+ },
+ {
+ "type": "Element",
+ "span": {
+ "start": 241,
+ "end": 426,
+ "ctxt": 0
+ },
+ "tagName": "exampleOfACDATA",
+ "attributes": [],
+ "children": [
+ {
+ "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 ",
+ "raw": "\n "
+ }
+ ]
+ },
+ {
+ "type": "Text",
+ "span": {
+ "start": 426,
+ "end": 431,
+ "ctxt": 0
+ },
+ "data": "\n ",
+ "raw": "\n "
+ },
+ {
+ "type": "Element",
+ "span": {
+ "start": 431,
+ "end": 484,
+ "ctxt": 0
+ },
+ "tagName": "p",
+ "attributes": [],
+ "children": [
+ {
+ "type": "CdataSection",
+ "span": {
+ "start": 434,
+ "end": 480,
+ "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": "CdataSection",
+ "span": {
+ "start": 492,
+ "end": 511,
+ "ctxt": 0
+ },
+ "data": "content",
+ "raw": ""
+ }
+ ]
+ },
+ {
+ "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": "CdataSection",
+ "span": {
+ "start": 523,
+ "end": 542,
+ "ctxt": 0
+ },
+ "data": "&ing",
+ "raw": ""
+ }
+ ]
+ },
+ {
+ "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": "CdataSection",
+ "span": {
+ "start": 554,
+ "end": 575,
+ "ctxt": 0
+ },
+ "data": "&ing ]",
+ "raw": ""
+ }
+ ]
+ },
+ {
+ "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": "CdataSection",
+ "span": {
+ "start": 587,
+ "end": 609,
+ "ctxt": 0
+ },
+ "data": "&ing]] ",
+ "raw": ""
+ }
+ ]
+ },
+ {
+ "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": "CdataSection",
+ "span": {
+ "start": 621,
+ "end": 656,
+ "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": "CdataSection",
+ "span": {
+ "start": 668,
+ "end": 731,
+ "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": "CdataSection",
+ "span": {
+ "start": 743,
+ "end": 756,
+ "ctxt": 0
+ },
+ "data": "1",
+ "raw": ""
+ },
+ {
+ "type": "CdataSection",
+ "span": {
+ "start": 756,
+ "end": 769,
+ "ctxt": 0
+ },
+ "data": "2",
+ "raw": ""
+ }
+ ]
+ },
+ {
+ "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": 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": " ",
+ "raw": " "
+ }
+ ]
+ },
+ {
+ "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": "CdataSection",
+ "span": {
+ "start": 820,
+ "end": 846,
+ "ctxt": 0
+ },
+ "data": "bracket ]after",
+ "raw": ""
+ }
+ ]
+ },
+ {
+ "type": "Text",
+ "span": {
+ "start": 850,
+ "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",
+ "raw": "\n"
+ }
+ ]
+ }
+ ]
+}
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
new file mode 100644
index 000000000000..183e10f1b6c9
--- /dev/null
+++ b/crates/swc_xml_parser/tests/fixture/cdata_section/span.rust-debug
@@ -0,0 +1,778 @@
+
+ x Document
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:1:1]
+ 1 | ,->
+ 2 | | An example of escaped CENDs
+ 3 | |
+ 4 | |
+ 6 | |
+ 7 | |
+ 12 | |
+ 13 | | Hello, world!]]>
+ 14 | |
+ 15 | |
+ 16 | |
+ 17 | |
+ 18 | | text]]>
+ 19 | | ]]>
+ 20 | |
+ 21 | |
+ 22 | |
+ 23 | |
+ 24 | |
+ 25 | `->
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:1:1]
+ 1 | ,->
+ 2 | | An example of escaped CENDs
+ 3 | |
+ 4 | |
+ 6 | |
+ 7 | |
+ 12 | |
+ 13 | | Hello, world!]]>
+ 14 | |
+ 15 | |
+ 16 | |
+ 17 | |
+ 18 | | text]]>
+ 19 | | ]]>
+ 20 | |
+ 21 | |
+ 22 | |
+ 23 | |
+ 24 | |
+ 25 | `->
+ `----
+
+ x Element
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:1:1]
+ 1 | ,->
+ 2 | | An example of escaped CENDs
+ 3 | |
+ 4 | |
+ 6 | |
+ 7 | |
+ 12 | |
+ 13 | | Hello, world!]]>
+ 14 | |
+ 15 | |
+ 16 | |
+ 17 | |
+ 18 | | text]]>
+ 19 | | ]]>
+ 20 | |
+ 21 | |
+ 22 | |
+ 23 | |
+ 24 | |
+ 25 | `->
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:1:1]
+ 1 | ,->
+ 2 | `-> An example of escaped CENDs
+ 3 |
+ `----
+
+ x Text
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:1:1]
+ 1 | ,->
+ 2 | `-> An example of escaped CENDs
+ 3 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:1:1]
+ 1 |
+ 2 | An example of escaped CENDs
+ : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ 3 |
+ `----
+
+ x Element
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:1:1]
+ 1 |
+ 2 | An example of escaped CENDs
+ : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ 3 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:1:1]
+ 1 |
+ 2 | An example of escaped CENDs
+ : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ 3 |
+ `----
+
+ x Text
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:1:1]
+ 1 |
+ 2 | An example of escaped CENDs
+ : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ 3 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:1:1]
+ 1 |
+ 2 | ,-> An example of escaped CENDs
+ 3 | `->
+ 4 |
+ 4 |
+ : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ 4 |
+ : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ 4 |
+ 4 | `->
+ `----
+
+ x Text
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:2:1]
+ 2 | An example of escaped CENDs
+ 3 | ,->
+ 4 | `->
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:3:1]
+ 3 |
+ 4 | ,->
+ 6 |
+ `----
+
+ x Comment
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:3:1]
+ 3 |
+ 4 | ,->
+ 6 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:4:1]
+ 4 |
+ 6 | `->
+ 7 | and the > in the second CDATA block -->
+ 6 | `->
+ 7 | in the second CDATA block -->
+ 6 | ,->
+ 7 | |
+ 12 | `->
+ 13 | Hello, world!]]>
+ `----
+
+ x Element
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:5:1]
+ 5 | and the > in the second CDATA block -->
+ 6 | ,->
+ 7 | |
+ 12 | `->
+ 13 | Hello, world!]]>
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:5:1]
+ 5 | and the > in the second CDATA block -->
+ 6 | ,->
+ 7 | `-> in the second CDATA block -->
+ 6 | ,->
+ 7 | `->
+ 7 | ,-> ]]>
+ 12 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:10:1]
+ 10 | but my document is still well formed!
+ 11 | ,-> ]]>
+ 12 | `->
+ 13 | Hello, world!]]>
+ `----
+
+ x Text
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:10:1]
+ 10 | but my document is still well formed!
+ 11 | ,-> ]]>
+ 12 | `->
+ 13 | Hello, world!]]>
+ `----
+
+ x Child
+ ,-[$DIR/tests/fixture/cdata_section/input.xml:11:1]
+ 11 | ]]>
+ 12 | ,->
+ 13 | `-> Hello, world!]]>
+ 14 |
+ `----
+
+ x Text
+ ,-[$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 | 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/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..8c653e3e0fbe
--- /dev/null
+++ b/crates/swc_xml_parser/tests/recovery/cdata-after/output.stderr
@@ -0,0 +1,7 @@
+
+ x Unexpected token in end phase
+ ,-[$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
new file mode 100644
index 000000000000..b364f3d4d5b9
--- /dev/null
+++ b/crates/swc_xml_parser/tests/recovery/cdata-after/span.rust-debug
@@ -0,0 +1,95 @@
+
+ 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 | `->
+ 4 |
+ `----
+
+ x Element
+ ,-[$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 Text
+ ,-[$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
+ : ^^^^^^^^^^^
+ 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
+ : ^^^^
+ 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:1:1]
+ 1 |
+ 2 | Test
+ : ^
+ 3 |
+ 4 |
+ `----
+
+ x Text
+ ,-[$DIR/tests/recovery/cdata-after/input.xml:1:1]
+ 1 |
+ 2 | Test
+ : ^
+ 3 |
+ 4 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/recovery/cdata-after/input.xml:3:1]
+ 3 |
+ 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..78ac267b3459
--- /dev/null
+++ b/crates/swc_xml_parser/tests/recovery/cdata-before/output.stderr
@@ -0,0 +1,7 @@
+
+ x Unexpected token in start phase
+ ,-[$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
new file mode 100644
index 000000000000..575581c10722
--- /dev/null
+++ b/crates/swc_xml_parser/tests/recovery/cdata-before/span.rust-debug
@@ -0,0 +1,95 @@
+
+ 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 |
+ : ^^^^^^^^^^^^^^^^^^^
+ 2 |
+ `----
+
+ x Child
+ ,-[$DIR/tests/recovery/cdata-before/input.xml:1:1]
+ 1 |
+ 2 | ,->
+ 3 | | Test
+ 4 | `->
+ `----
+
+ x Element
+ ,-[$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 |
+ 2 | ,->
+ 3 | `-> Test
+ 4 |
+ `----
+
+ x Text
+ ,-[$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]
+ 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
+ : ^^^^
+ 4 |
+ `----
+
+ x Text
+ ,-[$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
+ : ^
+ 4 |
+ `----
+
+ x Text
+ ,-[$DIR/tests/recovery/cdata-before/input.xml:2:1]
+ 2 |
+ 3 | Test
+ : ^
+ 4 |
+ `----
diff --git a/crates/swc_xml_visit/src/lib.rs b/crates/swc_xml_visit/src/lib.rs
index 3519770cf8e9..d54c5bf90216 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,