From 638892071a8713a278c114aae6fedc74f77a8cc0 Mon Sep 17 00:00:00 2001 From: Alexander Akait <4567934+alexander-akait@users.noreply.github.com> Date: Wed, 16 Nov 2022 07:10:02 +0300 Subject: [PATCH] fix(xml/parser): Fix parsing of pi (#6450) --- crates/swc_xml_codegen/src/lib.rs | 2 - crates/swc_xml_codegen/src/macros.rs | 10 +- .../tests/fixture/base/output.min.xml | 3 +- .../tests/fixture/base/output.xml | 3 +- .../tests/options/indent_type/output.xml | 3 +- crates/swc_xml_parser/src/error.rs | 6 + crates/swc_xml_parser/src/lexer/mod.rs | 68 +- .../tests/fixture/pi/dom.rust-debug | 70 ++ .../swc_xml_parser/tests/fixture/pi/input.xml | 25 + .../tests/fixture/pi/output.json | 472 +++++++++++++ .../tests/fixture/pi/span.rust-debug | 629 ++++++++++++++++++ .../tests/recovery/pi/bad-pi-1/dom.rust-debug | 7 + .../tests/recovery/pi/bad-pi-1/input.xml | 4 + .../tests/recovery/pi/bad-pi-1/output.json | 52 ++ .../tests/recovery/pi/bad-pi-1/output.stderr | 6 + .../recovery/pi/bad-pi-1/span.rust-debug | 62 ++ .../recovery/pi/bad-pi-10/dom.rust-debug | 6 + .../tests/recovery/pi/bad-pi-10/input.xml | 3 + .../tests/recovery/pi/bad-pi-10/output.json | 52 ++ .../tests/recovery/pi/bad-pi-10/output.stderr | 6 + .../recovery/pi/bad-pi-10/span.rust-debug | 59 ++ .../recovery/pi/bad-pi-11/dom.rust-debug | 6 + .../tests/recovery/pi/bad-pi-11/input.xml | 3 + .../tests/recovery/pi/bad-pi-11/output.json | 52 ++ .../tests/recovery/pi/bad-pi-11/output.stderr | 6 + .../recovery/pi/bad-pi-11/span.rust-debug | 59 ++ .../recovery/pi/bad-pi-12/dom.rust-debug | 4 + .../tests/recovery/pi/bad-pi-12/input.xml | 2 + .../tests/recovery/pi/bad-pi-12/output.json | 42 ++ .../tests/recovery/pi/bad-pi-12/output.stderr | 12 + .../recovery/pi/bad-pi-12/span.rust-debug | 42 ++ .../tests/recovery/pi/bad-pi-2/dom.rust-debug | 8 + .../tests/recovery/pi/bad-pi-2/input.xml | 4 + .../tests/recovery/pi/bad-pi-2/output.json | 74 +++ .../tests/recovery/pi/bad-pi-2/output.stderr | 6 + .../recovery/pi/bad-pi-2/span.rust-debug | 84 +++ .../tests/recovery/pi/bad-pi-3/dom.rust-debug | 1 + .../tests/recovery/pi/bad-pi-3/input.xml | 1 + .../tests/recovery/pi/bad-pi-3/output.json | 20 + .../tests/recovery/pi/bad-pi-3/output.stderr | 12 + .../recovery/pi/bad-pi-3/span.rust-debug | 18 + .../tests/recovery/pi/bad-pi-4/dom.rust-debug | 1 + .../tests/recovery/pi/bad-pi-4/input.xml | 1 + .../tests/recovery/pi/bad-pi-4/output.json | 20 + .../tests/recovery/pi/bad-pi-4/output.stderr | 18 + .../recovery/pi/bad-pi-4/span.rust-debug | 18 + .../tests/recovery/pi/bad-pi-5/dom.rust-debug | 6 + .../tests/recovery/pi/bad-pi-5/input.xml | 3 + .../tests/recovery/pi/bad-pi-5/output.json | 52 ++ .../tests/recovery/pi/bad-pi-5/output.stderr | 6 + .../recovery/pi/bad-pi-5/span.rust-debug | 59 ++ .../tests/recovery/pi/bad-pi-6/dom.rust-debug | 1 + .../tests/recovery/pi/bad-pi-6/input.xml | 1 + .../tests/recovery/pi/bad-pi-6/output.json | 20 + .../tests/recovery/pi/bad-pi-6/output.stderr | 18 + .../recovery/pi/bad-pi-6/span.rust-debug | 18 + .../tests/recovery/pi/bad-pi-7/dom.rust-debug | 6 + .../tests/recovery/pi/bad-pi-7/input.xml | 3 + .../tests/recovery/pi/bad-pi-7/output.json | 52 ++ .../tests/recovery/pi/bad-pi-7/output.stderr | 6 + .../recovery/pi/bad-pi-7/span.rust-debug | 59 ++ .../tests/recovery/pi/bad-pi-8/dom.rust-debug | 6 + .../tests/recovery/pi/bad-pi-8/input.xml | 3 + .../tests/recovery/pi/bad-pi-8/output.json | 52 ++ .../tests/recovery/pi/bad-pi-8/output.stderr | 6 + .../recovery/pi/bad-pi-8/span.rust-debug | 59 ++ .../tests/recovery/pi/bad-pi-9/dom.rust-debug | 6 + .../tests/recovery/pi/bad-pi-9/input.xml | 3 + .../tests/recovery/pi/bad-pi-9/output.json | 52 ++ .../tests/recovery/pi/bad-pi-9/output.stderr | 6 + .../recovery/pi/bad-pi-9/span.rust-debug | 59 ++ 71 files changed, 2595 insertions(+), 29 deletions(-) create mode 100644 crates/swc_xml_parser/tests/fixture/pi/dom.rust-debug create mode 100644 crates/swc_xml_parser/tests/fixture/pi/input.xml create mode 100644 crates/swc_xml_parser/tests/fixture/pi/output.json create mode 100644 crates/swc_xml_parser/tests/fixture/pi/span.rust-debug create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-1/dom.rust-debug create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-1/input.xml create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-1/output.json create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-1/output.stderr create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-1/span.rust-debug create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-10/dom.rust-debug create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-10/input.xml create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-10/output.json create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-10/output.stderr create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-10/span.rust-debug create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-11/dom.rust-debug create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-11/input.xml create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-11/output.json create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-11/output.stderr create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-11/span.rust-debug create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-12/dom.rust-debug create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-12/input.xml create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-12/output.json create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-12/output.stderr create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-12/span.rust-debug create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-2/dom.rust-debug create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-2/input.xml create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-2/output.json create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-2/output.stderr create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-2/span.rust-debug create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-3/dom.rust-debug create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-3/input.xml create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-3/output.json create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-3/output.stderr create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-3/span.rust-debug create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-4/dom.rust-debug create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-4/input.xml create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-4/output.json create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-4/output.stderr create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-4/span.rust-debug create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-5/dom.rust-debug create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-5/input.xml create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-5/output.json create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-5/output.stderr create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-5/span.rust-debug create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-6/dom.rust-debug create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-6/input.xml create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-6/output.json create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-6/output.stderr create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-6/span.rust-debug create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-7/dom.rust-debug create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-7/input.xml create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-7/output.json create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-7/output.stderr create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-7/span.rust-debug create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-8/dom.rust-debug create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-8/input.xml create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-8/output.json create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-8/output.stderr create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-8/span.rust-debug create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-9/dom.rust-debug create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-9/input.xml create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-9/output.json create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-9/output.stderr create mode 100644 crates/swc_xml_parser/tests/recovery/pi/bad-pi-9/span.rust-debug diff --git a/crates/swc_xml_codegen/src/lib.rs b/crates/swc_xml_codegen/src/lib.rs index d503f301274..197bf1bde28 100644 --- a/crates/swc_xml_codegen/src/lib.rs +++ b/crates/swc_xml_codegen/src/lib.rs @@ -285,8 +285,6 @@ where processing_instruction.push_str("?>"); write_multiline_raw!(self, n.span, &processing_instruction); - // TODO only for top instructions - newline!(self); } fn create_context_for_element(&self, n: &Element) -> Ctx { diff --git a/crates/swc_xml_codegen/src/macros.rs b/crates/swc_xml_codegen/src/macros.rs index 8abe3e7406e..a0ff38c7880 100644 --- a/crates/swc_xml_codegen/src/macros.rs +++ b/crates/swc_xml_codegen/src/macros.rs @@ -22,11 +22,11 @@ macro_rules! write_multiline_raw { }}; } -macro_rules! newline { - ($g:expr) => {{ - $g.wr.write_newline()?; - }}; -} +// macro_rules! newline { +// ($g:expr) => {{ +// $g.wr.write_newline()?; +// }}; +// } macro_rules! formatting_newline { ($g:expr) => {{ diff --git a/crates/swc_xml_codegen/tests/fixture/base/output.min.xml b/crates/swc_xml_codegen/tests/fixture/base/output.min.xml index 9157c3399b1..48849b439e1 100644 --- a/crates/swc_xml_codegen/tests/fixture/base/output.min.xml +++ b/crates/swc_xml_codegen/tests/fixture/base/output.min.xml @@ -1,5 +1,4 @@ - - + Tove Jani Reminder diff --git a/crates/swc_xml_codegen/tests/fixture/base/output.xml b/crates/swc_xml_codegen/tests/fixture/base/output.xml index 9157c3399b1..48849b439e1 100644 --- a/crates/swc_xml_codegen/tests/fixture/base/output.xml +++ b/crates/swc_xml_codegen/tests/fixture/base/output.xml @@ -1,5 +1,4 @@ - - + Tove Jani Reminder diff --git a/crates/swc_xml_codegen/tests/options/indent_type/output.xml b/crates/swc_xml_codegen/tests/options/indent_type/output.xml index 9157c3399b1..48849b439e1 100644 --- a/crates/swc_xml_codegen/tests/options/indent_type/output.xml +++ b/crates/swc_xml_codegen/tests/options/indent_type/output.xml @@ -1,5 +1,4 @@ - - + Tove Jani Reminder diff --git a/crates/swc_xml_parser/src/error.rs b/crates/swc_xml_parser/src/error.rs index 84af58443af..61dd226ac9c 100644 --- a/crates/swc_xml_parser/src/error.rs +++ b/crates/swc_xml_parser/src/error.rs @@ -91,6 +91,10 @@ impl Error { "Unexpected colon before attribute name".into() } ErrorKind::UnexpectedSolidusInTag => "Unexpected solidus in tag".into(), + ErrorKind::NoTargetNameInProcessingInstruction => "No target name".into(), + ErrorKind::MissingWhitespaceBeforeQuestionInProcessingInstruction => { + "Missing whitespace before '?'".into() + } // Parser errors ErrorKind::UnexpectedTokenInStartPhase => "Unexpected token in start phase".into(), @@ -152,6 +156,8 @@ pub enum ErrorKind { UnexpectedCharacterAfterDoctypeSystemIdentifier, UnexpectedColonBeforeAttributeName, UnexpectedSolidusInTag, + NoTargetNameInProcessingInstruction, + MissingWhitespaceBeforeQuestionInProcessingInstruction, // Parser errors UnexpectedTokenInStartPhase, diff --git a/crates/swc_xml_parser/src/lexer/mod.rs b/crates/swc_xml_parser/src/lexer/mod.rs index 4b0cee8ca4c..997cca46b05 100644 --- a/crates/swc_xml_parser/src/lexer/mod.rs +++ b/crates/swc_xml_parser/src/lexer/mod.rs @@ -19,9 +19,10 @@ pub enum State { EndTagNameAfter, Pi, PiTarget, + PiTargetQuestion, PiTargetAfter, PiData, - PiAfter, + PiEnd, MarkupDeclaration, CommentStart, CommentStartDash, @@ -1166,15 +1167,26 @@ where // U+000A LINE FEED (LF) // U+0020 SPACE // EOF - // Parse error. Reprocess the current input character in the bogus comment - // state. + // Parse error. + // Switch to the pi target after state. Some(c) if is_spacy_except_ff(c) => { self.emit_error(ErrorKind::InvalidCharacterOfProcessingInstruction); - self.reconsume_in_state(State::BogusComment); + self.create_processing_instruction_token(); + self.state = State::PiTargetAfter; } None => { - self.emit_error(ErrorKind::EofInTag); - self.reconsume_in_state(State::BogusComment); + self.emit_error(ErrorKind::EofInProcessingInstruction); + self.create_processing_instruction_token(); + self.emit_current_processing_instruction(); + self.reconsume_in_state(State::Data); + } + // U+003F QUESTION MARK(?) + // Emit error + // Reprocess the current input character in the pi end state (recovery mode). + Some('?') => { + self.emit_error(ErrorKind::NoTargetNameInProcessingInstruction); + self.create_processing_instruction_token(); + self.state = State::PiEnd; } Some(c) => { self.validate_input_stream_character(c); @@ -1190,7 +1202,7 @@ where // U+0009 CHARACTER TABULATION (tab) // U+000A LINE FEED (LF) // U+0020 SPACE - // Switch to the before attribute name state. + // Switch to the pi target state. Some(c) if is_spacy_except_ff(c) => { self.state = State::PiTargetAfter; } @@ -1203,9 +1215,9 @@ where self.reconsume_in_state(State::Data); } // U+003F QUESTION MARK(?) - // Switch to the pi after state. + // Switch to the pi target question. Some('?') => { - self.state = State::PiAfter; + self.state = State::PiTargetQuestion; } // Anything else // Append the current input character to the processing instruction target and @@ -1216,6 +1228,27 @@ where } } } + State::PiTargetQuestion => { + // Consume the next input character: + match self.consume_next_char() { + // U+003E GREATER-THAN SIGN (>) + Some('>') => { + self.reconsume_in_state(State::PiEnd); + } + _ => { + self.errors.push(Error::new( + Span::new( + self.cur_pos - BytePos(1), + self.input.cur_pos() - BytePos(1), + Default::default(), + ), + ErrorKind::MissingWhitespaceBeforeQuestionInProcessingInstruction, + )); + self.set_processing_instruction_token(None, Some('?')); + self.reconsume_in_state(State::PiData); + } + } + } State::PiTargetAfter => { // Consume the next input character: match self.consume_next_char() { @@ -1239,7 +1272,7 @@ where // U+003F QUESTION MARK(?) // Switch to the pi after state. Some('?') => { - self.state = State::PiAfter; + self.state = State::PiEnd; } // EOF // Parse error. Emit the current processing instruction token and then reprocess @@ -1258,7 +1291,7 @@ where } } } - State::PiAfter => { + State::PiEnd => { // Consume the next input character: match self.consume_next_char() { // U+003E GREATER-THAN SIGN (>) @@ -1267,15 +1300,18 @@ where self.emit_current_processing_instruction(); self.state = State::Data; } - // U+003F QUESTION MARK(?) - // Append the current input character to the PI’s data and stay in the current - // state. - Some(c @ '?') => { - self.set_processing_instruction_token(None, Some(c)); + // EOF + // Parse error. Emit the current processing instruction token and then reprocess + // the current input character in the data state. + None => { + self.emit_error(ErrorKind::EofInProcessingInstruction); + self.emit_current_processing_instruction(); + self.reconsume_in_state(State::Data); } // Anything else // Reprocess the current input character in the pi data state. _ => { + self.set_processing_instruction_token(None, Some('?')); self.reconsume_in_state(State::PiData); } } diff --git a/crates/swc_xml_parser/tests/fixture/pi/dom.rust-debug b/crates/swc_xml_parser/tests/fixture/pi/dom.rust-debug new file mode 100644 index 00000000000..873c342af68 --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/pi/dom.rust-debug @@ -0,0 +1,70 @@ +| +| " + " + +| " + " + +| " + " + +| " + " + +| " + " + +| " + " + +| " + " + +| " + " + +| " + " + +| " + " + +| " + " + +| " + " + +| " + " + +| " + " + +| " + " + +| " + " + +| " + " + +| " + " + +| " + " + +| " + " + +| " + " + +| " + " + +| " +" diff --git a/crates/swc_xml_parser/tests/fixture/pi/input.xml b/crates/swc_xml_parser/tests/fixture/pi/input.xml new file mode 100644 index 00000000000..7421f4f2e8c --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/pi/input.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/crates/swc_xml_parser/tests/fixture/pi/output.json b/crates/swc_xml_parser/tests/fixture/pi/output.json new file mode 100644 index 00000000000..61cb155dd95 --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/pi/output.json @@ -0,0 +1,472 @@ +{ + "type": "Document", + "span": { + "start": 1, + "end": 648, + "ctxt": 0 + }, + "children": [ + { + "type": "Element", + "span": { + "start": 1, + "end": 648, + "ctxt": 0 + }, + "tagName": "root", + "attributes": [], + "children": [ + { + "type": "Text", + "span": { + "start": 7, + "end": 12, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "ProcessingInstruction", + "span": { + "start": 12, + "end": 23, + "ctxt": 0 + }, + "target": "xslt", + "data": "ma" + }, + { + "type": "Text", + "span": { + "start": 23, + "end": 28, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "ProcessingInstruction", + "span": { + "start": 28, + "end": 50, + "ctxt": 0 + }, + "target": "xslt\n", + "data": "m" + }, + { + "type": "Text", + "span": { + "start": 50, + "end": 55, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "ProcessingInstruction", + "span": { + "start": 55, + "end": 63, + "ctxt": 0 + }, + "target": "xslt", + "data": "" + }, + { + "type": "Text", + "span": { + "start": 63, + "end": 68, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "ProcessingInstruction", + "span": { + "start": 68, + "end": 77, + "ctxt": 0 + }, + "target": "xslt", + "data": "" + }, + { + "type": "Text", + "span": { + "start": 77, + "end": 82, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "ProcessingInstruction", + "span": { + "start": 82, + "end": 100, + "ctxt": 0 + }, + "target": "xml-stylesheet", + "data": "" + }, + { + "type": "Text", + "span": { + "start": 100, + "end": 105, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "ProcessingInstruction", + "span": { + "start": 105, + "end": 126, + "ctxt": 0 + }, + "target": "foo", + "data": "version=\"1.0\"" + }, + { + "type": "Text", + "span": { + "start": 126, + "end": 131, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "ProcessingInstruction", + "span": { + "start": 131, + "end": 152, + "ctxt": 0 + }, + "target": "foo", + "data": "version='1.0'" + }, + { + "type": "Text", + "span": { + "start": 152, + "end": 157, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "ProcessingInstruction", + "span": { + "start": 157, + "end": 195, + "ctxt": 0 + }, + "target": "foo", + "data": "version='1.0' encoding=\"UTF-8\"" + }, + { + "type": "Text", + "span": { + "start": 195, + "end": 200, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "ProcessingInstruction", + "span": { + "start": 200, + "end": 238, + "ctxt": 0 + }, + "target": "foo", + "data": "version='1.0' encoding='UTF-8'" + }, + { + "type": "Text", + "span": { + "start": 238, + "end": 243, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "ProcessingInstruction", + "span": { + "start": 243, + "end": 281, + "ctxt": 0 + }, + "target": "foo", + "data": "version='1.0' encoding='utf-8'" + }, + { + "type": "Text", + "span": { + "start": 281, + "end": 286, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "ProcessingInstruction", + "span": { + "start": 286, + "end": 325, + "ctxt": 0 + }, + "target": "foo", + "data": "version='1.0' encoding='EUC-JP'" + }, + { + "type": "Text", + "span": { + "start": 325, + "end": 330, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "ProcessingInstruction", + "span": { + "start": 330, + "end": 385, + "ctxt": 0 + }, + "target": "foo", + "data": "version='1.0' encoding='UTF-8' standalone='yes'" + }, + { + "type": "Text", + "span": { + "start": 385, + "end": 390, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "ProcessingInstruction", + "span": { + "start": 390, + "end": 444, + "ctxt": 0 + }, + "target": "foo", + "data": "version='1.0' encoding='UTF-8' standalone='no'" + }, + { + "type": "Text", + "span": { + "start": 444, + "end": 449, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "ProcessingInstruction", + "span": { + "start": 449, + "end": 486, + "ctxt": 0 + }, + "target": "foo", + "data": "version='1.0' standalone='no'" + }, + { + "type": "Text", + "span": { + "start": 486, + "end": 491, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "ProcessingInstruction", + "span": { + "start": 491, + "end": 529, + "ctxt": 0 + }, + "target": "foo", + "data": "version='1.0' standalone='no' " + }, + { + "type": "Text", + "span": { + "start": 529, + "end": 534, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "ProcessingInstruction", + "span": { + "start": 534, + "end": 541, + "ctxt": 0 + }, + "target": "foo", + "data": "" + }, + { + "type": "Text", + "span": { + "start": 541, + "end": 546, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "ProcessingInstruction", + "span": { + "start": 546, + "end": 555, + "ctxt": 0 + }, + "target": "f", + "data": "?oo" + }, + { + "type": "Text", + "span": { + "start": 555, + "end": 560, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "ProcessingInstruction", + "span": { + "start": 560, + "end": 570, + "ctxt": 0 + }, + "target": "f", + "data": "?oo?" + }, + { + "type": "Text", + "span": { + "start": 570, + "end": 575, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "ProcessingInstruction", + "span": { + "start": 575, + "end": 586, + "ctxt": 0 + }, + "target": "f", + "data": "?????" + }, + { + "type": "Text", + "span": { + "start": 586, + "end": 591, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "ProcessingInstruction", + "span": { + "start": 591, + "end": 604, + "ctxt": 0 + }, + "target": "test", + "data": "aaa " + }, + { + "type": "Text", + "span": { + "start": 604, + "end": 609, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "ProcessingInstruction", + "span": { + "start": 609, + "end": 620, + "ctxt": 0 + }, + "target": "test", + "data": "? " + }, + { + "type": "Text", + "span": { + "start": 620, + "end": 625, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "ProcessingInstruction", + "span": { + "start": 625, + "end": 640, + "ctxt": 0 + }, + "target": "test", + "data": "a a a " + }, + { + "type": "Text", + "span": { + "start": 640, + "end": 641, + "ctxt": 0 + }, + "data": "\n", + "raw": "\n" + } + ] + } + ] +} diff --git a/crates/swc_xml_parser/tests/fixture/pi/span.rust-debug b/crates/swc_xml_parser/tests/fixture/pi/span.rust-debug new file mode 100644 index 00000000000..9530927c5db --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/pi/span.rust-debug @@ -0,0 +1,629 @@ + + x Document + ,-[$DIR/tests/fixture/pi/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | | + 5 | | + 6 | | + 7 | | + 8 | | + 9 | | + 10 | | + 11 | | + 12 | | + 13 | | + 14 | | + 15 | | + 16 | | + 17 | | + 18 | | + 19 | | + 20 | | + 21 | | + 22 | | + 23 | | + 24 | | + 25 | `-> + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | | + 5 | | + 6 | | + 7 | | + 8 | | + 9 | | + 10 | | + 11 | | + 12 | | + 13 | | + 14 | | + 15 | | + 16 | | + 17 | | + 18 | | + 19 | | + 20 | | + 21 | | + 22 | | + 23 | | + 24 | | + 25 | `-> + `---- + + x Element + ,-[$DIR/tests/fixture/pi/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | | + 5 | | + 6 | | + 7 | | + 8 | | + 9 | | + 10 | | + 11 | | + 12 | | + 13 | | + 14 | | + 15 | | + 16 | | + 17 | | + 18 | | + 19 | | + 20 | | + 21 | | + 22 | | + 23 | | + 24 | | + 25 | `-> + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:1:1] + 1 | ,-> + 2 | `-> + `---- + + x Text + ,-[$DIR/tests/fixture/pi/input.xml:1:1] + 1 | ,-> + 2 | `-> + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:2:5] + 2 | + : ^^^^^^^^^^^ + `---- + + x ProcessingInstruction + ,-[$DIR/tests/fixture/pi/input.xml:2:5] + 2 | + : ^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:2:5] + 2 | ,-> + 3 | `-> + 3 | `-> m?> + `---- + + x ProcessingInstruction + ,-[$DIR/tests/fixture/pi/input.xml:3:5] + 3 | ,-> m?> + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:4:13] + 4 | ,-> m?> + 5 | `-> + `---- + + x Text + ,-[$DIR/tests/fixture/pi/input.xml:4:13] + 4 | ,-> m?> + 5 | `-> + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:5:5] + 5 | + : ^^^^^^^^ + `---- + + x ProcessingInstruction + ,-[$DIR/tests/fixture/pi/input.xml:5:5] + 5 | + : ^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:5:5] + 5 | ,-> + 6 | `-> + `---- + + x Text + ,-[$DIR/tests/fixture/pi/input.xml:5:5] + 5 | ,-> + 6 | `-> + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:6:5] + 6 | + : ^^^^^^^^^ + `---- + + x ProcessingInstruction + ,-[$DIR/tests/fixture/pi/input.xml:6:5] + 6 | + : ^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:6:5] + 6 | ,-> + 7 | `-> + `---- + + x Text + ,-[$DIR/tests/fixture/pi/input.xml:6:5] + 6 | ,-> + 7 | `-> + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:7:5] + 7 | + : ^^^^^^^^^^^^^^^^^^ + `---- + + x ProcessingInstruction + ,-[$DIR/tests/fixture/pi/input.xml:7:5] + 7 | + : ^^^^^^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:7:5] + 7 | ,-> + 8 | `-> + `---- + + x Text + ,-[$DIR/tests/fixture/pi/input.xml:7:5] + 7 | ,-> + 8 | `-> + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:8:5] + 8 | + : ^^^^^^^^^^^^^^^^^^^^^ + `---- + + x ProcessingInstruction + ,-[$DIR/tests/fixture/pi/input.xml:8:5] + 8 | + : ^^^^^^^^^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:8:5] + 8 | ,-> + 9 | `-> + `---- + + x Text + ,-[$DIR/tests/fixture/pi/input.xml:8:5] + 8 | ,-> + 9 | `-> + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:9:5] + 9 | + : ^^^^^^^^^^^^^^^^^^^^^ + `---- + + x ProcessingInstruction + ,-[$DIR/tests/fixture/pi/input.xml:9:5] + 9 | + : ^^^^^^^^^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:9:5] + 9 | ,-> + 10 | `-> + `---- + + x Text + ,-[$DIR/tests/fixture/pi/input.xml:9:5] + 9 | ,-> + 10 | `-> + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:10:5] + 10 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + `---- + + x ProcessingInstruction + ,-[$DIR/tests/fixture/pi/input.xml:10:5] + 10 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:10:5] + 10 | ,-> + 11 | `-> + `---- + + x Text + ,-[$DIR/tests/fixture/pi/input.xml:10:5] + 10 | ,-> + 11 | `-> + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:11:5] + 11 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + `---- + + x ProcessingInstruction + ,-[$DIR/tests/fixture/pi/input.xml:11:5] + 11 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:11:5] + 11 | ,-> + 12 | `-> + `---- + + x Text + ,-[$DIR/tests/fixture/pi/input.xml:11:5] + 11 | ,-> + 12 | `-> + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:12:5] + 12 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + `---- + + x ProcessingInstruction + ,-[$DIR/tests/fixture/pi/input.xml:12:5] + 12 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:12:5] + 12 | ,-> + 13 | `-> + `---- + + x Text + ,-[$DIR/tests/fixture/pi/input.xml:12:5] + 12 | ,-> + 13 | `-> + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:13:5] + 13 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + `---- + + x ProcessingInstruction + ,-[$DIR/tests/fixture/pi/input.xml:13:5] + 13 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:13:5] + 13 | ,-> + 14 | `-> + `---- + + x Text + ,-[$DIR/tests/fixture/pi/input.xml:13:5] + 13 | ,-> + 14 | `-> + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:14:5] + 14 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + `---- + + x ProcessingInstruction + ,-[$DIR/tests/fixture/pi/input.xml:14:5] + 14 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:14:5] + 14 | ,-> + 15 | `-> + `---- + + x Text + ,-[$DIR/tests/fixture/pi/input.xml:14:5] + 14 | ,-> + 15 | `-> + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:15:5] + 15 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + `---- + + x ProcessingInstruction + ,-[$DIR/tests/fixture/pi/input.xml:15:5] + 15 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:15:5] + 15 | ,-> + 16 | `-> + `---- + + x Text + ,-[$DIR/tests/fixture/pi/input.xml:15:5] + 15 | ,-> + 16 | `-> + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:16:5] + 16 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + `---- + + x ProcessingInstruction + ,-[$DIR/tests/fixture/pi/input.xml:16:5] + 16 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:16:5] + 16 | ,-> + 17 | `-> + `---- + + x Text + ,-[$DIR/tests/fixture/pi/input.xml:16:5] + 16 | ,-> + 17 | `-> + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:17:5] + 17 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + `---- + + x ProcessingInstruction + ,-[$DIR/tests/fixture/pi/input.xml:17:5] + 17 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:17:5] + 17 | ,-> + 18 | `-> + `---- + + x Text + ,-[$DIR/tests/fixture/pi/input.xml:17:5] + 17 | ,-> + 18 | `-> + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:18:5] + 18 | + : ^^^^^^^ + `---- + + x ProcessingInstruction + ,-[$DIR/tests/fixture/pi/input.xml:18:5] + 18 | + : ^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:18:5] + 18 | ,-> + 19 | `-> + `---- + + x Text + ,-[$DIR/tests/fixture/pi/input.xml:18:5] + 18 | ,-> + 19 | `-> + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:19:5] + 19 | + : ^^^^^^^^^ + `---- + + x ProcessingInstruction + ,-[$DIR/tests/fixture/pi/input.xml:19:5] + 19 | + : ^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:19:5] + 19 | ,-> + 20 | `-> + `---- + + x Text + ,-[$DIR/tests/fixture/pi/input.xml:19:5] + 19 | ,-> + 20 | `-> + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:20:5] + 20 | + : ^^^^^^^^^^ + `---- + + x ProcessingInstruction + ,-[$DIR/tests/fixture/pi/input.xml:20:5] + 20 | + : ^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:20:5] + 20 | ,-> + 21 | `-> + `---- + + x Text + ,-[$DIR/tests/fixture/pi/input.xml:20:5] + 20 | ,-> + 21 | `-> + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:21:5] + 21 | + : ^^^^^^^^^^^ + `---- + + x ProcessingInstruction + ,-[$DIR/tests/fixture/pi/input.xml:21:5] + 21 | + : ^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:21:5] + 21 | ,-> + 22 | `-> + `---- + + x Text + ,-[$DIR/tests/fixture/pi/input.xml:21:5] + 21 | ,-> + 22 | `-> + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:22:5] + 22 | + : ^^^^^^^^^^^^^ + `---- + + x ProcessingInstruction + ,-[$DIR/tests/fixture/pi/input.xml:22:5] + 22 | + : ^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:22:5] + 22 | ,-> + 23 | `-> + `---- + + x Text + ,-[$DIR/tests/fixture/pi/input.xml:22:5] + 22 | ,-> + 23 | `-> + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:23:5] + 23 | + : ^^^^^^^^^^^ + `---- + + x ProcessingInstruction + ,-[$DIR/tests/fixture/pi/input.xml:23:5] + 23 | + : ^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:23:5] + 23 | ,-> + 24 | `-> + `---- + + x Text + ,-[$DIR/tests/fixture/pi/input.xml:23:5] + 23 | ,-> + 24 | `-> + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:24:5] + 24 | + : ^^^^^^^^^^^^^^^ + `---- + + x ProcessingInstruction + ,-[$DIR/tests/fixture/pi/input.xml:24:5] + 24 | + : ^^^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:24:5] + 24 | + : ^ + 25 | + `---- + + x Text + ,-[$DIR/tests/fixture/pi/input.xml:24:5] + 24 | + : ^ + 25 | + `---- diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-1/dom.rust-debug b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-1/dom.rust-debug new file mode 100644 index 00000000000..db9f00c1b77 --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-1/dom.rust-debug @@ -0,0 +1,7 @@ +| +| " + " + +| " +" diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-1/input.xml b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-1/input.xml new file mode 100644 index 00000000000..869339006ec --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-1/input.xml @@ -0,0 +1,4 @@ + + + \ No newline at end of file diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-1/output.json b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-1/output.json new file mode 100644 index 00000000000..5412dda66de --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-1/output.json @@ -0,0 +1,52 @@ +{ + "type": "Document", + "span": { + "start": 1, + "end": 34, + "ctxt": 0 + }, + "children": [ + { + "type": "Element", + "span": { + "start": 1, + "end": 34, + "ctxt": 0 + }, + "tagName": "root", + "attributes": [], + "children": [ + { + "type": "Text", + "span": { + "start": 7, + "end": 12, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "ProcessingInstruction", + "span": { + "start": 12, + "end": 26, + "ctxt": 0 + }, + "target": "", + "data": "?xml\n m" + }, + { + "type": "Text", + "span": { + "start": 26, + "end": 27, + "ctxt": 0 + }, + "data": "\n", + "raw": "\n" + } + ] + } + ] +} diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-1/output.stderr b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-1/output.stderr new file mode 100644 index 00000000000..f2638694ee2 --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-1/output.stderr @@ -0,0 +1,6 @@ + + x No target name + ,-[$DIR/tests/recovery/pi/bad-pi-1/input.xml:2:5] + 2 | + 2 | | + 4 | `-> + `---- + + x Child + ,-[$DIR/tests/recovery/pi/bad-pi-1/input.xml:1:1] + 1 | ,-> + 2 | | + 4 | `-> + `---- + + x Element + ,-[$DIR/tests/recovery/pi/bad-pi-1/input.xml:1:1] + 1 | ,-> + 2 | | + 4 | `-> + `---- + + x Child + ,-[$DIR/tests/recovery/pi/bad-pi-1/input.xml:1:1] + 1 | ,-> + 2 | `-> + 2 | `-> m?> + `---- + + x ProcessingInstruction + ,-[$DIR/tests/recovery/pi/bad-pi-1/input.xml:2:5] + 2 | ,-> m?> + `---- + + x Child + ,-[$DIR/tests/recovery/pi/bad-pi-1/input.xml:3:5] + 3 | m?> + : ^ + 4 | + `---- + + x Text + ,-[$DIR/tests/recovery/pi/bad-pi-1/input.xml:3:5] + 3 | m?> + : ^ + 4 | + `---- diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-10/dom.rust-debug b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-10/dom.rust-debug new file mode 100644 index 00000000000..8a4757fa75e --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-10/dom.rust-debug @@ -0,0 +1,6 @@ +| +| " + " + +| " +" diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-10/input.xml b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-10/input.xml new file mode 100644 index 00000000000..10145bf44fe --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-10/input.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-10/output.json b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-10/output.json new file mode 100644 index 00000000000..b21cc54ac70 --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-10/output.json @@ -0,0 +1,52 @@ +{ + "type": "Document", + "span": { + "start": 1, + "end": 28, + "ctxt": 0 + }, + "children": [ + { + "type": "Element", + "span": { + "start": 1, + "end": 28, + "ctxt": 0 + }, + "tagName": "root", + "attributes": [], + "children": [ + { + "type": "Text", + "span": { + "start": 7, + "end": 12, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "ProcessingInstruction", + "span": { + "start": 12, + "end": 20, + "ctxt": 0 + }, + "target": "foo", + "data": "?" + }, + { + "type": "Text", + "span": { + "start": 20, + "end": 21, + "ctxt": 0 + }, + "data": "\n", + "raw": "\n" + } + ] + } + ] +} diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-10/output.stderr b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-10/output.stderr new file mode 100644 index 00000000000..09d8b73d31d --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-10/output.stderr @@ -0,0 +1,6 @@ + + x Missing whitespace before '?' + ,-[$DIR/tests/recovery/pi/bad-pi-10/input.xml:2:5] + 2 | + : ^ + `---- diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-10/span.rust-debug b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-10/span.rust-debug new file mode 100644 index 00000000000..86258404c48 --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-10/span.rust-debug @@ -0,0 +1,59 @@ + + x Document + ,-[$DIR/tests/recovery/pi/bad-pi-10/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | `-> + `---- + + x Child + ,-[$DIR/tests/recovery/pi/bad-pi-10/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | `-> + `---- + + x Element + ,-[$DIR/tests/recovery/pi/bad-pi-10/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | `-> + `---- + + x Child + ,-[$DIR/tests/recovery/pi/bad-pi-10/input.xml:1:1] + 1 | ,-> + 2 | `-> + `---- + + x Text + ,-[$DIR/tests/recovery/pi/bad-pi-10/input.xml:1:1] + 1 | ,-> + 2 | `-> + `---- + + x Child + ,-[$DIR/tests/recovery/pi/bad-pi-10/input.xml:2:5] + 2 | + : ^^^^^^^^ + `---- + + x ProcessingInstruction + ,-[$DIR/tests/recovery/pi/bad-pi-10/input.xml:2:5] + 2 | + : ^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/recovery/pi/bad-pi-10/input.xml:2:5] + 2 | + : ^ + 3 | + `---- + + x Text + ,-[$DIR/tests/recovery/pi/bad-pi-10/input.xml:2:5] + 2 | + : ^ + 3 | + `---- diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-11/dom.rust-debug b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-11/dom.rust-debug new file mode 100644 index 00000000000..1d5727a6d64 --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-11/dom.rust-debug @@ -0,0 +1,6 @@ +| +| " + " + +| " +" diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-11/input.xml b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-11/input.xml new file mode 100644 index 00000000000..d8543a2a2eb --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-11/input.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-11/output.json b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-11/output.json new file mode 100644 index 00000000000..1efc4cf2e5e --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-11/output.json @@ -0,0 +1,52 @@ +{ + "type": "Document", + "span": { + "start": 1, + "end": 33, + "ctxt": 0 + }, + "children": [ + { + "type": "Element", + "span": { + "start": 1, + "end": 33, + "ctxt": 0 + }, + "tagName": "root", + "attributes": [], + "children": [ + { + "type": "Text", + "span": { + "start": 7, + "end": 12, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "ProcessingInstruction", + "span": { + "start": 12, + "end": 25, + "ctxt": 0 + }, + "target": "", + "data": "?test?" + }, + { + "type": "Text", + "span": { + "start": 25, + "end": 26, + "ctxt": 0 + }, + "data": "\n", + "raw": "\n" + } + ] + } + ] +} diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-11/output.stderr b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-11/output.stderr new file mode 100644 index 00000000000..09841a2e86a --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-11/output.stderr @@ -0,0 +1,6 @@ + + x Invalid character of processing instruction + ,-[$DIR/tests/recovery/pi/bad-pi-11/input.xml:2:5] + 2 | + : ^ + `---- diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-11/span.rust-debug b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-11/span.rust-debug new file mode 100644 index 00000000000..b3907b0e61c --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-11/span.rust-debug @@ -0,0 +1,59 @@ + + x Document + ,-[$DIR/tests/recovery/pi/bad-pi-11/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | `-> + `---- + + x Child + ,-[$DIR/tests/recovery/pi/bad-pi-11/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | `-> + `---- + + x Element + ,-[$DIR/tests/recovery/pi/bad-pi-11/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | `-> + `---- + + x Child + ,-[$DIR/tests/recovery/pi/bad-pi-11/input.xml:1:1] + 1 | ,-> + 2 | `-> + `---- + + x Text + ,-[$DIR/tests/recovery/pi/bad-pi-11/input.xml:1:1] + 1 | ,-> + 2 | `-> + `---- + + x Child + ,-[$DIR/tests/recovery/pi/bad-pi-11/input.xml:2:5] + 2 | + : ^^^^^^^^^^^^^ + `---- + + x ProcessingInstruction + ,-[$DIR/tests/recovery/pi/bad-pi-11/input.xml:2:5] + 2 | + : ^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/recovery/pi/bad-pi-11/input.xml:2:5] + 2 | + : ^ + 3 | + `---- + + x Text + ,-[$DIR/tests/recovery/pi/bad-pi-11/input.xml:2:5] + 2 | + : ^ + 3 | + `---- diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-12/dom.rust-debug b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-12/dom.rust-debug new file mode 100644 index 00000000000..896e45622c4 --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-12/dom.rust-debug @@ -0,0 +1,4 @@ +| +| " + " + diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-12/input.xml b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-12/input.xml new file mode 100644 index 00000000000..1b8c814d1ff --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-12/input.xml @@ -0,0 +1,2 @@ + + + 2 | `-> + : ^^^^^^ + `---- + + x Element + ,-[$DIR/tests/recovery/pi/bad-pi-12/input.xml:1:1] + 1 | + : ^^^^^^ + `---- + + x Child + ,-[$DIR/tests/recovery/pi/bad-pi-12/input.xml:1:1] + 1 | ,-> + 2 | `-> + 2 | `-> +| +| " + " +| + +| " +" diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-2/input.xml b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-2/input.xml new file mode 100644 index 00000000000..11758283fff --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-2/input.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-2/output.json b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-2/output.json new file mode 100644 index 00000000000..5d94b90f3b0 --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-2/output.json @@ -0,0 +1,74 @@ +{ + "type": "Document", + "span": { + "start": 1, + "end": 77, + "ctxt": 0 + }, + "children": [ + { + "type": "ProcessingInstruction", + "span": { + "start": 1, + "end": 38, + "ctxt": 0 + }, + "target": "xml", + "data": "version='1.0'encoding='UTF-8'" + }, + { + "type": "Element", + "span": { + "start": 39, + "end": 77, + "ctxt": 0 + }, + "tagName": "root", + "attributes": [], + "children": [ + { + "type": "Text", + "span": { + "start": 45, + "end": 50, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 50, + "end": 69, + "ctxt": 0 + }, + "tagName": "foo", + "attributes": [], + "children": [ + { + "type": "ProcessingInstruction", + "span": { + "start": 55, + "end": 63, + "ctxt": 0 + }, + "target": "", + "data": "foo" + } + ] + }, + { + "type": "Text", + "span": { + "start": 69, + "end": 70, + "ctxt": 0 + }, + "data": "\n", + "raw": "\n" + } + ] + } + ] +} diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-2/output.stderr b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-2/output.stderr new file mode 100644 index 00000000000..cb6e24062d8 --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-2/output.stderr @@ -0,0 +1,6 @@ + + x Invalid character of processing instruction + ,-[$DIR/tests/recovery/pi/bad-pi-2/input.xml:3:5] + 3 | + : ^ + `---- diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-2/span.rust-debug b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-2/span.rust-debug new file mode 100644 index 00000000000..56d99507f92 --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-2/span.rust-debug @@ -0,0 +1,84 @@ + + x Document + ,-[$DIR/tests/recovery/pi/bad-pi-2/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | | + 4 | `-> + `---- + + x Child + ,-[$DIR/tests/recovery/pi/bad-pi-2/input.xml:1:1] + 1 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + `---- + + x ProcessingInstruction + ,-[$DIR/tests/recovery/pi/bad-pi-2/input.xml:1:1] + 1 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/recovery/pi/bad-pi-2/input.xml:2:1] + 2 | ,-> + 3 | | + 4 | `-> + `---- + + x Element + ,-[$DIR/tests/recovery/pi/bad-pi-2/input.xml:2:1] + 2 | ,-> + 3 | | + 4 | `-> + `---- + + x Child + ,-[$DIR/tests/recovery/pi/bad-pi-2/input.xml:2:1] + 2 | ,-> + 3 | `-> + `---- + + x Text + ,-[$DIR/tests/recovery/pi/bad-pi-2/input.xml:2:1] + 2 | ,-> + 3 | `-> + `---- + + x Child + ,-[$DIR/tests/recovery/pi/bad-pi-2/input.xml:3:5] + 3 | + : ^^^^^^^^^^^^^^^^^^^ + `---- + + x Element + ,-[$DIR/tests/recovery/pi/bad-pi-2/input.xml:3:5] + 3 | + : ^^^^^^^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/recovery/pi/bad-pi-2/input.xml:3:5] + 3 | + : ^^^^^^^^ + `---- + + x ProcessingInstruction + ,-[$DIR/tests/recovery/pi/bad-pi-2/input.xml:3:5] + 3 | + : ^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/recovery/pi/bad-pi-2/input.xml:3:5] + 3 | + : ^ + 4 | + `---- + + x Text + ,-[$DIR/tests/recovery/pi/bad-pi-2/input.xml:3:5] + 3 | + : ^ + 4 | + `---- diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-3/dom.rust-debug b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-3/dom.rust-debug new file mode 100644 index 00000000000..a35fd3e9c0d --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-3/dom.rust-debug @@ -0,0 +1 @@ + diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-3/input.xml b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-3/input.xml new file mode 100644 index 00000000000..62c114014ee --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-3/input.xml @@ -0,0 +1 @@ + diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-4/input.xml b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-4/input.xml new file mode 100644 index 00000000000..c55f05eacb0 --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-4/input.xml @@ -0,0 +1 @@ + +| " + " + +| " +" diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-5/input.xml b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-5/input.xml new file mode 100644 index 00000000000..3f33613ed42 --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-5/input.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-5/output.json b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-5/output.json new file mode 100644 index 00000000000..522862d1b03 --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-5/output.json @@ -0,0 +1,52 @@ +{ + "type": "Document", + "span": { + "start": 1, + "end": 28, + "ctxt": 0 + }, + "children": [ + { + "type": "Element", + "span": { + "start": 1, + "end": 28, + "ctxt": 0 + }, + "tagName": "root", + "attributes": [], + "children": [ + { + "type": "Text", + "span": { + "start": 7, + "end": 12, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "ProcessingInstruction", + "span": { + "start": 12, + "end": 20, + "ctxt": 0 + }, + "target": "fo", + "data": "?o" + }, + { + "type": "Text", + "span": { + "start": 20, + "end": 21, + "ctxt": 0 + }, + "data": "\n", + "raw": "\n" + } + ] + } + ] +} diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-5/output.stderr b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-5/output.stderr new file mode 100644 index 00000000000..63a76b71b8c --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-5/output.stderr @@ -0,0 +1,6 @@ + + x Missing whitespace before '?' + ,-[$DIR/tests/recovery/pi/bad-pi-5/input.xml:2:5] + 2 | + : ^ + `---- diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-5/span.rust-debug b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-5/span.rust-debug new file mode 100644 index 00000000000..f80bbc21110 --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-5/span.rust-debug @@ -0,0 +1,59 @@ + + x Document + ,-[$DIR/tests/recovery/pi/bad-pi-5/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | `-> + `---- + + x Child + ,-[$DIR/tests/recovery/pi/bad-pi-5/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | `-> + `---- + + x Element + ,-[$DIR/tests/recovery/pi/bad-pi-5/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | `-> + `---- + + x Child + ,-[$DIR/tests/recovery/pi/bad-pi-5/input.xml:1:1] + 1 | ,-> + 2 | `-> + `---- + + x Text + ,-[$DIR/tests/recovery/pi/bad-pi-5/input.xml:1:1] + 1 | ,-> + 2 | `-> + `---- + + x Child + ,-[$DIR/tests/recovery/pi/bad-pi-5/input.xml:2:5] + 2 | + : ^^^^^^^^ + `---- + + x ProcessingInstruction + ,-[$DIR/tests/recovery/pi/bad-pi-5/input.xml:2:5] + 2 | + : ^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/recovery/pi/bad-pi-5/input.xml:2:5] + 2 | + : ^ + 3 | + `---- + + x Text + ,-[$DIR/tests/recovery/pi/bad-pi-5/input.xml:2:5] + 2 | + : ^ + 3 | + `---- diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-6/dom.rust-debug b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-6/dom.rust-debug new file mode 100644 index 00000000000..e5ae4616d94 --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-6/dom.rust-debug @@ -0,0 +1 @@ + diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-6/input.xml b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-6/input.xml new file mode 100644 index 00000000000..c55f05eacb0 --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-6/input.xml @@ -0,0 +1 @@ + +| " + " + +| " +" diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-7/input.xml b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-7/input.xml new file mode 100644 index 00000000000..2c6fa981a4b --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-7/input.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-7/output.json b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-7/output.json new file mode 100644 index 00000000000..affe56f8d23 --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-7/output.json @@ -0,0 +1,52 @@ +{ + "type": "Document", + "span": { + "start": 1, + "end": 29, + "ctxt": 0 + }, + "children": [ + { + "type": "Element", + "span": { + "start": 1, + "end": 29, + "ctxt": 0 + }, + "tagName": "root", + "attributes": [], + "children": [ + { + "type": "Text", + "span": { + "start": 7, + "end": 12, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "ProcessingInstruction", + "span": { + "start": 12, + "end": 21, + "ctxt": 0 + }, + "target": "", + "data": "?foo?" + }, + { + "type": "Text", + "span": { + "start": 21, + "end": 22, + "ctxt": 0 + }, + "data": "\n", + "raw": "\n" + } + ] + } + ] +} diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-7/output.stderr b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-7/output.stderr new file mode 100644 index 00000000000..795fc67c997 --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-7/output.stderr @@ -0,0 +1,6 @@ + + x No target name + ,-[$DIR/tests/recovery/pi/bad-pi-7/input.xml:2:5] + 2 | + : ^ + `---- diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-7/span.rust-debug b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-7/span.rust-debug new file mode 100644 index 00000000000..e0f0561d5de --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-7/span.rust-debug @@ -0,0 +1,59 @@ + + x Document + ,-[$DIR/tests/recovery/pi/bad-pi-7/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | `-> + `---- + + x Child + ,-[$DIR/tests/recovery/pi/bad-pi-7/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | `-> + `---- + + x Element + ,-[$DIR/tests/recovery/pi/bad-pi-7/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | `-> + `---- + + x Child + ,-[$DIR/tests/recovery/pi/bad-pi-7/input.xml:1:1] + 1 | ,-> + 2 | `-> + `---- + + x Text + ,-[$DIR/tests/recovery/pi/bad-pi-7/input.xml:1:1] + 1 | ,-> + 2 | `-> + `---- + + x Child + ,-[$DIR/tests/recovery/pi/bad-pi-7/input.xml:2:5] + 2 | + : ^^^^^^^^^ + `---- + + x ProcessingInstruction + ,-[$DIR/tests/recovery/pi/bad-pi-7/input.xml:2:5] + 2 | + : ^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/recovery/pi/bad-pi-7/input.xml:2:5] + 2 | + : ^ + 3 | + `---- + + x Text + ,-[$DIR/tests/recovery/pi/bad-pi-7/input.xml:2:5] + 2 | + : ^ + 3 | + `---- diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-8/dom.rust-debug b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-8/dom.rust-debug new file mode 100644 index 00000000000..c4935d4f0ca --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-8/dom.rust-debug @@ -0,0 +1,6 @@ +| +| " + " + +| " +" diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-8/input.xml b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-8/input.xml new file mode 100644 index 00000000000..adffe852090 --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-8/input.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-8/output.json b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-8/output.json new file mode 100644 index 00000000000..299ffa02776 --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-8/output.json @@ -0,0 +1,52 @@ +{ + "type": "Document", + "span": { + "start": 1, + "end": 24, + "ctxt": 0 + }, + "children": [ + { + "type": "Element", + "span": { + "start": 1, + "end": 24, + "ctxt": 0 + }, + "tagName": "root", + "attributes": [], + "children": [ + { + "type": "Text", + "span": { + "start": 7, + "end": 12, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "ProcessingInstruction", + "span": { + "start": 12, + "end": 16, + "ctxt": 0 + }, + "target": "", + "data": "" + }, + { + "type": "Text", + "span": { + "start": 16, + "end": 17, + "ctxt": 0 + }, + "data": "\n", + "raw": "\n" + } + ] + } + ] +} diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-8/output.stderr b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-8/output.stderr new file mode 100644 index 00000000000..bc8f3338c4c --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-8/output.stderr @@ -0,0 +1,6 @@ + + x No target name + ,-[$DIR/tests/recovery/pi/bad-pi-8/input.xml:2:5] + 2 | + : ^ + `---- diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-8/span.rust-debug b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-8/span.rust-debug new file mode 100644 index 00000000000..a7a46241f5b --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-8/span.rust-debug @@ -0,0 +1,59 @@ + + x Document + ,-[$DIR/tests/recovery/pi/bad-pi-8/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | `-> + `---- + + x Child + ,-[$DIR/tests/recovery/pi/bad-pi-8/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | `-> + `---- + + x Element + ,-[$DIR/tests/recovery/pi/bad-pi-8/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | `-> + `---- + + x Child + ,-[$DIR/tests/recovery/pi/bad-pi-8/input.xml:1:1] + 1 | ,-> + 2 | `-> + `---- + + x Text + ,-[$DIR/tests/recovery/pi/bad-pi-8/input.xml:1:1] + 1 | ,-> + 2 | `-> + `---- + + x Child + ,-[$DIR/tests/recovery/pi/bad-pi-8/input.xml:2:5] + 2 | + : ^^^^ + `---- + + x ProcessingInstruction + ,-[$DIR/tests/recovery/pi/bad-pi-8/input.xml:2:5] + 2 | + : ^^^^ + `---- + + x Child + ,-[$DIR/tests/recovery/pi/bad-pi-8/input.xml:2:5] + 2 | + : ^ + 3 | + `---- + + x Text + ,-[$DIR/tests/recovery/pi/bad-pi-8/input.xml:2:5] + 2 | + : ^ + 3 | + `---- diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-9/dom.rust-debug b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-9/dom.rust-debug new file mode 100644 index 00000000000..f1cb98d4409 --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-9/dom.rust-debug @@ -0,0 +1,6 @@ +| +| " + " + +| " +" diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-9/input.xml b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-9/input.xml new file mode 100644 index 00000000000..db8e4dc0f4a --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-9/input.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-9/output.json b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-9/output.json new file mode 100644 index 00000000000..6f4092d0fcf --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-9/output.json @@ -0,0 +1,52 @@ +{ + "type": "Document", + "span": { + "start": 1, + "end": 29, + "ctxt": 0 + }, + "children": [ + { + "type": "Element", + "span": { + "start": 1, + "end": 29, + "ctxt": 0 + }, + "tagName": "root", + "attributes": [], + "children": [ + { + "type": "Text", + "span": { + "start": 7, + "end": 12, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "ProcessingInstruction", + "span": { + "start": 12, + "end": 21, + "ctxt": 0 + }, + "target": "foo", + "data": "? " + }, + { + "type": "Text", + "span": { + "start": 21, + "end": 22, + "ctxt": 0 + }, + "data": "\n", + "raw": "\n" + } + ] + } + ] +} diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-9/output.stderr b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-9/output.stderr new file mode 100644 index 00000000000..f9325faf0c2 --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-9/output.stderr @@ -0,0 +1,6 @@ + + x Missing whitespace before '?' + ,-[$DIR/tests/recovery/pi/bad-pi-9/input.xml:2:5] + 2 | + : ^ + `---- diff --git a/crates/swc_xml_parser/tests/recovery/pi/bad-pi-9/span.rust-debug b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-9/span.rust-debug new file mode 100644 index 00000000000..6df1d246948 --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/pi/bad-pi-9/span.rust-debug @@ -0,0 +1,59 @@ + + x Document + ,-[$DIR/tests/recovery/pi/bad-pi-9/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | `-> + `---- + + x Child + ,-[$DIR/tests/recovery/pi/bad-pi-9/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | `-> + `---- + + x Element + ,-[$DIR/tests/recovery/pi/bad-pi-9/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | `-> + `---- + + x Child + ,-[$DIR/tests/recovery/pi/bad-pi-9/input.xml:1:1] + 1 | ,-> + 2 | `-> + `---- + + x Text + ,-[$DIR/tests/recovery/pi/bad-pi-9/input.xml:1:1] + 1 | ,-> + 2 | `-> + `---- + + x Child + ,-[$DIR/tests/recovery/pi/bad-pi-9/input.xml:2:5] + 2 | + : ^^^^^^^^^ + `---- + + x ProcessingInstruction + ,-[$DIR/tests/recovery/pi/bad-pi-9/input.xml:2:5] + 2 | + : ^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/recovery/pi/bad-pi-9/input.xml:2:5] + 2 | + : ^ + 3 | + `---- + + x Text + ,-[$DIR/tests/recovery/pi/bad-pi-9/input.xml:2:5] + 2 | + : ^ + 3 | + `----