From cdf0d8a8b59a05498b6ca609d8a2ecf3c2f35f28 Mon Sep 17 00:00:00 2001 From: Alexander Akait <4567934+alexander-akait@users.noreply.github.com> Date: Fri, 2 Dec 2022 07:56:34 +0300 Subject: [PATCH] fix(xml/parser): Fix parsing of legacy document types (#6555) --- crates/swc_xml_parser/src/lexer/mod.rs | 41 +++ .../document_type/internal_subset-1/dom.txt | 3 + .../document_type/internal_subset-1/input.xml | 5 + .../internal_subset-1/output.json | 44 +++ .../internal_subset-1/span.swc-stderr | 55 ++++ .../document_type/internal_subset-2/dom.txt | 3 + .../document_type/internal_subset-2/input.xml | 4 + .../internal_subset-2/output.json | 44 +++ .../internal_subset-2/span.swc-stderr | 52 +++ .../document_type/internal_subset-3/dom.txt | 3 + .../document_type/internal_subset-3/input.xml | 6 + .../internal_subset-3/output.json | 44 +++ .../internal_subset-3/span.swc-stderr | 58 ++++ .../document_type/internal_subset-4/dom.txt | 3 + .../document_type/internal_subset-4/input.xml | 4 + .../internal_subset-4/output.json | 44 +++ .../internal_subset-4/span.swc-stderr | 52 +++ .../document_type/internal_subset-5/dom.txt | 3 + .../document_type/internal_subset-5/input.xml | 7 + .../internal_subset-5/output.json | 44 +++ .../internal_subset-5/span.swc-stderr | 61 ++++ .../document_type/internal_subset/dom.txt | 22 ++ .../document_type/internal_subset/input.xml | 16 + .../document_type/internal_subset/output.json | 182 +++++++++++ .../internal_subset/span.swc-stderr | 300 ++++++++++++++++++ .../internal_subset_empty-1/dom.txt | 3 + .../internal_subset_empty-1/input.xml | 2 + .../internal_subset_empty-1/output.json | 44 +++ .../internal_subset_empty-1/span.swc-stderr | 48 +++ .../internal_subset_empty-2/dom.txt | 3 + .../internal_subset_empty-2/input.xml | 2 + .../internal_subset_empty-2/output.json | 44 +++ .../internal_subset_empty-2/span.swc-stderr | 48 +++ .../internal_subset_empty/dom.txt | 3 + .../internal_subset_empty/input.xml | 2 + .../internal_subset_empty/output.json | 44 +++ .../internal_subset_empty/span.swc-stderr | 48 +++ .../fixture/document_type/only-name/dom.txt | 3 + .../fixture/document_type/only-name/input.xml | 2 + .../document_type/only-name/output.json | 44 +++ .../document_type/only-name/span.swc-stderr | 48 +++ .../fixture/document_type/public_id-1/dom.txt | 3 + .../document_type/public_id-1/input.xml | 2 + .../document_type/public_id-1/output.json | 44 +++ .../document_type/public_id-1/span.swc-stderr | 48 +++ .../fixture/document_type/public_id/dom.txt | 3 + .../fixture/document_type/public_id/input.xml | 2 + .../document_type/public_id/output.json | 44 +++ .../document_type/public_id/span.swc-stderr | 48 +++ .../fixture/document_type/system_id-1/dom.txt | 3 + .../document_type/system_id-1/input.xml | 2 + .../document_type/system_id-1/output.json | 44 +++ .../document_type/system_id-1/span.swc-stderr | 48 +++ .../fixture/document_type/system_id/dom.txt | 3 + .../fixture/document_type/system_id/input.xml | 2 + .../document_type/system_id/output.json | 44 +++ .../document_type/system_id/span.swc-stderr | 48 +++ 57 files changed, 1876 insertions(+) create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/internal_subset-1/dom.txt create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/internal_subset-1/input.xml create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/internal_subset-1/output.json create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/internal_subset-1/span.swc-stderr create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/internal_subset-2/dom.txt create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/internal_subset-2/input.xml create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/internal_subset-2/output.json create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/internal_subset-2/span.swc-stderr create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/internal_subset-3/dom.txt create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/internal_subset-3/input.xml create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/internal_subset-3/output.json create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/internal_subset-3/span.swc-stderr create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/internal_subset-4/dom.txt create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/internal_subset-4/input.xml create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/internal_subset-4/output.json create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/internal_subset-4/span.swc-stderr create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/internal_subset-5/dom.txt create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/internal_subset-5/input.xml create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/internal_subset-5/output.json create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/internal_subset-5/span.swc-stderr create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/internal_subset/dom.txt create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/internal_subset/input.xml create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/internal_subset/output.json create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/internal_subset/span.swc-stderr create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty-1/dom.txt create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty-1/input.xml create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty-1/output.json create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty-1/span.swc-stderr create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty-2/dom.txt create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty-2/input.xml create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty-2/output.json create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty-2/span.swc-stderr create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty/dom.txt create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty/input.xml create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty/output.json create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty/span.swc-stderr create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/only-name/dom.txt create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/only-name/input.xml create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/only-name/output.json create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/only-name/span.swc-stderr create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/public_id-1/dom.txt create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/public_id-1/input.xml create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/public_id-1/output.json create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/public_id-1/span.swc-stderr create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/public_id/dom.txt create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/public_id/input.xml create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/public_id/output.json create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/public_id/span.swc-stderr create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/system_id-1/dom.txt create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/system_id-1/input.xml create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/system_id-1/output.json create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/system_id-1/span.swc-stderr create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/system_id/dom.txt create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/system_id/input.xml create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/system_id/output.json create mode 100644 crates/swc_xml_parser/tests/fixture/document_type/system_id/span.swc-stderr diff --git a/crates/swc_xml_parser/src/lexer/mod.rs b/crates/swc_xml_parser/src/lexer/mod.rs index 6af81a1f33ea..8fc94befa1b1 100644 --- a/crates/swc_xml_parser/src/lexer/mod.rs +++ b/crates/swc_xml_parser/src/lexer/mod.rs @@ -61,6 +61,7 @@ pub enum State { DoctypeSystemIdentifierSingleQuoted, DoctypeSystemIdentifierDoubleQuoted, AfterDoctypeSystemIdentifier, + DoctypeTypeInternalSubSet, BogusDoctype, } @@ -2245,6 +2246,12 @@ where self.state = State::Data; self.emit_doctype_token(); } + // U+005B LEFT SQUARE BRACKET ([) + // Switch to the doctype internal subset state. + Some(c @ '[') => { + self.append_raw_to_doctype_token(c); + self.state = State::DoctypeTypeInternalSubSet; + } // EOF // Parse error. Switch to the data state. Emit DOCTYPE token. Reconsume the EOF // character. @@ -2825,6 +2832,12 @@ where self.state = State::Data; self.emit_doctype_token(); } + // U+005B LEFT SQUARE BRACKET ([) + // Switch to the doctype internal subset state. + Some(c @ '[') => { + self.append_raw_to_doctype_token(c); + self.state = State::DoctypeTypeInternalSubSet; + } // EOF // Parse error. Switch to the data state. Emit DOCTYPE token. Reconsume the EOF // character. @@ -2843,6 +2856,34 @@ where } } } + State::DoctypeTypeInternalSubSet => { + // Consume the next input character: + match self.consume_next_char() { + // U+005D RIGHT SQUARE BRACKET (]) + // Switch to the CDATA bracket state. + Some(c @ ']') => { + self.append_raw_to_doctype_token(c); + self.state = State::AfterDoctypeName; + } + // EOF + // Parse error. Switch to the data state. Emit DOCTYPE token. Reconsume the EOF + // character. + None => { + self.emit_error(ErrorKind::EofInDoctype); + self.state = State::Data; + self.emit_doctype_token(); + self.reconsume(); + } + // Anything else + // Append the current input character to the current DOCTYPE token's system + // identifier. + Some(c) => { + // TODO improve parse legacy declarations + self.validate_input_stream_character(c); + self.append_raw_to_doctype_token(c); + } + } + } State::BogusDoctype => { // Consume the next input character: match self.consume_next_char() { diff --git a/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-1/dom.txt b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-1/dom.txt new file mode 100644 index 000000000000..4193c808be8b --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-1/dom.txt @@ -0,0 +1,3 @@ +| +| +| "test" diff --git a/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-1/input.xml b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-1/input.xml new file mode 100644 index 000000000000..5220a26f5fdf --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-1/input.xml @@ -0,0 +1,5 @@ + +]> +test \ No newline at end of file diff --git a/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-1/output.json b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-1/output.json new file mode 100644 index 000000000000..cd34ac0216d1 --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-1/output.json @@ -0,0 +1,44 @@ +{ + "type": "Document", + "span": { + "start": 1, + "end": 112, + "ctxt": 0 + }, + "children": [ + { + "type": "DocumentType", + "span": { + "start": 1, + "end": 94, + "ctxt": 0 + }, + "name": "svg", + "publicId": null, + "systemId": null, + "raw": "\n]>" + }, + { + "type": "Element", + "span": { + "start": 95, + "end": 112, + "ctxt": 0 + }, + "tagName": "root", + "attributes": [], + "children": [ + { + "type": "Text", + "span": { + "start": 101, + "end": 105, + "ctxt": 0 + }, + "data": "test", + "raw": "test" + } + ] + } + ] +} diff --git a/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-1/span.swc-stderr b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-1/span.swc-stderr new file mode 100644 index 000000000000..1a4c942a497a --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-1/span.swc-stderr @@ -0,0 +1,55 @@ + + x Document + ,-[$DIR/tests/fixture/document_type/internal_subset-1/input.xml:1:1] + 1 | ,-> + 4 | | ]> + 5 | `-> test + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset-1/input.xml:1:1] + 1 | ,-> + 4 | `-> ]> + 5 | test + `---- + + x DocumentType + ,-[$DIR/tests/fixture/document_type/internal_subset-1/input.xml:1:1] + 1 | ,-> + 4 | `-> ]> + 5 | test + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset-1/input.xml:4:1] + 4 | ]> + 5 | test + : ^^^^^^^^^^^^^^^^^ + `---- + + x Element + ,-[$DIR/tests/fixture/document_type/internal_subset-1/input.xml:4:1] + 4 | ]> + 5 | test + : ^^^^^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset-1/input.xml:4:1] + 4 | ]> + 5 | test + : ^^^^ + `---- + + x Text + ,-[$DIR/tests/fixture/document_type/internal_subset-1/input.xml:4:1] + 4 | ]> + 5 | test + : ^^^^ + `---- diff --git a/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-2/dom.txt b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-2/dom.txt new file mode 100644 index 000000000000..4193c808be8b --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-2/dom.txt @@ -0,0 +1,3 @@ +| +| +| "test" diff --git a/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-2/input.xml b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-2/input.xml new file mode 100644 index 000000000000..3ed2f51f13d7 --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-2/input.xml @@ -0,0 +1,4 @@ + +]> +test \ No newline at end of file diff --git a/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-2/output.json b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-2/output.json new file mode 100644 index 000000000000..246c755fcebd --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-2/output.json @@ -0,0 +1,44 @@ +{ + "type": "Document", + "span": { + "start": 1, + "end": 127, + "ctxt": 0 + }, + "children": [ + { + "type": "DocumentType", + "span": { + "start": 1, + "end": 109, + "ctxt": 0 + }, + "name": "svg", + "publicId": null, + "systemId": null, + "raw": "\n]>" + }, + { + "type": "Element", + "span": { + "start": 110, + "end": 127, + "ctxt": 0 + }, + "tagName": "root", + "attributes": [], + "children": [ + { + "type": "Text", + "span": { + "start": 116, + "end": 120, + "ctxt": 0 + }, + "data": "test", + "raw": "test" + } + ] + } + ] +} diff --git a/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-2/span.swc-stderr b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-2/span.swc-stderr new file mode 100644 index 000000000000..eb9f7b8f1927 --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-2/span.swc-stderr @@ -0,0 +1,52 @@ + + x Document + ,-[$DIR/tests/fixture/document_type/internal_subset-2/input.xml:1:1] + 1 | ,-> + 3 | | ]> + 4 | `-> test + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset-2/input.xml:1:1] + 1 | ,-> + 3 | `-> ]> + 4 | test + `---- + + x DocumentType + ,-[$DIR/tests/fixture/document_type/internal_subset-2/input.xml:1:1] + 1 | ,-> + 3 | `-> ]> + 4 | test + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset-2/input.xml:3:1] + 3 | ]> + 4 | test + : ^^^^^^^^^^^^^^^^^ + `---- + + x Element + ,-[$DIR/tests/fixture/document_type/internal_subset-2/input.xml:3:1] + 3 | ]> + 4 | test + : ^^^^^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset-2/input.xml:3:1] + 3 | ]> + 4 | test + : ^^^^ + `---- + + x Text + ,-[$DIR/tests/fixture/document_type/internal_subset-2/input.xml:3:1] + 3 | ]> + 4 | test + : ^^^^ + `---- diff --git a/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-3/dom.txt b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-3/dom.txt new file mode 100644 index 000000000000..4193c808be8b --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-3/dom.txt @@ -0,0 +1,3 @@ +| +| +| "test" diff --git a/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-3/input.xml b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-3/input.xml new file mode 100644 index 000000000000..eb679de85898 --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-3/input.xml @@ -0,0 +1,6 @@ + +]> +test \ No newline at end of file diff --git a/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-3/output.json b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-3/output.json new file mode 100644 index 000000000000..0f5319765afa --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-3/output.json @@ -0,0 +1,44 @@ +{ + "type": "Document", + "span": { + "start": 1, + "end": 205, + "ctxt": 0 + }, + "children": [ + { + "type": "DocumentType", + "span": { + "start": 1, + "end": 187, + "ctxt": 0 + }, + "name": "svg", + "publicId": null, + "systemId": null, + "raw": "\n]>" + }, + { + "type": "Element", + "span": { + "start": 188, + "end": 205, + "ctxt": 0 + }, + "tagName": "root", + "attributes": [], + "children": [ + { + "type": "Text", + "span": { + "start": 194, + "end": 198, + "ctxt": 0 + }, + "data": "test", + "raw": "test" + } + ] + } + ] +} diff --git a/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-3/span.swc-stderr b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-3/span.swc-stderr new file mode 100644 index 000000000000..1b357f51d5ff --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-3/span.swc-stderr @@ -0,0 +1,58 @@ + + x Document + ,-[$DIR/tests/fixture/document_type/internal_subset-3/input.xml:1:1] + 1 | ,-> + 5 | | ]> + 6 | `-> test + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset-3/input.xml:1:1] + 1 | ,-> + 5 | `-> ]> + 6 | test + `---- + + x DocumentType + ,-[$DIR/tests/fixture/document_type/internal_subset-3/input.xml:1:1] + 1 | ,-> + 5 | `-> ]> + 6 | test + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset-3/input.xml:5:1] + 5 | ]> + 6 | test + : ^^^^^^^^^^^^^^^^^ + `---- + + x Element + ,-[$DIR/tests/fixture/document_type/internal_subset-3/input.xml:5:1] + 5 | ]> + 6 | test + : ^^^^^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset-3/input.xml:5:1] + 5 | ]> + 6 | test + : ^^^^ + `---- + + x Text + ,-[$DIR/tests/fixture/document_type/internal_subset-3/input.xml:5:1] + 5 | ]> + 6 | test + : ^^^^ + `---- diff --git a/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-4/dom.txt b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-4/dom.txt new file mode 100644 index 000000000000..4193c808be8b --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-4/dom.txt @@ -0,0 +1,3 @@ +| +| +| "test" diff --git a/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-4/input.xml b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-4/input.xml new file mode 100644 index 000000000000..40f2f256b194 --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-4/input.xml @@ -0,0 +1,4 @@ + +]> +test \ No newline at end of file diff --git a/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-4/output.json b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-4/output.json new file mode 100644 index 000000000000..26baff560ccd --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-4/output.json @@ -0,0 +1,44 @@ +{ + "type": "Document", + "span": { + "start": 1, + "end": 105, + "ctxt": 0 + }, + "children": [ + { + "type": "DocumentType", + "span": { + "start": 1, + "end": 87, + "ctxt": 0 + }, + "name": "svg", + "publicId": null, + "systemId": null, + "raw": "\n]>" + }, + { + "type": "Element", + "span": { + "start": 88, + "end": 105, + "ctxt": 0 + }, + "tagName": "root", + "attributes": [], + "children": [ + { + "type": "Text", + "span": { + "start": 94, + "end": 98, + "ctxt": 0 + }, + "data": "test", + "raw": "test" + } + ] + } + ] +} diff --git a/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-4/span.swc-stderr b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-4/span.swc-stderr new file mode 100644 index 000000000000..3534c5e0dc53 --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-4/span.swc-stderr @@ -0,0 +1,52 @@ + + x Document + ,-[$DIR/tests/fixture/document_type/internal_subset-4/input.xml:1:1] + 1 | ,-> + 3 | | ]> + 4 | `-> test + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset-4/input.xml:1:1] + 1 | ,-> + 3 | `-> ]> + 4 | test + `---- + + x DocumentType + ,-[$DIR/tests/fixture/document_type/internal_subset-4/input.xml:1:1] + 1 | ,-> + 3 | `-> ]> + 4 | test + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset-4/input.xml:3:1] + 3 | ]> + 4 | test + : ^^^^^^^^^^^^^^^^^ + `---- + + x Element + ,-[$DIR/tests/fixture/document_type/internal_subset-4/input.xml:3:1] + 3 | ]> + 4 | test + : ^^^^^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset-4/input.xml:3:1] + 3 | ]> + 4 | test + : ^^^^ + `---- + + x Text + ,-[$DIR/tests/fixture/document_type/internal_subset-4/input.xml:3:1] + 3 | ]> + 4 | test + : ^^^^ + `---- diff --git a/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-5/dom.txt b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-5/dom.txt new file mode 100644 index 000000000000..4193c808be8b --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-5/dom.txt @@ -0,0 +1,3 @@ +| +| +| "test" diff --git a/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-5/input.xml b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-5/input.xml new file mode 100644 index 000000000000..5895dada5c65 --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-5/input.xml @@ -0,0 +1,7 @@ + + + + +]> +test \ No newline at end of file diff --git a/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-5/output.json b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-5/output.json new file mode 100644 index 000000000000..335e881351a3 --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-5/output.json @@ -0,0 +1,44 @@ +{ + "type": "Document", + "span": { + "start": 1, + "end": 224, + "ctxt": 0 + }, + "children": [ + { + "type": "DocumentType", + "span": { + "start": 1, + "end": 206, + "ctxt": 0 + }, + "name": "svg", + "publicId": null, + "systemId": null, + "raw": "\n \n \n \n]>" + }, + { + "type": "Element", + "span": { + "start": 207, + "end": 224, + "ctxt": 0 + }, + "tagName": "root", + "attributes": [], + "children": [ + { + "type": "Text", + "span": { + "start": 213, + "end": 217, + "ctxt": 0 + }, + "data": "test", + "raw": "test" + } + ] + } + ] +} diff --git a/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-5/span.swc-stderr b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-5/span.swc-stderr new file mode 100644 index 000000000000..00db3dc990ce --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset-5/span.swc-stderr @@ -0,0 +1,61 @@ + + x Document + ,-[$DIR/tests/fixture/document_type/internal_subset-5/input.xml:1:1] + 1 | ,-> + 3 | | + 4 | | + 5 | | + 6 | | ]> + 7 | `-> test + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset-5/input.xml:1:1] + 1 | ,-> + 3 | | + 4 | | + 5 | | + 6 | `-> ]> + 7 | test + `---- + + x DocumentType + ,-[$DIR/tests/fixture/document_type/internal_subset-5/input.xml:1:1] + 1 | ,-> + 3 | | + 4 | | + 5 | | + 6 | `-> ]> + 7 | test + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset-5/input.xml:6:1] + 6 | ]> + 7 | test + : ^^^^^^^^^^^^^^^^^ + `---- + + x Element + ,-[$DIR/tests/fixture/document_type/internal_subset-5/input.xml:6:1] + 6 | ]> + 7 | test + : ^^^^^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset-5/input.xml:6:1] + 6 | ]> + 7 | test + : ^^^^ + `---- + + x Text + ,-[$DIR/tests/fixture/document_type/internal_subset-5/input.xml:6:1] + 6 | ]> + 7 | test + : ^^^^ + `---- diff --git a/crates/swc_xml_parser/tests/fixture/document_type/internal_subset/dom.txt b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset/dom.txt new file mode 100644 index 000000000000..4b36c15b4e4d --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset/dom.txt @@ -0,0 +1,22 @@ + +| +| +| " + " +| +| " + " +| +| "Fred Bloggs" +| " + " +| +| "2008-11-27" +| " + " +| +| "Male" +| " + " +| " +" diff --git a/crates/swc_xml_parser/tests/fixture/document_type/internal_subset/input.xml b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset/input.xml new file mode 100644 index 000000000000..a4e36cb5a0db --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset/input.xml @@ -0,0 +1,16 @@ + + + + + + + +]> + + + Fred Bloggs + 2008-11-27 + Male + + \ No newline at end of file diff --git a/crates/swc_xml_parser/tests/fixture/document_type/internal_subset/output.json b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset/output.json new file mode 100644 index 000000000000..c78e9292861d --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset/output.json @@ -0,0 +1,182 @@ +{ + "type": "Document", + "span": { + "start": 1, + "end": 473, + "ctxt": 0 + }, + "children": [ + { + "type": "ProcessingInstruction", + "span": { + "start": 1, + "end": 56, + "ctxt": 0 + }, + "target": "xml", + "data": "version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"" + }, + { + "type": "DocumentType", + "span": { + "start": 57, + "end": 312, + "ctxt": 0 + }, + "name": "people_list", + "publicId": null, + "systemId": null, + "raw": "\n\n\n\n\n\n]>" + }, + { + "type": "Element", + "span": { + "start": 313, + "end": 473, + "ctxt": 0 + }, + "tagName": "people_list", + "attributes": [], + "children": [ + { + "type": "Text", + "span": { + "start": 326, + "end": 331, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 331, + "end": 458, + "ctxt": 0 + }, + "tagName": "person", + "attributes": [], + "children": [ + { + "type": "Text", + "span": { + "start": 339, + "end": 348, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 348, + "end": 372, + "ctxt": 0 + }, + "tagName": "name", + "attributes": [], + "children": [ + { + "type": "Text", + "span": { + "start": 354, + "end": 365, + "ctxt": 0 + }, + "data": "Fred Bloggs", + "raw": "Fred Bloggs" + } + ] + }, + { + "type": "Text", + "span": { + "start": 372, + "end": 381, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 381, + "end": 414, + "ctxt": 0 + }, + "tagName": "birthdate", + "attributes": [], + "children": [ + { + "type": "Text", + "span": { + "start": 392, + "end": 402, + "ctxt": 0 + }, + "data": "2008-11-27", + "raw": "2008-11-27" + } + ] + }, + { + "type": "Text", + "span": { + "start": 414, + "end": 423, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + }, + { + "type": "Element", + "span": { + "start": 423, + "end": 444, + "ctxt": 0 + }, + "tagName": "gender", + "attributes": [], + "children": [ + { + "type": "Text", + "span": { + "start": 431, + "end": 435, + "ctxt": 0 + }, + "data": "Male", + "raw": "Male" + } + ] + }, + { + "type": "Text", + "span": { + "start": 444, + "end": 449, + "ctxt": 0 + }, + "data": "\n ", + "raw": "\n " + } + ] + }, + { + "type": "Text", + "span": { + "start": 458, + "end": 459, + "ctxt": 0 + }, + "data": "\n", + "raw": "\n" + } + ] + } + ] +} diff --git a/crates/swc_xml_parser/tests/fixture/document_type/internal_subset/span.swc-stderr b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset/span.swc-stderr new file mode 100644 index 000000000000..cfec1ed5cc7e --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset/span.swc-stderr @@ -0,0 +1,300 @@ + + x Document + ,-[$DIR/tests/fixture/document_type/internal_subset/input.xml:1:1] + 1 | ,-> + 2 | | + 4 | | + 5 | | + 6 | | + 7 | | + 8 | | + 9 | | ]> + 10 | | + 11 | | + 12 | | Fred Bloggs + 13 | | 2008-11-27 + 14 | | Male + 15 | | + 16 | `-> + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset/input.xml:1:1] + 1 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 2 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 2 | + 2 | ,-> + 4 | | + 5 | | + 6 | | + 7 | | + 8 | | + 9 | `-> ]> + 10 | + `---- + + x DocumentType + ,-[$DIR/tests/fixture/document_type/internal_subset/input.xml:1:1] + 1 | + 2 | ,-> + 4 | | + 5 | | + 6 | | + 7 | | + 8 | | + 9 | `-> ]> + 10 | + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset/input.xml:9:1] + 9 | ]> + 10 | ,-> + 11 | | + 12 | | Fred Bloggs + 13 | | 2008-11-27 + 14 | | Male + 15 | | + 16 | `-> + `---- + + x Element + ,-[$DIR/tests/fixture/document_type/internal_subset/input.xml:9:1] + 9 | ]> + 10 | ,-> + 11 | | + 12 | | Fred Bloggs + 13 | | 2008-11-27 + 14 | | Male + 15 | | + 16 | `-> + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset/input.xml:9:1] + 9 | ]> + 10 | ,-> + 11 | `-> + 12 | Fred Bloggs + `---- + + x Text + ,-[$DIR/tests/fixture/document_type/internal_subset/input.xml:9:1] + 9 | ]> + 10 | ,-> + 11 | `-> + 12 | Fred Bloggs + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset/input.xml:10:1] + 10 | + 11 | ,-> + 12 | | Fred Bloggs + 13 | | 2008-11-27 + 14 | | Male + 15 | `-> + 16 | + `---- + + x Element + ,-[$DIR/tests/fixture/document_type/internal_subset/input.xml:10:1] + 10 | + 11 | ,-> + 12 | | Fred Bloggs + 13 | | 2008-11-27 + 14 | | Male + 15 | `-> + 16 | + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset/input.xml:10:1] + 10 | + 11 | ,-> + 12 | `-> Fred Bloggs + 13 | 2008-11-27 + `---- + + x Text + ,-[$DIR/tests/fixture/document_type/internal_subset/input.xml:10:1] + 10 | + 11 | ,-> + 12 | `-> Fred Bloggs + 13 | 2008-11-27 + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset/input.xml:11:1] + 11 | + 12 | Fred Bloggs + : ^^^^^^^^^^^^^^^^^^^^^^^^ + 13 | 2008-11-27 + `---- + + x Element + ,-[$DIR/tests/fixture/document_type/internal_subset/input.xml:11:1] + 11 | + 12 | Fred Bloggs + : ^^^^^^^^^^^^^^^^^^^^^^^^ + 13 | 2008-11-27 + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset/input.xml:11:1] + 11 | + 12 | Fred Bloggs + : ^^^^^^^^^^^ + 13 | 2008-11-27 + `---- + + x Text + ,-[$DIR/tests/fixture/document_type/internal_subset/input.xml:11:1] + 11 | + 12 | Fred Bloggs + : ^^^^^^^^^^^ + 13 | 2008-11-27 + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset/input.xml:11:1] + 11 | + 12 | ,-> Fred Bloggs + 13 | `-> 2008-11-27 + 14 | Male + `---- + + x Text + ,-[$DIR/tests/fixture/document_type/internal_subset/input.xml:11:1] + 11 | + 12 | ,-> Fred Bloggs + 13 | `-> 2008-11-27 + 14 | Male + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset/input.xml:12:1] + 12 | Fred Bloggs + 13 | 2008-11-27 + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 14 | Male + `---- + + x Element + ,-[$DIR/tests/fixture/document_type/internal_subset/input.xml:12:1] + 12 | Fred Bloggs + 13 | 2008-11-27 + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 14 | Male + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset/input.xml:12:1] + 12 | Fred Bloggs + 13 | 2008-11-27 + : ^^^^^^^^^^ + 14 | Male + `---- + + x Text + ,-[$DIR/tests/fixture/document_type/internal_subset/input.xml:12:1] + 12 | Fred Bloggs + 13 | 2008-11-27 + : ^^^^^^^^^^ + 14 | Male + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset/input.xml:12:1] + 12 | Fred Bloggs + 13 | ,-> 2008-11-27 + 14 | `-> Male + 15 | + `---- + + x Text + ,-[$DIR/tests/fixture/document_type/internal_subset/input.xml:12:1] + 12 | Fred Bloggs + 13 | ,-> 2008-11-27 + 14 | `-> Male + 15 | + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset/input.xml:13:1] + 13 | 2008-11-27 + 14 | Male + : ^^^^^^^^^^^^^^^^^^^^^ + 15 | + `---- + + x Element + ,-[$DIR/tests/fixture/document_type/internal_subset/input.xml:13:1] + 13 | 2008-11-27 + 14 | Male + : ^^^^^^^^^^^^^^^^^^^^^ + 15 | + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset/input.xml:13:1] + 13 | 2008-11-27 + 14 | Male + : ^^^^ + 15 | + `---- + + x Text + ,-[$DIR/tests/fixture/document_type/internal_subset/input.xml:13:1] + 13 | 2008-11-27 + 14 | Male + : ^^^^ + 15 | + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset/input.xml:13:1] + 13 | 2008-11-27 + 14 | ,-> Male + 15 | `-> + 16 | + `---- + + x Text + ,-[$DIR/tests/fixture/document_type/internal_subset/input.xml:13:1] + 13 | 2008-11-27 + 14 | ,-> Male + 15 | `-> + 16 | + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset/input.xml:14:1] + 14 | Male + 15 | + : ^ + 16 | + `---- + + x Text + ,-[$DIR/tests/fixture/document_type/internal_subset/input.xml:14:1] + 14 | Male + 15 | + : ^ + 16 | + `---- diff --git a/crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty-1/dom.txt b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty-1/dom.txt new file mode 100644 index 000000000000..aae50a1e17f8 --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty-1/dom.txt @@ -0,0 +1,3 @@ +| +| +| "test" diff --git a/crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty-1/input.xml b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty-1/input.xml new file mode 100644 index 000000000000..c15ab170f56e --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty-1/input.xml @@ -0,0 +1,2 @@ + +test \ No newline at end of file diff --git a/crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty-1/output.json b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty-1/output.json new file mode 100644 index 000000000000..87fba53ed95b --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty-1/output.json @@ -0,0 +1,44 @@ +{ + "type": "Document", + "span": { + "start": 1, + "end": 42, + "ctxt": 0 + }, + "children": [ + { + "type": "DocumentType", + "span": { + "start": 1, + "end": 24, + "ctxt": 0 + }, + "name": "greeting", + "publicId": null, + "systemId": null, + "raw": "" + }, + { + "type": "Element", + "span": { + "start": 25, + "end": 42, + "ctxt": 0 + }, + "tagName": "root", + "attributes": [], + "children": [ + { + "type": "Text", + "span": { + "start": 31, + "end": 35, + "ctxt": 0 + }, + "data": "test", + "raw": "test" + } + ] + } + ] +} diff --git a/crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty-1/span.swc-stderr b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty-1/span.swc-stderr new file mode 100644 index 000000000000..e1777cdb6898 --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty-1/span.swc-stderr @@ -0,0 +1,48 @@ + + x Document + ,-[$DIR/tests/fixture/document_type/internal_subset_empty-1/input.xml:1:1] + 1 | ,-> + 2 | `-> test + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset_empty-1/input.xml:1:1] + 1 | + : ^^^^^^^^^^^^^^^^^^^^^^^ + 2 | test + `---- + + x DocumentType + ,-[$DIR/tests/fixture/document_type/internal_subset_empty-1/input.xml:1:1] + 1 | + : ^^^^^^^^^^^^^^^^^^^^^^^ + 2 | test + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset_empty-1/input.xml:1:1] + 1 | + 2 | test + : ^^^^^^^^^^^^^^^^^ + `---- + + x Element + ,-[$DIR/tests/fixture/document_type/internal_subset_empty-1/input.xml:1:1] + 1 | + 2 | test + : ^^^^^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset_empty-1/input.xml:1:1] + 1 | + 2 | test + : ^^^^ + `---- + + x Text + ,-[$DIR/tests/fixture/document_type/internal_subset_empty-1/input.xml:1:1] + 1 | + 2 | test + : ^^^^ + `---- diff --git a/crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty-2/dom.txt b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty-2/dom.txt new file mode 100644 index 000000000000..aae50a1e17f8 --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty-2/dom.txt @@ -0,0 +1,3 @@ +| +| +| "test" diff --git a/crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty-2/input.xml b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty-2/input.xml new file mode 100644 index 000000000000..58e6e348a1e5 --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty-2/input.xml @@ -0,0 +1,2 @@ + +test \ No newline at end of file diff --git a/crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty-2/output.json b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty-2/output.json new file mode 100644 index 000000000000..9737f7271551 --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty-2/output.json @@ -0,0 +1,44 @@ +{ + "type": "Document", + "span": { + "start": 1, + "end": 43, + "ctxt": 0 + }, + "children": [ + { + "type": "DocumentType", + "span": { + "start": 1, + "end": 25, + "ctxt": 0 + }, + "name": "greeting", + "publicId": null, + "systemId": null, + "raw": "" + }, + { + "type": "Element", + "span": { + "start": 26, + "end": 43, + "ctxt": 0 + }, + "tagName": "root", + "attributes": [], + "children": [ + { + "type": "Text", + "span": { + "start": 32, + "end": 36, + "ctxt": 0 + }, + "data": "test", + "raw": "test" + } + ] + } + ] +} diff --git a/crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty-2/span.swc-stderr b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty-2/span.swc-stderr new file mode 100644 index 000000000000..0cf9c7567d49 --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty-2/span.swc-stderr @@ -0,0 +1,48 @@ + + x Document + ,-[$DIR/tests/fixture/document_type/internal_subset_empty-2/input.xml:1:1] + 1 | ,-> + 2 | `-> test + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset_empty-2/input.xml:1:1] + 1 | + : ^^^^^^^^^^^^^^^^^^^^^^^^ + 2 | test + `---- + + x DocumentType + ,-[$DIR/tests/fixture/document_type/internal_subset_empty-2/input.xml:1:1] + 1 | + : ^^^^^^^^^^^^^^^^^^^^^^^^ + 2 | test + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset_empty-2/input.xml:1:1] + 1 | + 2 | test + : ^^^^^^^^^^^^^^^^^ + `---- + + x Element + ,-[$DIR/tests/fixture/document_type/internal_subset_empty-2/input.xml:1:1] + 1 | + 2 | test + : ^^^^^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset_empty-2/input.xml:1:1] + 1 | + 2 | test + : ^^^^ + `---- + + x Text + ,-[$DIR/tests/fixture/document_type/internal_subset_empty-2/input.xml:1:1] + 1 | + 2 | test + : ^^^^ + `---- diff --git a/crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty/dom.txt b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty/dom.txt new file mode 100644 index 000000000000..aae50a1e17f8 --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty/dom.txt @@ -0,0 +1,3 @@ +| +| +| "test" diff --git a/crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty/input.xml b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty/input.xml new file mode 100644 index 000000000000..2c782f6c5546 --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty/input.xml @@ -0,0 +1,2 @@ + +test \ No newline at end of file diff --git a/crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty/output.json b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty/output.json new file mode 100644 index 000000000000..57967fcb5572 --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty/output.json @@ -0,0 +1,44 @@ +{ + "type": "Document", + "span": { + "start": 1, + "end": 41, + "ctxt": 0 + }, + "children": [ + { + "type": "DocumentType", + "span": { + "start": 1, + "end": 23, + "ctxt": 0 + }, + "name": "greeting", + "publicId": null, + "systemId": null, + "raw": "" + }, + { + "type": "Element", + "span": { + "start": 24, + "end": 41, + "ctxt": 0 + }, + "tagName": "root", + "attributes": [], + "children": [ + { + "type": "Text", + "span": { + "start": 30, + "end": 34, + "ctxt": 0 + }, + "data": "test", + "raw": "test" + } + ] + } + ] +} diff --git a/crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty/span.swc-stderr b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty/span.swc-stderr new file mode 100644 index 000000000000..a687fe18390b --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/internal_subset_empty/span.swc-stderr @@ -0,0 +1,48 @@ + + x Document + ,-[$DIR/tests/fixture/document_type/internal_subset_empty/input.xml:1:1] + 1 | ,-> + 2 | `-> test + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset_empty/input.xml:1:1] + 1 | + : ^^^^^^^^^^^^^^^^^^^^^^ + 2 | test + `---- + + x DocumentType + ,-[$DIR/tests/fixture/document_type/internal_subset_empty/input.xml:1:1] + 1 | + : ^^^^^^^^^^^^^^^^^^^^^^ + 2 | test + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset_empty/input.xml:1:1] + 1 | + 2 | test + : ^^^^^^^^^^^^^^^^^ + `---- + + x Element + ,-[$DIR/tests/fixture/document_type/internal_subset_empty/input.xml:1:1] + 1 | + 2 | test + : ^^^^^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/internal_subset_empty/input.xml:1:1] + 1 | + 2 | test + : ^^^^ + `---- + + x Text + ,-[$DIR/tests/fixture/document_type/internal_subset_empty/input.xml:1:1] + 1 | + 2 | test + : ^^^^ + `---- diff --git a/crates/swc_xml_parser/tests/fixture/document_type/only-name/dom.txt b/crates/swc_xml_parser/tests/fixture/document_type/only-name/dom.txt new file mode 100644 index 000000000000..aae50a1e17f8 --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/only-name/dom.txt @@ -0,0 +1,3 @@ +| +| +| "test" diff --git a/crates/swc_xml_parser/tests/fixture/document_type/only-name/input.xml b/crates/swc_xml_parser/tests/fixture/document_type/only-name/input.xml new file mode 100644 index 000000000000..388ea4c8c765 --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/only-name/input.xml @@ -0,0 +1,2 @@ + +test \ No newline at end of file diff --git a/crates/swc_xml_parser/tests/fixture/document_type/only-name/output.json b/crates/swc_xml_parser/tests/fixture/document_type/only-name/output.json new file mode 100644 index 000000000000..b40382ca18d7 --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/only-name/output.json @@ -0,0 +1,44 @@ +{ + "type": "Document", + "span": { + "start": 1, + "end": 38, + "ctxt": 0 + }, + "children": [ + { + "type": "DocumentType", + "span": { + "start": 1, + "end": 20, + "ctxt": 0 + }, + "name": "greeting", + "publicId": null, + "systemId": null, + "raw": " + 2 | `-> test + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/only-name/input.xml:1:1] + 1 | + : ^^^^^^^^^^^^^^^^^^^ + 2 | test + `---- + + x DocumentType + ,-[$DIR/tests/fixture/document_type/only-name/input.xml:1:1] + 1 | + : ^^^^^^^^^^^^^^^^^^^ + 2 | test + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/only-name/input.xml:1:1] + 1 | + 2 | test + : ^^^^^^^^^^^^^^^^^ + `---- + + x Element + ,-[$DIR/tests/fixture/document_type/only-name/input.xml:1:1] + 1 | + 2 | test + : ^^^^^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/only-name/input.xml:1:1] + 1 | + 2 | test + : ^^^^ + `---- + + x Text + ,-[$DIR/tests/fixture/document_type/only-name/input.xml:1:1] + 1 | + 2 | test + : ^^^^ + `---- diff --git a/crates/swc_xml_parser/tests/fixture/document_type/public_id-1/dom.txt b/crates/swc_xml_parser/tests/fixture/document_type/public_id-1/dom.txt new file mode 100644 index 000000000000..7fb8e46f849c --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/public_id-1/dom.txt @@ -0,0 +1,3 @@ +| +| +| "test" diff --git a/crates/swc_xml_parser/tests/fixture/document_type/public_id-1/input.xml b/crates/swc_xml_parser/tests/fixture/document_type/public_id-1/input.xml new file mode 100644 index 000000000000..3c5a3cda1b6a --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/public_id-1/input.xml @@ -0,0 +1,2 @@ + +test \ No newline at end of file diff --git a/crates/swc_xml_parser/tests/fixture/document_type/public_id-1/output.json b/crates/swc_xml_parser/tests/fixture/document_type/public_id-1/output.json new file mode 100644 index 000000000000..119df5ff8f71 --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/public_id-1/output.json @@ -0,0 +1,44 @@ +{ + "type": "Document", + "span": { + "start": 1, + "end": 71, + "ctxt": 0 + }, + "children": [ + { + "type": "DocumentType", + "span": { + "start": 1, + "end": 53, + "ctxt": 0 + }, + "name": "greeting", + "publicId": "hello.dtd", + "systemId": "goodbye.dtd", + "raw": "" + }, + { + "type": "Element", + "span": { + "start": 54, + "end": 71, + "ctxt": 0 + }, + "tagName": "root", + "attributes": [], + "children": [ + { + "type": "Text", + "span": { + "start": 60, + "end": 64, + "ctxt": 0 + }, + "data": "test", + "raw": "test" + } + ] + } + ] +} diff --git a/crates/swc_xml_parser/tests/fixture/document_type/public_id-1/span.swc-stderr b/crates/swc_xml_parser/tests/fixture/document_type/public_id-1/span.swc-stderr new file mode 100644 index 000000000000..34ad64fcca9a --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/public_id-1/span.swc-stderr @@ -0,0 +1,48 @@ + + x Document + ,-[$DIR/tests/fixture/document_type/public_id-1/input.xml:1:1] + 1 | ,-> + 2 | `-> test + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/public_id-1/input.xml:1:1] + 1 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 2 | test + `---- + + x DocumentType + ,-[$DIR/tests/fixture/document_type/public_id-1/input.xml:1:1] + 1 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 2 | test + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/public_id-1/input.xml:1:1] + 1 | + 2 | test + : ^^^^^^^^^^^^^^^^^ + `---- + + x Element + ,-[$DIR/tests/fixture/document_type/public_id-1/input.xml:1:1] + 1 | + 2 | test + : ^^^^^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/public_id-1/input.xml:1:1] + 1 | + 2 | test + : ^^^^ + `---- + + x Text + ,-[$DIR/tests/fixture/document_type/public_id-1/input.xml:1:1] + 1 | + 2 | test + : ^^^^ + `---- diff --git a/crates/swc_xml_parser/tests/fixture/document_type/public_id/dom.txt b/crates/swc_xml_parser/tests/fixture/document_type/public_id/dom.txt new file mode 100644 index 000000000000..7fb8e46f849c --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/public_id/dom.txt @@ -0,0 +1,3 @@ +| +| +| "test" diff --git a/crates/swc_xml_parser/tests/fixture/document_type/public_id/input.xml b/crates/swc_xml_parser/tests/fixture/document_type/public_id/input.xml new file mode 100644 index 000000000000..5a5667486dbb --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/public_id/input.xml @@ -0,0 +1,2 @@ + +test \ No newline at end of file diff --git a/crates/swc_xml_parser/tests/fixture/document_type/public_id/output.json b/crates/swc_xml_parser/tests/fixture/document_type/public_id/output.json new file mode 100644 index 000000000000..be373e2559ae --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/public_id/output.json @@ -0,0 +1,44 @@ +{ + "type": "Document", + "span": { + "start": 1, + "end": 71, + "ctxt": 0 + }, + "children": [ + { + "type": "DocumentType", + "span": { + "start": 1, + "end": 53, + "ctxt": 0 + }, + "name": "greeting", + "publicId": "hello.dtd", + "systemId": "goodbye.dtd", + "raw": "" + }, + { + "type": "Element", + "span": { + "start": 54, + "end": 71, + "ctxt": 0 + }, + "tagName": "root", + "attributes": [], + "children": [ + { + "type": "Text", + "span": { + "start": 60, + "end": 64, + "ctxt": 0 + }, + "data": "test", + "raw": "test" + } + ] + } + ] +} diff --git a/crates/swc_xml_parser/tests/fixture/document_type/public_id/span.swc-stderr b/crates/swc_xml_parser/tests/fixture/document_type/public_id/span.swc-stderr new file mode 100644 index 000000000000..32586d4d9438 --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/public_id/span.swc-stderr @@ -0,0 +1,48 @@ + + x Document + ,-[$DIR/tests/fixture/document_type/public_id/input.xml:1:1] + 1 | ,-> + 2 | `-> test + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/public_id/input.xml:1:1] + 1 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 2 | test + `---- + + x DocumentType + ,-[$DIR/tests/fixture/document_type/public_id/input.xml:1:1] + 1 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 2 | test + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/public_id/input.xml:1:1] + 1 | + 2 | test + : ^^^^^^^^^^^^^^^^^ + `---- + + x Element + ,-[$DIR/tests/fixture/document_type/public_id/input.xml:1:1] + 1 | + 2 | test + : ^^^^^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/public_id/input.xml:1:1] + 1 | + 2 | test + : ^^^^ + `---- + + x Text + ,-[$DIR/tests/fixture/document_type/public_id/input.xml:1:1] + 1 | + 2 | test + : ^^^^ + `---- diff --git a/crates/swc_xml_parser/tests/fixture/document_type/system_id-1/dom.txt b/crates/swc_xml_parser/tests/fixture/document_type/system_id-1/dom.txt new file mode 100644 index 000000000000..09d349bb8203 --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/system_id-1/dom.txt @@ -0,0 +1,3 @@ +| +| +| "Text" diff --git a/crates/swc_xml_parser/tests/fixture/document_type/system_id-1/input.xml b/crates/swc_xml_parser/tests/fixture/document_type/system_id-1/input.xml new file mode 100644 index 000000000000..f24913bc18a2 --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/system_id-1/input.xml @@ -0,0 +1,2 @@ + +Text diff --git a/crates/swc_xml_parser/tests/fixture/document_type/system_id-1/output.json b/crates/swc_xml_parser/tests/fixture/document_type/system_id-1/output.json new file mode 100644 index 000000000000..cb5f6894c192 --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/system_id-1/output.json @@ -0,0 +1,44 @@ +{ + "type": "Document", + "span": { + "start": 1, + "end": 58, + "ctxt": 0 + }, + "children": [ + { + "type": "DocumentType", + "span": { + "start": 1, + "end": 39, + "ctxt": 0 + }, + "name": "greeting", + "publicId": null, + "systemId": "hello.dtd", + "raw": "" + }, + { + "type": "Element", + "span": { + "start": 40, + "end": 57, + "ctxt": 0 + }, + "tagName": "root", + "attributes": [], + "children": [ + { + "type": "Text", + "span": { + "start": 46, + "end": 50, + "ctxt": 0 + }, + "data": "Text", + "raw": "Text" + } + ] + } + ] +} diff --git a/crates/swc_xml_parser/tests/fixture/document_type/system_id-1/span.swc-stderr b/crates/swc_xml_parser/tests/fixture/document_type/system_id-1/span.swc-stderr new file mode 100644 index 000000000000..f7b46b59eeb3 --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/system_id-1/span.swc-stderr @@ -0,0 +1,48 @@ + + x Document + ,-[$DIR/tests/fixture/document_type/system_id-1/input.xml:1:1] + 1 | ,-> + 2 | `-> Text + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/system_id-1/input.xml:1:1] + 1 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 2 | Text + `---- + + x DocumentType + ,-[$DIR/tests/fixture/document_type/system_id-1/input.xml:1:1] + 1 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 2 | Text + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/system_id-1/input.xml:1:1] + 1 | + 2 | Text + : ^^^^^^^^^^^^^^^^^ + `---- + + x Element + ,-[$DIR/tests/fixture/document_type/system_id-1/input.xml:1:1] + 1 | + 2 | Text + : ^^^^^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/system_id-1/input.xml:1:1] + 1 | + 2 | Text + : ^^^^ + `---- + + x Text + ,-[$DIR/tests/fixture/document_type/system_id-1/input.xml:1:1] + 1 | + 2 | Text + : ^^^^ + `---- diff --git a/crates/swc_xml_parser/tests/fixture/document_type/system_id/dom.txt b/crates/swc_xml_parser/tests/fixture/document_type/system_id/dom.txt new file mode 100644 index 000000000000..09d349bb8203 --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/system_id/dom.txt @@ -0,0 +1,3 @@ +| +| +| "Text" diff --git a/crates/swc_xml_parser/tests/fixture/document_type/system_id/input.xml b/crates/swc_xml_parser/tests/fixture/document_type/system_id/input.xml new file mode 100644 index 000000000000..6b9d7bcaf10e --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/system_id/input.xml @@ -0,0 +1,2 @@ + +Text diff --git a/crates/swc_xml_parser/tests/fixture/document_type/system_id/output.json b/crates/swc_xml_parser/tests/fixture/document_type/system_id/output.json new file mode 100644 index 000000000000..9355fedb7ad4 --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/system_id/output.json @@ -0,0 +1,44 @@ +{ + "type": "Document", + "span": { + "start": 1, + "end": 58, + "ctxt": 0 + }, + "children": [ + { + "type": "DocumentType", + "span": { + "start": 1, + "end": 39, + "ctxt": 0 + }, + "name": "greeting", + "publicId": null, + "systemId": "hello.dtd", + "raw": "" + }, + { + "type": "Element", + "span": { + "start": 40, + "end": 57, + "ctxt": 0 + }, + "tagName": "root", + "attributes": [], + "children": [ + { + "type": "Text", + "span": { + "start": 46, + "end": 50, + "ctxt": 0 + }, + "data": "Text", + "raw": "Text" + } + ] + } + ] +} diff --git a/crates/swc_xml_parser/tests/fixture/document_type/system_id/span.swc-stderr b/crates/swc_xml_parser/tests/fixture/document_type/system_id/span.swc-stderr new file mode 100644 index 000000000000..a4b516fa5beb --- /dev/null +++ b/crates/swc_xml_parser/tests/fixture/document_type/system_id/span.swc-stderr @@ -0,0 +1,48 @@ + + x Document + ,-[$DIR/tests/fixture/document_type/system_id/input.xml:1:1] + 1 | ,-> + 2 | `-> Text + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/system_id/input.xml:1:1] + 1 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 2 | Text + `---- + + x DocumentType + ,-[$DIR/tests/fixture/document_type/system_id/input.xml:1:1] + 1 | + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 2 | Text + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/system_id/input.xml:1:1] + 1 | + 2 | Text + : ^^^^^^^^^^^^^^^^^ + `---- + + x Element + ,-[$DIR/tests/fixture/document_type/system_id/input.xml:1:1] + 1 | + 2 | Text + : ^^^^^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/document_type/system_id/input.xml:1:1] + 1 | + 2 | Text + : ^^^^ + `---- + + x Text + ,-[$DIR/tests/fixture/document_type/system_id/input.xml:1:1] + 1 | + 2 | Text + : ^^^^ + `----