From 01232f09883de34eb3eb94d364f9bd2a3b985703 Mon Sep 17 00:00:00 2001 From: Alexander Akait <4567934+alexander-akait@users.noreply.github.com> Date: Sat, 3 Dec 2022 06:52:48 +0300 Subject: [PATCH] fix(xml/parser): Fix various bugs (#6566) --- crates/swc_xml_codegen/src/lib.rs | 4 +- .../tests/fixture/base/input.xml | 6 + .../tests/fixture/base/output.min.xml | 6 + .../tests/fixture/base/output.xml | 6 + crates/swc_xml_parser/src/error.rs | 16 + crates/swc_xml_parser/src/lexer/mod.rs | 291 ++++-- .../tests/fixture/attribute/dom.txt | 98 ++ .../tests/fixture/attribute/input.xml | 27 + .../tests/fixture/attribute/output.json | 913 ++++++++++++++++++ .../tests/fixture/attribute/span.swc-stderr | 873 +++++++++++++++++ .../tests/fixture/cdata_section/dom.txt | 12 + .../tests/fixture/cdata_section/input.xml | 5 + .../tests/fixture/cdata_section/output.json | 94 +- .../fixture/cdata_section/span.swc-stderr | 175 +++- .../tests/fixture/comment-no-dtd/dom.txt | 2 + .../tests/fixture/comment-no-dtd/input.xml | 2 + .../tests/fixture/comment-no-dtd/output.json | 31 + .../fixture/comment-no-dtd/span.swc-stderr | 34 + .../tests/fixture/comments/dom.txt | 28 + .../tests/fixture/comments/input.xml | 10 + .../tests/fixture/comments/output.json | 322 ++++-- .../tests/fixture/comments/span.swc-stderr | 870 +++++++++++------ .../tests/fixture/entity/dom.txt | 18 +- .../tests/fixture/entity/input.xml | 9 +- .../tests/fixture/entity/output.json | 170 +++- .../tests/fixture/entity/span.swc-stderr | 395 ++++++-- .../swc_xml_parser/tests/fixture/pi/dom.txt | 4 +- .../swc_xml_parser/tests/fixture/pi/input.xml | 1 + .../tests/fixture/pi/output.json | 198 ++-- .../tests/fixture/pi/span.swc-stderr | 907 ++++++++--------- .../attribute-character-reference/dom.txt | 7 + .../attribute-character-reference/input.xml | 3 + .../attribute-character-reference/output.json | 68 ++ .../output.swc-stderr | 8 + .../span.swc-stderr | 69 ++ .../tests/recovery/attribute-no-equal/dom.txt | 31 + .../recovery/attribute-no-equal/input.xml | 8 + .../recovery/attribute-no-equal/output.json | 304 ++++++ .../attribute-no-equal/output.swc-stderr | 48 + .../attribute-no-equal/span.swc-stderr | 260 +++++ .../attribute-no-space-between/dom.txt | 8 + .../attribute-no-space-between/input.xml | 3 + .../attribute-no-space-between/output.json | 82 ++ .../output.swc-stderr | 8 + .../span.swc-stderr | 69 ++ .../attribute-partially-quoted-1/dom.txt | 6 + .../attribute-partially-quoted-1/input.xml | 3 + .../attribute-partially-quoted-1/output.json | 58 ++ .../output.swc-stderr | 29 + .../span.swc-stderr | 51 + .../attribute-partially-quoted/dom.txt | 6 + .../attribute-partially-quoted/input.xml | 3 + .../attribute-partially-quoted/output.json | 58 ++ .../output.swc-stderr | 29 + .../span.swc-stderr | 51 + .../tests/recovery/attribute-unquoted/dom.txt | 7 + .../recovery/attribute-unquoted/input.xml | 3 + .../recovery/attribute-unquoted/output.json | 68 ++ .../attribute-unquoted/output.swc-stderr | 8 + .../attribute-unquoted/span.swc-stderr | 75 ++ .../tests/recovery/attribute-value/dom.txt | 15 + .../tests/recovery/attribute-value/input.xml | 5 + .../recovery/attribute-value/output.json | 140 +++ .../attribute-value/output.swc-stderr | 24 + .../recovery/attribute-value/span.swc-stderr | 147 +++ .../tests/recovery/comments/bad-40/dom.txt | 12 +- .../recovery/comments/bad-40/output.json | 12 +- .../comments/bad-40/output.swc-stderr | 24 + .../recovery/element-missing-name/dom.txt | 6 + .../recovery/element-missing-name/input.xml | 5 + .../recovery/element-missing-name/output.json | 32 + .../element-missing-name/output.swc-stderr | 24 + .../element-missing-name/span.swc-stderr | 45 + .../recovery/no-quotes/output.swc-stderr | 31 + 74 files changed, 6366 insertions(+), 1114 deletions(-) create mode 100644 crates/swc_xml_parser/tests/fixture/attribute/dom.txt create mode 100644 crates/swc_xml_parser/tests/fixture/attribute/input.xml create mode 100644 crates/swc_xml_parser/tests/fixture/attribute/output.json create mode 100644 crates/swc_xml_parser/tests/fixture/attribute/span.swc-stderr create mode 100644 crates/swc_xml_parser/tests/fixture/comment-no-dtd/dom.txt create mode 100644 crates/swc_xml_parser/tests/fixture/comment-no-dtd/input.xml create mode 100644 crates/swc_xml_parser/tests/fixture/comment-no-dtd/output.json create mode 100644 crates/swc_xml_parser/tests/fixture/comment-no-dtd/span.swc-stderr create mode 100644 crates/swc_xml_parser/tests/recovery/attribute-character-reference/dom.txt create mode 100644 crates/swc_xml_parser/tests/recovery/attribute-character-reference/input.xml create mode 100644 crates/swc_xml_parser/tests/recovery/attribute-character-reference/output.json create mode 100644 crates/swc_xml_parser/tests/recovery/attribute-character-reference/output.swc-stderr create mode 100644 crates/swc_xml_parser/tests/recovery/attribute-character-reference/span.swc-stderr create mode 100644 crates/swc_xml_parser/tests/recovery/attribute-no-equal/dom.txt create mode 100644 crates/swc_xml_parser/tests/recovery/attribute-no-equal/input.xml create mode 100644 crates/swc_xml_parser/tests/recovery/attribute-no-equal/output.json create mode 100644 crates/swc_xml_parser/tests/recovery/attribute-no-equal/output.swc-stderr create mode 100644 crates/swc_xml_parser/tests/recovery/attribute-no-equal/span.swc-stderr create mode 100644 crates/swc_xml_parser/tests/recovery/attribute-no-space-between/dom.txt create mode 100644 crates/swc_xml_parser/tests/recovery/attribute-no-space-between/input.xml create mode 100644 crates/swc_xml_parser/tests/recovery/attribute-no-space-between/output.json create mode 100644 crates/swc_xml_parser/tests/recovery/attribute-no-space-between/output.swc-stderr create mode 100644 crates/swc_xml_parser/tests/recovery/attribute-no-space-between/span.swc-stderr create mode 100644 crates/swc_xml_parser/tests/recovery/attribute-partially-quoted-1/dom.txt create mode 100644 crates/swc_xml_parser/tests/recovery/attribute-partially-quoted-1/input.xml create mode 100644 crates/swc_xml_parser/tests/recovery/attribute-partially-quoted-1/output.json create mode 100644 crates/swc_xml_parser/tests/recovery/attribute-partially-quoted-1/output.swc-stderr create mode 100644 crates/swc_xml_parser/tests/recovery/attribute-partially-quoted-1/span.swc-stderr create mode 100644 crates/swc_xml_parser/tests/recovery/attribute-partially-quoted/dom.txt create mode 100644 crates/swc_xml_parser/tests/recovery/attribute-partially-quoted/input.xml create mode 100644 crates/swc_xml_parser/tests/recovery/attribute-partially-quoted/output.json create mode 100644 crates/swc_xml_parser/tests/recovery/attribute-partially-quoted/output.swc-stderr create mode 100644 crates/swc_xml_parser/tests/recovery/attribute-partially-quoted/span.swc-stderr create mode 100644 crates/swc_xml_parser/tests/recovery/attribute-unquoted/dom.txt create mode 100644 crates/swc_xml_parser/tests/recovery/attribute-unquoted/input.xml create mode 100644 crates/swc_xml_parser/tests/recovery/attribute-unquoted/output.json create mode 100644 crates/swc_xml_parser/tests/recovery/attribute-unquoted/output.swc-stderr create mode 100644 crates/swc_xml_parser/tests/recovery/attribute-unquoted/span.swc-stderr create mode 100644 crates/swc_xml_parser/tests/recovery/attribute-value/dom.txt create mode 100644 crates/swc_xml_parser/tests/recovery/attribute-value/input.xml create mode 100644 crates/swc_xml_parser/tests/recovery/attribute-value/output.json create mode 100644 crates/swc_xml_parser/tests/recovery/attribute-value/output.swc-stderr create mode 100644 crates/swc_xml_parser/tests/recovery/attribute-value/span.swc-stderr create mode 100644 crates/swc_xml_parser/tests/recovery/element-missing-name/dom.txt create mode 100644 crates/swc_xml_parser/tests/recovery/element-missing-name/input.xml create mode 100644 crates/swc_xml_parser/tests/recovery/element-missing-name/output.json create mode 100644 crates/swc_xml_parser/tests/recovery/element-missing-name/output.swc-stderr create mode 100644 crates/swc_xml_parser/tests/recovery/element-missing-name/span.swc-stderr diff --git a/crates/swc_xml_codegen/src/lib.rs b/crates/swc_xml_codegen/src/lib.rs index eba6ba723df1..2ddf5961581a 100644 --- a/crates/swc_xml_codegen/src/lib.rs +++ b/crates/swc_xml_codegen/src/lib.rs @@ -352,7 +352,7 @@ fn normalize_attribute_value(value: &str) -> String { let mut normalized = String::with_capacity(value.len() + 2); normalized.push('"'); - normalized.push_str(value); + normalized.push_str(&escape_string(value, true)); normalized.push('"'); normalized @@ -463,7 +463,7 @@ fn escape_string(value: &str, is_attribute_mode: bool) -> String { result.push_str("&"); } '"' if is_attribute_mode => result.push_str("""), - '<' if !is_attribute_mode => { + '<' if is_attribute_mode => { result.push_str("<"); } '>' if !is_attribute_mode => { diff --git a/crates/swc_xml_codegen/tests/fixture/base/input.xml b/crates/swc_xml_codegen/tests/fixture/base/input.xml index 9157c3399b12..e8d576681efc 100644 --- a/crates/swc_xml_codegen/tests/fixture/base/input.xml +++ b/crates/swc_xml_codegen/tests/fixture/base/input.xml @@ -4,4 +4,10 @@ Jani Reminder Don't forget me this weekend! + + + + + + \ No newline at end of file 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 48849b439e1d..e57cde7f6010 100644 --- a/crates/swc_xml_codegen/tests/fixture/base/output.min.xml +++ b/crates/swc_xml_codegen/tests/fixture/base/output.min.xml @@ -3,4 +3,10 @@ Jani Reminder Don't forget me this weekend! + + + + + + \ No newline at end of file diff --git a/crates/swc_xml_codegen/tests/fixture/base/output.xml b/crates/swc_xml_codegen/tests/fixture/base/output.xml index 48849b439e1d..4c561945db09 100644 --- a/crates/swc_xml_codegen/tests/fixture/base/output.xml +++ b/crates/swc_xml_codegen/tests/fixture/base/output.xml @@ -3,4 +3,10 @@ Jani Reminder Don't forget me this weekend! + + + + + + \ No newline at end of file diff --git a/crates/swc_xml_parser/src/error.rs b/crates/swc_xml_parser/src/error.rs index 3a0031766bb9..3c5ef1fffcf4 100644 --- a/crates/swc_xml_parser/src/error.rs +++ b/crates/swc_xml_parser/src/error.rs @@ -57,6 +57,7 @@ impl Error { "Invalid character of processing instruction".into() } ErrorKind::InvalidCharacterInTag => "Invalid character in tag".into(), + ErrorKind::InvalidEntityCharacter => "Invalid entity character".into(), ErrorKind::MissingDoctypeName => "Missing doctype name".into(), ErrorKind::MissingDoctypePublicIdentifier => "Missing doctype public identifier".into(), ErrorKind::MissingQuoteBeforeDoctypePublicIdentifier => { @@ -81,6 +82,13 @@ impl Error { "Missing whitespace between doctype public and system identifiers".into() } ErrorKind::MissingEndTagName => "Missing end tag name".into(), + ErrorKind::MissingQuoteBeforeAttributeValue => { + "Missing quote before attribute value".into() + } + ErrorKind::MissingEqualAfterAttributeName => { + "Missing equal after attribute name".into() + } + ErrorKind::MissingSpaceBetweenAttributes => "Missing space between attributes".into(), ErrorKind::NestedComment => "Nested comment".into(), ErrorKind::DoubleHyphenWithInComment => "Double hyper within comment".into(), ErrorKind::NoncharacterInInputStream => "Noncharacter in input stream".into(), @@ -97,6 +105,9 @@ impl Error { ErrorKind::MissingWhitespaceBeforeQuestionInProcessingInstruction => { "Missing whitespace before '?'".into() } + ErrorKind::UnescapedCharacterInAttributeValue(c) => { + format!("Unescaped \"{}\" not allowed in attribute values", c).into() + } // Parser errors ErrorKind::UnexpectedTokenInStartPhase => "Unexpected token in start phase".into(), @@ -142,6 +153,7 @@ pub enum ErrorKind { InvalidFirstCharacterOfTagName, InvalidCharacterOfProcessingInstruction, InvalidCharacterInTag, + InvalidEntityCharacter, MissingDoctypeName, MissingDoctypePublicIdentifier, MissingQuoteBeforeDoctypePublicIdentifier, @@ -152,6 +164,9 @@ pub enum ErrorKind { MissingWhitespaceBeforeDoctypeName, MissingWhitespaceBetweenDoctypePublicAndSystemIdentifiers, MissingEndTagName, + MissingQuoteBeforeAttributeValue, + MissingEqualAfterAttributeName, + MissingSpaceBetweenAttributes, NestedComment, DoubleHyphenWithInComment, NoncharacterInInputStream, @@ -162,6 +177,7 @@ pub enum ErrorKind { UnexpectedSolidusInTag, NoTargetNameInProcessingInstruction, MissingWhitespaceBeforeQuestionInProcessingInstruction, + UnescapedCharacterInAttributeValue(char), // Parser errors UnexpectedTokenInStartPhase, diff --git a/crates/swc_xml_parser/src/lexer/mod.rs b/crates/swc_xml_parser/src/lexer/mod.rs index 8fc94befa1b1..380f57195d2b 100644 --- a/crates/swc_xml_parser/src/lexer/mod.rs +++ b/crates/swc_xml_parser/src/lexer/mod.rs @@ -44,6 +44,7 @@ pub enum State { TagAttributeValueDoubleQuoted, TagAttributeValueSingleQuoted, TagAttributeValueUnquoted, + TagAttributeValueAfter, CharacterReferenceInAttributeValue, BogusComment, Doctype, @@ -293,8 +294,13 @@ where self.pending_tokens.push_back(TokenAndSpan { span, token }); } - fn consume_character_reference(&mut self) -> Option { + fn consume_character_reference(&mut self) -> Option<(char, String)> { let cur_pos = self.input.cur_pos(); + let anything_else = |lexer: &mut Lexer| { + lexer.emit_error(ErrorKind::InvalidEntityCharacter); + lexer.cur_pos = cur_pos; + lexer.input.reset_to(cur_pos); + }; // This section defines how to consume a character reference, optionally with an // additional allowed character, which, if specified where the algorithm is @@ -306,31 +312,113 @@ where // The behavior depends on identity of next character (the one immediately after // the U+0026 AMPERSAND character), as follows: match self.consume_next_char() { - // U+0009 CHARACTER TABULATION (Tab) - // U+000A LINE FEED (LF) - // U+000C FORM FEED (FF) - // U+0020 SPACE (Space) - // U+003C LESSER-THAN SIGN (<) - // U+003E GREATER-THAN SIGN (%) - // U+0026 AMPERSAND (&) - // EOF - // Not a character reference. No characters are consumed and nothing is returned (This - // is not an error, either). - Some(c) if is_spacy(c) => { - self.cur_pos = cur_pos; - self.input.reset_to(cur_pos); - } - Some('<') | Some('%') | Some('&') | None => { - self.cur_pos = cur_pos; - self.input.reset_to(cur_pos); - } // The additional allowed character if there is one // Not a character reference. No characters are consumed and nothing is returned (This // is not an error, either). Some(c) if self.additional_allowed_character == Some(c) => { + self.emit_error(ErrorKind::InvalidEntityCharacter); self.cur_pos = cur_pos; self.input.reset_to(cur_pos); } + Some('l') => match self.consume_next_char() { + Some('t') => { + match self.consume_next_char() { + Some(';') => {} + _ => { + self.emit_error(ErrorKind::MissingSemicolonAfterCharacterReference); + } + } + + return Some(('<', String::from("<"))); + } + _ => { + anything_else(self); + } + }, + Some('g') => match self.consume_next_char() { + Some('t') => { + match self.consume_next_char() { + Some(';') => {} + _ => { + self.emit_error(ErrorKind::MissingSemicolonAfterCharacterReference); + } + } + + return Some(('>', String::from(">"))); + } + _ => { + anything_else(self); + } + }, + Some('q') => match self.consume_next_char() { + Some('u') => match self.consume_next_char() { + Some('o') => match self.consume_next_char() { + Some('t') => { + match self.consume_next_char() { + Some(';') => {} + _ => { + self.emit_error( + ErrorKind::MissingSemicolonAfterCharacterReference, + ); + } + } + + return Some(('"', String::from("""))); + } + _ => { + anything_else(self); + } + }, + _ => { + anything_else(self); + } + }, + _ => { + anything_else(self); + } + }, + Some('a') => match self.consume_next_char() { + Some('p') => match self.consume_next_char() { + Some('o') => match self.consume_next_char() { + Some('s') => { + match self.consume_next_char() { + Some(';') => {} + _ => { + self.emit_error( + ErrorKind::MissingSemicolonAfterCharacterReference, + ); + } + } + + return Some(('\'', String::from("'"))); + } + _ => { + anything_else(self); + } + }, + _ => { + anything_else(self); + } + }, + Some('m') => match self.consume_next_char() { + Some('p') => { + match self.consume_next_char() { + Some(';') => {} + _ => { + self.emit_error(ErrorKind::MissingSemicolonAfterCharacterReference); + } + } + + return Some(('&', String::from("&"))); + } + _ => { + anything_else(self); + } + }, + _ => { + anything_else(self); + } + }, Some('#') => { let mut base = 10; let mut characters = vec![]; @@ -418,7 +506,7 @@ where if is_surrogate(cr) { self.emit_error(ErrorKind::SurrogateCharacterReference); - return Some(char::REPLACEMENT_CHARACTER); + return Some((char::REPLACEMENT_CHARACTER, String::from("empty"))); } let c = match char::from_u32(cr) { @@ -428,11 +516,10 @@ where } }; - return Some(c); + return Some((c, String::from("empty"))); } _ => { - self.cur_pos = cur_pos; - self.input.reset_to(cur_pos); + anything_else(self); } } @@ -639,6 +726,38 @@ where } } + fn append_to_attribute_with_entity(&mut self, value: Option<(Option, Option<&str>)>) { + if let Some(Tag { attributes, .. }) = &mut self.current_tag_token { + if let Some(attribute) = attributes.last_mut() { + if let Some(value) = value { + if let Some(c) = value.0 { + if let Some(old_value) = &mut attribute.value { + old_value.push(c); + } else { + let mut new_value = String::with_capacity(255); + + new_value.push(c); + + attribute.value = Some(new_value); + } + } + + if let Some(c) = value.1 { + if let Some(raw_value) = &mut attribute.raw_value { + raw_value.push_str(c); + } else { + let mut raw_new_value = String::with_capacity(255); + + raw_new_value.push_str(c); + + attribute.raw_value = Some(raw_new_value); + } + } + } + } + } + } + fn update_attribute_span(&mut self) { if let Some(attribute_start_position) = self.attribute_start_position { if let Some(Tag { @@ -875,6 +994,14 @@ where }); } + #[inline(always)] + fn emit_character_token_with_entity(&mut self, c: char, raw: &str) { + self.emit_token(Token::Character { + value: c, + raw: Some(raw.into()), + }); + } + fn read_token_and_span(&mut self) -> LexResult { if self.finished { return Err(ErrorKind::Eof); @@ -939,8 +1066,8 @@ where let character_reference = self.consume_character_reference(); - if let Some(c) = character_reference { - self.emit_character_token((c, c)); + if let Some((c, raw)) = character_reference { + self.emit_character_token_with_entity(c, &raw); } else { self.emit_character_token(('&', '&')); } @@ -954,7 +1081,7 @@ where // EOF // Parse error. // Switch to the pi target after state. - Some(c) if is_spacy_except_ff(c) => { + Some(c) if is_whitespace(c) => { self.emit_error(ErrorKind::InvalidCharacterOfProcessingInstruction); self.create_processing_instruction_token(); self.state = State::PiTargetAfter; @@ -988,7 +1115,7 @@ where // U+000A LINE FEED (LF) // U+0020 SPACE // Switch to the pi target state. - Some(c) if is_spacy_except_ff(c) => { + Some(c) if is_whitespace(c) => { self.state = State::PiTargetAfter; } // EOF @@ -1041,7 +1168,7 @@ where // U+000A LINE FEED (LF) // U+0020 SPACE (Space) // Stay in the current state. - Some(c) if is_spacy_except_ff(c) => { + Some(c) if is_whitespace(c) => { self.skip_next_lf(c); } // Anything else @@ -1678,7 +1805,7 @@ where // U+000A LINE FEED (LF) // U+0020 SPACE (Space) // Switch to the before attribute name state. - Some(c) if is_spacy_except_ff(c) => { + Some(c) if is_whitespace(c) => { self.skip_next_lf(c); self.state = State::TagAttributeNameBefore; } @@ -1745,7 +1872,7 @@ where // U+000A LINE FEED (LF) // U+0020 SPACE // Ignore the character. - Some(c) if is_spacy_except_ff(c) => { + Some(c) if is_whitespace(c) => { self.skip_next_lf(c); } // U+003E GREATER-THAN SIGN(>) @@ -1777,11 +1904,9 @@ where // Start a new attribute in the current tag token. Set that attribute’s name to // the current input character and its value to the empty string and then switch // to the tag attribute name state. - // We set `None` for `value` to support boolean attributes in AST - Some(c) => { - self.validate_input_stream_character(c); - self.start_new_attribute(Some(c)); - self.state = State::TagAttributeName; + _ => { + self.start_new_attribute(None); + self.reconsume_in_state(State::TagAttributeName); } } } @@ -1796,6 +1921,7 @@ where // U+003E GREATER-THEN SIGN (>) // Emit the current token as start tag token. Switch to the data state. Some('>') => { + self.emit_error(ErrorKind::MissingEqualAfterAttributeName); self.emit_tag_token(None); self.state = State::Data; } @@ -1803,7 +1929,7 @@ where // U+000A LINE FEED (LF) // U+0020 SPACE (Space) // Switch to the tag attribute name after state. - Some(c) if is_spacy_except_ff(c) => { + Some(c) if is_whitespace(c) => { self.update_attribute_span(); self.skip_next_lf(c); self.reconsume_in_state(State::TagAttributeNameAfter); @@ -1811,6 +1937,7 @@ where // U+002F SOLIDUS (/) // Set current tag to empty tag. Switch to the empty tag state. Some('/') => { + self.emit_error(ErrorKind::MissingEqualAfterAttributeName); self.set_tag_to_empty_tag(); self.state = State::EmptyTag; } @@ -1847,7 +1974,7 @@ where // U+000A LINE FEED (LF) // U+0020 SPACE // Ignore the character. - Some(c) if is_spacy_except_ff(c) => { + Some(c) if is_whitespace(c) => { self.skip_next_lf(c); } // U+003D EQUALS SIGN(=) @@ -1880,6 +2007,7 @@ where // the current input character and its value to the empty string and then switch // to the tag attribute name state. Some(c) => { + self.emit_error(ErrorKind::MissingEqualAfterAttributeName); self.validate_input_stream_character(c); self.start_new_attribute(Some(c)); self.state = State::TagAttributeName; @@ -1893,7 +2021,7 @@ where // U+000A LINE FEED (LF) // U+0020 SPACE // Ignore the character. - Some(c) if is_spacy_except_ff(c) => { + Some(c) if is_whitespace(c) => { self.skip_next_lf(c); } // U+0022 QUOTATION MARK (") @@ -1908,11 +2036,6 @@ where self.append_to_attribute(None, Some((true, None, Some(c)))); self.state = State::TagAttributeValueSingleQuoted; } - // U+0026 AMPERSAND (&): - // Reprocess the input character in the tag attribute value unquoted state. - Some('&') => { - self.reconsume_in_state(State::TagAttributeValueUnquoted); - } // U+003E GREATER-THAN SIGN(>) // Emit the current token and then switch to the data state. Some('>') => { @@ -1931,6 +2054,7 @@ where // Append the current input character to the current attribute’s value and then // switch to the tag attribute value unquoted state. Some(c) => { + self.emit_error(ErrorKind::MissingQuoteBeforeAttributeValue); self.validate_input_stream_character(c); self.append_to_attribute(None, Some((true, Some(c), Some(c)))); self.state = State::TagAttributeValueUnquoted; @@ -1945,7 +2069,7 @@ where // We set value to support empty attributes (i.e. `attr=""`) Some(c @ '"') => { self.append_to_attribute(None, Some((false, None, Some(c)))); - self.state = State::TagAttributeNameBefore; + self.state = State::TagAttributeValueAfter; } // U+0026 AMPERSAND (&) // Switch to character reference in attribute value state, with the additional @@ -1955,6 +2079,11 @@ where self.state = State::CharacterReferenceInAttributeValue; self.additional_allowed_character = Some('"'); } + // (<) + Some(c @ '<') => { + self.emit_error(ErrorKind::UnescapedCharacterInAttributeValue('<')); + self.append_to_attribute(None, Some((false, Some(c), Some(c)))); + } // EOF // Parse error. Emit the current token and then reprocess the current input // character in the data state. @@ -1980,7 +2109,7 @@ where // We set value to support empty attributes (i.e. `attr=''`) Some(c @ '\'') => { self.append_to_attribute(None, Some((false, None, Some(c)))); - self.state = State::TagAttributeNameBefore; + self.state = State::TagAttributeValueAfter; } // U+0026 AMPERSAND (&) // Switch to character reference in attribute value state, with the additional @@ -1990,6 +2119,11 @@ where self.state = State::CharacterReferenceInAttributeValue; self.additional_allowed_character = Some('\''); } + // (<) + Some(c @ '<') => { + self.emit_error(ErrorKind::UnescapedCharacterInAttributeValue('<')); + self.append_to_attribute(None, Some((false, Some(c), Some(c)))); + } // EOF // Parse error. Emit the current token and then reprocess the current input // character in the data state. @@ -2013,10 +2147,10 @@ where // U+000A LINE FEED (LF) // U+0020 SPACE (Space) // Switch to the before attribute name state. - Some(c) if is_spacy_except_ff(c) => { + Some(c) if is_whitespace(c) => { self.update_attribute_span(); self.skip_next_lf(c); - self.state = State::TagAttributeNameBefore; + self.state = State::TagAttributeValueAfter; } // U+0026 AMPERSAND (&) // Set the return state to the attribute value (unquoted) state. Switch to @@ -2026,6 +2160,11 @@ where self.state = State::CharacterReferenceInAttributeValue; self.additional_allowed_character = Some('>'); } + // (<) + Some(c @ '<') => { + self.emit_error(ErrorKind::UnescapedCharacterInAttributeValue('<')); + self.append_to_attribute(None, Some((false, Some(c), Some(c)))); + } // U+003E GREATER-THAN SIGN (>) // Emit the current token as start tag token and then switch to the data state. Some('>') => { @@ -2051,6 +2190,24 @@ where } } } + State::TagAttributeValueAfter => match self.consume_next_char() { + Some(c) if is_whitespace(c) => { + self.reconsume_in_state(State::TagAttributeNameBefore); + } + Some('>') | Some('/') => { + self.reconsume_in_state(State::TagAttributeNameBefore); + } + None => { + self.emit_error(ErrorKind::EofInTag); + self.update_attribute_span(); + self.emit_tag_token(Some(TagKind::Start)); + self.reconsume_in_state(State::Data); + } + _ => { + self.emit_error(ErrorKind::MissingSpaceBetweenAttributes); + self.reconsume_in_state(State::TagAttributeNameBefore); + } + }, State::CharacterReferenceInAttributeValue => { // Attempt to consume a character reference. // @@ -2063,8 +2220,8 @@ where let character_reference = self.consume_character_reference(); - if let Some(c) = character_reference { - self.append_to_attribute(None, Some((false, Some(c), Some(c)))); + if let Some((c, raw)) = character_reference { + self.append_to_attribute_with_entity(Some((Some(c), Some(&raw)))); } else { self.append_to_attribute(None, Some((false, Some('&'), Some('&')))); } @@ -2109,7 +2266,7 @@ where // U+000C FORM FEED (FF) // U+0020 SPACE // Switch to the before DOCTYPE name state. - Some(c) if is_spacy(c) => { + Some(c) if is_whitespace(c) => { self.append_raw_to_doctype_token(c); self.state = State::BeforeDoctypeName; } @@ -2140,7 +2297,7 @@ where // U+000C FORM FEED (FF) // U+0020 SPACE // Ignore the character. - Some(c) if is_spacy(c) => { + Some(c) if is_whitespace(c) => { self.append_raw_to_doctype_token(c); } // Uppercase ASCII letter @@ -2191,7 +2348,7 @@ where // U+000C FORM FEED (FF) // U+0020 SPACE // Switch to the after DOCTYPE name state. - Some(c) if is_spacy(c) => { + Some(c) if is_whitespace(c) => { self.append_raw_to_doctype_token(c); self.state = State::AfterDoctypeName; } @@ -2236,7 +2393,7 @@ where // U+000C FORM FEED (FF) // U+0020 SPACE // Ignore the character. - Some(c) if is_spacy(c) => { + Some(c) if is_whitespace(c) => { self.append_raw_to_doctype_token(c); } // U+003E GREATER-THAN SIGN (>) @@ -2325,7 +2482,7 @@ where // U+000C FORM FEED (FF) // U+0020 SPACE (Space) // Switch to the before DOCTYPE public identifier state. - Some(c) if is_spacy(c) => { + Some(c) if is_whitespace(c) => { self.append_raw_to_doctype_token(c); self.state = State::BeforeDoctypePublicIdentifier; } @@ -2389,7 +2546,7 @@ where // U+000C FORM FEED (FF) // U+0020 SPACE // Switch to the before DOCTYPE system identifier state. - Some(c) if is_spacy(c) => { + Some(c) if is_whitespace(c) => { self.append_raw_to_doctype_token(c); self.state = State::BeforeDoctypeSystemIdentifier; } @@ -2451,7 +2608,7 @@ where // U+000C FORM FEED (FF) // U+0020 SPACE // Ignore the character. - Some(c) if is_spacy(c) => { + Some(c) if is_whitespace(c) => { self.append_raw_to_doctype_token(c); } // U+0022 QUOTATION MARK (") @@ -2508,7 +2665,7 @@ where // U+000C FORM FEED (FF) // U+0020 SPACE // Ignore the character. - Some(c) if is_spacy(c) => { + Some(c) if is_whitespace(c) => { self.append_raw_to_doctype_token(c); } // U+0022 QUOTATION MARK (") @@ -2636,7 +2793,7 @@ where // U+000C FORM FEED (FF) // U+0020 SPACE // Switch to the between DOCTYPE public and system identifiers state. - Some(c) if is_spacy(c) => { + Some(c) if is_whitespace(c) => { self.append_raw_to_doctype_token(c); self.state = State::BetweenDoctypePublicAndSystemIdentifiers; } @@ -2697,7 +2854,7 @@ where // U+000C FORM FEED (FF) // U+0020 SPACE // Ignore the character. - Some(c) if is_spacy(c) => { + Some(c) if is_whitespace(c) => { self.append_raw_to_doctype_token(c); } // U+003E GREATER-THAN SIGN (>) @@ -2822,7 +2979,7 @@ where // U+000C FORM FEED (FF) // U+0020 SPACE // Ignore the character. - Some(c) if is_spacy(c) => { + Some(c) if is_whitespace(c) => { self.append_raw_to_doctype_token(c); } // U+003E GREATER-THAN SIGN (>) @@ -2922,18 +3079,12 @@ where } } -// By spec '\r` removed before tokenizer, but we keep them to have better AST -// and don't break logic to ignore characters -#[inline(always)] -fn is_spacy(c: char) -> bool { - matches!(c, '\x09' | '\x0a' | '\x0c' | '\x0d' | '\x20') -} +// S ::= +// (#x20 | #x9 | #xD | #xA)+ -// By spec '\r` removed before tokenizer, but we keep them to have better AST -// and don't break logic to ignore characters #[inline(always)] -fn is_spacy_except_ff(c: char) -> bool { - matches!(c, '\x09' | '\x0c' | '\x0d' | '\x20') +fn is_whitespace(c: char) -> bool { + matches!(c, '\x20' | '\x09' | '\x0d' | '\x0a') } #[inline(always)] diff --git a/crates/swc_xml_parser/tests/fixture/attribute/dom.txt b/crates/swc_xml_parser/tests/fixture/attribute/dom.txt new file mode 100644 index 000000000000..e7705013a766 --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/attribute/dom.txt @@ -0,0 +1,98 @@ +| +| " + " +| +| a="b" +| " + " +| +| a="test" +| "test" +| " + " +| +| a=""test1"" +| b="'test2'" +| " + " +| +| a=""test1"" +| b="'test2'" +| "test" +| " + " +| +| foo:a="test" +| "test" +| " + " +| +| bar:b="'test2'" +| foo:a=""test1"" +| "test" +| " + " +| +| a="test1" +| " + " +| +| foo="" +| " + " +| +| foo="'" +| " + " +| +| foo="" +| " + " +| +| foo=""" +| " + " +| +| myAttribute="attribute value" +| " + " +| +| myAttribute="attribute + value" +| " + " +| +| myAttribute2="attribute value" +| nsA:myAttribute1="attribute value" +| "..." +| " + " +| +| attributeName="He said "OK"" +| " + " +| +| attributeName="He said +| attributeName="He said >OK>" +| " + " +| +| attributeName="He said >OK>" +| " + " +| +| attributeName="He said 'OK'" +| " + " +| +| attributeName="He said &OK&" +| " + " +| +| a="b" +| c="d" +| " +" diff --git a/crates/swc_xml_parser/tests/fixture/attribute/input.xml b/crates/swc_xml_parser/tests/fixture/attribute/input.xml new file mode 100644 index 000000000000..6c06e43075d8 --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/attribute/input.xml @@ -0,0 +1,27 @@ + + + test + + test + test + test + + + + + + + + ... + + + + + + + + \ No newline at end of file diff --git a/crates/swc_xml_parser/tests/fixture/attribute/output.json b/crates/swc_xml_parser/tests/fixture/attribute/output.json new file mode 100644 index 000000000000..5659d9110c64 --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/attribute/output.json @@ -0,0 +1,913 @@ +{ + "type": "Document", + "span": { + "start": 1, + "end": 900, + "ctxt": 0 + }, + "children": [ + { + "type": "Element", + "span": { + "start": 1, + "end": 900, + "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": 24, + "ctxt": 0 + }, + "tagName": "foo", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "a", + "rawName": "a", + "value": "b", + "rawValue": "'b'" + } + ], + "children": [] + }, + { + "type": "Text", + "span": { + "start": 24, + "end": 29, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 29, + "end": 53, + "ctxt": 0 + }, + "tagName": "foo", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "a", + "rawName": "a", + "value": "test", + "rawValue": "\"test\"" + } + ], + "children": [ + { + "type": "Text", + "span": { + "start": 43, + "end": 47, + "ctxt": 0 + }, + "data": "test", + "raw": "test" + } + ] + }, + { + "type": "Text", + "span": { + "start": 53, + "end": 58, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 58, + "end": 88, + "ctxt": 0 + }, + "tagName": "foo", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "a", + "rawName": "a", + "value": "\"test1\"", + "rawValue": "'\"test1\"'" + }, + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "b", + "rawName": "b", + "value": "'test2'", + "rawValue": "\"'test2'\"" + } + ], + "children": [] + }, + { + "type": "Text", + "span": { + "start": 88, + "end": 93, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 93, + "end": 132, + "ctxt": 0 + }, + "tagName": "foo", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "a", + "rawName": "a", + "value": "\"test1\"", + "rawValue": "'\"test1\"'" + }, + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "b", + "rawName": "b", + "value": "'test2'", + "rawValue": "\"'test2'\"" + } + ], + "children": [ + { + "type": "Text", + "span": { + "start": 122, + "end": 126, + "ctxt": 0 + }, + "data": "test", + "raw": "test" + } + ] + }, + { + "type": "Text", + "span": { + "start": 132, + "end": 137, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 137, + "end": 165, + "ctxt": 0 + }, + "tagName": "foo", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "foo:a", + "rawName": "foo:a", + "value": "test", + "rawValue": "\"test\"" + } + ], + "children": [ + { + "type": "Text", + "span": { + "start": 155, + "end": 159, + "ctxt": 0 + }, + "data": "test", + "raw": "test" + } + ] + }, + { + "type": "Text", + "span": { + "start": 165, + "end": 170, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 170, + "end": 217, + "ctxt": 0 + }, + "tagName": "foo", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "foo:a", + "rawName": "foo:a", + "value": "\"test1\"", + "rawValue": "'\"test1\"'" + }, + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "bar:b", + "rawName": "bar:b", + "value": "'test2'", + "rawValue": "\"'test2'\"" + } + ], + "children": [ + { + "type": "Text", + "span": { + "start": 207, + "end": 211, + "ctxt": 0 + }, + "data": "test", + "raw": "test" + } + ] + }, + { + "type": "Text", + "span": { + "start": 217, + "end": 222, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 222, + "end": 252, + "ctxt": 0 + }, + "tagName": "foo", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 229, + "end": 230, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "a", + "rawName": "a", + "value": "test1", + "rawValue": "'test1'" + } + ], + "children": [] + }, + { + "type": "Text", + "span": { + "start": 252, + "end": 257, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 257, + "end": 275, + "ctxt": 0 + }, + "tagName": "foo", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "foo", + "rawName": "foo", + "value": "", + "rawValue": "\"\"" + } + ], + "children": [] + }, + { + "type": "Text", + "span": { + "start": 275, + "end": 280, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 280, + "end": 299, + "ctxt": 0 + }, + "tagName": "foo", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "foo", + "rawName": "foo", + "value": "'", + "rawValue": "\"'\"" + } + ], + "children": [] + }, + { + "type": "Text", + "span": { + "start": 299, + "end": 304, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 304, + "end": 322, + "ctxt": 0 + }, + "tagName": "foo", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "foo", + "rawName": "foo", + "value": "", + "rawValue": "''" + } + ], + "children": [] + }, + { + "type": "Text", + "span": { + "start": 322, + "end": 327, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 327, + "end": 346, + "ctxt": 0 + }, + "tagName": "foo", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "foo", + "rawName": "foo", + "value": "\"", + "rawValue": "'\"'" + } + ], + "children": [] + }, + { + "type": "Text", + "span": { + "start": 346, + "end": 351, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 351, + "end": 393, + "ctxt": 0 + }, + "tagName": "MyElement", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "myAttribute", + "rawName": "myAttribute", + "value": "attribute value", + "rawValue": "\"attribute value\"" + } + ], + "children": [] + }, + { + "type": "Text", + "span": { + "start": 393, + "end": 398, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 398, + "end": 444, + "ctxt": 0 + }, + "tagName": "MyElement", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "myAttribute", + "rawName": "myAttribute", + "value": "attribute\n value", + "rawValue": "\"attribute\n value\"" + } + ], + "children": [] + }, + { + "type": "Text", + "span": { + "start": 444, + "end": 449, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 449, + "end": 541, + "ctxt": 0 + }, + "tagName": "MyElement", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "nsA:myAttribute1", + "rawName": "nsA:myAttribute1", + "value": "attribute value", + "rawValue": "\"attribute value\"" + }, + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "myAttribute2", + "rawName": "myAttribute2", + "value": "attribute value", + "rawValue": "\"attribute value\"" + } + ], + "children": [ + { + "type": "Text", + "span": { + "start": 526, + "end": 529, + "ctxt": 0 + }, + "data": "...", + "raw": "..." + } + ] + }, + { + "type": "Text", + "span": { + "start": 541, + "end": 546, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 546, + "end": 596, + "ctxt": 0 + }, + "tagName": "foo", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "attributeName", + "rawName": "attributeName", + "value": "He said \"OK\"", + "rawValue": "\"He said "OK"\"" + } + ], + "children": [] + }, + { + "type": "Text", + "span": { + "start": 596, + "end": 601, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 601, + "end": 647, + "ctxt": 0 + }, + "tagName": "foo", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "attributeName", + "rawName": "attributeName", + "value": "He said OK>", + "rawValue": "\"He said >OK>\"" + } + ], + "children": [] + }, + { + "type": "Text", + "span": { + "start": 698, + "end": 703, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 703, + "end": 743, + "ctxt": 0 + }, + "tagName": "foo", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "attributeName", + "rawName": "attributeName", + "value": "He said >OK>", + "rawValue": "\"He said >OK>\"" + } + ], + "children": [] + }, + { + "type": "Text", + "span": { + "start": 743, + "end": 748, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 748, + "end": 798, + "ctxt": 0 + }, + "tagName": "foo", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "attributeName", + "rawName": "attributeName", + "value": "He said 'OK'", + "rawValue": "\"He said 'OK'\"" + } + ], + "children": [] + }, + { + "type": "Text", + "span": { + "start": 798, + "end": 803, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 803, + "end": 851, + "ctxt": 0 + }, + "tagName": "foo", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "attributeName", + "rawName": "attributeName", + "value": "He said &OK&", + "rawValue": "\"He said &OK&\"" + } + ], + "children": [] + }, + { + "type": "Text", + "span": { + "start": 851, + "end": 856, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 856, + "end": 892, + "ctxt": 0 + }, + "tagName": "foo", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "a", + "rawName": "a", + "value": "b", + "rawValue": "\"b\"" + }, + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "c", + "rawName": "c", + "value": "d", + "rawValue": "\"d\"" + } + ], + "children": [] + }, + { + "type": "Text", + "span": { + "start": 892, + "end": 893, + "ctxt": 0 + }, + "data": "\n", + "raw": "\n" + } + ] + } + ] +} diff --git a/crates/swc_xml_parser/tests/fixture/attribute/span.swc-stderr b/crates/swc_xml_parser/tests/fixture/attribute/span.swc-stderr new file mode 100644 index 000000000000..01e274decdec --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/attribute/span.swc-stderr @@ -0,0 +1,873 @@ + + x Document + ,-[$DIR/tests/fixture/attribute/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | | test + 4 | | + 5 | | test + 6 | | test + 7 | | test + 8 | | + 9 | | + 10 | | + 11 | | + 12 | | + 13 | | + 14 | | + 16 | | ... + 17 | | + 18 | | + 19 | | + 20 | | + 21 | | + 22 | | + 23 | | + 27 | `-> + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | | test + 4 | | + 5 | | test + 6 | | test + 7 | | test + 8 | | + 9 | | + 10 | | + 11 | | + 12 | | + 13 | | + 14 | | + 16 | | ... + 17 | | + 18 | | + 19 | | + 20 | | + 21 | | + 22 | | + 23 | | + 27 | `-> + `---- + + x Element + ,-[$DIR/tests/fixture/attribute/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | | test + 4 | | + 5 | | test + 6 | | test + 7 | | test + 8 | | + 9 | | + 10 | | + 11 | | + 12 | | + 13 | | + 14 | | + 16 | | ... + 17 | | + 18 | | + 19 | | + 20 | | + 21 | | + 22 | | + 23 | | + 27 | `-> + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:1:1] + 1 | ,-> + 2 | `-> + 3 | test + `---- + + x Text + ,-[$DIR/tests/fixture/attribute/input.xml:1:1] + 1 | ,-> + 2 | `-> + 3 | test + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:1:1] + 1 | + 2 | + : ^^^^^^^^^^^^ + 3 | test + `---- + + x Element + ,-[$DIR/tests/fixture/attribute/input.xml:1:1] + 1 | + 2 | + : ^^^^^^^^^^^^ + 3 | test + `---- + + x Attribute + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:1:1] + 1 | + 2 | ,-> + 3 | `-> test + 4 | + `---- + + x Text + ,-[$DIR/tests/fixture/attribute/input.xml:1:1] + 1 | + 2 | ,-> + 3 | `-> test + 4 | + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:2:1] + 2 | + 3 | test + : ^^^^^^^^^^^^^^^^^^^^^^^^ + 4 | + `---- + + x Element + ,-[$DIR/tests/fixture/attribute/input.xml:2:1] + 2 | + 3 | test + : ^^^^^^^^^^^^^^^^^^^^^^^^ + 4 | + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:2:1] + 2 | + 3 | test + : ^^^^ + 4 | + `---- + + x Text + ,-[$DIR/tests/fixture/attribute/input.xml:2:1] + 2 | + 3 | test + : ^^^^ + 4 | + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:2:1] + 2 | + 3 | ,-> test + 4 | `-> + 5 | test + `---- + + x Text + ,-[$DIR/tests/fixture/attribute/input.xml:2:1] + 2 | + 3 | ,-> test + 4 | `-> + 5 | test + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:3:1] + 3 | test + 4 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 5 | test + `---- + + x Element + ,-[$DIR/tests/fixture/attribute/input.xml:3:1] + 3 | test + 4 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 5 | test + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:3:1] + 3 | test + 4 | ,-> + 5 | `-> test + 6 | test + `---- + + x Text + ,-[$DIR/tests/fixture/attribute/input.xml:3:1] + 3 | test + 4 | ,-> + 5 | `-> test + 6 | test + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:4:1] + 4 | + 5 | test + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 6 | test + `---- + + x Element + ,-[$DIR/tests/fixture/attribute/input.xml:4:1] + 4 | + 5 | test + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 6 | test + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:4:1] + 4 | + 5 | test + : ^^^^ + 6 | test + `---- + + x Text + ,-[$DIR/tests/fixture/attribute/input.xml:4:1] + 4 | + 5 | test + : ^^^^ + 6 | test + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:4:1] + 4 | + 5 | ,-> test + 6 | `-> test + 7 | test + `---- + + x Text + ,-[$DIR/tests/fixture/attribute/input.xml:4:1] + 4 | + 5 | ,-> test + 6 | `-> test + 7 | test + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:5:1] + 5 | test + 6 | test + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 7 | test + `---- + + x Element + ,-[$DIR/tests/fixture/attribute/input.xml:5:1] + 5 | test + 6 | test + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 7 | test + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:5:1] + 5 | test + 6 | test + : ^^^^ + 7 | test + `---- + + x Text + ,-[$DIR/tests/fixture/attribute/input.xml:5:1] + 5 | test + 6 | test + : ^^^^ + 7 | test + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:5:1] + 5 | test + 6 | ,-> test + 7 | `-> test + 8 | + `---- + + x Text + ,-[$DIR/tests/fixture/attribute/input.xml:5:1] + 5 | test + 6 | ,-> test + 7 | `-> test + 8 | + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:6:1] + 6 | test + 7 | test + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 8 | + `---- + + x Element + ,-[$DIR/tests/fixture/attribute/input.xml:6:1] + 6 | test + 7 | test + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 8 | + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:6:1] + 6 | test + 7 | test + : ^^^^ + 8 | + `---- + + x Text + ,-[$DIR/tests/fixture/attribute/input.xml:6:1] + 6 | test + 7 | test + : ^^^^ + 8 | + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:6:1] + 6 | test + 7 | ,-> test + 8 | `-> + 9 | + `---- + + x Text + ,-[$DIR/tests/fixture/attribute/input.xml:6:1] + 6 | test + 7 | ,-> test + 8 | `-> + 9 | + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:7:1] + 7 | test + 8 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 9 | + `---- + + x Element + ,-[$DIR/tests/fixture/attribute/input.xml:7:1] + 7 | test + 8 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 9 | + `---- + + x Attribute + ,-[$DIR/tests/fixture/attribute/input.xml:7:1] + 7 | test + 8 | + : ^ + 9 | + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:7:1] + 7 | test + 8 | ,-> + 9 | `-> + 10 | + `---- + + x Text + ,-[$DIR/tests/fixture/attribute/input.xml:7:1] + 7 | test + 8 | ,-> + 9 | `-> + 10 | + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:8:1] + 8 | + 9 | + : ^^^^^^^^^^^^^^^^^^ + 10 | + `---- + + x Element + ,-[$DIR/tests/fixture/attribute/input.xml:8:1] + 8 | + 9 | + : ^^^^^^^^^^^^^^^^^^ + 10 | + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:8:1] + 8 | + 9 | ,-> + 10 | `-> + 11 | + `---- + + x Text + ,-[$DIR/tests/fixture/attribute/input.xml:8:1] + 8 | + 9 | ,-> + 10 | `-> + 11 | + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:9:1] + 9 | + 10 | + : ^^^^^^^^^^^^^^^^^^^ + 11 | + `---- + + x Element + ,-[$DIR/tests/fixture/attribute/input.xml:9:1] + 9 | + 10 | + : ^^^^^^^^^^^^^^^^^^^ + 11 | + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:9:1] + 9 | + 10 | ,-> + 11 | `-> + 12 | + `---- + + x Text + ,-[$DIR/tests/fixture/attribute/input.xml:9:1] + 9 | + 10 | ,-> + 11 | `-> + 12 | + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:10:1] + 10 | + 11 | + : ^^^^^^^^^^^^^^^^^^ + 12 | + `---- + + x Element + ,-[$DIR/tests/fixture/attribute/input.xml:10:1] + 10 | + 11 | + : ^^^^^^^^^^^^^^^^^^ + 12 | + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:10:1] + 10 | + 11 | ,-> + 12 | `-> + 13 | + `---- + + x Text + ,-[$DIR/tests/fixture/attribute/input.xml:10:1] + 10 | + 11 | ,-> + 12 | `-> + 13 | + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:11:1] + 11 | + 12 | + : ^^^^^^^^^^^^^^^^^^^ + 13 | + `---- + + x Element + ,-[$DIR/tests/fixture/attribute/input.xml:11:1] + 11 | + 12 | + : ^^^^^^^^^^^^^^^^^^^ + 13 | + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:11:1] + 11 | + 12 | ,-> + 13 | `-> + 14 | + 13 | `-> + 14 | + 13 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 14 | + 13 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 14 | + 13 | ,-> + 14 | `-> + `---- + + x Text + ,-[$DIR/tests/fixture/attribute/input.xml:12:1] + 12 | + 13 | ,-> + 14 | `-> + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:13:1] + 13 | + 14 | ,-> + 16 | ... + `---- + + x Element + ,-[$DIR/tests/fixture/attribute/input.xml:13:1] + 13 | + 14 | ,-> + 16 | ... + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:14:1] + 14 | + 16 | `-> ... + 17 | + `---- + + x Text + ,-[$DIR/tests/fixture/attribute/input.xml:14:1] + 14 | + 16 | `-> ... + 17 | + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:15:1] + 15 | value"/> + 16 | ... + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 17 | + `---- + + x Element + ,-[$DIR/tests/fixture/attribute/input.xml:15:1] + 15 | value"/> + 16 | ... + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 17 | + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:15:1] + 15 | value"/> + 16 | ... + : ^^^ + 17 | + `---- + + x Text + ,-[$DIR/tests/fixture/attribute/input.xml:15:1] + 15 | value"/> + 16 | ... + : ^^^ + 17 | + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:15:1] + 15 | value"/> + 16 | ,-> ... + 17 | `-> + 18 | + `---- + + x Text + ,-[$DIR/tests/fixture/attribute/input.xml:15:1] + 15 | value"/> + 16 | ,-> ... + 17 | `-> + 18 | + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:16:1] + 16 | ... + 17 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 18 | + `---- + + x Element + ,-[$DIR/tests/fixture/attribute/input.xml:16:1] + 16 | ... + 17 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 18 | + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:16:1] + 16 | ... + 17 | ,-> + 18 | `-> + 19 | + `---- + + x Text + ,-[$DIR/tests/fixture/attribute/input.xml:16:1] + 16 | ... + 17 | ,-> + 18 | `-> + 19 | + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:17:1] + 17 | + 18 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 19 | + `---- + + x Element + ,-[$DIR/tests/fixture/attribute/input.xml:17:1] + 17 | + 18 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 19 | + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:17:1] + 17 | + 18 | ,-> + 19 | `-> + 20 | + `---- + + x Text + ,-[$DIR/tests/fixture/attribute/input.xml:17:1] + 17 | + 18 | ,-> + 19 | `-> + 20 | + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:18:1] + 18 | + 19 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 20 | + `---- + + x Element + ,-[$DIR/tests/fixture/attribute/input.xml:18:1] + 18 | + 19 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 20 | + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:18:1] + 18 | + 19 | ,-> + 20 | `-> + 21 | + `---- + + x Text + ,-[$DIR/tests/fixture/attribute/input.xml:18:1] + 18 | + 19 | ,-> + 20 | `-> + 21 | + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:19:1] + 19 | + 20 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 21 | + `---- + + x Element + ,-[$DIR/tests/fixture/attribute/input.xml:19:1] + 19 | + 20 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 21 | + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:19:1] + 19 | + 20 | ,-> + 21 | `-> + 22 | + `---- + + x Text + ,-[$DIR/tests/fixture/attribute/input.xml:19:1] + 19 | + 20 | ,-> + 21 | `-> + 22 | + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:20:1] + 20 | + 21 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 22 | + `---- + + x Element + ,-[$DIR/tests/fixture/attribute/input.xml:20:1] + 20 | + 21 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 22 | + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:20:1] + 20 | + 21 | ,-> + 22 | `-> + 23 | + 21 | ,-> + 22 | `-> + 23 | + 22 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 23 | + 22 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 23 | + 22 | ,-> + 23 | `-> + 22 | ,-> + 23 | `-> + 23 | ,-> > + 27 | + `---- + + x Element + ,-[$DIR/tests/fixture/attribute/input.xml:22:1] + 22 | + 23 | ,-> > + 27 | + `---- + + x Child + ,-[$DIR/tests/fixture/attribute/input.xml:25:1] + 25 | c="d" + 26 | > + : ^ + 27 | + `---- + + x Text + ,-[$DIR/tests/fixture/attribute/input.xml:25:1] + 25 | c="d" + 26 | > + : ^ + 27 | + `---- diff --git a/crates/swc_xml_parser/tests/fixture/cdata_section/dom.txt b/crates/swc_xml_parser/tests/fixture/cdata_section/dom.txt index b3932f237ef5..2b9c890962d4 100644 --- a/crates/swc_xml_parser/tests/fixture/cdata_section/dom.txt +++ b/crates/swc_xml_parser/tests/fixture/cdata_section/dom.txt @@ -54,4 +54,16 @@ " |

| " + " +| +| " + " +| +| " + bar" +| "foo + " +| " + " +| "" " diff --git a/crates/swc_xml_parser/tests/fixture/cdata_section/input.xml b/crates/swc_xml_parser/tests/fixture/cdata_section/input.xml index 0a7a04578438..1b84f58f4590 100644 --- a/crates/swc_xml_parser/tests/fixture/cdata_section/input.xml +++ b/crates/swc_xml_parser/tests/fixture/cdata_section/input.xml @@ -22,4 +22,9 @@

+ + + bar Value ]]>foo + + "
diff --git a/crates/swc_xml_parser/tests/fixture/cdata_section/output.json b/crates/swc_xml_parser/tests/fixture/cdata_section/output.json index d33659fa05ba..1571c77d6dc7 100644 --- a/crates/swc_xml_parser/tests/fixture/cdata_section/output.json +++ b/crates/swc_xml_parser/tests/fixture/cdata_section/output.json @@ -2,7 +2,7 @@ "type": "Document", "span": { "start": 1, - "end": 883, + "end": 1021, "ctxt": 0 }, "children": [ @@ -10,7 +10,7 @@ "type": "Element", "span": { "start": 1, - "end": 882, + "end": 1020, "ctxt": 0 }, "tagName": "root", @@ -526,11 +526,95 @@ "type": "Text", "span": { "start": 874, - "end": 875, + "end": 879, "ctxt": 0 }, - "data": "\n", - "raw": "\n" + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 879, + "end": 1011, + "ctxt": 0 + }, + "tagName": "DocumentElement", + "attributes": [], + "children": [ + { + "type": "Text", + "span": { + "start": 896, + "end": 905, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 905, + "end": 988, + "ctxt": 0 + }, + "tagName": "foo", + "attributes": [], + "children": [ + { + "type": "Text", + "span": { + "start": 910, + "end": 926, + "ctxt": 0 + }, + "data": "\n bar", + "raw": "\n bar" + }, + { + "type": "CdataSection", + "span": { + "start": 926, + "end": 970, + "ctxt": 0 + }, + "data": " Some Value ", + "raw": " Value ]]>" + }, + { + "type": "Text", + "span": { + "start": 970, + "end": 982, + "ctxt": 0 + }, + "data": "foo\n ", + "raw": "foo\n " + } + ] + }, + { + "type": "Text", + "span": { + "start": 988, + "end": 993, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + } + ] + }, + { + "type": "Text", + "span": { + "start": 1011, + "end": 1013, + "ctxt": 0 + }, + "data": "\"\n", + "raw": "\"\n" } ] } diff --git a/crates/swc_xml_parser/tests/fixture/cdata_section/span.swc-stderr b/crates/swc_xml_parser/tests/fixture/cdata_section/span.swc-stderr index 183e10f1b6c9..973e9370e587 100644 --- a/crates/swc_xml_parser/tests/fixture/cdata_section/span.swc-stderr +++ b/crates/swc_xml_parser/tests/fixture/cdata_section/span.swc-stderr @@ -25,7 +25,12 @@ 22 | |

23 | |

24 | |

- 25 | `->
+ 25 | | + 26 | | + 27 | | bar Value ]]>foo + 28 | | + 29 | | " + 30 | `->
`---- x Child @@ -54,7 +59,12 @@ 22 | |

23 | |

24 | |

- 25 | `-> + 25 | | + 26 | | + 27 | | bar Value ]]>foo + 28 | | + 29 | | " + 30 | `-> `---- x Element @@ -83,7 +93,12 @@ 22 | |

23 | |

24 | |

- 25 | `-> + 25 | | + 26 | | + 27 | | bar Value ]]>foo + 28 | | + 29 | | " + 30 | `-> `---- x Child @@ -726,7 +741,7 @@ 22 |

23 | ,->

24 | `->

- 25 | + 25 | `---- x Text @@ -734,7 +749,7 @@ 22 |

23 | ,->

24 | `->

- 25 | + 25 | `---- x Child @@ -742,7 +757,7 @@ 23 |

24 |

: ^^^^^^^^^^^^^^^^^^^ - 25 | + 25 | `---- x Element @@ -750,7 +765,7 @@ 23 |

24 |

: ^^^^^^^^^^^^^^^^^^^ - 25 | + 25 | `---- x Child @@ -758,21 +773,149 @@ 23 |

24 |

: ^^^^^^^^^^^^ - 25 | + 25 | `---- x Child ,-[$DIR/tests/fixture/cdata_section/input.xml:23:1] - 23 |

- 24 |

- : ^ - 25 | + 23 |

+ 24 | ,->

+ 25 | `-> + 26 | `---- x Text ,-[$DIR/tests/fixture/cdata_section/input.xml:23:1] - 23 |

- 24 |

- : ^ - 25 | + 23 |

+ 24 | ,->

+ 25 | `-> + 26 | + `---- + + x Child + ,-[$DIR/tests/fixture/cdata_section/input.xml:24:1] + 24 |

+ 25 | ,-> + 26 | | + 27 | | bar Value ]]>foo + 28 | | + 29 | `-> " + 30 | + `---- + + x Element + ,-[$DIR/tests/fixture/cdata_section/input.xml:24:1] + 24 |

+ 25 | ,-> + 26 | | + 27 | | bar Value ]]>foo + 28 | | + 29 | `-> " + 30 | + `---- + + x Child + ,-[$DIR/tests/fixture/cdata_section/input.xml:24:1] + 24 |

+ 25 | ,-> + 26 | `-> + 27 | bar Value ]]>foo + `---- + + x Text + ,-[$DIR/tests/fixture/cdata_section/input.xml:24:1] + 24 |

+ 25 | ,-> + 26 | `-> + 27 | bar Value ]]>foo + `---- + + x Child + ,-[$DIR/tests/fixture/cdata_section/input.xml:25:1] + 25 | + 26 | ,-> + 27 | | bar Value ]]>foo + 28 | `-> + 29 | " + `---- + + x Element + ,-[$DIR/tests/fixture/cdata_section/input.xml:25:1] + 25 | + 26 | ,-> + 27 | | bar Value ]]>foo + 28 | `-> + 29 | " + `---- + + x Child + ,-[$DIR/tests/fixture/cdata_section/input.xml:25:1] + 25 | + 26 | ,-> + 27 | `-> bar Value ]]>foo + 28 | + `---- + + x Text + ,-[$DIR/tests/fixture/cdata_section/input.xml:25:1] + 25 | + 26 | ,-> + 27 | `-> bar Value ]]>foo + 28 | + `---- + + x Child + ,-[$DIR/tests/fixture/cdata_section/input.xml:26:1] + 26 | + 27 | bar Value ]]>foo + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 28 | + `---- + + x Child + ,-[$DIR/tests/fixture/cdata_section/input.xml:26:1] + 26 | + 27 | ,-> bar Value ]]>foo + 28 | `-> + 29 | " + `---- + + x Text + ,-[$DIR/tests/fixture/cdata_section/input.xml:26:1] + 26 | + 27 | ,-> bar Value ]]>foo + 28 | `-> + 29 | " + `---- + + x Child + ,-[$DIR/tests/fixture/cdata_section/input.xml:27:1] + 27 | bar Value ]]>foo + 28 | ,-> + 29 | `-> " + 30 | + `---- + + x Text + ,-[$DIR/tests/fixture/cdata_section/input.xml:27:1] + 27 | bar Value ]]>foo + 28 | ,->
+ 29 | `->
" + 30 | + `---- + + x Child + ,-[$DIR/tests/fixture/cdata_section/input.xml:28:1] + 28 |
+ 29 |
" + : ^^ + 30 | + `---- + + x Text + ,-[$DIR/tests/fixture/cdata_section/input.xml:28:1] + 28 |
+ 29 |
" + : ^^ + 30 | `---- diff --git a/crates/swc_xml_parser/tests/fixture/comment-no-dtd/dom.txt b/crates/swc_xml_parser/tests/fixture/comment-no-dtd/dom.txt new file mode 100644 index 000000000000..b72ebdb72284 --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/comment-no-dtd/dom.txt @@ -0,0 +1,2 @@ +| +| diff --git a/crates/swc_xml_parser/tests/fixture/comment-no-dtd/input.xml b/crates/swc_xml_parser/tests/fixture/comment-no-dtd/input.xml new file mode 100644 index 000000000000..e67ed03f18c1 --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/comment-no-dtd/input.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/crates/swc_xml_parser/tests/fixture/comment-no-dtd/output.json b/crates/swc_xml_parser/tests/fixture/comment-no-dtd/output.json new file mode 100644 index 000000000000..941cb6cefdbf --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/comment-no-dtd/output.json @@ -0,0 +1,31 @@ +{ + "type": "Document", + "span": { + "start": 1, + "end": 39, + "ctxt": 0 + }, + "children": [ + { + "type": "Comment", + "span": { + "start": 1, + "end": 20, + "ctxt": 0 + }, + "data": " My Comment ", + "raw": "" + }, + { + "type": "Element", + "span": { + "start": 21, + "end": 39, + "ctxt": 0 + }, + "tagName": "DocumentElement", + "attributes": [], + "children": [] + } + ] +} diff --git a/crates/swc_xml_parser/tests/fixture/comment-no-dtd/span.swc-stderr b/crates/swc_xml_parser/tests/fixture/comment-no-dtd/span.swc-stderr new file mode 100644 index 000000000000..2cd68361c734 --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/comment-no-dtd/span.swc-stderr @@ -0,0 +1,34 @@ + + x Document + ,-[$DIR/tests/fixture/comment-no-dtd/input.xml:1:1] + 1 | ,-> + 2 | `-> + `---- + + x Child + ,-[$DIR/tests/fixture/comment-no-dtd/input.xml:1:1] + 1 | + : ^^^^^^^^^^^^^^^^^^^ + 2 | + `---- + + x Comment + ,-[$DIR/tests/fixture/comment-no-dtd/input.xml:1:1] + 1 | + : ^^^^^^^^^^^^^^^^^^^ + 2 | + `---- + + x Child + ,-[$DIR/tests/fixture/comment-no-dtd/input.xml:1:1] + 1 | + 2 | + : ^^^^^^^^^^^^^^^^^^ + `---- + + x Element + ,-[$DIR/tests/fixture/comment-no-dtd/input.xml:1:1] + 1 | + 2 | + : ^^^^^^^^^^^^^^^^^^ + `---- diff --git a/crates/swc_xml_parser/tests/fixture/comments/dom.txt b/crates/swc_xml_parser/tests/fixture/comments/dom.txt index 85f6a65ed484..04f5e34c9571 100644 --- a/crates/swc_xml_parser/tests/fixture/comments/dom.txt +++ b/crates/swc_xml_parser/tests/fixture/comments/dom.txt @@ -1,4 +1,5 @@ +| | | " " @@ -39,5 +40,32 @@ | " " | +| " + " +| +| myAttribute="myAttributeValue" +| " + " +| +| " + " +| +| "Element Value" +| " + " +| " + " +| +| myAttribute="my Attribute Value" +| " + " +| +| " + Element " +| +| " Value + " +| " + " | " " diff --git a/crates/swc_xml_parser/tests/fixture/comments/input.xml b/crates/swc_xml_parser/tests/fixture/comments/input.xml index 77fc50e97741..a04e0315cded 100644 --- a/crates/swc_xml_parser/tests/fixture/comments/input.xml +++ b/crates/swc_xml_parser/tests/fixture/comments/input.xml @@ -1,4 +1,5 @@ + @@ -13,5 +14,14 @@ + + + Element Value + + + + Element Value + + diff --git a/crates/swc_xml_parser/tests/fixture/comments/output.json b/crates/swc_xml_parser/tests/fixture/comments/output.json index ababfb96ae4a..819e9273139d 100644 --- a/crates/swc_xml_parser/tests/fixture/comments/output.json +++ b/crates/swc_xml_parser/tests/fixture/comments/output.json @@ -2,7 +2,7 @@ "type": "Document", "span": { "start": 1, - "end": 264, + "end": 606, "ctxt": 0 }, "children": [ @@ -17,10 +17,20 @@ "data": "version=\"1.0\" encoding=\"UTF-8\"" }, { - "type": "Element", + "type": "Comment", "span": { "start": 40, - "end": 262, + "end": 59, + "ctxt": 0 + }, + "data": " My Comment ", + "raw": "" + }, + { + "type": "Element", + "span": { + "start": 60, + "end": 604, "ctxt": 0 }, "tagName": "root", @@ -29,8 +39,8 @@ { "type": "Text", "span": { - "start": 46, - "end": 51, + "start": 66, + "end": 71, "ctxt": 0 }, "data": "\n ", @@ -39,8 +49,8 @@ { "type": "Comment", "span": { - "start": 51, - "end": 65, + "start": 71, + "end": 85, "ctxt": 0 }, "data": "comment", @@ -49,8 +59,8 @@ { "type": "Text", "span": { - "start": 65, - "end": 70, + "start": 85, + "end": 90, "ctxt": 0 }, "data": "\n ", @@ -59,8 +69,8 @@ { "type": "Comment", "span": { - "start": 70, - "end": 83, + "start": 90, + "end": 103, "ctxt": 0 }, "data": "", @@ -69,8 +79,8 @@ { "type": "Text", "span": { - "start": 83, - "end": 88, + "start": 103, + "end": 108, "ctxt": 0 }, "data": "\n ", @@ -79,8 +89,8 @@ { "type": "Comment", "span": { - "start": 88, - "end": 99, + "start": 108, + "end": 119, "ctxt": 0 }, "data": "", @@ -189,8 +199,8 @@ { "type": "Text", "span": { - "start": 175, - "end": 180, + "start": 195, + "end": 200, "ctxt": 0 }, "data": "\n ", @@ -199,8 +209,8 @@ { "type": "Comment", "span": { - "start": 180, - "end": 188, + "start": 200, + "end": 208, "ctxt": 0 }, "data": "<", @@ -209,8 +219,8 @@ { "type": "Text", "span": { - "start": 188, - "end": 193, + "start": 208, + "end": 213, "ctxt": 0 }, "data": "\n ", @@ -219,8 +229,8 @@ { "type": "Comment", "span": { - "start": 193, - "end": 202, + "start": 213, + "end": 222, "ctxt": 0 }, "data": "-a", @@ -269,8 +279,8 @@ { "type": "Text", "span": { - "start": 232, - "end": 237, + "start": 252, + "end": 257, "ctxt": 0 }, "data": "\n ", @@ -279,8 +289,8 @@ { "type": "Comment", "span": { - "start": 237, - "end": 254, + "start": 257, + "end": 274, "ctxt": 0 }, "data": "-", @@ -289,8 +299,206 @@ { "type": "Text", "span": { - "start": 254, - "end": 255, + "start": 274, + "end": 279, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 279, + "end": 429, + "ctxt": 0 + }, + "tagName": "DocumentElement", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "myAttribute", + "rawName": "myAttribute", + "value": "myAttributeValue", + "rawValue": "\"myAttributeValue\"" + } + ], + "children": [ + { + "type": "Text", + "span": { + "start": 327, + "end": 336, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Comment", + "span": { + "start": 336, + "end": 355, + "ctxt": 0 + }, + "data": " My Comment ", + "raw": "" + }, + { + "type": "Text", + "span": { + "start": 355, + "end": 364, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 364, + "end": 406, + "ctxt": 0 + }, + "tagName": "ChildElement", + "attributes": [], + "children": [ + { + "type": "Text", + "span": { + "start": 378, + "end": 391, + "ctxt": 0 + }, + "data": "Element Value", + "raw": "Element Value" + } + ] + }, + { + "type": "Text", + "span": { + "start": 406, + "end": 411, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + } + ] + }, + { + "type": "Text", + "span": { + "start": 429, + "end": 434, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 434, + "end": 596, + "ctxt": 0 + }, + "tagName": "DocumentElement", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "myAttribute", + "rawName": "myAttribute", + "value": "my Attribute Value", + "rawValue": "\"my Attribute Value\"" + } + ], + "children": [ + { + "type": "Text", + "span": { + "start": 484, + "end": 493, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 493, + "end": 573, + "ctxt": 0 + }, + "tagName": "ChildElement", + "attributes": [], + "children": [ + { + "type": "Text", + "span": { + "start": 507, + "end": 524, + "ctxt": 0 + }, + "data": "\n Element ", + "raw": "\n Element " + }, + { + "type": "Comment", + "span": { + "start": 524, + "end": 543, + "ctxt": 0 + }, + "data": " My Comment ", + "raw": "" + }, + { + "type": "Text", + "span": { + "start": 543, + "end": 558, + "ctxt": 0 + }, + "data": " Value\n ", + "raw": " Value\n " + } + ] + }, + { + "type": "Text", + "span": { + "start": 573, + "end": 578, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + } + ] + }, + { + "type": "Text", + "span": { + "start": 596, + "end": 597, "ctxt": 0 }, "data": "\n", diff --git a/crates/swc_xml_parser/tests/fixture/comments/span.swc-stderr b/crates/swc_xml_parser/tests/fixture/comments/span.swc-stderr index 4cf2e32fe11f..a7a8fcd75e98 100644 --- a/crates/swc_xml_parser/tests/fixture/comments/span.swc-stderr +++ b/crates/swc_xml_parser/tests/fixture/comments/span.swc-stderr @@ -2,506 +2,820 @@ x Document ,-[$DIR/tests/fixture/comments/input.xml:1:1] 1 | ,-> - 2 | | - 3 | | - 4 | | - 5 | | - 6 | | - 7 | | - 8 | | - 9 | | - 10 | | - 11 | | - 12 | | - 13 | | - 14 | | - 15 | | - 16 | | - 17 | `-> + 2 | | + 3 | | + 4 | | + 5 | | + 6 | | + 7 | | + 8 | | + 9 | | + 10 | | + 11 | | + 12 | | + 13 | | + 14 | | + 15 | | + 16 | | + 17 | | + 18 | | + 19 | | Element Value + 20 | | + 21 | | + 22 | | + 23 | | Element Value + 24 | | + 25 | | + 26 | | + 27 | `-> `---- x Child ,-[$DIR/tests/fixture/comments/input.xml:1:1] 1 | : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 2 | + 2 | `---- x ProcessingInstruction ,-[$DIR/tests/fixture/comments/input.xml:1:1] 1 | : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 2 | + 2 | `---- - x Child - ,-[$DIR/tests/fixture/comments/input.xml:1:1] - 1 | - 2 | ,-> - 3 | | - 4 | | - 5 | | - 6 | | - 7 | | - 8 | | - 9 | | - 10 | | - 11 | | - 12 | | - 13 | | - 14 | | - 15 | | - 16 | `-> - `---- - - x Element - ,-[$DIR/tests/fixture/comments/input.xml:1:1] - 1 | - 2 | ,-> - 3 | | - 4 | | - 5 | | - 6 | | - 7 | | - 8 | | - 9 | | - 10 | | - 11 | | - 12 | | - 13 | | - 14 | | - 15 | | - 16 | `-> - `---- - x Child ,-[$DIR/tests/fixture/comments/input.xml:1:1] - 1 | - 2 | ,-> - 3 | `-> - 4 | + 1 | + 2 | + : ^^^^^^^^^^^^^^^^^^^ + 3 | `---- - x Text + x Comment ,-[$DIR/tests/fixture/comments/input.xml:1:1] - 1 | - 2 | ,-> - 3 | `-> - 4 | + 1 | + 2 | + : ^^^^^^^^^^^^^^^^^^^ + 3 | `---- x Child - ,-[$DIR/tests/fixture/comments/input.xml:2:1] - 2 | - 3 | - : ^^^^^^^^^^^^^^ - 4 | - `---- + ,-[$DIR/tests/fixture/comments/input.xml:2:1] + 2 | + 3 | ,-> + 4 | | + 5 | | + 6 | | + 7 | | + 8 | | + 9 | | + 10 | | + 11 | | + 12 | | + 13 | | + 14 | | + 15 | | + 16 | | + 17 | | + 18 | | + 19 | | Element Value + 20 | | + 21 | | + 22 | | + 23 | | Element Value + 24 | | + 25 | | + 26 | `-> + `---- - x Comment - ,-[$DIR/tests/fixture/comments/input.xml:2:1] - 2 | - 3 | - : ^^^^^^^^^^^^^^ - 4 | - `---- + x Element + ,-[$DIR/tests/fixture/comments/input.xml:2:1] + 2 | + 3 | ,-> + 4 | | + 5 | | + 6 | | + 7 | | + 8 | | + 9 | | + 10 | | + 11 | | + 12 | | + 13 | | + 14 | | + 15 | | + 16 | | + 17 | | + 18 | | + 19 | | Element Value + 20 | | + 21 | | + 22 | | + 23 | | Element Value + 24 | | + 25 | | + 26 | `-> + `---- x Child ,-[$DIR/tests/fixture/comments/input.xml:2:1] - 2 | - 3 | ,-> - 4 | `-> - 5 | + 2 | + 3 | ,-> + 4 | `-> + 5 | `---- x Text ,-[$DIR/tests/fixture/comments/input.xml:2:1] - 2 | - 3 | ,-> - 4 | `-> - 5 | + 2 | + 3 | ,-> + 4 | `-> + 5 | `---- x Child ,-[$DIR/tests/fixture/comments/input.xml:3:1] - 3 | - 4 | - : ^^^^^^^^^^^^^ - 5 | + 3 | + 4 | + : ^^^^^^^^^^^^^^ + 5 | `---- x Comment ,-[$DIR/tests/fixture/comments/input.xml:3:1] - 3 | - 4 | - : ^^^^^^^^^^^^^ - 5 | + 3 | + 4 | + : ^^^^^^^^^^^^^^ + 5 | `---- x Child ,-[$DIR/tests/fixture/comments/input.xml:3:1] - 3 | - 4 | ,-> - 5 | `-> - 6 | + 3 | + 4 | ,-> + 5 | `-> + 6 | `---- x Text ,-[$DIR/tests/fixture/comments/input.xml:3:1] - 3 | - 4 | ,-> - 5 | `-> - 6 | + 3 | + 4 | ,-> + 5 | `-> + 6 | `---- x Child ,-[$DIR/tests/fixture/comments/input.xml:4:1] - 4 | - 5 | - : ^^^^^^^^^^^ - 6 | + 4 | + 5 | + : ^^^^^^^^^^^^^ + 6 | `---- x Comment ,-[$DIR/tests/fixture/comments/input.xml:4:1] - 4 | - 5 | - : ^^^^^^^^^^^ - 6 | + 4 | + 5 | + : ^^^^^^^^^^^^^ + 6 | `---- x Child ,-[$DIR/tests/fixture/comments/input.xml:4:1] - 4 | - 5 | ,-> - 6 | `-> - 7 | + 4 | + 5 | ,-> + 6 | `-> + 7 | `---- x Text ,-[$DIR/tests/fixture/comments/input.xml:4:1] - 4 | - 5 | ,-> - 6 | `-> - 7 | + 4 | + 5 | ,-> + 6 | `-> + 7 | `---- x Child ,-[$DIR/tests/fixture/comments/input.xml:5:1] - 5 | - 6 | - : ^^^^^^^^^^ - 7 | + 5 | + 6 | + : ^^^^^^^^^^^ + 7 | `---- x Comment ,-[$DIR/tests/fixture/comments/input.xml:5:1] - 5 | - 6 | - : ^^^^^^^^^^ - 7 | + 5 | + 6 | + : ^^^^^^^^^^^ + 7 | `---- x Child ,-[$DIR/tests/fixture/comments/input.xml:5:1] - 5 | - 6 | ,-> - 7 | `-> - 8 | + 5 | + 6 | ,-> + 7 | `-> + 8 | `---- x Text ,-[$DIR/tests/fixture/comments/input.xml:5:1] - 5 | - 6 | ,-> - 7 | `-> - 8 | + 5 | + 6 | ,-> + 7 | `-> + 8 | `---- x Child ,-[$DIR/tests/fixture/comments/input.xml:6:1] - 6 | - 7 | - : ^^^^^^^^^^^ - 8 | + 6 | + 7 | + : ^^^^^^^^^^ + 8 | `---- x Comment ,-[$DIR/tests/fixture/comments/input.xml:6:1] - 6 | - 7 | - : ^^^^^^^^^^^ - 8 | + 6 | + 7 | + : ^^^^^^^^^^ + 8 | `---- x Child ,-[$DIR/tests/fixture/comments/input.xml:6:1] - 6 | - 7 | ,-> - 8 | `-> - 9 | + 6 | + 7 | ,-> + 8 | `-> + 9 | `---- x Text ,-[$DIR/tests/fixture/comments/input.xml:6:1] - 6 | - 7 | ,-> - 8 | `-> - 9 | + 6 | + 7 | ,-> + 8 | `-> + 9 | `---- x Child ,-[$DIR/tests/fixture/comments/input.xml:7:1] - 7 | - 8 | - : ^^^^^^^^^^^^ - 9 | + 7 | + 8 | + : ^^^^^^^^^^^ + 9 | `---- x Comment ,-[$DIR/tests/fixture/comments/input.xml:7:1] - 7 | - 8 | - : ^^^^^^^^^^^^ - 9 | + 7 | + 8 | + : ^^^^^^^^^^^ + 9 | `---- x Child ,-[$DIR/tests/fixture/comments/input.xml:7:1] - 7 | - 8 | ,-> - 9 | `-> - 10 | + 7 | + 8 | ,-> + 9 | `-> + 10 | `---- x Text ,-[$DIR/tests/fixture/comments/input.xml:7:1] - 7 | - 8 | ,-> - 9 | `-> - 10 | + 7 | + 8 | ,-> + 9 | `-> + 10 | `---- x Child ,-[$DIR/tests/fixture/comments/input.xml:8:1] - 8 | - 9 | - : ^^^^^^^^^ - 10 | + 8 | + 9 | + : ^^^^^^^^^^^^ + 10 | `---- x Comment ,-[$DIR/tests/fixture/comments/input.xml:8:1] - 8 | - 9 | - : ^^^^^^^^^ - 10 | + 8 | + 9 | + : ^^^^^^^^^^^^ + 10 | `---- x Child ,-[$DIR/tests/fixture/comments/input.xml:8:1] - 8 | - 9 | ,-> - 10 | `-> - 11 | + 8 | + 9 | ,-> + 10 | `-> + 11 | `---- x Text ,-[$DIR/tests/fixture/comments/input.xml:8:1] - 8 | - 9 | ,-> - 10 | `-> - 11 | + 8 | + 9 | ,-> + 10 | `-> + 11 | `---- x Child ,-[$DIR/tests/fixture/comments/input.xml:9:1] - 9 | - 10 | + 9 | + 10 | : ^^^^^^^^^ - 11 | + 11 | `---- x Comment ,-[$DIR/tests/fixture/comments/input.xml:9:1] - 9 | - 10 | + 9 | + 10 | : ^^^^^^^^^ - 11 | + 11 | `---- x Child ,-[$DIR/tests/fixture/comments/input.xml:9:1] - 9 | - 10 | ,-> - 11 | `-> - 12 | + 9 | + 10 | ,-> + 11 | `-> + 12 | `---- x Text ,-[$DIR/tests/fixture/comments/input.xml:9:1] - 9 | - 10 | ,-> - 11 | `-> - 12 | + 9 | + 10 | ,-> + 11 | `-> + 12 | `---- x Child ,-[$DIR/tests/fixture/comments/input.xml:10:1] - 10 | - 11 | - : ^^^^^^^^ - 12 | + 10 | + 11 | + : ^^^^^^^^^ + 12 | `---- x Comment ,-[$DIR/tests/fixture/comments/input.xml:10:1] - 10 | - 11 | - : ^^^^^^^^ - 12 | + 10 | + 11 | + : ^^^^^^^^^ + 12 | `---- x Child ,-[$DIR/tests/fixture/comments/input.xml:10:1] - 10 | - 11 | ,-> - 12 | `-> - 13 | + 10 | + 11 | ,-> + 12 | `-> + 13 | `---- x Text ,-[$DIR/tests/fixture/comments/input.xml:10:1] - 10 | - 11 | ,-> - 12 | `-> - 13 | + 10 | + 11 | ,-> + 12 | `-> + 13 | `---- x Child ,-[$DIR/tests/fixture/comments/input.xml:11:1] - 11 | - 12 | - : ^^^^^^^^^ - 13 | + 11 | + 12 | + : ^^^^^^^^ + 13 | `---- x Comment ,-[$DIR/tests/fixture/comments/input.xml:11:1] - 11 | - 12 | - : ^^^^^^^^^ - 13 | + 11 | + 12 | + : ^^^^^^^^ + 13 | `---- x Child ,-[$DIR/tests/fixture/comments/input.xml:11:1] - 11 | - 12 | ,-> - 13 | `-> - 14 | + 11 | + 12 | ,-> + 13 | `-> + 14 | `---- x Text ,-[$DIR/tests/fixture/comments/input.xml:11:1] - 11 | - 12 | ,-> - 13 | `-> - 14 | + 11 | + 12 | ,-> + 13 | `-> + 14 | `---- x Child ,-[$DIR/tests/fixture/comments/input.xml:12:1] - 12 | - 13 | - : ^^^^^^^ - 14 | + 12 | + 13 | + : ^^^^^^^^^ + 14 | `---- x Comment ,-[$DIR/tests/fixture/comments/input.xml:12:1] - 12 | - 13 | - : ^^^^^^^ - 14 | + 12 | + 13 | + : ^^^^^^^^^ + 14 | `---- x Child ,-[$DIR/tests/fixture/comments/input.xml:12:1] - 12 | - 13 | ,-> - 14 | `-> - 15 | + 12 | + 13 | ,-> + 14 | `-> + 15 | `---- x Text ,-[$DIR/tests/fixture/comments/input.xml:12:1] - 12 | - 13 | ,-> - 14 | `-> - 15 | + 12 | + 13 | ,-> + 14 | `-> + 15 | `---- x Child ,-[$DIR/tests/fixture/comments/input.xml:13:1] - 13 | - 14 | - : ^^^^^^^^^^^^^ - 15 | + 13 | + 14 | + : ^^^^^^^ + 15 | `---- x Comment ,-[$DIR/tests/fixture/comments/input.xml:13:1] - 13 | - 14 | - : ^^^^^^^^^^^^^ - 15 | + 13 | + 14 | + : ^^^^^^^ + 15 | `---- x Child ,-[$DIR/tests/fixture/comments/input.xml:13:1] - 13 | - 14 | ,-> - 15 | `-> - 16 | + 13 | + 14 | ,-> + 15 | `-> + 16 | `---- x Text ,-[$DIR/tests/fixture/comments/input.xml:13:1] - 13 | - 14 | ,-> - 15 | `-> - 16 | + 13 | + 14 | ,-> + 15 | `-> + 16 | `---- x Child ,-[$DIR/tests/fixture/comments/input.xml:14:1] - 14 | - 15 | - : ^^^^^^^^^^^^^^^^^ - 16 | + 14 | + 15 | + : ^^^^^^^^^^^^^ + 16 | `---- x Comment ,-[$DIR/tests/fixture/comments/input.xml:14:1] - 14 | - 15 | - : ^^^^^^^^^^^^^^^^^ - 16 | + 14 | + 15 | + : ^^^^^^^^^^^^^ + 16 | `---- x Child ,-[$DIR/tests/fixture/comments/input.xml:14:1] - 14 | - 15 | - : ^ - 16 | + 14 | + 15 | ,-> + 16 | `-> + 17 | `---- x Text ,-[$DIR/tests/fixture/comments/input.xml:14:1] - 14 | - 15 | - : ^ - 16 | + 14 | + 15 | ,-> + 16 | `-> + 17 | + `---- + + x Child + ,-[$DIR/tests/fixture/comments/input.xml:15:1] + 15 | + 16 | + : ^^^^^^^^^^^^^^^^^ + 17 | + `---- + + x Comment + ,-[$DIR/tests/fixture/comments/input.xml:15:1] + 15 | + 16 | + : ^^^^^^^^^^^^^^^^^ + 17 | + `---- + + x Child + ,-[$DIR/tests/fixture/comments/input.xml:15:1] + 15 | + 16 | ,-> + 17 | `-> + 18 | + `---- + + x Text + ,-[$DIR/tests/fixture/comments/input.xml:15:1] + 15 | + 16 | ,-> + 17 | `-> + 18 | + `---- + + x Child + ,-[$DIR/tests/fixture/comments/input.xml:16:1] + 16 | + 17 | ,-> + 18 | | + 19 | | Element Value + 20 | `-> + 21 | + `---- + + x Element + ,-[$DIR/tests/fixture/comments/input.xml:16:1] + 16 | + 17 | ,-> + 18 | | + 19 | | Element Value + 20 | `-> + 21 | + `---- + + x Attribute + + x Child + ,-[$DIR/tests/fixture/comments/input.xml:16:1] + 16 | + 17 | ,-> + 18 | `-> + 19 | Element Value + `---- + + x Text + ,-[$DIR/tests/fixture/comments/input.xml:16:1] + 16 | + 17 | ,-> + 18 | `-> + 19 | Element Value + `---- + + x Child + ,-[$DIR/tests/fixture/comments/input.xml:17:1] + 17 | + 18 | + : ^^^^^^^^^^^^^^^^^^^ + 19 | Element Value + `---- + + x Comment + ,-[$DIR/tests/fixture/comments/input.xml:17:1] + 17 | + 18 | + : ^^^^^^^^^^^^^^^^^^^ + 19 | Element Value + `---- + + x Child + ,-[$DIR/tests/fixture/comments/input.xml:17:1] + 17 | + 18 | ,-> + 19 | `-> Element Value + 20 | + `---- + + x Text + ,-[$DIR/tests/fixture/comments/input.xml:17:1] + 17 | + 18 | ,-> + 19 | `-> Element Value + 20 | + `---- + + x Child + ,-[$DIR/tests/fixture/comments/input.xml:18:1] + 18 | + 19 | Element Value + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 20 | + `---- + + x Element + ,-[$DIR/tests/fixture/comments/input.xml:18:1] + 18 | + 19 | Element Value + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 20 | + `---- + + x Child + ,-[$DIR/tests/fixture/comments/input.xml:18:1] + 18 | + 19 | Element Value + : ^^^^^^^^^^^^^ + 20 | + `---- + + x Text + ,-[$DIR/tests/fixture/comments/input.xml:18:1] + 18 | + 19 | Element Value + : ^^^^^^^^^^^^^ + 20 | + `---- + + x Child + ,-[$DIR/tests/fixture/comments/input.xml:18:1] + 18 | + 19 | ,-> Element Value + 20 | `-> + 21 | + `---- + + x Text + ,-[$DIR/tests/fixture/comments/input.xml:18:1] + 18 | + 19 | ,-> Element Value + 20 | `-> + 21 | + `---- + + x Child + ,-[$DIR/tests/fixture/comments/input.xml:19:1] + 19 | Element Value + 20 | ,-> + 21 | `-> + 22 | + `---- + + x Text + ,-[$DIR/tests/fixture/comments/input.xml:19:1] + 19 | Element Value + 20 | ,-> + 21 | `-> + 22 | + `---- + + x Child + ,-[$DIR/tests/fixture/comments/input.xml:20:1] + 20 | + 21 | ,-> + 22 | | + 23 | | Element Value + 24 | | + 25 | `-> + 26 | + `---- + + x Element + ,-[$DIR/tests/fixture/comments/input.xml:20:1] + 20 | + 21 | ,-> + 22 | | + 23 | | Element Value + 24 | | + 25 | `-> + 26 | + `---- + + x Child + ,-[$DIR/tests/fixture/comments/input.xml:20:1] + 20 | + 21 | ,-> + 22 | `-> + 23 | Element Value + `---- + + x Text + ,-[$DIR/tests/fixture/comments/input.xml:20:1] + 20 | + 21 | ,-> + 22 | `-> + 23 | Element Value + `---- + + x Child + ,-[$DIR/tests/fixture/comments/input.xml:21:1] + 21 | + 22 | ,-> + 23 | | Element Value + 24 | `-> + 25 | + `---- + + x Element + ,-[$DIR/tests/fixture/comments/input.xml:21:1] + 21 | + 22 | ,-> + 23 | | Element Value + 24 | `-> + 25 | + `---- + + x Child + ,-[$DIR/tests/fixture/comments/input.xml:21:1] + 21 | + 22 | ,-> + 23 | `-> Element Value + 24 | + `---- + + x Text + ,-[$DIR/tests/fixture/comments/input.xml:21:1] + 21 | + 22 | ,-> + 23 | `-> Element Value + 24 | + `---- + + x Child + ,-[$DIR/tests/fixture/comments/input.xml:22:1] + 22 | + 23 | Element Value + : ^^^^^^^^^^^^^^^^^^^ + 24 | + `---- + + x Comment + ,-[$DIR/tests/fixture/comments/input.xml:22:1] + 22 | + 23 | Element Value + : ^^^^^^^^^^^^^^^^^^^ + 24 | + `---- + + x Child + ,-[$DIR/tests/fixture/comments/input.xml:22:1] + 22 | + 23 | ,-> Element Value + 24 | `-> + 25 | + `---- + + x Text + ,-[$DIR/tests/fixture/comments/input.xml:22:1] + 22 | + 23 | ,-> Element Value + 24 | `-> + 25 | + `---- + + x Child + ,-[$DIR/tests/fixture/comments/input.xml:23:1] + 23 | Element Value + 24 | ,-> + 25 | `-> + 26 | + `---- + + x Text + ,-[$DIR/tests/fixture/comments/input.xml:23:1] + 23 | Element Value + 24 | ,-> + 25 | `-> + 26 | + `---- + + x Child + ,-[$DIR/tests/fixture/comments/input.xml:24:1] + 24 | + 25 | + : ^ + 26 | + `---- + + x Text + ,-[$DIR/tests/fixture/comments/input.xml:24:1] + 24 | + 25 | + : ^ + 26 | `---- diff --git a/crates/swc_xml_parser/tests/fixture/entity/dom.txt b/crates/swc_xml_parser/tests/fixture/entity/dom.txt index d5ecd9e4b98a..7b1486594320 100644 --- a/crates/swc_xml_parser/tests/fixture/entity/dom.txt +++ b/crates/swc_xml_parser/tests/fixture/entity/dom.txt @@ -1,12 +1,14 @@ + + | | " " | -| a="¬i;" +| a="noti;" | " " | -| a="&lang=" +| a="lang=" | " " | @@ -15,5 +17,17 @@ " | | test="Ē" +| " + " +| +| "♂" +| " + " +| +| "O'Reilly & Associates" +| " + " +| +| "©©™™" | " " diff --git a/crates/swc_xml_parser/tests/fixture/entity/input.xml b/crates/swc_xml_parser/tests/fixture/entity/input.xml index d87525221ce1..f7c56e14c586 100644 --- a/crates/swc_xml_parser/tests/fixture/entity/input.xml +++ b/crates/swc_xml_parser/tests/fixture/entity/input.xml @@ -1,6 +1,11 @@ + + - - + + + + O'Reilly & Associates + ©©™™ \ No newline at end of file diff --git a/crates/swc_xml_parser/tests/fixture/entity/output.json b/crates/swc_xml_parser/tests/fixture/entity/output.json index 95e93c270de4..8518f8d73889 100644 --- a/crates/swc_xml_parser/tests/fixture/entity/output.json +++ b/crates/swc_xml_parser/tests/fixture/entity/output.json @@ -2,15 +2,35 @@ "type": "Document", "span": { "start": 1, - "end": 121, + "end": 343, "ctxt": 0 }, "children": [ { - "type": "Element", + "type": "ProcessingInstruction", "span": { "start": 1, - "end": 121, + "end": 39, + "ctxt": 0 + }, + "target": "xml", + "data": "version=\"1.0\" encoding=\"UTF-8\"" + }, + { + "type": "ProcessingInstruction", + "span": { + "start": 40, + "end": 90, + "ctxt": 0 + }, + "target": "xml-stylesheet", + "data": "href=\"copy.css\" type=\"text/css\"" + }, + { + "type": "Element", + "span": { + "start": 91, + "end": 343, "ctxt": 0 }, "tagName": "root", @@ -19,8 +39,8 @@ { "type": "Text", "span": { - "start": 7, - "end": 12, + "start": 97, + "end": 102, "ctxt": 0 }, "data": "\n ", @@ -29,8 +49,8 @@ { "type": "Element", "span": { - "start": 12, - "end": 27, + "start": 102, + "end": 116, "ctxt": 0 }, "tagName": "h", @@ -46,8 +66,8 @@ "prefix": null, "name": "a", "rawName": "a", - "value": "¬i;", - "rawValue": "'¬i;'" + "value": "noti;", + "rawValue": "'noti;'" } ], "children": [] @@ -55,8 +75,8 @@ { "type": "Text", "span": { - "start": 27, - "end": 32, + "start": 116, + "end": 121, "ctxt": 0 }, "data": "\n ", @@ -65,8 +85,8 @@ { "type": "Element", "span": { - "start": 32, - "end": 47, + "start": 121, + "end": 135, "ctxt": 0 }, "tagName": "h", @@ -82,8 +102,8 @@ "prefix": null, "name": "a", "rawName": "a", - "value": "&lang=", - "rawValue": "'&lang='" + "value": "lang=", + "rawValue": "'lang='" } ], "children": [] @@ -91,8 +111,8 @@ { "type": "Text", "span": { - "start": 47, - "end": 52, + "start": 135, + "end": 140, "ctxt": 0 }, "data": "\n ", @@ -101,8 +121,8 @@ { "type": "Element", "span": { - "start": 52, - "end": 80, + "start": 140, + "end": 168, "ctxt": 0 }, "tagName": "test", @@ -119,7 +139,7 @@ "name": "test", "rawName": "test", "value": "Ӓ", - "rawValue": "\"Ӓ\"" + "rawValue": "\"empty\"" } ], "children": [] @@ -127,8 +147,8 @@ { "type": "Text", "span": { - "start": 80, - "end": 85, + "start": 168, + "end": 173, "ctxt": 0 }, "data": "\n ", @@ -137,8 +157,8 @@ { "type": "Element", "span": { - "start": 85, - "end": 113, + "start": 173, + "end": 201, "ctxt": 0 }, "tagName": "test", @@ -155,7 +175,7 @@ "name": "test", "rawName": "test", "value": "Ē", - "rawValue": "\"Ē\"" + "rawValue": "\"empty\"" } ], "children": [] @@ -163,8 +183,104 @@ { "type": "Text", "span": { - "start": 113, - "end": 114, + "start": 201, + "end": 206, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 206, + "end": 239, + "ctxt": 0 + }, + "tagName": "Geschlecht", + "attributes": [], + "children": [ + { + "type": "Text", + "span": { + "start": 218, + "end": 226, + "ctxt": 0 + }, + "data": "♂", + "raw": "empty" + } + ] + }, + { + "type": "Text", + "span": { + "start": 239, + "end": 244, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 244, + "end": 292, + "ctxt": 0 + }, + "tagName": "copyright", + "attributes": [], + "children": [ + { + "type": "Text", + "span": { + "start": 255, + "end": 280, + "ctxt": 0 + }, + "data": "O'Reilly & Associates", + "raw": "O'Reilly & Associates" + } + ] + }, + { + "type": "Text", + "span": { + "start": 292, + "end": 297, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 297, + "end": 335, + "ctxt": 0 + }, + "tagName": "foo", + "attributes": [], + "children": [ + { + "type": "Text", + "span": { + "start": 302, + "end": 329, + "ctxt": 0 + }, + "data": "©©™™", + "raw": "emptyemptyemptyempty" + } + ] + }, + { + "type": "Text", + "span": { + "start": 335, + "end": 336, "ctxt": 0 }, "data": "\n", diff --git a/crates/swc_xml_parser/tests/fixture/entity/span.swc-stderr b/crates/swc_xml_parser/tests/fixture/entity/span.swc-stderr index efdf7b86a625..5a33eeb8ba5a 100644 --- a/crates/swc_xml_parser/tests/fixture/entity/span.swc-stderr +++ b/crates/swc_xml_parser/tests/fixture/entity/span.swc-stderr @@ -1,174 +1,363 @@ x Document + ,-[$DIR/tests/fixture/entity/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | | + 4 | | + 5 | | + 6 | | + 7 | | + 8 | | + 9 | | O'Reilly & Associates + 10 | | ©©™™ + 11 | `-> + `---- + + x Child + ,-[$DIR/tests/fixture/entity/input.xml:1:1] + 1 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 2 | + `---- + + x ProcessingInstruction ,-[$DIR/tests/fixture/entity/input.xml:1:1] - 1 | ,-> - 2 | | - 3 | | - 4 | | - 5 | | - 6 | `-> + 1 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 2 | `---- x Child ,-[$DIR/tests/fixture/entity/input.xml:1:1] - 1 | ,-> - 2 | | - 3 | | - 4 | | - 5 | | - 6 | `-> + 1 | + 2 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 3 | `---- - x Element + x ProcessingInstruction ,-[$DIR/tests/fixture/entity/input.xml:1:1] - 1 | ,-> - 2 | | - 3 | | - 4 | | - 5 | | - 6 | `-> + 1 | + 2 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 3 | `---- x Child - ,-[$DIR/tests/fixture/entity/input.xml:1:1] - 1 | ,-> - 2 | `-> - 3 | + ,-[$DIR/tests/fixture/entity/input.xml:2:1] + 2 | + 3 | ,-> + 4 | | + 5 | | + 6 | | + 7 | | + 8 | | + 9 | | O'Reilly & Associates + 10 | | ©©™™ + 11 | `-> + `---- + + x Element + ,-[$DIR/tests/fixture/entity/input.xml:2:1] + 2 | + 3 | ,-> + 4 | | + 5 | | + 6 | | + 7 | | + 8 | | + 9 | | O'Reilly & Associates + 10 | | ©©™™ + 11 | `-> + `---- + + x Child + ,-[$DIR/tests/fixture/entity/input.xml:2:1] + 2 | + 3 | ,-> + 4 | `-> + 5 | `---- x Text - ,-[$DIR/tests/fixture/entity/input.xml:1:1] - 1 | ,-> - 2 | `-> - 3 | + ,-[$DIR/tests/fixture/entity/input.xml:2:1] + 2 | + 3 | ,-> + 4 | `-> + 5 | `---- x Child - ,-[$DIR/tests/fixture/entity/input.xml:1:1] - 1 | - 2 | - : ^^^^^^^^^^^^^^^ - 3 | + ,-[$DIR/tests/fixture/entity/input.xml:3:1] + 3 | + 4 | + : ^^^^^^^^^^^^^^ + 5 | `---- x Element - ,-[$DIR/tests/fixture/entity/input.xml:1:1] - 1 | - 2 | - : ^^^^^^^^^^^^^^^ - 3 | + ,-[$DIR/tests/fixture/entity/input.xml:3:1] + 3 | + 4 | + : ^^^^^^^^^^^^^^ + 5 | `---- x Attribute x Child - ,-[$DIR/tests/fixture/entity/input.xml:1:1] - 1 | - 2 | ,-> - 3 | `-> - 4 | + ,-[$DIR/tests/fixture/entity/input.xml:3:1] + 3 | + 4 | ,-> + 5 | `-> + 6 | `---- x Text - ,-[$DIR/tests/fixture/entity/input.xml:1:1] - 1 | - 2 | ,-> - 3 | `-> - 4 | + ,-[$DIR/tests/fixture/entity/input.xml:3:1] + 3 | + 4 | ,-> + 5 | `-> + 6 | `---- x Child - ,-[$DIR/tests/fixture/entity/input.xml:2:1] - 2 | - 3 | - : ^^^^^^^^^^^^^^^ - 4 | + ,-[$DIR/tests/fixture/entity/input.xml:4:1] + 4 | + 5 | + : ^^^^^^^^^^^^^^ + 6 | `---- x Element - ,-[$DIR/tests/fixture/entity/input.xml:2:1] - 2 | - 3 | - : ^^^^^^^^^^^^^^^ - 4 | + ,-[$DIR/tests/fixture/entity/input.xml:4:1] + 4 | + 5 | + : ^^^^^^^^^^^^^^ + 6 | `---- x Child - ,-[$DIR/tests/fixture/entity/input.xml:2:1] - 2 | - 3 | ,-> - 4 | `-> - 5 | + ,-[$DIR/tests/fixture/entity/input.xml:4:1] + 4 | + 5 | ,-> + 6 | `-> + 7 | `---- x Text - ,-[$DIR/tests/fixture/entity/input.xml:2:1] - 2 | - 3 | ,-> - 4 | `-> - 5 | + ,-[$DIR/tests/fixture/entity/input.xml:4:1] + 4 | + 5 | ,-> + 6 | `-> + 7 | `---- x Child - ,-[$DIR/tests/fixture/entity/input.xml:3:1] - 3 | - 4 | + ,-[$DIR/tests/fixture/entity/input.xml:5:1] + 5 | + 6 | : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 5 | + 7 | `---- x Element - ,-[$DIR/tests/fixture/entity/input.xml:3:1] - 3 | - 4 | + ,-[$DIR/tests/fixture/entity/input.xml:5:1] + 5 | + 6 | : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 5 | + 7 | `---- x Child - ,-[$DIR/tests/fixture/entity/input.xml:3:1] - 3 | - 4 | ,-> - 5 | `-> - 6 | + ,-[$DIR/tests/fixture/entity/input.xml:5:1] + 5 | + 6 | ,-> + 7 | `-> + 8 | `---- x Text - ,-[$DIR/tests/fixture/entity/input.xml:3:1] - 3 | - 4 | ,-> - 5 | `-> - 6 | + ,-[$DIR/tests/fixture/entity/input.xml:5:1] + 5 | + 6 | ,-> + 7 | `-> + 8 | `---- x Child - ,-[$DIR/tests/fixture/entity/input.xml:4:1] - 4 | - 5 | + ,-[$DIR/tests/fixture/entity/input.xml:6:1] + 6 | + 7 | : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 6 | + 8 | `---- x Element - ,-[$DIR/tests/fixture/entity/input.xml:4:1] - 4 | - 5 | + ,-[$DIR/tests/fixture/entity/input.xml:6:1] + 6 | + 7 | : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 6 | + 8 | `---- x Child - ,-[$DIR/tests/fixture/entity/input.xml:4:1] - 4 | - 5 | - : ^ - 6 | + ,-[$DIR/tests/fixture/entity/input.xml:6:1] + 6 | + 7 | ,-> + 8 | `-> + 9 | O'Reilly & Associates `---- x Text - ,-[$DIR/tests/fixture/entity/input.xml:4:1] - 4 | - 5 | - : ^ - 6 | + ,-[$DIR/tests/fixture/entity/input.xml:6:1] + 6 | + 7 | ,-> + 8 | `-> + 9 | O'Reilly & Associates + `---- + + x Child + ,-[$DIR/tests/fixture/entity/input.xml:7:1] + 7 | + 8 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 9 | O'Reilly & Associates + `---- + + x Element + ,-[$DIR/tests/fixture/entity/input.xml:7:1] + 7 | + 8 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 9 | O'Reilly & Associates + `---- + + x Child + ,-[$DIR/tests/fixture/entity/input.xml:7:1] + 7 | + 8 | + : ^^^^^^^^ + 9 | O'Reilly & Associates + `---- + + x Text + ,-[$DIR/tests/fixture/entity/input.xml:7:1] + 7 | + 8 | + : ^^^^^^^^ + 9 | O'Reilly & Associates `---- + + x Child + ,-[$DIR/tests/fixture/entity/input.xml:7:1] + 7 | + 8 | ,-> + 9 | `-> O'Reilly & Associates + 10 | ©©™™ + `---- + + x Text + ,-[$DIR/tests/fixture/entity/input.xml:7:1] + 7 | + 8 | ,-> + 9 | `-> O'Reilly & Associates + 10 | ©©™™ + `---- + + x Child + ,-[$DIR/tests/fixture/entity/input.xml:8:1] + 8 | + 9 | O'Reilly & Associates + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 10 | ©©™™ + `---- + + x Element + ,-[$DIR/tests/fixture/entity/input.xml:8:1] + 8 | + 9 | O'Reilly & Associates + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 10 | ©©™™ + `---- + + x Child + ,-[$DIR/tests/fixture/entity/input.xml:8:1] + 8 | + 9 | O'Reilly & Associates + : ^^^^^^^^^^^^^^^^^^^^^^^^^ + 10 | ©©™™ + `---- + + x Text + ,-[$DIR/tests/fixture/entity/input.xml:8:1] + 8 | + 9 | O'Reilly & Associates + : ^^^^^^^^^^^^^^^^^^^^^^^^^ + 10 | ©©™™ + `---- + + x Child + ,-[$DIR/tests/fixture/entity/input.xml:8:1] + 8 | + 9 | ,-> O'Reilly & Associates + 10 | `-> ©©™™ + 11 | + `---- + + x Text + ,-[$DIR/tests/fixture/entity/input.xml:8:1] + 8 | + 9 | ,-> O'Reilly & Associates + 10 | `-> ©©™™ + 11 | + `---- + + x Child + ,-[$DIR/tests/fixture/entity/input.xml:9:1] + 9 | O'Reilly & Associates + 10 | ©©™™ + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 11 | + `---- + + x Element + ,-[$DIR/tests/fixture/entity/input.xml:9:1] + 9 | O'Reilly & Associates + 10 | ©©™™ + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 11 | + `---- + + x Child + ,-[$DIR/tests/fixture/entity/input.xml:9:1] + 9 | O'Reilly & Associates + 10 | ©©™™ + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 11 | + `---- + + x Text + ,-[$DIR/tests/fixture/entity/input.xml:9:1] + 9 | O'Reilly & Associates + 10 | ©©™™ + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 11 | + `---- + + x Child + ,-[$DIR/tests/fixture/entity/input.xml:9:1] + 9 | O'Reilly & Associates + 10 | ©©™™ + : ^ + 11 | + `---- + + x Text + ,-[$DIR/tests/fixture/entity/input.xml:9:1] + 9 | O'Reilly & Associates + 10 | ©©™™ + : ^ + 11 | + `---- diff --git a/crates/swc_xml_parser/tests/fixture/pi/dom.txt b/crates/swc_xml_parser/tests/fixture/pi/dom.txt index 873c342af684..ffd162eaf3a1 100644 --- a/crates/swc_xml_parser/tests/fixture/pi/dom.txt +++ b/crates/swc_xml_parser/tests/fixture/pi/dom.txt @@ -1,11 +1,11 @@ + | | " " | " " - + | " " diff --git a/crates/swc_xml_parser/tests/fixture/pi/input.xml b/crates/swc_xml_parser/tests/fixture/pi/input.xml index 7421f4f2e8c2..a0425e25aa26 100644 --- a/crates/swc_xml_parser/tests/fixture/pi/input.xml +++ b/crates/swc_xml_parser/tests/fixture/pi/input.xml @@ -1,3 +1,4 @@ + - 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 | `-> + 1 | ,-> + 2 | | + 3 | | + 4 | | + 6 | | + 7 | | + 8 | | + 9 | | + 10 | | + 11 | | + 12 | | + 13 | | + 14 | | + 15 | | + 16 | | + 17 | | + 18 | | + 19 | | + 20 | | + 21 | | + 22 | | + 23 | | + 24 | | + 25 | | + 26 | `-> `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:1:1] - 1 | ,-> - 2 | `-> - 3 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 2 | `---- - x Text + x ProcessingInstruction ,-[$DIR/tests/fixture/pi/input.xml:1:1] - 1 | ,-> - 2 | `-> - 3 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 2 | `---- x Child - ,-[$DIR/tests/fixture/pi/input.xml:1:1] - 1 | - 2 | - : ^^^^^^^^^^^ - 3 | + 2 | ,-> + 3 | | + 4 | | + 6 | | + 7 | | + 8 | | + 9 | | + 10 | | + 11 | | + 12 | | + 13 | | + 14 | | + 15 | | + 16 | | + 17 | | + 18 | | + 19 | | + 20 | | + 21 | | + 22 | | + 23 | | + 24 | | + 25 | | + 26 | `-> + `---- - x ProcessingInstruction - ,-[$DIR/tests/fixture/pi/input.xml:1:1] - 1 | - 2 | - : ^^^^^^^^^^^ - 3 | + 2 | ,-> + 3 | | + 4 | | + 6 | | + 7 | | + 8 | | + 9 | | + 10 | | + 11 | | + 12 | | + 13 | | + 14 | | + 15 | | + 16 | | + 17 | | + 18 | | + 19 | | + 20 | | + 21 | | + 22 | | + 23 | | + 24 | | + 25 | | + 26 | `-> + `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:1:1] - 1 | - 2 | ,-> - 3 | `-> + 1 | + 2 | ,-> + 3 | `-> + 4 | - 2 | ,-> - 3 | `-> + 1 | + 2 | ,-> + 3 | `-> + 4 | - 3 | ,-> m?> - 5 | + 2 | + 3 | + : ^^^^^^^^^^^ + 4 | - 3 | ,-> m?> - 5 | + 2 | + 3 | + : ^^^^^^^^^^^ + 4 | m?> - 5 | `-> - 6 | + ,-[$DIR/tests/fixture/pi/input.xml:2:1] + 2 | + 3 | ,-> + 4 | `-> `---- x Text - ,-[$DIR/tests/fixture/pi/input.xml:3:1] - 3 | m?> - 5 | `-> - 6 | + ,-[$DIR/tests/fixture/pi/input.xml:2:1] + 2 | + 3 | ,-> + 4 | `-> `---- x Child - ,-[$DIR/tests/fixture/pi/input.xml:4:1] - 4 | m?> - 5 | - : ^^^^^^^^ - 6 | + ,-[$DIR/tests/fixture/pi/input.xml:3:1] + 3 | + 4 | ,-> m?> + 6 | `---- x ProcessingInstruction - ,-[$DIR/tests/fixture/pi/input.xml:4:1] - 4 | m?> - 5 | - : ^^^^^^^^ - 6 | + ,-[$DIR/tests/fixture/pi/input.xml:3:1] + 3 | + 4 | ,-> m?> + 6 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:4:1] - 4 | m?> - 5 | ,-> - 6 | `-> - 7 | + 4 | m?> + 6 | `-> + 7 | `---- x Text ,-[$DIR/tests/fixture/pi/input.xml:4:1] - 4 | m?> - 5 | ,-> - 6 | `-> - 7 | + 4 | m?> + 6 | `-> + 7 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:5:1] - 5 | - 6 | - : ^^^^^^^^^ - 7 | + 5 | m?> + 6 | + : ^^^^^^^^ + 7 | `---- x ProcessingInstruction ,-[$DIR/tests/fixture/pi/input.xml:5:1] - 5 | - 6 | - : ^^^^^^^^^ - 7 | + 5 | m?> + 6 | + : ^^^^^^^^ + 7 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:5:1] - 5 | - 6 | ,-> - 7 | `-> - 8 | + 5 | m?> + 6 | ,-> + 7 | `-> + 8 | `---- x Text ,-[$DIR/tests/fixture/pi/input.xml:5:1] - 5 | - 6 | ,-> - 7 | `-> - 8 | + 5 | m?> + 6 | ,-> + 7 | `-> + 8 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:6:1] - 6 | - 7 | - : ^^^^^^^^^^^^^^^^^^ - 8 | + 6 | + 7 | + : ^^^^^^^^^ + 8 | `---- x ProcessingInstruction ,-[$DIR/tests/fixture/pi/input.xml:6:1] - 6 | - 7 | - : ^^^^^^^^^^^^^^^^^^ - 8 | + 6 | + 7 | + : ^^^^^^^^^ + 8 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:6:1] - 6 | - 7 | ,-> - 8 | `-> - 9 | + 6 | + 7 | ,-> + 8 | `-> + 9 | `---- x Text ,-[$DIR/tests/fixture/pi/input.xml:6:1] - 6 | - 7 | ,-> - 8 | `-> - 9 | + 6 | + 7 | ,-> + 8 | `-> + 9 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:7:1] - 7 | - 8 | - : ^^^^^^^^^^^^^^^^^^^^^ - 9 | + 7 | + 8 | + : ^^^^^^^^^^^^^^^^^^ + 9 | `---- x ProcessingInstruction ,-[$DIR/tests/fixture/pi/input.xml:7:1] - 7 | - 8 | - : ^^^^^^^^^^^^^^^^^^^^^ - 9 | + 7 | + 8 | + : ^^^^^^^^^^^^^^^^^^ + 9 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:7:1] - 7 | - 8 | ,-> - 9 | `-> - 10 | + 7 | + 8 | ,-> + 9 | `-> + 10 | `---- x Text ,-[$DIR/tests/fixture/pi/input.xml:7:1] - 7 | - 8 | ,-> - 9 | `-> - 10 | + 7 | + 8 | ,-> + 9 | `-> + 10 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:8:1] - 8 | - 9 | + 8 | + 9 | : ^^^^^^^^^^^^^^^^^^^^^ - 10 | + 10 | `---- x ProcessingInstruction ,-[$DIR/tests/fixture/pi/input.xml:8:1] - 8 | - 9 | + 8 | + 9 | : ^^^^^^^^^^^^^^^^^^^^^ - 10 | + 10 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:8:1] - 8 | - 9 | ,-> - 10 | `-> - 11 | + 8 | + 9 | ,-> + 10 | `-> + 11 | `---- x Text ,-[$DIR/tests/fixture/pi/input.xml:8:1] - 8 | - 9 | ,-> - 10 | `-> - 11 | + 8 | + 9 | ,-> + 10 | `-> + 11 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:9:1] - 9 | - 10 | - : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 11 | + 9 | + 10 | + : ^^^^^^^^^^^^^^^^^^^^^ + 11 | `---- x ProcessingInstruction ,-[$DIR/tests/fixture/pi/input.xml:9:1] - 9 | - 10 | - : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 11 | + 9 | + 10 | + : ^^^^^^^^^^^^^^^^^^^^^ + 11 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:9:1] - 9 | - 10 | ,-> - 11 | `-> - 12 | + 9 | + 10 | ,-> + 11 | `-> + 12 | `---- x Text ,-[$DIR/tests/fixture/pi/input.xml:9:1] - 9 | - 10 | ,-> - 11 | `-> - 12 | + 9 | + 10 | ,-> + 11 | `-> + 12 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:10:1] - 10 | - 11 | + 10 | + 11 | : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 12 | + 12 | `---- x ProcessingInstruction ,-[$DIR/tests/fixture/pi/input.xml:10:1] - 10 | - 11 | + 10 | + 11 | : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 12 | + 12 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:10:1] - 10 | - 11 | ,-> - 12 | `-> - 13 | + 10 | + 11 | ,-> + 12 | `-> + 13 | `---- x Text ,-[$DIR/tests/fixture/pi/input.xml:10:1] - 10 | - 11 | ,-> - 12 | `-> - 13 | + 10 | + 11 | ,-> + 12 | `-> + 13 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:11:1] - 11 | - 12 | + 11 | + 12 | : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 13 | + 13 | `---- x ProcessingInstruction ,-[$DIR/tests/fixture/pi/input.xml:11:1] - 11 | - 12 | + 11 | + 12 | : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 13 | + 13 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:11:1] - 11 | - 12 | ,-> - 13 | `-> - 14 | + 11 | + 12 | ,-> + 13 | `-> + 14 | `---- x Text ,-[$DIR/tests/fixture/pi/input.xml:11:1] - 11 | - 12 | ,-> - 13 | `-> - 14 | + 11 | + 12 | ,-> + 13 | `-> + 14 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:12:1] - 12 | - 13 | - : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 14 | + 12 | + 13 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 14 | `---- x ProcessingInstruction ,-[$DIR/tests/fixture/pi/input.xml:12:1] - 12 | - 13 | - : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 14 | + 12 | + 13 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 14 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:12:1] - 12 | - 13 | ,-> - 14 | `-> - 15 | + 12 | + 13 | ,-> + 14 | `-> + 15 | `---- x Text ,-[$DIR/tests/fixture/pi/input.xml:12:1] - 12 | - 13 | ,-> - 14 | `-> - 15 | + 12 | + 13 | ,-> + 14 | `-> + 15 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:13:1] - 13 | - 14 | - : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 15 | + 13 | + 14 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 15 | `---- x ProcessingInstruction ,-[$DIR/tests/fixture/pi/input.xml:13:1] - 13 | - 14 | - : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 15 | + 13 | + 14 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 15 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:13:1] - 13 | - 14 | ,-> - 15 | `-> - 16 | + 13 | + 14 | ,-> + 15 | `-> + 16 | `---- x Text ,-[$DIR/tests/fixture/pi/input.xml:13:1] - 13 | - 14 | ,-> - 15 | `-> - 16 | + 13 | + 14 | ,-> + 15 | `-> + 16 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:14:1] - 14 | - 15 | - : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 16 | + 14 | + 15 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 16 | `---- x ProcessingInstruction ,-[$DIR/tests/fixture/pi/input.xml:14:1] - 14 | - 15 | - : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 16 | + 14 | + 15 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 16 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:14:1] - 14 | - 15 | ,-> - 16 | `-> - 17 | + 14 | + 15 | ,-> + 16 | `-> + 17 | `---- x Text ,-[$DIR/tests/fixture/pi/input.xml:14:1] - 14 | - 15 | ,-> - 16 | `-> - 17 | + 14 | + 15 | ,-> + 16 | `-> + 17 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:15:1] - 15 | - 16 | - : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 17 | + 15 | + 16 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 17 | `---- x ProcessingInstruction ,-[$DIR/tests/fixture/pi/input.xml:15:1] - 15 | - 16 | - : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 17 | + 15 | + 16 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 17 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:15:1] - 15 | - 16 | ,-> - 17 | `-> - 18 | + 15 | + 16 | ,-> + 17 | `-> + 18 | `---- x Text ,-[$DIR/tests/fixture/pi/input.xml:15:1] - 15 | - 16 | ,-> - 17 | `-> - 18 | + 15 | + 16 | ,-> + 17 | `-> + 18 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:16:1] - 16 | - 17 | - : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 18 | + 16 | + 17 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 18 | `---- x ProcessingInstruction ,-[$DIR/tests/fixture/pi/input.xml:16:1] - 16 | - 17 | - : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 18 | + 16 | + 17 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 18 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:16:1] - 16 | - 17 | ,-> - 18 | `-> - 19 | + 16 | + 17 | ,-> + 18 | `-> + 19 | `---- x Text ,-[$DIR/tests/fixture/pi/input.xml:16:1] - 16 | - 17 | ,-> - 18 | `-> - 19 | + 16 | + 17 | ,-> + 18 | `-> + 19 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:17:1] - 17 | - 18 | - : ^^^^^^^ - 19 | + 17 | + 18 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 19 | `---- x ProcessingInstruction ,-[$DIR/tests/fixture/pi/input.xml:17:1] - 17 | - 18 | - : ^^^^^^^ - 19 | + 17 | + 18 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 19 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:17:1] - 17 | - 18 | ,-> - 19 | `-> - 20 | + 17 | + 18 | ,-> + 19 | `-> + 20 | `---- x Text ,-[$DIR/tests/fixture/pi/input.xml:17:1] - 17 | - 18 | ,-> - 19 | `-> - 20 | + 17 | + 18 | ,-> + 19 | `-> + 20 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:18:1] - 18 | - 19 | - : ^^^^^^^^^ - 20 | + 18 | + 19 | + : ^^^^^^^ + 20 | `---- x ProcessingInstruction ,-[$DIR/tests/fixture/pi/input.xml:18:1] - 18 | - 19 | - : ^^^^^^^^^ - 20 | + 18 | + 19 | + : ^^^^^^^ + 20 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:18:1] - 18 | - 19 | ,-> - 20 | `-> - 21 | + 18 | + 19 | ,-> + 20 | `-> + 21 | `---- x Text ,-[$DIR/tests/fixture/pi/input.xml:18:1] - 18 | - 19 | ,-> - 20 | `-> - 21 | + 18 | + 19 | ,-> + 20 | `-> + 21 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:19:1] - 19 | - 20 | - : ^^^^^^^^^^ - 21 | + 19 | + 20 | + : ^^^^^^^^^ + 21 | `---- x ProcessingInstruction ,-[$DIR/tests/fixture/pi/input.xml:19:1] - 19 | - 20 | - : ^^^^^^^^^^ - 21 | + 19 | + 20 | + : ^^^^^^^^^ + 21 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:19:1] - 19 | - 20 | ,-> - 21 | `-> - 22 | + 19 | + 20 | ,-> + 21 | `-> + 22 | `---- x Text ,-[$DIR/tests/fixture/pi/input.xml:19:1] - 19 | - 20 | ,-> - 21 | `-> - 22 | + 19 | + 20 | ,-> + 21 | `-> + 22 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:20:1] - 20 | - 21 | - : ^^^^^^^^^^^ - 22 | + 20 | + 21 | + : ^^^^^^^^^^ + 22 | `---- x ProcessingInstruction ,-[$DIR/tests/fixture/pi/input.xml:20:1] - 20 | - 21 | - : ^^^^^^^^^^^ - 22 | + 20 | + 21 | + : ^^^^^^^^^^ + 22 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:20:1] - 20 | - 21 | ,-> - 22 | `-> - 23 | + 20 | + 21 | ,-> + 22 | `-> + 23 | `---- x Text ,-[$DIR/tests/fixture/pi/input.xml:20:1] - 20 | - 21 | ,-> - 22 | `-> - 23 | + 20 | + 21 | ,-> + 22 | `-> + 23 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:21:1] - 21 | - 22 | - : ^^^^^^^^^^^^^ - 23 | + 21 | + 22 | + : ^^^^^^^^^^^ + 23 | `---- x ProcessingInstruction ,-[$DIR/tests/fixture/pi/input.xml:21:1] - 21 | - 22 | - : ^^^^^^^^^^^^^ - 23 | + 21 | + 22 | + : ^^^^^^^^^^^ + 23 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:21:1] - 21 | - 22 | ,-> - 23 | `-> - 24 | + 21 | + 22 | ,-> + 23 | `-> + 24 | `---- x Text ,-[$DIR/tests/fixture/pi/input.xml:21:1] - 21 | - 22 | ,-> - 23 | `-> - 24 | + 21 | + 22 | ,-> + 23 | `-> + 24 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:22:1] - 22 | - 23 | - : ^^^^^^^^^^^ - 24 | + 22 | + 23 | + : ^^^^^^^^^^^^^ + 24 | `---- x ProcessingInstruction ,-[$DIR/tests/fixture/pi/input.xml:22:1] - 22 | - 23 | - : ^^^^^^^^^^^ - 24 | + 22 | + 23 | + : ^^^^^^^^^^^^^ + 24 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:22:1] - 22 | - 23 | ,-> - 24 | `-> - 25 | + 22 | + 23 | ,-> + 24 | `-> + 25 | `---- x Text ,-[$DIR/tests/fixture/pi/input.xml:22:1] - 22 | - 23 | ,-> - 24 | `-> - 25 | + 22 | + 23 | ,-> + 24 | `-> + 25 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:23:1] - 23 | - 24 | - : ^^^^^^^^^^^^^^^ - 25 | + 23 | + 24 | + : ^^^^^^^^^^^ + 25 | `---- x ProcessingInstruction ,-[$DIR/tests/fixture/pi/input.xml:23:1] - 23 | - 24 | - : ^^^^^^^^^^^^^^^ - 25 | + 23 | + 24 | + : ^^^^^^^^^^^ + 25 | `---- x Child ,-[$DIR/tests/fixture/pi/input.xml:23:1] - 23 | - 24 | - : ^ - 25 | + 23 | + 24 | ,-> + 25 | `-> + 26 | `---- x Text ,-[$DIR/tests/fixture/pi/input.xml:23:1] - 23 | - 24 | + 23 | + 24 | ,-> + 25 | `-> + 26 | + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:24:1] + 24 | + 25 | + : ^^^^^^^^^^^^^^^ + 26 | + `---- + + x ProcessingInstruction + ,-[$DIR/tests/fixture/pi/input.xml:24:1] + 24 | + 25 | + : ^^^^^^^^^^^^^^^ + 26 | + `---- + + x Child + ,-[$DIR/tests/fixture/pi/input.xml:24:1] + 24 | + 25 | + : ^ + 26 | + `---- + + x Text + ,-[$DIR/tests/fixture/pi/input.xml:24:1] + 24 | + 25 | : ^ - 25 | + 26 | `---- diff --git a/crates/swc_xml_parser/tests/recovery/attribute-character-reference/dom.txt b/crates/swc_xml_parser/tests/recovery/attribute-character-reference/dom.txt new file mode 100644 index 000000000000..6e9d0a758f0f --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/attribute-character-reference/dom.txt @@ -0,0 +1,7 @@ +| +| " + " +| +| bar="&" +| " +" diff --git a/crates/swc_xml_parser/tests/recovery/attribute-character-reference/input.xml b/crates/swc_xml_parser/tests/recovery/attribute-character-reference/input.xml new file mode 100644 index 000000000000..9a137146e2c7 --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/attribute-character-reference/input.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/crates/swc_xml_parser/tests/recovery/attribute-character-reference/output.json b/crates/swc_xml_parser/tests/recovery/attribute-character-reference/output.json new file mode 100644 index 000000000000..65b17f0a6f40 --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/attribute-character-reference/output.json @@ -0,0 +1,68 @@ +{ + "type": "Document", + "span": { + "start": 1, + "end": 39, + "ctxt": 0 + }, + "children": [ + { + "type": "Element", + "span": { + "start": 1, + "end": 39, + "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": 31, + "ctxt": 0 + }, + "tagName": "foo", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "bar", + "rawName": "bar", + "value": "&", + "rawValue": "\"&\"" + } + ], + "children": [] + }, + { + "type": "Text", + "span": { + "start": 31, + "end": 32, + "ctxt": 0 + }, + "data": "\n", + "raw": "\n" + } + ] + } + ] +} diff --git a/crates/swc_xml_parser/tests/recovery/attribute-character-reference/output.swc-stderr b/crates/swc_xml_parser/tests/recovery/attribute-character-reference/output.swc-stderr new file mode 100644 index 000000000000..51e4f7efaadf --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/attribute-character-reference/output.swc-stderr @@ -0,0 +1,8 @@ + + x Invalid entity character + ,-[$DIR/tests/recovery/attribute-character-reference/input.xml:1:1] + 1 | + 2 | + : ^ + 3 | + `---- diff --git a/crates/swc_xml_parser/tests/recovery/attribute-character-reference/span.swc-stderr b/crates/swc_xml_parser/tests/recovery/attribute-character-reference/span.swc-stderr new file mode 100644 index 000000000000..d1df8b54ad00 --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/attribute-character-reference/span.swc-stderr @@ -0,0 +1,69 @@ + + x Document + ,-[$DIR/tests/recovery/attribute-character-reference/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | `-> + `---- + + x Child + ,-[$DIR/tests/recovery/attribute-character-reference/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | `-> + `---- + + x Element + ,-[$DIR/tests/recovery/attribute-character-reference/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | `-> + `---- + + x Child + ,-[$DIR/tests/recovery/attribute-character-reference/input.xml:1:1] + 1 | ,-> + 2 | `-> + 3 | + `---- + + x Text + ,-[$DIR/tests/recovery/attribute-character-reference/input.xml:1:1] + 1 | ,-> + 2 | `-> + 3 | + `---- + + x Child + ,-[$DIR/tests/recovery/attribute-character-reference/input.xml:1:1] + 1 | + 2 | + : ^^^^^^^^^^^^^^^^^^^ + 3 | + `---- + + x Element + ,-[$DIR/tests/recovery/attribute-character-reference/input.xml:1:1] + 1 | + 2 | + : ^^^^^^^^^^^^^^^^^^^ + 3 | + `---- + + x Attribute + + x Child + ,-[$DIR/tests/recovery/attribute-character-reference/input.xml:1:1] + 1 | + 2 | + : ^ + 3 | + `---- + + x Text + ,-[$DIR/tests/recovery/attribute-character-reference/input.xml:1:1] + 1 | + 2 | + : ^ + 3 | + `---- diff --git a/crates/swc_xml_parser/tests/recovery/attribute-no-equal/dom.txt b/crates/swc_xml_parser/tests/recovery/attribute-no-equal/dom.txt new file mode 100644 index 000000000000..6fcb5d045195 --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/attribute-no-equal/dom.txt @@ -0,0 +1,31 @@ +| +| " + " +| +| a="" +| " + " +| +| a="" +| " + " +| +| a="b" +| q="" +| " + " +| +| a="b" +| q="" +| " + " +| +| a="b" +| q="" +| " + " +| +| a="b" +| q="" +| " +" diff --git a/crates/swc_xml_parser/tests/recovery/attribute-no-equal/input.xml b/crates/swc_xml_parser/tests/recovery/attribute-no-equal/input.xml new file mode 100644 index 000000000000..db419f473bef --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/attribute-no-equal/input.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/crates/swc_xml_parser/tests/recovery/attribute-no-equal/output.json b/crates/swc_xml_parser/tests/recovery/attribute-no-equal/output.json new file mode 100644 index 000000000000..54684715868d --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/attribute-no-equal/output.json @@ -0,0 +1,304 @@ +{ + "type": "Document", + "span": { + "start": 1, + "end": 114, + "ctxt": 0 + }, + "children": [ + { + "type": "Element", + "span": { + "start": 1, + "end": 114, + "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": 21, + "ctxt": 0 + }, + "tagName": "c", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "a", + "rawName": "a", + "value": null, + "rawValue": null + } + ], + "children": [] + }, + { + "type": "Text", + "span": { + "start": 21, + "end": 26, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 26, + "end": 32, + "ctxt": 0 + }, + "tagName": "c", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "a", + "rawName": "a", + "value": null, + "rawValue": null + } + ], + "children": [] + }, + { + "type": "Text", + "span": { + "start": 32, + "end": 37, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 37, + "end": 49, + "ctxt": 0 + }, + "tagName": "c", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "a", + "rawName": "a", + "value": "b", + "rawValue": "'b'" + }, + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "q", + "rawName": "q", + "value": null, + "rawValue": null + } + ], + "children": [] + }, + { + "type": "Text", + "span": { + "start": 49, + "end": 54, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 54, + "end": 66, + "ctxt": 0 + }, + "tagName": "c", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 57, + "end": 58, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "q", + "rawName": "q", + "value": null, + "rawValue": null + }, + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "a", + "rawName": "a", + "value": "b", + "rawValue": "'b'" + } + ], + "children": [] + }, + { + "type": "Text", + "span": { + "start": 66, + "end": 71, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 71, + "end": 86, + "ctxt": 0 + }, + "tagName": "c", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "a", + "rawName": "a", + "value": "b", + "rawValue": "'b'" + }, + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "q", + "rawName": "q", + "value": null, + "rawValue": null + } + ], + "children": [] + }, + { + "type": "Text", + "span": { + "start": 86, + "end": 91, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 91, + "end": 106, + "ctxt": 0 + }, + "tagName": "c", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 94, + "end": 95, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "q", + "rawName": "q", + "value": null, + "rawValue": null + }, + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "a", + "rawName": "a", + "value": "b", + "rawValue": "'b'" + } + ], + "children": [] + }, + { + "type": "Text", + "span": { + "start": 106, + "end": 107, + "ctxt": 0 + }, + "data": "\n", + "raw": "\n" + } + ] + } + ] +} diff --git a/crates/swc_xml_parser/tests/recovery/attribute-no-equal/output.swc-stderr b/crates/swc_xml_parser/tests/recovery/attribute-no-equal/output.swc-stderr new file mode 100644 index 000000000000..81ec73bb0094 --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/attribute-no-equal/output.swc-stderr @@ -0,0 +1,48 @@ + + x Missing equal after attribute name + ,-[$DIR/tests/recovery/attribute-no-equal/input.xml:1:1] + 1 | + 2 | + : ^ + 3 | + `---- + + x Missing equal after attribute name + ,-[$DIR/tests/recovery/attribute-no-equal/input.xml:2:1] + 2 | + 3 | + : ^ + 4 | + `---- + + x Missing equal after attribute name + ,-[$DIR/tests/recovery/attribute-no-equal/input.xml:3:1] + 3 | + 4 | + : ^ + 5 | + `---- + + x Missing equal after attribute name + ,-[$DIR/tests/recovery/attribute-no-equal/input.xml:4:1] + 4 | + 5 | + : ^ + 6 | + `---- + + x Missing equal after attribute name + ,-[$DIR/tests/recovery/attribute-no-equal/input.xml:5:1] + 5 | + 6 | + : ^ + 7 | + `---- + + x Missing equal after attribute name + ,-[$DIR/tests/recovery/attribute-no-equal/input.xml:6:1] + 6 | + 7 | + : ^ + 8 | + `---- diff --git a/crates/swc_xml_parser/tests/recovery/attribute-no-equal/span.swc-stderr b/crates/swc_xml_parser/tests/recovery/attribute-no-equal/span.swc-stderr new file mode 100644 index 000000000000..da5dddf25b27 --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/attribute-no-equal/span.swc-stderr @@ -0,0 +1,260 @@ + + x Document + ,-[$DIR/tests/recovery/attribute-no-equal/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | | + 4 | | + 5 | | + 6 | | + 7 | | + 8 | `-> + `---- + + x Child + ,-[$DIR/tests/recovery/attribute-no-equal/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | | + 4 | | + 5 | | + 6 | | + 7 | | + 8 | `-> + `---- + + x Element + ,-[$DIR/tests/recovery/attribute-no-equal/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | | + 4 | | + 5 | | + 6 | | + 7 | | + 8 | `-> + `---- + + x Child + ,-[$DIR/tests/recovery/attribute-no-equal/input.xml:1:1] + 1 | ,-> + 2 | `-> + 3 | + `---- + + x Text + ,-[$DIR/tests/recovery/attribute-no-equal/input.xml:1:1] + 1 | ,-> + 2 | `-> + 3 | + `---- + + x Child + ,-[$DIR/tests/recovery/attribute-no-equal/input.xml:1:1] + 1 | + 2 | + : ^^^^^^^^^ + 3 | + `---- + + x Element + ,-[$DIR/tests/recovery/attribute-no-equal/input.xml:1:1] + 1 | + 2 | + : ^^^^^^^^^ + 3 | + `---- + + x Attribute + + x Child + ,-[$DIR/tests/recovery/attribute-no-equal/input.xml:1:1] + 1 | + 2 | ,-> + 3 | `-> + 4 | + `---- + + x Text + ,-[$DIR/tests/recovery/attribute-no-equal/input.xml:1:1] + 1 | + 2 | ,-> + 3 | `-> + 4 | + `---- + + x Child + ,-[$DIR/tests/recovery/attribute-no-equal/input.xml:2:1] + 2 | + 3 | + : ^^^^^^ + 4 | + `---- + + x Element + ,-[$DIR/tests/recovery/attribute-no-equal/input.xml:2:1] + 2 | + 3 | + : ^^^^^^ + 4 | + `---- + + x Child + ,-[$DIR/tests/recovery/attribute-no-equal/input.xml:2:1] + 2 | + 3 | ,-> + 4 | `-> + 5 | + `---- + + x Text + ,-[$DIR/tests/recovery/attribute-no-equal/input.xml:2:1] + 2 | + 3 | ,-> + 4 | `-> + 5 | + `---- + + x Child + ,-[$DIR/tests/recovery/attribute-no-equal/input.xml:3:1] + 3 | + 4 | + : ^^^^^^^^^^^^ + 5 | + `---- + + x Element + ,-[$DIR/tests/recovery/attribute-no-equal/input.xml:3:1] + 3 | + 4 | + : ^^^^^^^^^^^^ + 5 | + `---- + + x Child + ,-[$DIR/tests/recovery/attribute-no-equal/input.xml:3:1] + 3 | + 4 | ,-> + 5 | `-> + 6 | + `---- + + x Text + ,-[$DIR/tests/recovery/attribute-no-equal/input.xml:3:1] + 3 | + 4 | ,-> + 5 | `-> + 6 | + `---- + + x Child + ,-[$DIR/tests/recovery/attribute-no-equal/input.xml:4:1] + 4 | + 5 | + : ^^^^^^^^^^^^ + 6 | + `---- + + x Element + ,-[$DIR/tests/recovery/attribute-no-equal/input.xml:4:1] + 4 | + 5 | + : ^^^^^^^^^^^^ + 6 | + `---- + + x Attribute + ,-[$DIR/tests/recovery/attribute-no-equal/input.xml:4:1] + 4 | + 5 | + : ^ + 6 | + `---- + + x Child + ,-[$DIR/tests/recovery/attribute-no-equal/input.xml:4:1] + 4 | + 5 | ,-> + 6 | `-> + 7 | + `---- + + x Text + ,-[$DIR/tests/recovery/attribute-no-equal/input.xml:4:1] + 4 | + 5 | ,-> + 6 | `-> + 7 | + `---- + + x Child + ,-[$DIR/tests/recovery/attribute-no-equal/input.xml:5:1] + 5 | + 6 | + : ^^^^^^^^^^^^^^^ + 7 | + `---- + + x Element + ,-[$DIR/tests/recovery/attribute-no-equal/input.xml:5:1] + 5 | + 6 | + : ^^^^^^^^^^^^^^^ + 7 | + `---- + + x Child + ,-[$DIR/tests/recovery/attribute-no-equal/input.xml:5:1] + 5 | + 6 | ,-> + 7 | `-> + 8 | + `---- + + x Text + ,-[$DIR/tests/recovery/attribute-no-equal/input.xml:5:1] + 5 | + 6 | ,-> + 7 | `-> + 8 | + `---- + + x Child + ,-[$DIR/tests/recovery/attribute-no-equal/input.xml:6:1] + 6 | + 7 | + : ^^^^^^^^^^^^^^^ + 8 | + `---- + + x Element + ,-[$DIR/tests/recovery/attribute-no-equal/input.xml:6:1] + 6 | + 7 | + : ^^^^^^^^^^^^^^^ + 8 | + `---- + + x Attribute + ,-[$DIR/tests/recovery/attribute-no-equal/input.xml:6:1] + 6 | + 7 | + : ^ + 8 | + `---- + + x Child + ,-[$DIR/tests/recovery/attribute-no-equal/input.xml:6:1] + 6 | + 7 | + : ^ + 8 | + `---- + + x Text + ,-[$DIR/tests/recovery/attribute-no-equal/input.xml:6:1] + 6 | + 7 | + : ^ + 8 | + `---- diff --git a/crates/swc_xml_parser/tests/recovery/attribute-no-space-between/dom.txt b/crates/swc_xml_parser/tests/recovery/attribute-no-space-between/dom.txt new file mode 100644 index 000000000000..d6d7f686defc --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/attribute-no-space-between/dom.txt @@ -0,0 +1,8 @@ +| +| " + " +| +| a="v" +| b="v" +| " +" diff --git a/crates/swc_xml_parser/tests/recovery/attribute-no-space-between/input.xml b/crates/swc_xml_parser/tests/recovery/attribute-no-space-between/input.xml new file mode 100644 index 000000000000..7bd92b4754c8 --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/attribute-no-space-between/input.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/crates/swc_xml_parser/tests/recovery/attribute-no-space-between/output.json b/crates/swc_xml_parser/tests/recovery/attribute-no-space-between/output.json new file mode 100644 index 000000000000..589d466b878b --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/attribute-no-space-between/output.json @@ -0,0 +1,82 @@ +{ + "type": "Document", + "span": { + "start": 1, + "end": 35, + "ctxt": 0 + }, + "children": [ + { + "type": "Element", + "span": { + "start": 1, + "end": 35, + "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": 27, + "ctxt": 0 + }, + "tagName": "c", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "a", + "rawName": "a", + "value": "v", + "rawValue": "'v'" + }, + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "b", + "rawName": "b", + "value": "v", + "rawValue": "'v'" + } + ], + "children": [] + }, + { + "type": "Text", + "span": { + "start": 27, + "end": 28, + "ctxt": 0 + }, + "data": "\n", + "raw": "\n" + } + ] + } + ] +} diff --git a/crates/swc_xml_parser/tests/recovery/attribute-no-space-between/output.swc-stderr b/crates/swc_xml_parser/tests/recovery/attribute-no-space-between/output.swc-stderr new file mode 100644 index 000000000000..c659611b7591 --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/attribute-no-space-between/output.swc-stderr @@ -0,0 +1,8 @@ + + x Missing space between attributes + ,-[$DIR/tests/recovery/attribute-no-space-between/input.xml:1:1] + 1 | + 2 | + : ^ + 3 | + `---- diff --git a/crates/swc_xml_parser/tests/recovery/attribute-no-space-between/span.swc-stderr b/crates/swc_xml_parser/tests/recovery/attribute-no-space-between/span.swc-stderr new file mode 100644 index 000000000000..fa5652df53d8 --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/attribute-no-space-between/span.swc-stderr @@ -0,0 +1,69 @@ + + x Document + ,-[$DIR/tests/recovery/attribute-no-space-between/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | `-> + `---- + + x Child + ,-[$DIR/tests/recovery/attribute-no-space-between/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | `-> + `---- + + x Element + ,-[$DIR/tests/recovery/attribute-no-space-between/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | `-> + `---- + + x Child + ,-[$DIR/tests/recovery/attribute-no-space-between/input.xml:1:1] + 1 | ,-> + 2 | `-> + 3 | + `---- + + x Text + ,-[$DIR/tests/recovery/attribute-no-space-between/input.xml:1:1] + 1 | ,-> + 2 | `-> + 3 | + `---- + + x Child + ,-[$DIR/tests/recovery/attribute-no-space-between/input.xml:1:1] + 1 | + 2 | + : ^^^^^^^^^^^^^^^ + 3 | + `---- + + x Element + ,-[$DIR/tests/recovery/attribute-no-space-between/input.xml:1:1] + 1 | + 2 | + : ^^^^^^^^^^^^^^^ + 3 | + `---- + + x Attribute + + x Child + ,-[$DIR/tests/recovery/attribute-no-space-between/input.xml:1:1] + 1 | + 2 | + : ^ + 3 | + `---- + + x Text + ,-[$DIR/tests/recovery/attribute-no-space-between/input.xml:1:1] + 1 | + 2 | + : ^ + 3 | + `---- diff --git a/crates/swc_xml_parser/tests/recovery/attribute-partially-quoted-1/dom.txt b/crates/swc_xml_parser/tests/recovery/attribute-partially-quoted-1/dom.txt new file mode 100644 index 000000000000..559a8b69ceba --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/attribute-partially-quoted-1/dom.txt @@ -0,0 +1,6 @@ +| +| " + " +| +| foo="test> +" diff --git a/crates/swc_xml_parser/tests/recovery/attribute-partially-quoted-1/input.xml b/crates/swc_xml_parser/tests/recovery/attribute-partially-quoted-1/input.xml new file mode 100644 index 000000000000..436b826cfc56 --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/attribute-partially-quoted-1/input.xml @@ -0,0 +1,3 @@ + + \n", + "rawValue": "\"test>\n" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/crates/swc_xml_parser/tests/recovery/attribute-partially-quoted-1/output.swc-stderr b/crates/swc_xml_parser/tests/recovery/attribute-partially-quoted-1/output.swc-stderr new file mode 100644 index 000000000000..9db82a62c498 --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/attribute-partially-quoted-1/output.swc-stderr @@ -0,0 +1,29 @@ + + x Unescaped "<" not allowed in attribute values + ,-[$DIR/tests/recovery/attribute-partially-quoted-1/input.xml:1:1] + 1 | + 2 | + 3 | + : ^ + `---- + + x Unexpected end of file in main phase + ,-[$DIR/tests/recovery/attribute-partially-quoted-1/input.xml:2:1] + 2 | + 3 | `-> + `---- + + x Child + ,-[$DIR/tests/recovery/attribute-partially-quoted-1/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | `-> + `---- + + x Child + ,-[$DIR/tests/recovery/attribute-partially-quoted-1/input.xml:1:1] + 1 | ,-> + 2 | `-> + 3 | + `---- + + x Child + ,-[$DIR/tests/recovery/attribute-partially-quoted-1/input.xml:1:1] + 1 | + 2 | ,-> + 3 | `-> + `---- + + x Attribute diff --git a/crates/swc_xml_parser/tests/recovery/attribute-partially-quoted/dom.txt b/crates/swc_xml_parser/tests/recovery/attribute-partially-quoted/dom.txt new file mode 100644 index 000000000000..559a8b69ceba --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/attribute-partially-quoted/dom.txt @@ -0,0 +1,6 @@ +| +| " + " +| +| foo="test> +" diff --git a/crates/swc_xml_parser/tests/recovery/attribute-partially-quoted/input.xml b/crates/swc_xml_parser/tests/recovery/attribute-partially-quoted/input.xml new file mode 100644 index 000000000000..7e125173725c --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/attribute-partially-quoted/input.xml @@ -0,0 +1,3 @@ + + \n" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/crates/swc_xml_parser/tests/recovery/attribute-partially-quoted/output.swc-stderr b/crates/swc_xml_parser/tests/recovery/attribute-partially-quoted/output.swc-stderr new file mode 100644 index 000000000000..17e7fe769c8d --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/attribute-partially-quoted/output.swc-stderr @@ -0,0 +1,29 @@ + + x Unescaped "<" not allowed in attribute values + ,-[$DIR/tests/recovery/attribute-partially-quoted/input.xml:1:1] + 1 | + 2 | + 3 | + : ^ + `---- + + x Eof in tag + ,-[$DIR/tests/recovery/attribute-partially-quoted/input.xml:2:1] + 2 | + 3 | + : ^ + `---- diff --git a/crates/swc_xml_parser/tests/recovery/attribute-partially-quoted/span.swc-stderr b/crates/swc_xml_parser/tests/recovery/attribute-partially-quoted/span.swc-stderr new file mode 100644 index 000000000000..8a08e2d46165 --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/attribute-partially-quoted/span.swc-stderr @@ -0,0 +1,51 @@ + + x Document + ,-[$DIR/tests/recovery/attribute-partially-quoted/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | `-> + `---- + + x Element + ,-[$DIR/tests/recovery/attribute-partially-quoted/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | + `---- + + x Text + ,-[$DIR/tests/recovery/attribute-partially-quoted/input.xml:1:1] + 1 | ,-> + 2 | `-> + 3 | `-> + `---- + + x Element + ,-[$DIR/tests/recovery/attribute-partially-quoted/input.xml:1:1] + 1 | + 2 | ,-> + + \ No newline at end of file diff --git a/crates/swc_xml_parser/tests/recovery/attribute-value/output.json b/crates/swc_xml_parser/tests/recovery/attribute-value/output.json new file mode 100644 index 000000000000..b44fa7b120fe --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/attribute-value/output.json @@ -0,0 +1,140 @@ +{ + "type": "Document", + "span": { + "start": 1, + "end": 85, + "ctxt": 0 + }, + "children": [ + { + "type": "Element", + "span": { + "start": 1, + "end": 85, + "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": 31, + "ctxt": 0 + }, + "tagName": "foo", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "bar", + "rawName": "bar", + "value": "<", + "rawValue": "\"<\"" + } + ], + "children": [] + }, + { + "type": "Text", + "span": { + "start": 31, + "end": 36, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 36, + "end": 55, + "ctxt": 0 + }, + "tagName": "foo", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "bar", + "rawName": "bar", + "value": "<", + "rawValue": "'<'" + } + ], + "children": [] + }, + { + "type": "Text", + "span": { + "start": 55, + "end": 60, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 60, + "end": 77, + "ctxt": 0 + }, + "tagName": "foo", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 65, + "end": 70, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "bar", + "rawName": "bar", + "value": "<", + "rawValue": "<" + } + ], + "children": [] + }, + { + "type": "Text", + "span": { + "start": 77, + "end": 78, + "ctxt": 0 + }, + "data": "\n", + "raw": "\n" + } + ] + } + ] +} diff --git a/crates/swc_xml_parser/tests/recovery/attribute-value/output.swc-stderr b/crates/swc_xml_parser/tests/recovery/attribute-value/output.swc-stderr new file mode 100644 index 000000000000..aa469f2ef8f4 --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/attribute-value/output.swc-stderr @@ -0,0 +1,24 @@ + + x Unescaped "<" not allowed in attribute values + ,-[$DIR/tests/recovery/attribute-value/input.xml:1:1] + 1 | + 2 | + : ^ + 3 | + `---- + + x Unescaped "<" not allowed in attribute values + ,-[$DIR/tests/recovery/attribute-value/input.xml:2:1] + 2 | + 3 | + : ^ + 4 | + `---- + + x Missing quote before attribute value + ,-[$DIR/tests/recovery/attribute-value/input.xml:3:1] + 3 | + 4 | + : ^ + 5 | + `---- diff --git a/crates/swc_xml_parser/tests/recovery/attribute-value/span.swc-stderr b/crates/swc_xml_parser/tests/recovery/attribute-value/span.swc-stderr new file mode 100644 index 000000000000..0da85ac5b8cc --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/attribute-value/span.swc-stderr @@ -0,0 +1,147 @@ + + x Document + ,-[$DIR/tests/recovery/attribute-value/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | | + 4 | | + 5 | `-> + `---- + + x Child + ,-[$DIR/tests/recovery/attribute-value/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | | + 4 | | + 5 | `-> + `---- + + x Element + ,-[$DIR/tests/recovery/attribute-value/input.xml:1:1] + 1 | ,-> + 2 | | + 3 | | + 4 | | + 5 | `-> + `---- + + x Child + ,-[$DIR/tests/recovery/attribute-value/input.xml:1:1] + 1 | ,-> + 2 | `-> + 3 | + `---- + + x Text + ,-[$DIR/tests/recovery/attribute-value/input.xml:1:1] + 1 | ,-> + 2 | `-> + 3 | + `---- + + x Child + ,-[$DIR/tests/recovery/attribute-value/input.xml:1:1] + 1 | + 2 | + : ^^^^^^^^^^^^^^^^^^^ + 3 | + `---- + + x Element + ,-[$DIR/tests/recovery/attribute-value/input.xml:1:1] + 1 | + 2 | + : ^^^^^^^^^^^^^^^^^^^ + 3 | + `---- + + x Attribute + + x Child + ,-[$DIR/tests/recovery/attribute-value/input.xml:1:1] + 1 | + 2 | ,-> + 3 | `-> + 4 | + `---- + + x Text + ,-[$DIR/tests/recovery/attribute-value/input.xml:1:1] + 1 | + 2 | ,-> + 3 | `-> + 4 | + `---- + + x Child + ,-[$DIR/tests/recovery/attribute-value/input.xml:2:1] + 2 | + 3 | + : ^^^^^^^^^^^^^^^^^^^ + 4 | + `---- + + x Element + ,-[$DIR/tests/recovery/attribute-value/input.xml:2:1] + 2 | + 3 | + : ^^^^^^^^^^^^^^^^^^^ + 4 | + `---- + + x Child + ,-[$DIR/tests/recovery/attribute-value/input.xml:2:1] + 2 | + 3 | ,-> + 4 | `-> + 5 | + `---- + + x Text + ,-[$DIR/tests/recovery/attribute-value/input.xml:2:1] + 2 | + 3 | ,-> + 4 | `-> + 5 | + `---- + + x Child + ,-[$DIR/tests/recovery/attribute-value/input.xml:3:1] + 3 | + 4 | + : ^^^^^^^^^^^^^^^^^ + 5 | + `---- + + x Element + ,-[$DIR/tests/recovery/attribute-value/input.xml:3:1] + 3 | + 4 | + : ^^^^^^^^^^^^^^^^^ + 5 | + `---- + + x Attribute + ,-[$DIR/tests/recovery/attribute-value/input.xml:3:1] + 3 | + 4 | + : ^^^^^ + 5 | + `---- + + x Child + ,-[$DIR/tests/recovery/attribute-value/input.xml:3:1] + 3 | + 4 | + : ^ + 5 | + `---- + + x Text + ,-[$DIR/tests/recovery/attribute-value/input.xml:3:1] + 3 | + 4 | + : ^ + 5 | + `---- diff --git a/crates/swc_xml_parser/tests/recovery/comments/bad-40/dom.txt b/crates/swc_xml_parser/tests/recovery/comments/bad-40/dom.txt index f30c6a900d63..e46eba712e2c 100644 --- a/crates/swc_xml_parser/tests/recovery/comments/bad-40/dom.txt +++ b/crates/swc_xml_parser/tests/recovery/comments/bad-40/dom.txt @@ -4,19 +4,19 @@ " | | -| "Char* ']]>' " +| "Char* ']]>' " | | def="NT-Char" | "Char" | "*)) -']]>' +']]>' " | | "CDATA sections" | " " | -| "| '<!DOCTYPE' +| "| ' | def="NT-Char" @@ -28,7 +28,7 @@ | def="NT-simpleDTD" | "simpleDTD" | "* -']')? '>'" +']')? '>'" | " " | @@ -42,7 +42,7 @@ | " " | -| "'<!&como;' +| "' | def="NT-Char" @@ -57,6 +57,6 @@ | def="NT-Char" | "Char" | "*)) -'&comc;>'" +'&comc;>'" | "--> " diff --git a/crates/swc_xml_parser/tests/recovery/comments/bad-40/output.json b/crates/swc_xml_parser/tests/recovery/comments/bad-40/output.json index 909e943f7a22..df192dd3f428 100644 --- a/crates/swc_xml_parser/tests/recovery/comments/bad-40/output.json +++ b/crates/swc_xml_parser/tests/recovery/comments/bad-40/output.json @@ -63,7 +63,7 @@ "end": 97, "ctxt": 0 }, - "data": "Char* ']]>' ", + "data": "Char* ']]>' ", "raw": "Char* ']]>' " }, { @@ -110,7 +110,7 @@ "end": 143, "ctxt": 0 }, - "data": "*))\n']]>'\n", + "data": "*))\n']]>'\n", "raw": "*))\n']]>'\n" }, { @@ -162,7 +162,7 @@ "end": 192, "ctxt": 0 }, - "data": "| '<!DOCTYPE'\n(", + "data": "| ''", "raw": "*\n']')? '>'" } ] @@ -377,7 +377,7 @@ "end": 396, "ctxt": 0 }, - "data": "'<!&como;'\n(", + "data": "''", "raw": "*))\n'&comc;>'" } ] diff --git a/crates/swc_xml_parser/tests/recovery/comments/bad-40/output.swc-stderr b/crates/swc_xml_parser/tests/recovery/comments/bad-40/output.swc-stderr index f5ad22a760dd..f4d22a51249e 100644 --- a/crates/swc_xml_parser/tests/recovery/comments/bad-40/output.swc-stderr +++ b/crates/swc_xml_parser/tests/recovery/comments/bad-40/output.swc-stderr @@ -23,6 +23,30 @@ 6 | CDATA sections `---- + x Invalid entity character + ,-[$DIR/tests/recovery/comments/bad-40/input.xml:13:1] + 13 | simpleDTD + 14 | '<!&como;' + : ^ + 15 | (Char* - + `---- + + x Invalid entity character + ,-[$DIR/tests/recovery/comments/bad-40/input.xml:15:1] + 15 | (Char* - + 16 | (Char* '&comc;' Char*)) + : ^ + 17 | '&comc;>'--> + `---- + + x Invalid entity character + ,-[$DIR/tests/recovery/comments/bad-40/input.xml:16:1] + 16 | (Char* '&comc;' Char*)) + 17 | '&comc;>'--> + : ^ + 18 |
+ `---- + x Opening and ending tag mismatch ,-[$DIR/tests/recovery/comments/bad-40/input.xml:17:1] 17 | '&comc;>'--> diff --git a/crates/swc_xml_parser/tests/recovery/element-missing-name/dom.txt b/crates/swc_xml_parser/tests/recovery/element-missing-name/dom.txt new file mode 100644 index 000000000000..70af32b85741 --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/element-missing-name/dom.txt @@ -0,0 +1,6 @@ +| +| " + <> + + < aa > +" diff --git a/crates/swc_xml_parser/tests/recovery/element-missing-name/input.xml b/crates/swc_xml_parser/tests/recovery/element-missing-name/input.xml new file mode 100644 index 000000000000..b08d7c2bba5a --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/element-missing-name/input.xml @@ -0,0 +1,5 @@ + + <> + + < aa > + \ No newline at end of file diff --git a/crates/swc_xml_parser/tests/recovery/element-missing-name/output.json b/crates/swc_xml_parser/tests/recovery/element-missing-name/output.json new file mode 100644 index 000000000000..bbef5ad649ae --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/element-missing-name/output.json @@ -0,0 +1,32 @@ +{ + "type": "Document", + "span": { + "start": 1, + "end": 41, + "ctxt": 0 + }, + "children": [ + { + "type": "Element", + "span": { + "start": 1, + "end": 41, + "ctxt": 0 + }, + "tagName": "root", + "attributes": [], + "children": [ + { + "type": "Text", + "span": { + "start": 7, + "end": 34, + "ctxt": 0 + }, + "data": "\n <>\n \n < aa >\n", + "raw": "\n <>\n \n < aa >\n" + } + ] + } + ] +} diff --git a/crates/swc_xml_parser/tests/recovery/element-missing-name/output.swc-stderr b/crates/swc_xml_parser/tests/recovery/element-missing-name/output.swc-stderr new file mode 100644 index 000000000000..ca99a66bd4ba --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/element-missing-name/output.swc-stderr @@ -0,0 +1,24 @@ + + x Invalid first character of tag name + ,-[$DIR/tests/recovery/element-missing-name/input.xml:1:1] + 1 | + 2 | <> + : ^ + 3 | + `---- + + x Missing end tag name + ,-[$DIR/tests/recovery/element-missing-name/input.xml:2:1] + 2 | <> + 3 | + : ^ + 4 | < aa > + `---- + + x Invalid first character of tag name + ,-[$DIR/tests/recovery/element-missing-name/input.xml:3:1] + 3 | + 4 | < aa > + : ^ + 5 | + `---- diff --git a/crates/swc_xml_parser/tests/recovery/element-missing-name/span.swc-stderr b/crates/swc_xml_parser/tests/recovery/element-missing-name/span.swc-stderr new file mode 100644 index 000000000000..a818ca71f3d8 --- /dev/null +++ b/crates/swc_xml_parser/tests/recovery/element-missing-name/span.swc-stderr @@ -0,0 +1,45 @@ + + x Document + ,-[$DIR/tests/recovery/element-missing-name/input.xml:1:1] + 1 | ,-> + 2 | | <> + 3 | | + 4 | | < aa > + 5 | `-> + `---- + + x Child + ,-[$DIR/tests/recovery/element-missing-name/input.xml:1:1] + 1 | ,-> + 2 | | <> + 3 | | + 4 | | < aa > + 5 | `-> + `---- + + x Element + ,-[$DIR/tests/recovery/element-missing-name/input.xml:1:1] + 1 | ,-> + 2 | | <> + 3 | | + 4 | | < aa > + 5 | `-> + `---- + + x Child + ,-[$DIR/tests/recovery/element-missing-name/input.xml:1:1] + 1 | ,-> + 2 | | <> + 3 | | + 4 | `-> < aa > + 5 | + `---- + + x Text + ,-[$DIR/tests/recovery/element-missing-name/input.xml:1:1] + 1 | ,-> + 2 | | <> + 3 | | + 4 | `-> < aa > + 5 | + `---- diff --git a/crates/swc_xml_parser/tests/recovery/no-quotes/output.swc-stderr b/crates/swc_xml_parser/tests/recovery/no-quotes/output.swc-stderr index b88fd9c3a52c..343463758f15 100644 --- a/crates/swc_xml_parser/tests/recovery/no-quotes/output.swc-stderr +++ b/crates/swc_xml_parser/tests/recovery/no-quotes/output.swc-stderr @@ -1,4 +1,35 @@ + x Unescaped "<" not allowed in attribute values + ,-[$DIR/tests/recovery/no-quotes/input.xml:4:1] + 4 | Jani + 5 | Don't forget me this weekend! + 7 | + : ^ + `---- + x Eof in tag ,-[$DIR/tests/recovery/no-quotes/input.xml:6:1] 6 | Don't forget me this weekend!