diff --git a/src/tokenizer/__tests__/__input__/attributes-apostrophe.html b/src/__tests__/__fixtures__/attributes-apostrophe copy.html similarity index 100% rename from src/tokenizer/__tests__/__input__/attributes-apostrophe.html rename to src/__tests__/__fixtures__/attributes-apostrophe copy.html diff --git a/src/__tests__/__fixtures__/attributes-apostrophe.html b/src/__tests__/__fixtures__/attributes-apostrophe.html new file mode 100644 index 0000000..46b8f46 --- /dev/null +++ b/src/__tests__/__fixtures__/attributes-apostrophe.html @@ -0,0 +1 @@ +
diff --git a/src/tokenizer/__tests__/__input__/attributes-bare-wrong-quote.html b/src/__tests__/__fixtures__/attributes-bare-wrong-quote.html similarity index 100% rename from src/tokenizer/__tests__/__input__/attributes-bare-wrong-quote.html rename to src/__tests__/__fixtures__/attributes-bare-wrong-quote.html diff --git a/src/tokenizer/__tests__/__input__/attributes-bare.html b/src/__tests__/__fixtures__/attributes-bare.html similarity index 100% rename from src/tokenizer/__tests__/__input__/attributes-bare.html rename to src/__tests__/__fixtures__/attributes-bare.html diff --git a/src/tokenizer/__tests__/__input__/attributes-empty.html b/src/__tests__/__fixtures__/attributes-empty.html similarity index 100% rename from src/tokenizer/__tests__/__input__/attributes-empty.html rename to src/__tests__/__fixtures__/attributes-empty.html diff --git a/src/tokenizer/__tests__/__input__/attributes-multiline.html b/src/__tests__/__fixtures__/attributes-multiline.html similarity index 100% rename from src/tokenizer/__tests__/__input__/attributes-multiline.html rename to src/__tests__/__fixtures__/attributes-multiline.html diff --git a/src/tokenizer/__tests__/__input__/attributes-quote.html b/src/__tests__/__fixtures__/attributes-quote.html similarity index 100% rename from src/tokenizer/__tests__/__input__/attributes-quote.html rename to src/__tests__/__fixtures__/attributes-quote.html diff --git a/src/tokenizer/__tests__/__input__/comments.html b/src/__tests__/__fixtures__/comments.html similarity index 100% rename from src/tokenizer/__tests__/__input__/comments.html rename to src/__tests__/__fixtures__/comments.html diff --git a/src/tokenizer/__tests__/__input__/custom-elements.html b/src/__tests__/__fixtures__/custom-elements.html similarity index 100% rename from src/tokenizer/__tests__/__input__/custom-elements.html rename to src/__tests__/__fixtures__/custom-elements.html diff --git a/src/tokenizer/__tests__/__input__/custom-tag-raw-content.html b/src/__tests__/__fixtures__/custom-tag-raw-content.html similarity index 100% rename from src/tokenizer/__tests__/__input__/custom-tag-raw-content.html rename to src/__tests__/__fixtures__/custom-tag-raw-content.html diff --git a/src/tokenizer/__tests__/__input__/doctypes.html b/src/__tests__/__fixtures__/doctypes.html similarity index 100% rename from src/tokenizer/__tests__/__input__/doctypes.html rename to src/__tests__/__fixtures__/doctypes.html diff --git a/src/tokenizer/__tests__/__input__/empty.html b/src/__tests__/__fixtures__/empty.html similarity index 100% rename from src/tokenizer/__tests__/__input__/empty.html rename to src/__tests__/__fixtures__/empty.html diff --git a/src/tokenizer/__tests__/__input__/nested-tags.html b/src/__tests__/__fixtures__/nested-tags.html similarity index 100% rename from src/tokenizer/__tests__/__input__/nested-tags.html rename to src/__tests__/__fixtures__/nested-tags.html diff --git a/src/tokenizer/__tests__/__input__/opening-closing-text.html b/src/__tests__/__fixtures__/opening-closing-text.html similarity index 100% rename from src/tokenizer/__tests__/__input__/opening-closing-text.html rename to src/__tests__/__fixtures__/opening-closing-text.html diff --git a/src/tokenizer/__tests__/__input__/parsing-error-no-open-end.html b/src/__tests__/__fixtures__/parsing-error-no-open-end.html similarity index 100% rename from src/tokenizer/__tests__/__input__/parsing-error-no-open-end.html rename to src/__tests__/__fixtures__/parsing-error-no-open-end.html diff --git a/src/tokenizer/__tests__/__input__/script-elements-attributes.html b/src/__tests__/__fixtures__/script-elements-attributes.html similarity index 100% rename from src/tokenizer/__tests__/__input__/script-elements-attributes.html rename to src/__tests__/__fixtures__/script-elements-attributes.html diff --git a/src/tokenizer/__tests__/__input__/script-elements.html b/src/__tests__/__fixtures__/script-elements.html similarity index 100% rename from src/tokenizer/__tests__/__input__/script-elements.html rename to src/__tests__/__fixtures__/script-elements.html diff --git a/src/tokenizer/__tests__/__input__/style-elements-attributes.html b/src/__tests__/__fixtures__/style-elements-attributes.html similarity index 100% rename from src/tokenizer/__tests__/__input__/style-elements-attributes.html rename to src/__tests__/__fixtures__/style-elements-attributes.html diff --git a/src/tokenizer/__tests__/__input__/style-elements.html b/src/__tests__/__fixtures__/style-elements.html similarity index 100% rename from src/tokenizer/__tests__/__input__/style-elements.html rename to src/__tests__/__fixtures__/style-elements.html diff --git a/src/tokenizer/__tests__/__input__/svg.html b/src/__tests__/__fixtures__/svg.html similarity index 100% rename from src/tokenizer/__tests__/__input__/svg.html rename to src/__tests__/__fixtures__/svg.html diff --git a/src/tokenizer/__tests__/__input__/tags-register.html b/src/__tests__/__fixtures__/tags-register.html similarity index 100% rename from src/tokenizer/__tests__/__input__/tags-register.html rename to src/__tests__/__fixtures__/tags-register.html diff --git a/src/tokenizer/__tests__/__input__/templates-attributes-key.html b/src/__tests__/__fixtures__/templates-attributes-key.html similarity index 100% rename from src/tokenizer/__tests__/__input__/templates-attributes-key.html rename to src/__tests__/__fixtures__/templates-attributes-key.html diff --git a/src/tokenizer/__tests__/__input__/templates-attributes-value-bare.html b/src/__tests__/__fixtures__/templates-attributes-value-bare.html similarity index 100% rename from src/tokenizer/__tests__/__input__/templates-attributes-value-bare.html rename to src/__tests__/__fixtures__/templates-attributes-value-bare.html diff --git a/src/tokenizer/__tests__/__input__/templates-attributes-value-wrapped-2.html b/src/__tests__/__fixtures__/templates-attributes-value-wrapped-2.html similarity index 100% rename from src/tokenizer/__tests__/__input__/templates-attributes-value-wrapped-2.html rename to src/__tests__/__fixtures__/templates-attributes-value-wrapped-2.html diff --git a/src/tokenizer/__tests__/__input__/templates-attributes-value-wrapped.html b/src/__tests__/__fixtures__/templates-attributes-value-wrapped.html similarity index 100% rename from src/tokenizer/__tests__/__input__/templates-attributes-value-wrapped.html rename to src/__tests__/__fixtures__/templates-attributes-value-wrapped.html diff --git a/src/tokenizer/__tests__/__input__/templates-comment.html b/src/__tests__/__fixtures__/templates-comment.html similarity index 100% rename from src/tokenizer/__tests__/__input__/templates-comment.html rename to src/__tests__/__fixtures__/templates-comment.html diff --git a/src/tokenizer/__tests__/__input__/templates-content-end.html b/src/__tests__/__fixtures__/templates-content-end.html similarity index 100% rename from src/tokenizer/__tests__/__input__/templates-content-end.html rename to src/__tests__/__fixtures__/templates-content-end.html diff --git a/src/tokenizer/__tests__/__input__/templates-data.html b/src/__tests__/__fixtures__/templates-data.html similarity index 100% rename from src/tokenizer/__tests__/__input__/templates-data.html rename to src/__tests__/__fixtures__/templates-data.html diff --git a/src/tokenizer/__tests__/__input__/templates-script-content.html b/src/__tests__/__fixtures__/templates-script-content.html similarity index 100% rename from src/tokenizer/__tests__/__input__/templates-script-content.html rename to src/__tests__/__fixtures__/templates-script-content.html diff --git a/src/tokenizer/__tests__/__input__/templates-style-content.html b/src/__tests__/__fixtures__/templates-style-content.html similarity index 100% rename from src/tokenizer/__tests__/__input__/templates-style-content.html rename to src/__tests__/__fixtures__/templates-style-content.html diff --git a/src/tokenizer/__tests__/__input__/void-tags.html b/src/__tests__/__fixtures__/void-tags.html similarity index 100% rename from src/tokenizer/__tests__/__input__/void-tags.html rename to src/__tests__/__fixtures__/void-tags.html diff --git a/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-attributes-apostrophe.html-0.json b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-attributes-apostrophe.html-0.json new file mode 100644 index 0000000..44a7c3c --- /dev/null +++ b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-attributes-apostrophe.html-0.json @@ -0,0 +1,351 @@ +[ + { + "type": "OpenTagStart", + "value": "", + "range": [ + 29, + 39 + ], + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 39 + } + }, + "parts": [] + }, + { + "type": "AttributeValueWrapperEnd", + "value": "'", + "range": [ + 39, + 40 + ], + "loc": { + "start": { + "line": 1, + "column": 39 + }, + "end": { + "line": 1, + "column": 40 + } + } + }, + { + "type": "AttributeKey", + "value": "with-spaces", + "range": [ + 41, + 52 + ], + "loc": { + "start": { + "line": 1, + "column": 41 + }, + "end": { + "line": 1, + "column": 52 + } + }, + "parts": [] + }, + { + "type": "AttributeAssignment", + "value": "=", + "range": [ + 52, + 53 + ], + "loc": { + "start": { + "line": 1, + "column": 52 + }, + "end": { + "line": 1, + "column": 53 + } + } + }, + { + "type": "AttributeValueWrapperStart", + "value": "'", + "range": [ + 53, + 54 + ], + "loc": { + "start": { + "line": 1, + "column": 53 + }, + "end": { + "line": 1, + "column": 54 + } + } + }, + { + "type": "AttributeValue", + "value": "spaces test", + "range": [ + 54, + 65 + ], + "loc": { + "start": { + "line": 1, + "column": 54 + }, + "end": { + "line": 1, + "column": 65 + } + }, + "parts": [] + }, + { + "type": "AttributeValueWrapperEnd", + "value": "'", + "range": [ + 65, + 66 + ], + "loc": { + "start": { + "line": 1, + "column": 65 + }, + "end": { + "line": 1, + "column": 66 + } + } + }, + { + "type": "OpenTagEnd", + "value": ">", + "range": [ + 66, + 67 + ], + "loc": { + "start": { + "line": 1, + "column": 66 + }, + "end": { + "line": 1, + "column": 67 + } + } + }, + { + "type": "CloseTag", + "value": "", + "range": [ + 67, + 73 + ], + "loc": { + "start": { + "line": 1, + "column": 67 + }, + "end": { + "line": 1, + "column": 73 + } + } + }, + { + "type": "Text", + "value": "\n", + "range": [ + 73, + 74 + ], + "loc": { + "start": { + "line": 1, + "column": 73 + }, + "end": { + "line": 2, + "column": 0 + } + }, + "parts": [] + } +] \ No newline at end of file diff --git a/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-attributes-bare-wrong-quote.html-0.json b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-attributes-bare-wrong-quote.html-0.json new file mode 100644 index 0000000..cd0f583 --- /dev/null +++ b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-attributes-bare-wrong-quote.html-0.json @@ -0,0 +1,112 @@ +[ + { + "type": "OpenTagStart", + "value": "", + "range": [ + 18, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + } + }, + { + "type": "CloseTag", + "value": "", + "range": [ + 19, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 23 + } + } + } +] \ No newline at end of file diff --git a/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-attributes-bare.html-0.json b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-attributes-bare.html-0.json new file mode 100644 index 0000000..ffd5d75 --- /dev/null +++ b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-attributes-bare.html-0.json @@ -0,0 +1,539 @@ +[ + { + "type": "OpenTagStart", + "value": "", + "range": [ + 37, + 38 + ], + "loc": { + "start": { + "line": 1, + "column": 37 + }, + "end": { + "line": 1, + "column": 38 + } + } + }, + { + "type": "CloseTag", + "value": "", + "range": [ + 38, + 44 + ], + "loc": { + "start": { + "line": 1, + "column": 38 + }, + "end": { + "line": 1, + "column": 44 + } + } + }, + { + "type": "Text", + "value": "\n\n", + "range": [ + 44, + 46 + ], + "loc": { + "start": { + "line": 1, + "column": 44 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "OpenTagStart", + "value": "", + "range": [ + 73, + 74 + ], + "loc": { + "start": { + "line": 3, + "column": 27 + }, + "end": { + "line": 3, + "column": 28 + } + } + }, + { + "type": "Text", + "value": "\n some text\n\n ", + "range": [ + 74, + 90 + ], + "loc": { + "start": { + "line": 3, + "column": 28 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "parts": [] + }, + { + "type": "OpenTagStart", + "value": "", + "range": [ + 137, + 138 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 3 + } + } + }, + { + "type": "Text", + "value": "\n custom element\n text\n ", + "range": [ + 138, + 169 + ], + "loc": { + "start": { + "line": 8, + "column": 3 + }, + "end": { + "line": 11, + "column": 2 + } + }, + "parts": [] + }, + { + "type": "CloseTag", + "value": "", + "range": [ + 169, + 186 + ], + "loc": { + "start": { + "line": 11, + "column": 2 + }, + "end": { + "line": 11, + "column": 19 + } + } + }, + { + "type": "Text", + "value": "\n", + "range": [ + 186, + 187 + ], + "loc": { + "start": { + "line": 11, + "column": 19 + }, + "end": { + "line": 12, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "CloseTag", + "value": "", + "range": [ + 187, + 194 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 7 + } + } + }, + { + "type": "Text", + "value": "\n", + "range": [ + 194, + 195 + ], + "loc": { + "start": { + "line": 12, + "column": 7 + }, + "end": { + "line": 13, + "column": 0 + } + }, + "parts": [] + } +] \ No newline at end of file diff --git a/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-attributes-empty.html-0.json b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-attributes-empty.html-0.json new file mode 100644 index 0000000..425c6b2 --- /dev/null +++ b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-attributes-empty.html-0.json @@ -0,0 +1,186 @@ +[ + { + "type": "OpenTagStart", + "value": "", + "range": [ + 6, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + { + "type": "Text", + "value": "\n some text\n\n ", + "range": [ + 7, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 4, + "column": 2 + } + }, + "parts": [] + }, + { + "type": "OpenTagStart", + "value": "", + "range": [ + 42, + 43 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 3 + } + } + }, + { + "type": "Text", + "value": "\n custom element\n text\n ", + "range": [ + 43, + 74 + ], + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 9, + "column": 2 + } + }, + "parts": [] + }, + { + "type": "CloseTag", + "value": "", + "range": [ + 74, + 91 + ], + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 19 + } + } + }, + { + "type": "Text", + "value": "\n", + "range": [ + 91, + 92 + ], + "loc": { + "start": { + "line": 9, + "column": 19 + }, + "end": { + "line": 10, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "CloseTag", + "value": "", + "range": [ + 92, + 99 + ], + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 7 + } + } + }, + { + "type": "Text", + "value": "\n", + "range": [ + 99, + 100 + ], + "loc": { + "start": { + "line": 10, + "column": 7 + }, + "end": { + "line": 11, + "column": 0 + } + }, + "parts": [] + } +] \ No newline at end of file diff --git a/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-attributes-multiline.html-0.json b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-attributes-multiline.html-0.json new file mode 100644 index 0000000..5df9bf0 --- /dev/null +++ b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-attributes-multiline.html-0.json @@ -0,0 +1,297 @@ +[ + { + "type": "OpenTagStart", + "value": "", + "range": [ + 37, + 38 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + } + }, + { + "type": "Text", + "value": "\n", + "range": [ + 38, + 39 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 6, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "CloseTag", + "value": "", + "range": [ + 39, + 45 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 6 + } + } + }, + { + "type": "Text", + "value": "\n", + "range": [ + 45, + 46 + ], + "loc": { + "start": { + "line": 6, + "column": 6 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "parts": [] + } +] \ No newline at end of file diff --git a/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-attributes-quote.html-0.json b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-attributes-quote.html-0.json new file mode 100644 index 0000000..3845acf --- /dev/null +++ b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-attributes-quote.html-0.json @@ -0,0 +1,738 @@ +[ + { + "type": "OpenTagStart", + "value": "", + "range": [ + 4, + 5 + ], + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + } + } + }, + { + "type": "Text", + "value": "\n ", + "range": [ + 5, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 2, + "column": 2 + } + }, + "parts": [] + }, + { + "type": "OpenTagStart", + "value": "", + "range": [ + 44, + 54 + ], + "loc": { + "start": { + "line": 2, + "column": 38 + }, + "end": { + "line": 2, + "column": 48 + } + }, + "parts": [] + }, + { + "type": "AttributeValueWrapperEnd", + "value": "\"", + "range": [ + 54, + 55 + ], + "loc": { + "start": { + "line": 2, + "column": 48 + }, + "end": { + "line": 2, + "column": 49 + } + } + }, + { + "type": "OpenTagEnd", + "value": ">", + "range": [ + 55, + 56 + ], + "loc": { + "start": { + "line": 2, + "column": 49 + }, + "end": { + "line": 2, + "column": 50 + } + } + }, + { + "type": "Text", + "value": "\n some text\n\n ", + "range": [ + 56, + 76 + ], + "loc": { + "start": { + "line": 2, + "column": 50 + }, + "end": { + "line": 5, + "column": 4 + } + }, + "parts": [] + }, + { + "type": "OpenTagStart", + "value": "", + "range": [ + 80, + 81 + ], + "loc": { + "start": { + "line": 5, + "column": 8 + }, + "end": { + "line": 5, + "column": 9 + } + } + }, + { + "type": "Text", + "value": "\n another text\n\n ", + "range": [ + 81, + 108 + ], + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 8, + "column": 6 + } + }, + "parts": [] + }, + { + "type": "OpenTagStart", + "value": "test", + "range": [ + 145, + 157 + ], + "loc": { + "start": { + "line": 9, + "column": 21 + }, + "end": { + "line": 9, + "column": 33 + } + }, + "parts": [] + }, + { + "type": "AttributeValueWrapperEnd", + "value": "\"", + "range": [ + 157, + 158 + ], + "loc": { + "start": { + "line": 9, + "column": 33 + }, + "end": { + "line": 9, + "column": 34 + } + } + }, + { + "type": "AttributeKey", + "value": "with-spaces", + "range": [ + 167, + 178 + ], + "loc": { + "start": { + "line": 10, + "column": 8 + }, + "end": { + "line": 10, + "column": 19 + } + }, + "parts": [] + }, + { + "type": "AttributeAssignment", + "value": "=", + "range": [ + 181, + 182 + ], + "loc": { + "start": { + "line": 10, + "column": 22 + }, + "end": { + "line": 10, + "column": 23 + } + } + }, + { + "type": "AttributeValueWrapperStart", + "value": "\"", + "range": [ + 184, + 185 + ], + "loc": { + "start": { + "line": 10, + "column": 25 + }, + "end": { + "line": 10, + "column": 26 + } + } + }, + { + "type": "AttributeValue", + "value": "spaces test", + "range": [ + 185, + 196 + ], + "loc": { + "start": { + "line": 10, + "column": 26 + }, + "end": { + "line": 10, + "column": 37 + } + }, + "parts": [] + }, + { + "type": "AttributeValueWrapperEnd", + "value": "\"", + "range": [ + 196, + 197 + ], + "loc": { + "start": { + "line": 10, + "column": 37 + }, + "end": { + "line": 10, + "column": 38 + } + } + }, + { + "type": "OpenTagEnd", + "value": ">", + "range": [ + 204, + 205 + ], + "loc": { + "start": { + "line": 11, + "column": 6 + }, + "end": { + "line": 11, + "column": 7 + } + } + }, + { + "type": "Text", + "value": "\n custom element\n text\n ", + "range": [ + 205, + 248 + ], + "loc": { + "start": { + "line": 11, + "column": 7 + }, + "end": { + "line": 14, + "column": 6 + } + }, + "parts": [] + }, + { + "type": "CloseTag", + "value": "", + "range": [ + 248, + 265 + ], + "loc": { + "start": { + "line": 14, + "column": 6 + }, + "end": { + "line": 14, + "column": 23 + } + } + }, + { + "type": "Text", + "value": "\n ", + "range": [ + 265, + 270 + ], + "loc": { + "start": { + "line": 14, + "column": 23 + }, + "end": { + "line": 15, + "column": 4 + } + }, + "parts": [] + }, + { + "type": "CloseTag", + "value": "", + "range": [ + 270, + 276 + ], + "loc": { + "start": { + "line": 15, + "column": 4 + }, + "end": { + "line": 15, + "column": 10 + } + } + }, + { + "type": "Text", + "value": "\n ", + "range": [ + 276, + 279 + ], + "loc": { + "start": { + "line": 15, + "column": 10 + }, + "end": { + "line": 16, + "column": 2 + } + }, + "parts": [] + }, + { + "type": "CloseTag", + "value": "", + "range": [ + 279, + 286 + ], + "loc": { + "start": { + "line": 16, + "column": 2 + }, + "end": { + "line": 16, + "column": 9 + } + } + }, + { + "type": "Text", + "value": "\n", + "range": [ + 286, + 287 + ], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 17, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "CloseTag", + "value": "", + "range": [ + 287, + 293 + ], + "loc": { + "start": { + "line": 17, + "column": 0 + }, + "end": { + "line": 17, + "column": 6 + } + } + }, + { + "type": "Text", + "value": "\n", + "range": [ + 293, + 294 + ], + "loc": { + "start": { + "line": 17, + "column": 6 + }, + "end": { + "line": 18, + "column": 0 + } + }, + "parts": [] + } +] \ No newline at end of file diff --git a/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-comments.html-0.json b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-comments.html-0.json new file mode 100644 index 0000000..adaeccc --- /dev/null +++ b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-comments.html-0.json @@ -0,0 +1,556 @@ +[ + { + "type": "CommentOpen", + "value": "", + "range": [ + 18, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 21 + } + } + }, + { + "type": "Text", + "value": "\n\n", + "range": [ + 21, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "OpenTagStart", + "value": "", + "range": [ + 27, + 28 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 5 + } + } + }, + { + "type": "Text", + "value": "\n ", + "range": [ + 28, + 31 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 4, + "column": 2 + } + }, + "parts": [] + }, + { + "type": "OpenTagStart", + "value": "", + "range": [ + 36, + 37 + ], + "loc": { + "start": { + "line": 4, + "column": 7 + }, + "end": { + "line": 4, + "column": 8 + } + } + }, + { + "type": "Text", + "value": "\n ", + "range": [ + 37, + 42 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 5, + "column": 4 + } + }, + "parts": [] + }, + { + "type": "CommentOpen", + "value": "", + "range": [ + 57, + 60 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 22 + } + } + }, + { + "type": "Text", + "value": "\n ", + "range": [ + 60, + 63 + ], + "loc": { + "start": { + "line": 5, + "column": 22 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "parts": [] + }, + { + "type": "CloseTag", + "value": "", + "range": [ + 63, + 70 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 9 + } + } + }, + { + "type": "Text", + "value": "\n\n ", + "range": [ + 70, + 74 + ], + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 8, + "column": 2 + } + }, + "parts": [] + }, + { + "type": "CommentOpen", + "value": "", + "range": [ + 98, + 101 + ], + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 13, + "column": 5 + } + } + }, + { + "type": "Text", + "value": "\n", + "range": [ + 101, + 102 + ], + "loc": { + "start": { + "line": 13, + "column": 5 + }, + "end": { + "line": 14, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "CloseTag", + "value": "", + "range": [ + 102, + 108 + ], + "loc": { + "start": { + "line": 14, + "column": 0 + }, + "end": { + "line": 14, + "column": 6 + } + } + }, + { + "type": "Text", + "value": "\n\n", + "range": [ + 108, + 110 + ], + "loc": { + "start": { + "line": 14, + "column": 6 + }, + "end": { + "line": 16, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "CommentOpen", + "value": "", + "range": [ + 132, + 135 + ], + "loc": { + "start": { + "line": 18, + "column": 8 + }, + "end": { + "line": 18, + "column": 11 + } + } + }, + { + "type": "Text", + "value": "\n\n", + "range": [ + 135, + 137 + ], + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 20, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "CommentOpen", + "value": "", + "range": [ + 171, + 174 + ], + "loc": { + "start": { + "line": 20, + "column": 34 + }, + "end": { + "line": 20, + "column": 37 + } + } + }, + { + "type": "Text", + "value": "\n", + "range": [ + 174, + 175 + ], + "loc": { + "start": { + "line": 20, + "column": 37 + }, + "end": { + "line": 21, + "column": 0 + } + }, + "parts": [] + } +] \ No newline at end of file diff --git a/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-custom-elements.html-0.json b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-custom-elements.html-0.json new file mode 100644 index 0000000..f3a6294 --- /dev/null +++ b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-custom-elements.html-0.json @@ -0,0 +1,186 @@ +[ + { + "type": "OpenTagStart", + "value": "", + "range": [ + 11, + 12 + ], + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + } + } + }, + { + "type": "Text", + "value": "\n some text\n\n ", + "range": [ + 12, + 28 + ], + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 4, + "column": 2 + } + }, + "parts": [] + }, + { + "type": "OpenTagStart", + "value": "", + "range": [ + 39, + 40 + ], + "loc": { + "start": { + "line": 4, + "column": 13 + }, + "end": { + "line": 4, + "column": 14 + } + } + }, + { + "type": "Text", + "value": "\n another text\n ", + "range": [ + 40, + 60 + ], + "loc": { + "start": { + "line": 4, + "column": 14 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "parts": [] + }, + { + "type": "CloseTag", + "value": "", + "range": [ + 60, + 73 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 15 + } + } + }, + { + "type": "Text", + "value": "\n", + "range": [ + 73, + 74 + ], + "loc": { + "start": { + "line": 6, + "column": 15 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "CloseTag", + "value": "", + "range": [ + 74, + 87 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 13 + } + } + }, + { + "type": "Text", + "value": "\n", + "range": [ + 87, + 88 + ], + "loc": { + "start": { + "line": 7, + "column": 13 + }, + "end": { + "line": 8, + "column": 0 + } + }, + "parts": [] + } +] \ No newline at end of file diff --git a/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-custom-tag-raw-content.html-0.json b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-custom-tag-raw-content.html-0.json new file mode 100644 index 0000000..9439a67 --- /dev/null +++ b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-custom-tag-raw-content.html-0.json @@ -0,0 +1,222 @@ +[ + { + "type": "OpenTagStart", + "value": "", + "range": [ + 18, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + } + }, + { + "type": "Text", + "value": "\n# Hello, world!\n\n```cpp{4-6,9}\n#include ", + "range": [ + 19, + 60 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 5, + "column": 9 + } + }, + "parts": [] + }, + { + "type": "OpenTagStart", + "value": "", + "range": [ + 69, + 70 + ], + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 19 + } + } + }, + { + "type": "Text", + "value": "\n\nclass Example {\n Example() {\n std::cout << \"Hello, world!\" << std::endl;\n }\n\n Example(std::string name) {\n std::cout << \"Hello, \" << name << std::endl;\n }\n};\n```\n", + "range": [ + 70, + 260 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 17, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "CloseTag", + "value": "", + "range": [ + 260, + 271 + ], + "loc": { + "start": { + "line": 17, + "column": 0 + }, + "end": { + "line": 17, + "column": 11 + } + } + } +] \ No newline at end of file diff --git a/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-doctypes.html-0.json b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-doctypes.html-0.json new file mode 100644 index 0000000..6e8071e --- /dev/null +++ b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-doctypes.html-0.json @@ -0,0 +1,764 @@ +[ + { + "type": "DoctypeOpen", + "value": "", + "range": [ + 9, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + } + }, + { + "type": "Text", + "value": "\n\n", + "range": [ + 10, + 12 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "DoctypeOpen", + "value": "", + "range": [ + 21, + 22 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 10 + } + } + }, + { + "type": "Text", + "value": "\n\n", + "range": [ + 22, + 24 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "DoctypeOpen", + "value": "", + "range": [ + 65, + 66 + ], + "loc": { + "start": { + "line": 5, + "column": 41 + }, + "end": { + "line": 5, + "column": 42 + } + } + }, + { + "type": "Text", + "value": "\n\n", + "range": [ + 66, + 68 + ], + "loc": { + "start": { + "line": 5, + "column": 42 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "DoctypeOpen", + "value": "", + "range": [ + 89, + 90 + ], + "loc": { + "start": { + "line": 7, + "column": 21 + }, + "end": { + "line": 7, + "column": 22 + } + } + }, + { + "type": "Text", + "value": "\n\n", + "range": [ + 90, + 92 + ], + "loc": { + "start": { + "line": 7, + "column": 22 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "DoctypeOpen", + "value": "", + "range": [ + 192, + 193 + ], + "loc": { + "start": { + "line": 9, + "column": 100 + }, + "end": { + "line": 9, + "column": 101 + } + } + }, + { + "type": "Text", + "value": "\n\n", + "range": [ + 193, + 195 + ], + "loc": { + "start": { + "line": 9, + "column": 101 + }, + "end": { + "line": 11, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "DoctypeOpen", + "value": "", + "range": [ + 302, + 303 + ], + "loc": { + "start": { + "line": 15, + "column": 0 + }, + "end": { + "line": 15, + "column": 1 + } + } + }, + { + "type": "Text", + "value": "\n", + "range": [ + 303, + 304 + ], + "loc": { + "start": { + "line": 15, + "column": 1 + }, + "end": { + "line": 16, + "column": 0 + } + }, + "parts": [] + } +] \ No newline at end of file diff --git a/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-empty.html-0.json b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-empty.html-0.json new file mode 100644 index 0000000..0637a08 --- /dev/null +++ b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-empty.html-0.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-nested-tags.html-0.json b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-nested-tags.html-0.json new file mode 100644 index 0000000..0078c55 --- /dev/null +++ b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-nested-tags.html-0.json @@ -0,0 +1,278 @@ +[ + { + "type": "OpenTagStart", + "value": "", + "range": [ + 4, + 5 + ], + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + } + } + }, + { + "type": "Text", + "value": "\n ", + "range": [ + 5, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 2, + "column": 2 + } + }, + "parts": [] + }, + { + "type": "OpenTagStart", + "value": "", + "range": [ + 13, + 14 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + } + } + }, + { + "type": "Text", + "value": "\n some text\n\n ", + "range": [ + 14, + 34 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 5, + "column": 4 + } + }, + "parts": [] + }, + { + "type": "OpenTagStart", + "value": "", + "range": [ + 39, + 40 + ], + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 10 + } + } + }, + { + "type": "Text", + "value": "\n another text\n ", + "range": [ + 40, + 64 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 7, + "column": 4 + } + }, + "parts": [] + }, + { + "type": "CloseTag", + "value": "", + "range": [ + 64, + 71 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 11 + } + } + }, + { + "type": "Text", + "value": "\n ", + "range": [ + 71, + 74 + ], + "loc": { + "start": { + "line": 7, + "column": 11 + }, + "end": { + "line": 8, + "column": 2 + } + }, + "parts": [] + }, + { + "type": "CloseTag", + "value": "", + "range": [ + 74, + 81 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 9 + } + } + }, + { + "type": "Text", + "value": "\n", + "range": [ + 81, + 82 + ], + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "CloseTag", + "value": "", + "range": [ + 82, + 88 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 6 + } + } + }, + { + "type": "Text", + "value": "\n", + "range": [ + 88, + 89 + ], + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 10, + "column": 0 + } + }, + "parts": [] + } +] \ No newline at end of file diff --git a/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-opening-closing-text.html-0.json b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-opening-closing-text.html-0.json new file mode 100644 index 0000000..a74e86e --- /dev/null +++ b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-opening-closing-text.html-0.json @@ -0,0 +1,94 @@ +[ + { + "type": "Text", + "value": "opening text\n\n", + "range": [ + 0, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "OpenTagStart", + "value": "", + "range": [ + 18, + 19 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 5 + } + } + }, + { + "type": "CloseTag", + "value": "", + "range": [ + 19, + 25 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + { + "type": "Text", + "value": "\n\nclosing text\n", + "range": [ + 25, + 40 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 6, + "column": 0 + } + }, + "parts": [] + } +] \ No newline at end of file diff --git a/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-script-elements-attributes.html-0.json b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-script-elements-attributes.html-0.json new file mode 100644 index 0000000..f98e8df --- /dev/null +++ b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-script-elements-attributes.html-0.json @@ -0,0 +1,776 @@ +[ + { + "type": "OpenTagStart", + "value": "", + "range": [ + 4, + 5 + ], + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + } + } + }, + { + "type": "Text", + "value": "\n dummy content\n\n ", + "range": [ + 5, + 25 + ], + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 4, + "column": 2 + } + }, + "parts": [] + }, + { + "type": "OpenScriptTagStart", + "value": "", + "range": [ + 79, + 80 + ], + "loc": { + "start": { + "line": 4, + "column": 56 + }, + "end": { + "line": 4, + "column": 57 + } + } + }, + { + "type": "ScriptTagContent", + "value": "\n console.log('test 1')\n ", + "range": [ + 80, + 109 + ], + "loc": { + "start": { + "line": 4, + "column": 57 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "parts": [] + }, + { + "type": "CloseScriptTag", + "value": "", + "range": [ + 109, + 118 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 11 + } + } + }, + { + "type": "Text", + "value": "\n\n ", + "range": [ + 118, + 122 + ], + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 8, + "column": 2 + } + }, + "parts": [] + }, + { + "type": "OpenScriptTagStart", + "value": "", + "range": [ + 169, + 170 + ], + "loc": { + "start": { + "line": 11, + "column": 2 + }, + "end": { + "line": 11, + "column": 3 + } + } + }, + { + "type": "ScriptTagContent", + "value": "\n let a = '
'\n console.log(a)\n ", + "range": [ + 170, + 218 + ], + "loc": { + "start": { + "line": 11, + "column": 3 + }, + "end": { + "line": 14, + "column": 2 + } + }, + "parts": [] + }, + { + "type": "CloseScriptTag", + "value": "", + "range": [ + 218, + 227 + ], + "loc": { + "start": { + "line": 14, + "column": 2 + }, + "end": { + "line": 14, + "column": 11 + } + } + }, + { + "type": "Text", + "value": "\n", + "range": [ + 227, + 228 + ], + "loc": { + "start": { + "line": 14, + "column": 11 + }, + "end": { + "line": 15, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "CloseTag", + "value": "", + "range": [ + 228, + 234 + ], + "loc": { + "start": { + "line": 15, + "column": 0 + }, + "end": { + "line": 15, + "column": 6 + } + } + }, + { + "type": "Text", + "value": "\n\n", + "range": [ + 234, + 236 + ], + "loc": { + "start": { + "line": 15, + "column": 6 + }, + "end": { + "line": 17, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "OpenScriptTagStart", + "value": "", + "range": [ + 272, + 273 + ], + "loc": { + "start": { + "line": 17, + "column": 36 + }, + "end": { + "line": 17, + "column": 37 + } + } + }, + { + "type": "ScriptTagContent", + "value": "\n console.log('test 2')\n", + "range": [ + 273, + 298 + ], + "loc": { + "start": { + "line": 17, + "column": 37 + }, + "end": { + "line": 19, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "CloseScriptTag", + "value": "", + "range": [ + 298, + 307 + ], + "loc": { + "start": { + "line": 19, + "column": 0 + }, + "end": { + "line": 19, + "column": 9 + } + } + }, + { + "type": "Text", + "value": "\n", + "range": [ + 307, + 308 + ], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 20, + "column": 0 + } + }, + "parts": [] + } +] \ No newline at end of file diff --git a/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-script-elements.html-0.json b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-script-elements.html-0.json new file mode 100644 index 0000000..f446e65 --- /dev/null +++ b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-script-elements.html-0.json @@ -0,0 +1,205 @@ +[ + { + "type": "Text", + "value": "opening text\n\n", + "range": [ + 0, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "OpenTagStart", + "value": "", + "range": [ + 18, + 19 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 5 + } + } + }, + { + "type": "Text", + "value": "\n ", + "range": [ + 19, + 22 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 4, + "column": 2 + } + }, + "parts": [] + }, + { + "type": "OpenScriptTagStart", + "value": "", + "range": [ + 29, + 30 + ], + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 10 + } + } + }, + { + "type": "ScriptTagContent", + "value": "\n console.log('')\n ", + "range": [ + 30, + 53 + ], + "loc": { + "start": { + "line": 4, + "column": 10 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "parts": [] + }, + { + "type": "CloseScriptTag", + "value": "", + "range": [ + 53, + 62 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 11 + } + } + }, + { + "type": "Text", + "value": "\n", + "range": [ + 62, + 63 + ], + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "CloseTag", + "value": "", + "range": [ + 63, + 69 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 6 + } + } + }, + { + "type": "Text", + "value": "\n\nclosing text\n", + "range": [ + 69, + 84 + ], + "loc": { + "start": { + "line": 7, + "column": 6 + }, + "end": { + "line": 10, + "column": 0 + } + }, + "parts": [] + } +] \ No newline at end of file diff --git a/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-style-elements-attributes.html-0.json b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-style-elements-attributes.html-0.json new file mode 100644 index 0000000..446bd49 --- /dev/null +++ b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-style-elements-attributes.html-0.json @@ -0,0 +1,592 @@ +[ + { + "type": "OpenStyleTagStart", + "value": "", + "range": [ + 41, + 42 + ], + "loc": { + "start": { + "line": 1, + "column": 41 + }, + "end": { + "line": 1, + "column": 42 + } + } + }, + { + "type": "StyleTagContent", + "value": "\n body {\n background-color: white;\n }\n", + "range": [ + 42, + 85 + ], + "loc": { + "start": { + "line": 1, + "column": 42 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "CloseStyleTag", + "value": "", + "range": [ + 85, + 93 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 8 + } + } + }, + { + "type": "Text", + "value": "\n\n", + "range": [ + 93, + 95 + ], + "loc": { + "start": { + "line": 5, + "column": 8 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "OpenTagStart", + "value": "", + "range": [ + 99, + 100 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 5 + } + } + }, + { + "type": "Text", + "value": "\n ", + "range": [ + 100, + 103 + ], + "loc": { + "start": { + "line": 7, + "column": 5 + }, + "end": { + "line": 8, + "column": 2 + } + }, + "parts": [] + }, + { + "type": "OpenStyleTagStart", + "value": "", + "range": [ + 163, + 164 + ], + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 13, + "column": 3 + } + } + }, + { + "type": "StyleTagContent", + "value": "\n body {\n background-color: red;\n }\n ", + "range": [ + 164, + 213 + ], + "loc": { + "start": { + "line": 13, + "column": 3 + }, + "end": { + "line": 17, + "column": 2 + } + }, + "parts": [] + }, + { + "type": "CloseStyleTag", + "value": "", + "range": [ + 213, + 221 + ], + "loc": { + "start": { + "line": 17, + "column": 2 + }, + "end": { + "line": 17, + "column": 10 + } + } + }, + { + "type": "Text", + "value": "\n", + "range": [ + 221, + 222 + ], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 18, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "CloseTag", + "value": "", + "range": [ + 222, + 228 + ], + "loc": { + "start": { + "line": 18, + "column": 0 + }, + "end": { + "line": 18, + "column": 6 + } + } + }, + { + "type": "Text", + "value": "\n", + "range": [ + 228, + 229 + ], + "loc": { + "start": { + "line": 18, + "column": 6 + }, + "end": { + "line": 19, + "column": 0 + } + }, + "parts": [] + } +] \ No newline at end of file diff --git a/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-style-elements.html-0.json b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-style-elements.html-0.json new file mode 100644 index 0000000..dbdf244 --- /dev/null +++ b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-style-elements.html-0.json @@ -0,0 +1,297 @@ +[ + { + "type": "Text", + "value": "opening text\n\n", + "range": [ + 0, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "OpenStyleTagStart", + "value": "", + "range": [ + 20, + 21 + ], + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 7 + } + } + }, + { + "type": "StyleTagContent", + "value": "\n body {\n background-color: white;\n }\n", + "range": [ + 21, + 64 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "CloseStyleTag", + "value": "", + "range": [ + 64, + 72 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 8 + } + } + }, + { + "type": "Text", + "value": "\n\n", + "range": [ + 72, + 74 + ], + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "OpenTagStart", + "value": "", + "range": [ + 78, + 79 + ], + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 5 + } + } + }, + { + "type": "Text", + "value": "\n ", + "range": [ + 79, + 82 + ], + "loc": { + "start": { + "line": 9, + "column": 5 + }, + "end": { + "line": 10, + "column": 2 + } + }, + "parts": [] + }, + { + "type": "OpenStyleTagStart", + "value": "", + "range": [ + 88, + 89 + ], + "loc": { + "start": { + "line": 10, + "column": 8 + }, + "end": { + "line": 10, + "column": 9 + } + } + }, + { + "type": "StyleTagContent", + "value": "\n body {\n background-color: red;\n }\n ", + "range": [ + 89, + 138 + ], + "loc": { + "start": { + "line": 10, + "column": 9 + }, + "end": { + "line": 14, + "column": 2 + } + }, + "parts": [] + }, + { + "type": "CloseStyleTag", + "value": "", + "range": [ + 138, + 146 + ], + "loc": { + "start": { + "line": 14, + "column": 2 + }, + "end": { + "line": 14, + "column": 10 + } + } + }, + { + "type": "Text", + "value": "\n", + "range": [ + 146, + 147 + ], + "loc": { + "start": { + "line": 14, + "column": 10 + }, + "end": { + "line": 15, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "CloseTag", + "value": "", + "range": [ + 147, + 153 + ], + "loc": { + "start": { + "line": 15, + "column": 0 + }, + "end": { + "line": 15, + "column": 6 + } + } + }, + { + "type": "Text", + "value": "\n\nclosing text\n", + "range": [ + 153, + 168 + ], + "loc": { + "start": { + "line": 15, + "column": 6 + }, + "end": { + "line": 18, + "column": 0 + } + }, + "parts": [] + } +] \ No newline at end of file diff --git a/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-svg.html-0.json b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-svg.html-0.json new file mode 100644 index 0000000..c2ade12 --- /dev/null +++ b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-svg.html-0.json @@ -0,0 +1,184 @@ +[ + { + "type": "OpenTagStart", + "value": "", + "range": [ + 39, + 40 + ], + "loc": { + "start": { + "line": 1, + "column": 39 + }, + "end": { + "line": 1, + "column": 40 + } + } + }, + { + "type": "OpenTagStart", + "value": "", + "range": [ + 48, + 50 + ], + "loc": { + "start": { + "line": 1, + "column": 48 + }, + "end": { + "line": 1, + "column": 50 + } + } + }, + { + "type": "CloseTag", + "value": "", + "range": [ + 50, + 56 + ], + "loc": { + "start": { + "line": 1, + "column": 50 + }, + "end": { + "line": 1, + "column": 56 + } + } + } +] \ No newline at end of file diff --git a/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-tags-register.html-0.json b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-tags-register.html-0.json new file mode 100644 index 0000000..19e80e9 --- /dev/null +++ b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-tags-register.html-0.json @@ -0,0 +1,973 @@ +[ + { + "type": "OpenTagStart", + "value": "", + "range": [ + 4, + 5 + ], + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + } + } + }, + { + "type": "Text", + "value": "\n", + "range": [ + 5, + 6 + ], + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 2, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "CloseTag", + "value": "", + "range": [ + 6, + 12 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 6 + } + } + }, + { + "type": "Text", + "value": "\n\n", + "range": [ + 12, + 14 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 4, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "OpenTagStart", + "value": "", + "range": [ + 18, + 19 + ], + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 5 + } + } + }, + { + "type": "CloseTag", + "value": "", + "range": [ + 19, + 25 + ], + "loc": { + "start": { + "line": 4, + "column": 5 + }, + "end": { + "line": 4, + "column": 11 + } + } + }, + { + "type": "Text", + "value": "\n\n", + "range": [ + 25, + 27 + ], + "loc": { + "start": { + "line": 4, + "column": 11 + }, + "end": { + "line": 6, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "OpenTagStart", + "value": "", + "range": [ + 32, + 33 + ], + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 6, + "column": 6 + } + } + }, + { + "type": "Text", + "value": "\n", + "range": [ + 33, + 34 + ], + "loc": { + "start": { + "line": 6, + "column": 6 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "CloseTag", + "value": "", + "range": [ + 34, + 41 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 7 + } + } + }, + { + "type": "Text", + "value": "\n\n", + "range": [ + 41, + 43 + ], + "loc": { + "start": { + "line": 7, + "column": 7 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "OpenTagStart", + "value": "", + "range": [ + 48, + 49 + ], + "loc": { + "start": { + "line": 9, + "column": 5 + }, + "end": { + "line": 9, + "column": 6 + } + } + }, + { + "type": "CloseTag", + "value": "", + "range": [ + 49, + 56 + ], + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 9, + "column": 13 + } + } + }, + { + "type": "Text", + "value": "\n\n", + "range": [ + 56, + 58 + ], + "loc": { + "start": { + "line": 9, + "column": 13 + }, + "end": { + "line": 11, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "OpenScriptTagStart", + "value": "", + "range": [ + 65, + 66 + ], + "loc": { + "start": { + "line": 11, + "column": 7 + }, + "end": { + "line": 11, + "column": 8 + } + } + }, + { + "type": "CloseScriptTag", + "value": "", + "range": [ + 66, + 75 + ], + "loc": { + "start": { + "line": 11, + "column": 8 + }, + "end": { + "line": 11, + "column": 17 + } + } + }, + { + "type": "Text", + "value": "\n", + "range": [ + 75, + 76 + ], + "loc": { + "start": { + "line": 11, + "column": 17 + }, + "end": { + "line": 12, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "OpenScriptTagStart", + "value": "", + "range": [ + 83, + 84 + ], + "loc": { + "start": { + "line": 12, + "column": 7 + }, + "end": { + "line": 12, + "column": 8 + } + } + }, + { + "type": "ScriptTagContent", + "value": "\n", + "range": [ + 84, + 85 + ], + "loc": { + "start": { + "line": 12, + "column": 8 + }, + "end": { + "line": 13, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "CloseScriptTag", + "value": "", + "range": [ + 85, + 94 + ], + "loc": { + "start": { + "line": 13, + "column": 0 + }, + "end": { + "line": 13, + "column": 9 + } + } + }, + { + "type": "Text", + "value": "\n", + "range": [ + 94, + 95 + ], + "loc": { + "start": { + "line": 13, + "column": 9 + }, + "end": { + "line": 14, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "OpenScriptTagStart", + "value": "", + "range": [ + 102, + 103 + ], + "loc": { + "start": { + "line": 14, + "column": 7 + }, + "end": { + "line": 14, + "column": 8 + } + } + }, + { + "type": "CloseScriptTag", + "value": "", + "range": [ + 103, + 112 + ], + "loc": { + "start": { + "line": 14, + "column": 8 + }, + "end": { + "line": 14, + "column": 17 + } + } + }, + { + "type": "Text", + "value": "\n", + "range": [ + 112, + 113 + ], + "loc": { + "start": { + "line": 14, + "column": 17 + }, + "end": { + "line": 15, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "OpenScriptTagStart", + "value": "", + "range": [ + 120, + 121 + ], + "loc": { + "start": { + "line": 15, + "column": 7 + }, + "end": { + "line": 15, + "column": 8 + } + } + }, + { + "type": "ScriptTagContent", + "value": "\n", + "range": [ + 121, + 122 + ], + "loc": { + "start": { + "line": 15, + "column": 8 + }, + "end": { + "line": 16, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "CloseScriptTag", + "value": "", + "range": [ + 122, + 131 + ], + "loc": { + "start": { + "line": 16, + "column": 0 + }, + "end": { + "line": 16, + "column": 9 + } + } + }, + { + "type": "Text", + "value": "\n\n", + "range": [ + 131, + 133 + ], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 18, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "OpenStyleTagStart", + "value": "", + "range": [ + 139, + 140 + ], + "loc": { + "start": { + "line": 18, + "column": 6 + }, + "end": { + "line": 18, + "column": 7 + } + } + }, + { + "type": "CloseStyleTag", + "value": "", + "range": [ + 140, + 148 + ], + "loc": { + "start": { + "line": 18, + "column": 7 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + { + "type": "Text", + "value": "\n", + "range": [ + 148, + 149 + ], + "loc": { + "start": { + "line": 18, + "column": 15 + }, + "end": { + "line": 19, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "OpenStyleTagStart", + "value": "", + "range": [ + 155, + 156 + ], + "loc": { + "start": { + "line": 19, + "column": 6 + }, + "end": { + "line": 19, + "column": 7 + } + } + }, + { + "type": "StyleTagContent", + "value": "\n", + "range": [ + 156, + 157 + ], + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 20, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "CloseStyleTag", + "value": "", + "range": [ + 157, + 165 + ], + "loc": { + "start": { + "line": 20, + "column": 0 + }, + "end": { + "line": 20, + "column": 8 + } + } + }, + { + "type": "Text", + "value": "\n", + "range": [ + 165, + 166 + ], + "loc": { + "start": { + "line": 20, + "column": 8 + }, + "end": { + "line": 21, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "OpenStyleTagStart", + "value": "", + "range": [ + 172, + 173 + ], + "loc": { + "start": { + "line": 21, + "column": 6 + }, + "end": { + "line": 21, + "column": 7 + } + } + }, + { + "type": "CloseStyleTag", + "value": "", + "range": [ + 173, + 181 + ], + "loc": { + "start": { + "line": 21, + "column": 7 + }, + "end": { + "line": 21, + "column": 15 + } + } + }, + { + "type": "Text", + "value": "\n", + "range": [ + 181, + 182 + ], + "loc": { + "start": { + "line": 21, + "column": 15 + }, + "end": { + "line": 22, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "OpenStyleTagStart", + "value": "", + "range": [ + 188, + 189 + ], + "loc": { + "start": { + "line": 22, + "column": 6 + }, + "end": { + "line": 22, + "column": 7 + } + } + }, + { + "type": "CloseStyleTag", + "value": "", + "range": [ + 189, + 197 + ], + "loc": { + "start": { + "line": 22, + "column": 7 + }, + "end": { + "line": 22, + "column": 15 + } + } + }, + { + "type": "Text", + "value": "\n", + "range": [ + 197, + 198 + ], + "loc": { + "start": { + "line": 22, + "column": 15 + }, + "end": { + "line": 23, + "column": 0 + } + }, + "parts": [] + } +] \ No newline at end of file diff --git a/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-templates-attributes-key.html-0.json b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-templates-attributes-key.html-0.json new file mode 100644 index 0000000..42b483b --- /dev/null +++ b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-templates-attributes-key.html-0.json @@ -0,0 +1,131 @@ +[ + { + "type": "OpenTagStart", + "value": "", + "range": [ + 11, + 12 + ], + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + } + } + }, + { + "type": "CloseTag", + "value": "", + "range": [ + 12, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 18 + } + } + } +] \ No newline at end of file diff --git a/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-templates-attributes-value-bare.html-0.json b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-templates-attributes-value-bare.html-0.json new file mode 100644 index 0000000..c07aa73 --- /dev/null +++ b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-templates-attributes-value-bare.html-0.json @@ -0,0 +1,132 @@ +[ + { + "type": "OpenTagStart", + "value": "", + "range": [ + 13, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + } + }, + { + "type": "CloseTag", + "value": "", + "range": [ + 14, + 20 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 20 + } + } + } +] \ No newline at end of file diff --git a/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-templates-attributes-value-wrapped-2.html-0.json b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-templates-attributes-value-wrapped-2.html-0.json new file mode 100644 index 0000000..aad453e --- /dev/null +++ b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-templates-attributes-value-wrapped-2.html-0.json @@ -0,0 +1,225 @@ +[ + { + "type": "OpenTagStart", + "value": "", + "range": [ + 32, + 33 + ], + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 33 + } + } + }, + { + "type": "CloseTag", + "value": "", + "range": [ + 33, + 39 + ], + "loc": { + "start": { + "line": 1, + "column": 33 + }, + "end": { + "line": 1, + "column": 39 + } + } + } +] \ No newline at end of file diff --git a/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-templates-attributes-value-wrapped.html-0.json b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-templates-attributes-value-wrapped.html-0.json new file mode 100644 index 0000000..fa4a7ed --- /dev/null +++ b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-templates-attributes-value-wrapped.html-0.json @@ -0,0 +1,168 @@ +[ + { + "type": "OpenTagStart", + "value": "", + "range": [ + 15, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + } + } + }, + { + "type": "CloseTag", + "value": "", + "range": [ + 16, + 22 + ], + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 22 + } + } + } +] \ No newline at end of file diff --git a/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-templates-comment.html-0.json b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-templates-comment.html-0.json new file mode 100644 index 0000000..3870dc1 --- /dev/null +++ b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-templates-comment.html-0.json @@ -0,0 +1,77 @@ +[ + { + "type": "CommentOpen", + "value": "", + "range": [ + 14, + 17 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 17 + } + } + } +] \ No newline at end of file diff --git a/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-templates-content-end.html-0.json b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-templates-content-end.html-0.json new file mode 100644 index 0000000..6ec2421 --- /dev/null +++ b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-templates-content-end.html-0.json @@ -0,0 +1,41 @@ +[ + { + "type": "Text", + "value": "${content}", + "range": [ + 0, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "parts": [ + { + "type": "Template", + "range": [ + 0, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "value": "${content}", + "partOf": "Text" + } + ] + } +] \ No newline at end of file diff --git a/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-templates-data.html-0.json b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-templates-data.html-0.json new file mode 100644 index 0000000..30757cd --- /dev/null +++ b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-templates-data.html-0.json @@ -0,0 +1,95 @@ +[ + { + "type": "OpenTagStart", + "value": "", + "range": [ + 4, + 5 + ], + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + } + } + }, + { + "type": "Text", + "value": "${children}", + "range": [ + 5, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "parts": [ + { + "type": "Template", + "range": [ + 5, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "value": "${children}", + "partOf": "Text" + } + ] + }, + { + "type": "CloseTag", + "value": "", + "range": [ + 16, + 22 + ], + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 22 + } + } + } +] \ No newline at end of file diff --git a/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-templates-script-content.html-0.json b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-templates-script-content.html-0.json new file mode 100644 index 0000000..e3bb287 --- /dev/null +++ b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-templates-script-content.html-0.json @@ -0,0 +1,95 @@ +[ + { + "type": "OpenScriptTagStart", + "value": "", + "range": [ + 7, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + } + }, + { + "type": "ScriptTagContent", + "value": "${content}", + "range": [ + 8, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "parts": [ + { + "type": "Template", + "range": [ + 8, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "value": "${content}", + "partOf": "ScriptTagContent" + } + ] + }, + { + "type": "CloseScriptTag", + "value": "", + "range": [ + 18, + 27 + ], + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 27 + } + } + } +] \ No newline at end of file diff --git a/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-templates-style-content.html-0.json b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-templates-style-content.html-0.json new file mode 100644 index 0000000..bc41637 --- /dev/null +++ b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-templates-style-content.html-0.json @@ -0,0 +1,95 @@ +[ + { + "type": "OpenStyleTagStart", + "value": "", + "range": [ + 6, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + { + "type": "StyleTagContent", + "value": "${content}", + "range": [ + 7, + 17 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "parts": [ + { + "type": "Template", + "range": [ + 7, + 17 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "value": "${content}", + "partOf": "StyleTagContent" + } + ] + }, + { + "type": "CloseStyleTag", + "value": "", + "range": [ + 17, + 25 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 25 + } + } + } +] \ No newline at end of file diff --git a/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-void-tags.html-0.json b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-void-tags.html-0.json new file mode 100644 index 0000000..d0538f5 --- /dev/null +++ b/src/__tests__/tokenizer/__file_snapshots__/Tokenizer-void-tags.html-0.json @@ -0,0 +1,93 @@ +[ + { + "type": "OpenTagStart", + "value": "", + "range": [ + 5, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + { + "type": "Text", + "value": "\n\n", + "range": [ + 7, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "parts": [] + }, + { + "type": "OpenTagStart", + "value": "", + "range": [ + 14, + 16 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 2 + } + } + } +] \ No newline at end of file diff --git a/src/__tests__/tokenizer/tokenizer.spec.ts b/src/__tests__/tokenizer/tokenizer.spec.ts new file mode 100644 index 0000000..a40b76d --- /dev/null +++ b/src/__tests__/tokenizer/tokenizer.spec.ts @@ -0,0 +1,93 @@ +import { toMatchFile } from "jest-file-snapshot"; +import fs from "fs"; +import path from "path"; +import { tokenize } from "../../tokenizer"; +import { defaultTokenAdapter } from "../../token-adapter"; +import { TokenizeOptions } from "../../tokenizer/tokenize"; +import { Range, TemplateInfo } from "../../types"; +expect.extend({ toMatchFile }); + +const readFixture = (name: string) => + fs.readFileSync(path.join(__dirname, "../__fixtures__", name), "utf-8"); + +const expectMatchSnapshot = (tokens: any[]) => { + expect(JSON.stringify(tokens, null, 2)).toMatchFile(undefined, { + fileExtension: ".json", + }); +}; + +const testTokenize = (name: string, options?: TokenizeOptions) => { + test(name, () => { + const input = readFixture(name); + const { tokens } = tokenize(input, defaultTokenAdapter, options); + expectMatchSnapshot(tokens); + }); +}; + +describe("Tokenizer", () => { + testTokenize("attributes-apostrophe.html"); + testTokenize("attributes-bare-wrong-quote.html"); + testTokenize("attributes-bare.html"); + testTokenize("attributes-empty.html"); + testTokenize("attributes-multiline.html"); + testTokenize("attributes-quote.html"); + testTokenize("comments.html"); + testTokenize("custom-elements.html"); + testTokenize("custom-tag-raw-content.html"); + testTokenize("doctypes.html"); + testTokenize("empty.html"); + testTokenize("nested-tags.html"); + testTokenize("opening-closing-text.html"); + testTokenize("script-elements-attributes.html"); + testTokenize("script-elements.html"); + testTokenize("style-elements-attributes.html"); + testTokenize("style-elements.html"); + testTokenize("svg.html"); + testTokenize("tags-register.html"); + testTokenize("void-tags.html"); + + testTokenize("templates-attributes-key.html", { + templateInfos: [ + { + open: [5, 7], + close: [10, 11], + }, + ] as TemplateInfo[], + }); + testTokenize("templates-attributes-value-bare.html", { + templateInfos: [[8, 13]] as Range[], + }); + testTokenize("templates-attributes-value-wrapped-2.html", { + templateInfos: [ + [16, 22], + [23, 31], + ] as Range[], + }); + testTokenize("templates-attributes-value-wrapped.html", { + templateInfos: [[9, 14]] as Range[], + }); + testTokenize("templates-comment.html", { + templateInfos: [[4, 14]] as Range[], + }); + testTokenize("templates-content-end.html", { + templateInfos: [[0, 10]] as Range[], + }); + testTokenize("templates-data.html", { + templateInfos: [[5, 16]] as Range[], + }); + testTokenize("templates-script-content.html", { + templateInfos: [[8, 18]] as Range[], + }); + testTokenize("templates-style-content.html", { + templateInfos: [[7, 17]] as Range[], + }); + + it("parsing error", () => { + const html = readFixture("parsing-error-no-open-end.html"); + expect(() => + tokenize(html, defaultTokenAdapter) + ).toThrowErrorMatchingInlineSnapshot( + `"Unexpected end of tag. Expected '>' to close the opening tag. (2:2)"` + ); + }); +}); diff --git a/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Attributes-apostrophe-0.json b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Attributes-apostrophe-0.json new file mode 100644 index 0000000..21d1de0 --- /dev/null +++ b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Attributes-apostrophe-0.json @@ -0,0 +1,387 @@ +{ + "type": "Document", + "range": [ + 0, + 74 + ], + "children": [ + { + "type": "Tag", + "range": [ + 0, + 73 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 73 + } + }, + "attributes": [ + { + "type": "Attribute", + "range": [ + 5, + 17 + ], + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "key": { + "type": "AttributeKey", + "value": "class", + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "range": [ + 5, + 10 + ], + "parts": [] + }, + "startWrapper": { + "type": "AttributeValueWrapperStart", + "value": "'", + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "range": [ + 11, + 12 + ] + }, + "value": { + "type": "AttributeValue", + "value": "test", + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "range": [ + 12, + 16 + ], + "parts": [] + }, + "endWrapper": { + "type": "AttributeValueWrapperEnd", + "value": "'", + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "range": [ + 16, + 17 + ] + } + }, + { + "type": "Attribute", + "range": [ + 18, + 40 + ], + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "key": { + "type": "AttributeKey", + "value": "data-test", + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "range": [ + 18, + 27 + ], + "parts": [] + }, + "startWrapper": { + "type": "AttributeValueWrapperStart", + "value": "'", + "loc": { + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "range": [ + 28, + 29 + ] + }, + "value": { + "type": "AttributeValue", + "value": "data", + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 39 + } + }, + "range": [ + 29, + 39 + ], + "parts": [] + }, + "endWrapper": { + "type": "AttributeValueWrapperEnd", + "value": "'", + "loc": { + "start": { + "line": 1, + "column": 39 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "range": [ + 39, + 40 + ] + } + }, + { + "type": "Attribute", + "range": [ + 41, + 66 + ], + "loc": { + "start": { + "line": 1, + "column": 41 + }, + "end": { + "line": 1, + "column": 66 + } + }, + "key": { + "type": "AttributeKey", + "value": "with-spaces", + "loc": { + "start": { + "line": 1, + "column": 41 + }, + "end": { + "line": 1, + "column": 52 + } + }, + "range": [ + 41, + 52 + ], + "parts": [] + }, + "startWrapper": { + "type": "AttributeValueWrapperStart", + "value": "'", + "loc": { + "start": { + "line": 1, + "column": 53 + }, + "end": { + "line": 1, + "column": 54 + } + }, + "range": [ + 53, + 54 + ] + }, + "value": { + "type": "AttributeValue", + "value": "spaces test", + "loc": { + "start": { + "line": 1, + "column": 54 + }, + "end": { + "line": 1, + "column": 65 + } + }, + "range": [ + 54, + 65 + ], + "parts": [] + }, + "endWrapper": { + "type": "AttributeValueWrapperEnd", + "value": "'", + "loc": { + "start": { + "line": 1, + "column": 65 + }, + "end": { + "line": 1, + "column": 66 + } + }, + "range": [ + 65, + 66 + ] + } + } + ], + "children": [], + "openStart": { + "type": "OpenTagStart", + "value": "", + "loc": { + "start": { + "line": 1, + "column": 66 + }, + "end": { + "line": 1, + "column": 67 + } + }, + "range": [ + 66, + 67 + ] + }, + "selfClosing": false, + "close": { + "type": "CloseTag", + "value": "", + "loc": { + "start": { + "line": 1, + "column": 67 + }, + "end": { + "line": 1, + "column": 73 + } + }, + "range": [ + 67, + 73 + ] + } + }, + { + "type": "Text", + "value": "\n", + "loc": { + "start": { + "line": 1, + "column": 73 + }, + "end": { + "line": 2, + "column": 0 + } + }, + "range": [ + 73, + 74 + ], + "parts": [] + } + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 0 + } + } +} \ No newline at end of file diff --git a/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Attributes-bare-0.json b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Attributes-bare-0.json new file mode 100644 index 0000000..cd0d018 --- /dev/null +++ b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Attributes-bare-0.json @@ -0,0 +1,619 @@ +{ + "type": "Document", + "range": [ + 0, + 195 + ], + "children": [ + { + "type": "Tag", + "range": [ + 0, + 44 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 44 + } + }, + "attributes": [ + { + "type": "Attribute", + "range": [ + 5, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "key": { + "type": "AttributeKey", + "value": "key", + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 5, + 8 + ], + "parts": [] + }, + "value": { + "type": "AttributeValue", + "value": "value", + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "range": [ + 11, + 16 + ], + "parts": [] + } + }, + { + "type": "Attribute", + "range": [ + 18, + 37 + ], + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 37 + } + }, + "key": { + "type": "AttributeKey", + "value": "and-another", + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "range": [ + 18, + 29 + ], + "parts": [] + }, + "value": { + "type": "AttributeValue", + "value": "value", + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 37 + } + }, + "range": [ + 32, + 37 + ], + "parts": [] + } + } + ], + "children": [], + "openStart": { + "type": "OpenTagStart", + "value": "", + "loc": { + "start": { + "line": 1, + "column": 37 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "range": [ + 37, + 38 + ] + }, + "selfClosing": false, + "close": { + "type": "CloseTag", + "value": "", + "loc": { + "start": { + "line": 1, + "column": 38 + }, + "end": { + "line": 1, + "column": 44 + } + }, + "range": [ + 38, + 44 + ] + } + }, + { + "type": "Text", + "value": "\n\n", + "loc": { + "start": { + "line": 1, + "column": 44 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "range": [ + 44, + 46 + ], + "parts": [] + }, + { + "type": "Tag", + "range": [ + 46, + 194 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 12, + "column": 7 + } + }, + "attributes": [ + { + "type": "Attribute", + "range": [ + 52, + 73 + ], + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 27 + } + }, + "key": { + "type": "AttributeKey", + "value": "some", + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "range": [ + 52, + 56 + ], + "parts": [] + }, + "value": { + "type": "AttributeValue", + "value": "custom-attribute", + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 27 + } + }, + "range": [ + 57, + 73 + ], + "parts": [] + } + } + ], + "children": [ + { + "type": "Text", + "value": "\n some text\n\n ", + "loc": { + "start": { + "line": 3, + "column": 28 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "range": [ + 74, + 90 + ], + "parts": [] + }, + { + "type": "Tag", + "range": [ + 90, + 186 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 11, + "column": 19 + } + }, + "attributes": [ + { + "type": "Attribute", + "range": [ + 106, + 114 + ], + "loc": { + "start": { + "line": 6, + "column": 18 + }, + "end": { + "line": 6, + "column": 26 + } + }, + "key": { + "type": "AttributeKey", + "value": "and", + "loc": { + "start": { + "line": 6, + "column": 18 + }, + "end": { + "line": 6, + "column": 21 + } + }, + "range": [ + 106, + 109 + ], + "parts": [] + }, + "value": { + "type": "AttributeValue", + "value": "here", + "loc": { + "start": { + "line": 6, + "column": 22 + }, + "end": { + "line": 6, + "column": 26 + } + }, + "range": [ + 110, + 114 + ], + "parts": [] + } + }, + { + "type": "Attribute", + "range": [ + 119, + 134 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 19 + } + }, + "key": { + "type": "AttributeKey", + "value": "and-even", + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 12 + } + }, + "range": [ + 119, + 127 + ], + "parts": [] + }, + "value": { + "type": "AttributeValue", + "value": "here", + "loc": { + "start": { + "line": 7, + "column": 15 + }, + "end": { + "line": 7, + "column": 19 + } + }, + "range": [ + 130, + 134 + ], + "parts": [] + } + } + ], + "children": [ + { + "type": "Text", + "value": "\n custom element\n text\n ", + "loc": { + "start": { + "line": 8, + "column": 3 + }, + "end": { + "line": 11, + "column": 2 + } + }, + "range": [ + 138, + 169 + ], + "parts": [] + } + ], + "openStart": { + "type": "OpenTagStart", + "value": "", + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 3 + } + }, + "range": [ + 137, + 138 + ] + }, + "selfClosing": false, + "close": { + "type": "CloseTag", + "value": "", + "loc": { + "start": { + "line": 11, + "column": 2 + }, + "end": { + "line": 11, + "column": 19 + } + }, + "range": [ + 169, + 186 + ] + } + }, + { + "type": "Text", + "value": "\n", + "loc": { + "start": { + "line": 11, + "column": 19 + }, + "end": { + "line": 12, + "column": 0 + } + }, + "range": [ + 186, + 187 + ], + "parts": [] + } + ], + "openStart": { + "type": "OpenTagStart", + "value": "", + "loc": { + "start": { + "line": 3, + "column": 27 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "range": [ + 73, + 74 + ] + }, + "selfClosing": false, + "close": { + "type": "CloseTag", + "value": "", + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 7 + } + }, + "range": [ + 187, + 194 + ] + } + }, + { + "type": "Text", + "value": "\n", + "loc": { + "start": { + "line": 12, + "column": 7 + }, + "end": { + "line": 13, + "column": 0 + } + }, + "range": [ + 194, + 195 + ], + "parts": [] + } + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 13, + "column": 0 + } + } +} \ No newline at end of file diff --git a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Attributes-bare-wrong-quote-0.json b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Attributes-bare-wrong-quote-0.json similarity index 100% rename from src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Attributes-bare-wrong-quote-0.json rename to src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Attributes-bare-wrong-quote-0.json diff --git a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Attributes-empty-0.json b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Attributes-empty-0.json similarity index 100% rename from src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Attributes-empty-0.json rename to src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Attributes-empty-0.json diff --git a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Attributes-multiline-(CRLF)-0.json b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Attributes-multiline-0.json similarity index 92% rename from src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Attributes-multiline-(CRLF)-0.json rename to src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Attributes-multiline-0.json index 8284924..8da2d09 100644 --- a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Attributes-multiline-(CRLF)-0.json +++ b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Attributes-multiline-0.json @@ -2,14 +2,14 @@ "type": "Document", "range": [ 0, - 52 + 46 ], "children": [ { "type": "Tag", "range": [ 0, - 50 + 45 ], "loc": { "start": { @@ -25,8 +25,8 @@ { "type": "Attribute", "range": [ - 8, - 16 + 7, + 15 ], "loc": { "start": { @@ -52,8 +52,8 @@ } }, "range": [ - 8, - 10 + 7, + 9 ], "parts": [] }, @@ -71,8 +71,8 @@ } }, "range": [ - 11, - 12 + 10, + 11 ] }, "value": { @@ -89,8 +89,8 @@ } }, "range": [ - 12, - 15 + 11, + 14 ], "parts": [] }, @@ -108,16 +108,16 @@ } }, "range": [ - 15, - 16 + 14, + 15 ] } }, { "type": "Attribute", "range": [ - 20, - 31 + 18, + 29 ], "loc": { "start": { @@ -143,8 +143,8 @@ } }, "range": [ - 20, - 25 + 18, + 23 ], "parts": [] }, @@ -162,8 +162,8 @@ } }, "range": [ - 26, - 27 + 24, + 25 ] }, "value": { @@ -180,8 +180,8 @@ } }, "range": [ - 27, - 30 + 25, + 28 ], "parts": [] }, @@ -199,16 +199,16 @@ } }, "range": [ - 30, - 31 + 28, + 29 ] } }, { "type": "Attribute", "range": [ - 35, - 39 + 32, + 36 ], "loc": { "start": { @@ -234,8 +234,8 @@ } }, "range": [ - 35, - 39 + 32, + 36 ], "parts": [] } @@ -244,7 +244,7 @@ "children": [ { "type": "Text", - "value": "\r\n", + "value": "\n", "loc": { "start": { "line": 5, @@ -256,8 +256,8 @@ } }, "range": [ - 42, - 44 + 38, + 39 ], "parts": [] } @@ -295,8 +295,8 @@ } }, "range": [ - 41, - 42 + 37, + 38 ] }, "selfClosing": false, @@ -314,14 +314,14 @@ } }, "range": [ - 44, - 50 + 39, + 45 ] } }, { "type": "Text", - "value": "\r\n", + "value": "\n", "loc": { "start": { "line": 6, @@ -333,8 +333,8 @@ } }, "range": [ - 50, - 52 + 45, + 46 ], "parts": [] } diff --git a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Attributes-apostrophe-0.json b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Attributes-quote-0.json similarity index 98% rename from src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Attributes-apostrophe-0.json rename to src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Attributes-quote-0.json index 843c291..c06bd2c 100644 --- a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Attributes-apostrophe-0.json +++ b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Attributes-quote-0.json @@ -96,7 +96,7 @@ }, "startWrapper": { "type": "AttributeValueWrapperStart", - "value": "'", + "value": "\"", "loc": { "start": { "line": 2, @@ -133,7 +133,7 @@ }, "endWrapper": { "type": "AttributeValueWrapperEnd", - "value": "'", + "value": "\"", "loc": { "start": { "line": 2, @@ -187,7 +187,7 @@ }, "startWrapper": { "type": "AttributeValueWrapperStart", - "value": "'", + "value": "\"", "loc": { "start": { "line": 2, @@ -224,7 +224,7 @@ }, "endWrapper": { "type": "AttributeValueWrapperEnd", - "value": "'", + "value": "\"", "loc": { "start": { "line": 2, @@ -311,8 +311,8 @@ "column": 6 }, "end": { - "column": 23, - "line": 14 + "line": 14, + "column": 23 } }, "attributes": [ @@ -353,7 +353,7 @@ }, "startWrapper": { "type": "AttributeValueWrapperStart", - "value": "'", + "value": "\"", "loc": { "start": { "line": 9, @@ -390,7 +390,7 @@ }, "endWrapper": { "type": "AttributeValueWrapperEnd", - "value": "'", + "value": "\"", "loc": { "start": { "line": 9, @@ -444,7 +444,7 @@ }, "startWrapper": { "type": "AttributeValueWrapperStart", - "value": "'", + "value": "\"", "loc": { "start": { "line": 10, @@ -481,7 +481,7 @@ }, "endWrapper": { "type": "AttributeValueWrapperEnd", - "value": "'", + "value": "\"", "loc": { "start": { "line": 10, diff --git a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Comments-0.json b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Comments-0.json similarity index 100% rename from src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Comments-0.json rename to src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Comments-0.json diff --git a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Custom-elements-0.json b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Custom-elements-0.json similarity index 100% rename from src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Custom-elements-0.json rename to src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Custom-elements-0.json diff --git a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Custom-Tag-Raw-Content-0.json b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Custom-tag-raw-content-0.json similarity index 62% rename from src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Custom-Tag-Raw-Content-0.json rename to src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Custom-tag-raw-content-0.json index 6ca7ff3..2961559 100644 --- a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Custom-Tag-Raw-Content-0.json +++ b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Custom-tag-raw-content-0.json @@ -9,7 +9,7 @@ "type": "Tag", "range": [ 0, - 271 + 19 ], "loc": { "start": { @@ -17,8 +17,8 @@ "column": 0 }, "end": { - "line": 17, - "column": 11 + "line": 1, + "column": 19 } }, "attributes": [ @@ -116,23 +116,100 @@ ], "children": [ { - "type": "RawContent", - "value": "\n# Hello, world!\n\n```cpp{4-6,9}\n#include \n\nclass Example {\n Example() {\n std::cout << \"Hello, world!\" << std::endl;\n }\n\n Example(std::string name) {\n std::cout << \"Hello, \" << name << std::endl;\n }\n};\n```\n", + "type": "Text", + "value": "\n# Hello, world!\n\n```cpp{4-6,9}\n#include ", "loc": { "start": { "line": 1, "column": 19 }, "end": { - "line": 17, - "column": 0 + "line": 5, + "column": 9 } }, "range": [ 19, - 260 + 60 ], "parts": [] + }, + { + "type": "Tag", + "range": [ + 60, + 70 + ], + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 19 + } + }, + "attributes": [], + "children": [ + { + "type": "Text", + "value": "\n\nclass Example {\n Example() {\n std::cout << \"Hello, world!\" << std::endl;\n }\n\n Example(std::string name) {\n std::cout << \"Hello, \" << name << std::endl;\n }\n};\n```\n", + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 17, + "column": 0 + } + }, + "range": [ + 70, + 260 + ], + "parts": [] + } + ], + "openStart": { + "type": "OpenTagStart", + "value": "", + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 19 + } + }, + "range": [ + 69, + 70 + ] + }, + "selfClosing": false } ], "openStart": { @@ -172,25 +249,7 @@ 19 ] }, - "selfClosing": false, - "close": { - "type": "CloseTag", - "value": "", - "loc": { - "start": { - "line": 17, - "column": 0 - }, - "end": { - "line": 17, - "column": 11 - } - }, - "range": [ - 260, - 271 - ] - } + "selfClosing": false } ], "loc": { diff --git a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Doctypes-0.json b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Doctypes-0.json similarity index 100% rename from src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Doctypes-0.json rename to src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Doctypes-0.json diff --git a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Empty-0.json b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Empty-0.json similarity index 100% rename from src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Empty-0.json rename to src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Empty-0.json diff --git a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Nested-tags-0.json b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Nested-tags-0.json similarity index 100% rename from src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Nested-tags-0.json rename to src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Nested-tags-0.json diff --git a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Opening-closing-text-0.json b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Opening-closing-text-0.json similarity index 100% rename from src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Opening-closing-text-0.json rename to src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Opening-closing-text-0.json diff --git a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Script-elements-0.json b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Script-elements-0.json similarity index 100% rename from src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Script-elements-0.json rename to src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Script-elements-0.json diff --git a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Script-elements-attributes-0.json b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Script-elements-attributes-0.json similarity index 100% rename from src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Script-elements-attributes-0.json rename to src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Script-elements-attributes-0.json diff --git a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Style-elements-0.json b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Style-elements-0.json similarity index 99% rename from src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Style-elements-0.json rename to src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Style-elements-0.json index 407cd52..46122b2 100644 --- a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Style-elements-0.json +++ b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Style-elements-0.json @@ -36,8 +36,8 @@ "column": 0 }, "end": { - "column": 8, - "line": 7 + "line": 7, + "column": 8 } }, "attributes": [], diff --git a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Style-elements-attributes-0.json b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Style-elements-attributes-0.json similarity index 100% rename from src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Style-elements-attributes-0.json rename to src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Style-elements-attributes-0.json diff --git a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Svg-0.json b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Svg-0.json similarity index 96% rename from src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Svg-0.json rename to src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Svg-0.json index 3068804..76773a0 100644 --- a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Svg-0.json +++ b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Svg-0.json @@ -17,8 +17,8 @@ "column": 0 }, "end": { - "column": 56, - "line": 1 + "line": 1, + "column": 56 } }, "attributes": [ @@ -34,8 +34,8 @@ "column": 5 }, "end": { - "column": 39, - "line": 1 + "line": 1, + "column": 39 } }, "key": { @@ -127,8 +127,8 @@ "column": 40 }, "end": { - "column": 50, - "line": 1 + "line": 1, + "column": 50 } }, "attributes": [], diff --git a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Tag-register-0.json b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Tags-register-0.json similarity index 100% rename from src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Tag-register-0.json rename to src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Tags-register-0.json diff --git a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Templates-Attributes-Key-0.json b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Templates-attributes-key-0.json similarity index 67% rename from src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Templates-Attributes-Key-0.json rename to src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Templates-attributes-key-0.json index 0adbbec..1042bf5 100644 --- a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Templates-Attributes-Key-0.json +++ b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Templates-attributes-key-0.json @@ -17,8 +17,8 @@ "column": 0 }, "end": { - "column": 18, - "line": 1 + "line": 1, + "column": 18 } }, "attributes": [ @@ -57,23 +57,59 @@ ], "parts": [ { - "loc": { - "end": { - "column": 11, - "line": 1 - }, - "start": { - "column": 5, - "line": 1 - } - }, + "type": "Template", "range": [ 5, 11 ], - "type": "Template", + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 11 + } + }, "value": "${key}", - "partOf": "AttributeKey" + "partOf": "AttributeKey", + "open": { + "type": "OpenTemplate", + "range": [ + 5, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "value": "${" + }, + "close": { + "type": "CloseTemplate", + "range": [ + 10, + 11 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "value": "}" + } } ] } diff --git a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Templates-Attributes-Value-Bare-0.json b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Templates-attributes-value-bare-0.json similarity index 97% rename from src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Templates-Attributes-Value-Bare-0.json rename to src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Templates-attributes-value-bare-0.json index b75c83b..7684fac 100644 --- a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Templates-Attributes-Value-Bare-0.json +++ b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Templates-attributes-value-bare-0.json @@ -77,7 +77,6 @@ "parts": [ { "type": "Template", - "partOf": "AttributeValue", "range": [ 8, 13 @@ -92,7 +91,8 @@ "column": 13 } }, - "value": "${id}" + "value": "${id}", + "partOf": "AttributeValue" } ] } diff --git a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Templates-Attributes-Value-Wrapped-0.json b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Templates-attributes-value-wrapped-0.json similarity index 98% rename from src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Templates-Attributes-Value-Wrapped-0.json rename to src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Templates-attributes-value-wrapped-0.json index 4dd0507..74d5e3c 100644 --- a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Templates-Attributes-Value-Wrapped-0.json +++ b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Templates-attributes-value-wrapped-0.json @@ -95,7 +95,6 @@ "parts": [ { "type": "Template", - "partOf": "AttributeValue", "range": [ 9, 14 @@ -110,7 +109,8 @@ "column": 14 } }, - "value": "${id}" + "value": "${id}", + "partOf": "AttributeValue" } ] }, diff --git a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Templates-Attributes-Value-Wrapped-2-0.json b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Templates-attributes-value-wrapped-2-0.json similarity index 94% rename from src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Templates-Attributes-Value-Wrapped-2-0.json rename to src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Templates-attributes-value-wrapped-2-0.json index 738c8d2..d5effd5 100644 --- a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Templates-Attributes-Value-Wrapped-2-0.json +++ b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Templates-attributes-value-wrapped-2-0.json @@ -109,11 +109,10 @@ "column": 16 } }, - "partOf": "AttributeValue", - "value": "one " + "value": "one ", + "partOf": "AttributeValue" }, { - "partOf": "AttributeValue", "type": "Template", "range": [ 16, @@ -129,7 +128,8 @@ "column": 22 } }, - "value": "${two}" + "value": "${two}", + "partOf": "AttributeValue" }, { "type": "Part", @@ -147,11 +147,10 @@ "column": 23 } }, - "partOf": "AttributeValue", - "value": " " + "value": " ", + "partOf": "AttributeValue" }, { - "partOf": "AttributeValue", "type": "Template", "range": [ 23, @@ -167,7 +166,8 @@ "column": 31 } }, - "value": "${three}" + "value": "${three}", + "partOf": "AttributeValue" } ] }, diff --git a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Templates-Comment-0.json b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Templates-comment-0.json similarity index 97% rename from src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Templates-Comment-0.json rename to src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Templates-comment-0.json index 8c64455..34a9d5f 100644 --- a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Templates-Comment-0.json +++ b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Templates-comment-0.json @@ -59,8 +59,6 @@ "parts": [ { "type": "Template", - "partOf": "CommentContent", - "value": "${comment}", "range": [ 4, 14 @@ -74,7 +72,9 @@ "line": 1, "column": 14 } - } + }, + "value": "${comment}", + "partOf": "CommentContent" } ] }, diff --git a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Templates-Content-End-0.json b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Templates-content-end-0.json similarity index 88% rename from src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Templates-Content-End-0.json rename to src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Templates-content-end-0.json index 92366c3..5ed6895 100644 --- a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Templates-Content-End-0.json +++ b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Templates-content-end-0.json @@ -24,21 +24,21 @@ ], "parts": [ { - "loc": { - "end": { - "column": 10, - "line": 1 - }, - "start": { - "column": 0, - "line": 1 - } - }, + "type": "Template", "range": [ 0, 10 ], - "type": "Template", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, "value": "${content}", "partOf": "Text" } diff --git a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Templates-Data-0.json b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Templates-data-0.json similarity index 97% rename from src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Templates-Data-0.json rename to src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Templates-data-0.json index a2ec1a0..74fe6a9 100644 --- a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Templates-Data-0.json +++ b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Templates-data-0.json @@ -43,8 +43,6 @@ "parts": [ { "type": "Template", - "partOf": "Text", - "value": "${children}", "range": [ 5, 16 @@ -58,7 +56,9 @@ "line": 1, "column": 16 } - } + }, + "value": "${children}", + "partOf": "Text" } ] } diff --git a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Templates-Script-Content-0.json b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Templates-script-content-0.json similarity index 100% rename from src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Templates-Script-Content-0.json rename to src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Templates-script-content-0.json index 7823ee7..ee5c02f 100644 --- a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Templates-Script-Content-0.json +++ b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Templates-script-content-0.json @@ -78,7 +78,6 @@ "parts": [ { "type": "Template", - "value": "${content}", "range": [ 8, 18 @@ -93,6 +92,7 @@ "column": 18 } }, + "value": "${content}", "partOf": "ScriptTagContent" } ] diff --git a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Templates-Style-Content-0.json b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Templates-style-content-0.json similarity index 100% rename from src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Templates-Style-Content-0.json rename to src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Templates-style-content-0.json index 78a2881..b7aa2fe 100644 --- a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Templates-Style-Content-0.json +++ b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Templates-style-content-0.json @@ -78,7 +78,6 @@ "parts": [ { "type": "Template", - "value": "${content}", "range": [ 7, 17 @@ -93,6 +92,7 @@ "column": 17 } }, + "value": "${content}", "partOf": "StyleTagContent" } ] diff --git a/src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Void-tags-0.json b/src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Void-tags-0.json similarity index 100% rename from src/tree-constructor/__tests__/__file_snapshots__/construct-tree-Void-tags-0.json rename to src/__tests__/tree-constructor/__file_snapshots__/construct-tree-Void-tags-0.json diff --git a/src/__tests__/tree-constructor/construct-tree.spec.ts b/src/__tests__/tree-constructor/construct-tree.spec.ts new file mode 100644 index 0000000..3b9043c --- /dev/null +++ b/src/__tests__/tree-constructor/construct-tree.spec.ts @@ -0,0 +1,77 @@ +import { constructTree } from "../../tree-constructor/construct-tree"; + +import ATTRIBUTES_APOSTROPHE_INPUT from "../tokenizer/__file_snapshots__/Tokenizer-attributes-apostrophe.html-0.json"; +import ATTRIBUTES_BARE_INPUT from "../tokenizer/__file_snapshots__/Tokenizer-attributes-bare.html-0.json"; +import ATTRIBUTES_BARE_WRONG_QUOTE_INPUT from "../tokenizer/__file_snapshots__/Tokenizer-attributes-bare-wrong-quote.html-0.json"; +import ATTRIBUTES_EMPTY_INPUT from "../tokenizer/__file_snapshots__/Tokenizer-attributes-empty.html-0.json"; +import ATTRIBUTES_MULTILINE_INPUT from "../tokenizer/__file_snapshots__/Tokenizer-attributes-multiline.html-0.json"; +import ATTRIBUTES_QUOTE_INPUT from "../tokenizer/__file_snapshots__/Tokenizer-attributes-quote.html-0.json"; +import COMMENTS_INPUT from "../tokenizer/__file_snapshots__/Tokenizer-comments.html-0.json"; +import CUSTOM_ELEMENTS_INPUT from "../tokenizer/__file_snapshots__/Tokenizer-custom-elements.html-0.json"; +import CUSTOM_TAG_RAW_CONTENT from "../tokenizer/__file_snapshots__/Tokenizer-custom-tag-raw-content.html-0.json"; +import DOCTYPES_INPUT from "../tokenizer/__file_snapshots__/Tokenizer-doctypes.html-0.json"; +import EMPTY_INPUT from "../tokenizer/__file_snapshots__/Tokenizer-empty.html-0.json"; +import NESTED_TAGS_INPUT from "../tokenizer/__file_snapshots__/Tokenizer-nested-tags.html-0.json"; +import OPENING_CLOSING_TEXT_INPUT from "../tokenizer/__file_snapshots__/Tokenizer-opening-closing-text.html-0.json"; +import SCRIPT_ELEMENTS_INPUT from "../tokenizer/__file_snapshots__/Tokenizer-script-elements.html-0.json"; +import SCRIPT_ELEMENTS_ATTRIBUTES_INPUT from "../tokenizer/__file_snapshots__/Tokenizer-script-elements-attributes.html-0.json"; +import STYLE_ELEMENTS_INPUT from "../tokenizer/__file_snapshots__/Tokenizer-style-elements.html-0.json"; +import STYLE_ELEMENTS_ATTRIBUTES_INPUT from "../tokenizer/__file_snapshots__/Tokenizer-style-elements-attributes.html-0.json"; +import SVG_INPUT from "../tokenizer/__file_snapshots__/Tokenizer-svg.html-0.json"; +import TAGS_REGISTER_INPUT from "../tokenizer/__file_snapshots__/Tokenizer-tags-register.html-0.json"; +import TEMPLATE_ATTRIBUTES_KEY from "../tokenizer/__file_snapshots__/Tokenizer-templates-attributes-key.html-0.json"; +import TEMPLATE_ATTRIBUTES_VALUE_BARE from "../tokenizer/__file_snapshots__/Tokenizer-templates-attributes-value-bare.html-0.json"; +import TEMPLATE_ATTRIBUTES_VALUE_WRAPPED from "../tokenizer/__file_snapshots__/Tokenizer-templates-attributes-value-wrapped.html-0.json"; +import TEMPLATE_ATTRIBUTES_VALUE_WRAPPED_2 from "../tokenizer/__file_snapshots__/Tokenizer-templates-attributes-value-wrapped-2.html-0.json"; +import TEMPLATE_COMMENT from "../tokenizer/__file_snapshots__/Tokenizer-templates-comment.html-0.json"; +import TEMPLATE_CONTENT_END from "../tokenizer/__file_snapshots__/Tokenizer-templates-content-end.html-0.json"; +import TEMPLATE_DATA from "../tokenizer/__file_snapshots__/Tokenizer-templates-data.html-0.json"; +import TEMPLATE_SCRIPT_CONTENT from "../tokenizer/__file_snapshots__/Tokenizer-templates-script-content.html-0.json"; +import TEMPLATE_STYLE_CONTENT from "../tokenizer/__file_snapshots__/Tokenizer-templates-style-content.html-0.json"; +import VOID_TAGS_INPUT from "../tokenizer/__file_snapshots__/Tokenizer-void-tags.html-0.json"; +import { clearParent } from "../../utils"; +import { toMatchFile } from "jest-file-snapshot"; + +expect.extend({ toMatchFile }); + +describe("construct-tree", () => { + test.each([ + ["Attributes apostrophe", ATTRIBUTES_APOSTROPHE_INPUT], + ["Attributes bare", ATTRIBUTES_BARE_INPUT], + ["Attributes bare wrong quote", ATTRIBUTES_BARE_WRONG_QUOTE_INPUT], + ["Attributes empty", ATTRIBUTES_EMPTY_INPUT], + ["Attributes multiline", ATTRIBUTES_MULTILINE_INPUT], + ["Attributes quote", ATTRIBUTES_QUOTE_INPUT], + ["Comments", COMMENTS_INPUT], + ["Custom elements", CUSTOM_ELEMENTS_INPUT], + ["Custom tag raw content", CUSTOM_TAG_RAW_CONTENT], + ["Doctypes", DOCTYPES_INPUT], + ["Empty", EMPTY_INPUT], + ["Nested tags", NESTED_TAGS_INPUT], + ["Opening closing text", OPENING_CLOSING_TEXT_INPUT], + ["Script elements", SCRIPT_ELEMENTS_INPUT], + ["Script elements attributes", SCRIPT_ELEMENTS_ATTRIBUTES_INPUT], + ["Style elements", STYLE_ELEMENTS_INPUT], + ["Style elements attributes", STYLE_ELEMENTS_ATTRIBUTES_INPUT], + ["Svg", SVG_INPUT], + ["Tags register", TAGS_REGISTER_INPUT], + ["Templates attributes key", TEMPLATE_ATTRIBUTES_KEY], + ["Templates attributes value bare", TEMPLATE_ATTRIBUTES_VALUE_BARE], + ["Templates attributes value wrapped", TEMPLATE_ATTRIBUTES_VALUE_WRAPPED], + [ + "Templates attributes value wrapped 2", + TEMPLATE_ATTRIBUTES_VALUE_WRAPPED_2, + ], + ["Templates comment", TEMPLATE_COMMENT], + ["Templates content end", TEMPLATE_CONTENT_END], + ["Templates data", TEMPLATE_DATA], + ["Templates script content", TEMPLATE_SCRIPT_CONTENT], + ["Templates style content", TEMPLATE_STYLE_CONTENT], + ["Void tags", VOID_TAGS_INPUT], + ])("%s", (_name: string, inputTokens: any) => { + const { ast } = constructTree(inputTokens); + expect(JSON.stringify(clearParent(ast), null, 2)).toMatchFile(undefined, { + fileExtension: ".json", + }); + }); +}); diff --git a/src/tokenizer/__tests__/__output__/attributes-apostrophe.ts b/src/tokenizer/__tests__/__output__/attributes-apostrophe.ts deleted file mode 100644 index fe5ea7c..0000000 --- a/src/tokenizer/__tests__/__output__/attributes-apostrophe.ts +++ /dev/null @@ -1,620 +0,0 @@ -import { TokenTypes } from "../../../constants"; - -export default [ - { - type: TokenTypes.OpenTagStart, - value: "", - range: [4, 5], - loc: { - start: { - line: 1, - column: 4, - }, - end: { - line: 1, - column: 5, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n ", - range: [5, 8], - loc: { - start: { - line: 1, - column: 5, - }, - end: { - line: 2, - column: 2, - }, - }, - parts: [], - }, - { - type: TokenTypes.OpenTagStart, - value: "", - range: [44, 54], - loc: { - start: { - line: 2, - column: 38, - }, - end: { - line: 2, - column: 48, - }, - }, - parts: [], - }, - { - type: TokenTypes.AttributeValueWrapperEnd, - value: "'", - range: [54, 55], - loc: { - start: { - line: 2, - column: 48, - }, - end: { - line: 2, - column: 49, - }, - }, - }, - { - type: TokenTypes.OpenTagEnd, - value: ">", - range: [55, 56], - loc: { - start: { - line: 2, - column: 49, - }, - end: { - line: 2, - column: 50, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n some text\n\n ", - range: [56, 76], - loc: { - start: { - line: 2, - column: 50, - }, - end: { - line: 5, - column: 4, - }, - }, - parts: [], - }, - { - type: TokenTypes.OpenTagStart, - value: "", - range: [80, 81], - loc: { - start: { - line: 5, - column: 8, - }, - end: { - line: 5, - column: 9, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n another text\n\n ", - range: [81, 108], - loc: { - start: { - line: 5, - column: 9, - }, - end: { - line: 8, - column: 6, - }, - }, - parts: [], - }, - { - type: TokenTypes.OpenTagStart, - value: "test", - range: [145, 157], - loc: { - start: { - line: 9, - column: 21, - }, - end: { - line: 9, - column: 33, - }, - }, - parts: [], - }, - { - type: TokenTypes.AttributeValueWrapperEnd, - value: "'", - range: [157, 158], - loc: { - start: { - line: 9, - column: 33, - }, - end: { - line: 9, - column: 34, - }, - }, - }, - { - type: TokenTypes.AttributeKey, - value: "with-spaces", - range: [167, 178], - loc: { - start: { - line: 10, - column: 8, - }, - end: { - line: 10, - column: 19, - }, - }, - parts: [], - }, - { - type: TokenTypes.AttributeAssignment, - value: "=", - range: [181, 182], - loc: { - start: { - line: 10, - column: 22, - }, - end: { - line: 10, - column: 23, - }, - }, - }, - { - type: TokenTypes.AttributeValueWrapperStart, - value: "'", - range: [184, 185], - loc: { - start: { - line: 10, - column: 25, - }, - end: { - line: 10, - column: 26, - }, - }, - }, - { - type: TokenTypes.AttributeValue, - value: "spaces test", - range: [185, 196], - loc: { - start: { - line: 10, - column: 26, - }, - end: { - column: 37, - line: 10, - }, - }, - parts: [], - }, - { - type: TokenTypes.AttributeValueWrapperEnd, - value: "'", - range: [196, 197], - loc: { - start: { - line: 10, - column: 37, - }, - end: { - line: 10, - column: 38, - }, - }, - }, - { - type: TokenTypes.OpenTagEnd, - value: ">", - range: [204, 205], - loc: { - start: { - column: 6, - line: 11, - }, - end: { - line: 11, - column: 7, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n custom element\n text\n ", - range: [205, 248], - loc: { - start: { - column: 7, - line: 11, - }, - end: { - column: 6, - line: 14, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseTag, - value: "", - range: [248, 265], - loc: { - start: { - column: 6, - line: 14, - }, - end: { - column: 23, - line: 14, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n ", - range: [265, 270], - loc: { - start: { - line: 14, - column: 23, - }, - end: { - line: 15, - column: 4, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseTag, - value: "", - range: [270, 276], - loc: { - start: { - column: 4, - line: 15, - }, - end: { - line: 15, - column: 10, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n ", - range: [276, 279], - loc: { - start: { - line: 15, - column: 10, - }, - end: { - line: 16, - column: 2, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseTag, - value: "", - range: [279, 286], - loc: { - start: { - line: 16, - column: 2, - }, - end: { - line: 16, - column: 9, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n", - range: [286, 287], - loc: { - start: { - line: 16, - column: 9, - }, - end: { - line: 17, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseTag, - value: "", - range: [287, 293], - loc: { - start: { - line: 17, - column: 0, - }, - end: { - line: 17, - column: 6, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n", - range: [293, 294], - loc: { - start: { - line: 17, - column: 6, - }, - end: { - line: 18, - column: 0, - }, - }, - parts: [], - }, -]; diff --git a/src/tokenizer/__tests__/__output__/attributes-bare-wrong-quote.ts b/src/tokenizer/__tests__/__output__/attributes-bare-wrong-quote.ts deleted file mode 100644 index a31d235..0000000 --- a/src/tokenizer/__tests__/__output__/attributes-bare-wrong-quote.ts +++ /dev/null @@ -1,99 +0,0 @@ -import { TokenTypes } from "../../../constants"; -import { AnyToken } from "../../../types"; - -const OUTPUT: AnyToken[] = [ - { - type: TokenTypes.OpenTagStart, - value: "", - range: [18, 19], - loc: { - start: { - line: 1, - column: 18, - }, - end: { - line: 1, - column: 19, - }, - }, - }, - { - type: TokenTypes.CloseTag, - value: "", - range: [19, 23], - loc: { - start: { - line: 1, - column: 19, - }, - end: { - line: 1, - column: 23, - }, - }, - }, -]; - -export default OUTPUT; diff --git a/src/tokenizer/__tests__/__output__/attributes-bare.ts b/src/tokenizer/__tests__/__output__/attributes-bare.ts deleted file mode 100644 index 17a7261..0000000 --- a/src/tokenizer/__tests__/__output__/attributes-bare.ts +++ /dev/null @@ -1,454 +0,0 @@ -import { TokenTypes } from "../../../constants"; - -export default [ - { - type: TokenTypes.OpenTagStart, - value: "", - range: [37, 38], - loc: { - start: { - line: 1, - column: 37, - }, - end: { - line: 1, - column: 38, - }, - }, - }, - { - type: TokenTypes.CloseTag, - value: "", - range: [38, 44], - loc: { - start: { - line: 1, - column: 38, - }, - end: { - line: 1, - column: 44, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n\n", - range: [44, 46], - loc: { - start: { - line: 1, - column: 44, - }, - end: { - line: 3, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.OpenTagStart, - value: "", - range: [73, 74], - loc: { - start: { - line: 3, - column: 27, - }, - end: { - line: 3, - column: 28, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n some text\n\n ", - range: [74, 90], - loc: { - start: { - line: 3, - column: 28, - }, - end: { - line: 6, - column: 2, - }, - }, - parts: [], - }, - { - type: TokenTypes.OpenTagStart, - value: "", - range: [137, 138], - loc: { - start: { - line: 8, - column: 2, - }, - end: { - line: 8, - column: 3, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n custom element\n text\n ", - range: [138, 169], - loc: { - start: { - line: 8, - column: 3, - }, - end: { - line: 11, - column: 2, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseTag, - value: "", - range: [169, 186], - loc: { - start: { - line: 11, - column: 2, - }, - end: { - line: 11, - column: 19, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n", - range: [186, 187], - loc: { - start: { - line: 11, - column: 19, - }, - end: { - line: 12, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseTag, - value: "", - range: [187, 194], - loc: { - start: { - line: 12, - column: 0, - }, - end: { - line: 12, - column: 7, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n", - range: [194, 195], - loc: { - start: { - line: 12, - column: 7, - }, - end: { - line: 13, - column: 0, - }, - }, - parts: [], - }, -]; diff --git a/src/tokenizer/__tests__/__output__/attributes-empty.ts b/src/tokenizer/__tests__/__output__/attributes-empty.ts deleted file mode 100644 index b764c72..0000000 --- a/src/tokenizer/__tests__/__output__/attributes-empty.ts +++ /dev/null @@ -1,160 +0,0 @@ -import { TokenTypes } from "../../../constants"; -import { AnyToken } from "../../../types"; - -const OUTPUT: AnyToken[] = [ - { - type: TokenTypes.OpenTagStart, - value: "", - range: [6, 7], - loc: { - start: { - line: 1, - column: 6, - }, - end: { - line: 1, - column: 7, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n some text\n\n ", - range: [7, 23], - loc: { - start: { - line: 1, - column: 7, - }, - end: { - line: 4, - column: 2, - }, - }, - parts: [], - }, - { - type: TokenTypes.OpenTagStart, - value: "", - range: [42, 43], - loc: { - start: { - line: 6, - column: 2, - }, - end: { - line: 6, - column: 3, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n custom element\n text\n ", - range: [43, 74], - loc: { - start: { - line: 6, - column: 3, - }, - end: { - line: 9, - column: 2, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseTag, - value: "", - range: [74, 91], - loc: { - start: { - line: 9, - column: 2, - }, - end: { - line: 9, - column: 19, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n", - range: [91, 92], - loc: { - start: { - line: 9, - column: 19, - }, - end: { - line: 10, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseTag, - value: "", - range: [92, 99], - loc: { - start: { - line: 10, - column: 0, - }, - end: { - line: 10, - column: 7, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n", - range: [99, 100], - loc: { - start: { - line: 10, - column: 7, - }, - end: { - line: 11, - column: 0, - }, - }, - parts: [], - }, -]; -export default OUTPUT; diff --git a/src/tokenizer/__tests__/__output__/attributes-multiline-crlf.ts b/src/tokenizer/__tests__/__output__/attributes-multiline-crlf.ts deleted file mode 100644 index 0420c8c..0000000 --- a/src/tokenizer/__tests__/__output__/attributes-multiline-crlf.ts +++ /dev/null @@ -1,253 +0,0 @@ -import { TokenTypes } from "../../../constants"; -import { AnyToken } from "../../../types"; - -const OUTPUT: AnyToken[] = [ - { - type: TokenTypes.OpenTagStart, - range: [0, 4], - loc: { - start: { - column: 0, - line: 1, - }, - end: { - column: 4, - line: 1, - }, - }, - value: "", - range: [41, 42], - loc: { - start: { - line: 5, - column: 0, - }, - end: { - line: 5, - column: 1, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\r\n", - range: [42, 44], - loc: { - start: { - line: 5, - column: 1, - }, - end: { - line: 6, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseTag, - value: "", - range: [44, 50], - loc: { - start: { - line: 6, - column: 0, - }, - end: { - line: 6, - column: 6, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\r\n", - range: [50, 52], - loc: { - start: { - line: 6, - column: 6, - }, - end: { - line: 7, - column: 0, - }, - }, - parts: [], - }, -]; -export default OUTPUT; diff --git a/src/tokenizer/__tests__/__output__/attributes-quote.ts b/src/tokenizer/__tests__/__output__/attributes-quote.ts deleted file mode 100644 index b00812e..0000000 --- a/src/tokenizer/__tests__/__output__/attributes-quote.ts +++ /dev/null @@ -1,623 +0,0 @@ -import { TokenTypes } from "../../../constants"; -import { AnyToken } from "../../../types"; - -const OUTPUT: AnyToken[] = [ - { - type: TokenTypes.OpenTagStart, - value: "", - range: [4, 5], - loc: { - start: { - line: 1, - column: 4, - }, - end: { - line: 1, - column: 5, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n ", - range: [5, 8], - loc: { - start: { - line: 1, - column: 5, - }, - end: { - line: 2, - column: 2, - }, - }, - parts: [], - }, - { - type: TokenTypes.OpenTagStart, - value: "", - range: [44, 54], - loc: { - start: { - line: 2, - column: 38, - }, - end: { - line: 2, - column: 48, - }, - }, - parts: [], - }, - { - type: TokenTypes.AttributeValueWrapperEnd, - value: '"', - range: [54, 55], - loc: { - start: { - line: 2, - column: 48, - }, - end: { - line: 2, - column: 49, - }, - }, - }, - { - type: TokenTypes.OpenTagEnd, - value: ">", - range: [55, 56], - loc: { - start: { - line: 2, - column: 49, - }, - end: { - line: 2, - column: 50, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n some text\n\n ", - range: [56, 76], - loc: { - start: { - line: 2, - column: 50, - }, - end: { - line: 5, - column: 4, - }, - }, - parts: [], - }, - { - type: TokenTypes.OpenTagStart, - value: "", - range: [80, 81], - loc: { - start: { - line: 5, - column: 8, - }, - end: { - line: 5, - column: 9, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n another text\n\n ", - range: [81, 108], - loc: { - start: { - line: 5, - column: 9, - }, - end: { - line: 8, - column: 6, - }, - }, - parts: [], - }, - { - type: TokenTypes.OpenTagStart, - value: "test", - range: [145, 157], - loc: { - start: { - line: 9, - column: 21, - }, - end: { - line: 9, - column: 33, - }, - }, - parts: [], - }, - { - type: TokenTypes.AttributeValueWrapperEnd, - value: '"', - range: [157, 158], - loc: { - start: { - line: 9, - column: 33, - }, - end: { - line: 9, - column: 34, - }, - }, - }, - { - type: TokenTypes.AttributeKey, - value: "with-spaces", - range: [167, 178], - loc: { - start: { - line: 10, - column: 8, - }, - end: { - line: 10, - column: 19, - }, - }, - parts: [], - }, - { - type: TokenTypes.AttributeAssignment, - value: "=", - range: [181, 182], - loc: { - start: { - line: 10, - column: 22, - }, - end: { - line: 10, - column: 23, - }, - }, - }, - { - type: TokenTypes.AttributeValueWrapperStart, - value: '"', - range: [184, 185], - loc: { - start: { - line: 10, - column: 25, - }, - end: { - line: 10, - column: 26, - }, - }, - }, - { - type: TokenTypes.AttributeValue, - value: "spaces test", - range: [185, 196], - loc: { - start: { - line: 10, - column: 26, - }, - end: { - line: 10, - column: 37, - }, - }, - parts: [], - }, - { - type: TokenTypes.AttributeValueWrapperEnd, - value: '"', - range: [196, 197], - loc: { - start: { - line: 10, - column: 37, - }, - end: { - line: 10, - column: 38, - }, - }, - }, - { - type: TokenTypes.OpenTagEnd, - value: ">", - range: [204, 205], - loc: { - start: { - line: 11, - column: 6, - }, - end: { - line: 11, - column: 7, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n custom element\n text\n ", - range: [205, 248], - loc: { - start: { - line: 11, - column: 7, - }, - end: { - line: 14, - column: 6, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseTag, - value: "", - range: [248, 265], - loc: { - start: { - line: 14, - column: 6, - }, - end: { - line: 14, - column: 23, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n ", - range: [265, 270], - loc: { - start: { - line: 14, - column: 23, - }, - end: { - line: 15, - column: 4, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseTag, - value: "", - range: [270, 276], - loc: { - start: { - line: 15, - column: 4, - }, - end: { - line: 15, - column: 10, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n ", - range: [276, 279], - loc: { - start: { - line: 15, - column: 10, - }, - end: { - line: 16, - column: 2, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseTag, - value: "", - range: [279, 286], - loc: { - start: { - line: 16, - column: 2, - }, - end: { - line: 16, - column: 9, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n", - range: [286, 287], - loc: { - start: { - line: 16, - column: 9, - }, - end: { - line: 17, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseTag, - value: "", - range: [287, 293], - loc: { - start: { - line: 17, - column: 0, - }, - end: { - line: 17, - column: 6, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n", - range: [293, 294], - loc: { - start: { - line: 17, - column: 6, - }, - end: { - line: 18, - column: 0, - }, - }, - parts: [], - }, -]; - -export default OUTPUT; diff --git a/src/tokenizer/__tests__/__output__/comments.ts b/src/tokenizer/__tests__/__output__/comments.ts deleted file mode 100644 index ddb1131..0000000 --- a/src/tokenizer/__tests__/__output__/comments.ts +++ /dev/null @@ -1,471 +0,0 @@ -import { TokenTypes } from "../../../constants"; -import { AnyToken } from "../../../types"; - -const OUTPUT: AnyToken[] = [ - { - type: TokenTypes.CommentOpen, - value: "", - range: [18, 21], - loc: { - start: { - column: 18, - line: 1, - }, - end: { - line: 1, - column: 21, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n\n", - range: [21, 23], - loc: { - start: { - line: 1, - column: 21, - }, - end: { - line: 3, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.OpenTagStart, - value: "", - range: [27, 28], - loc: { - start: { - line: 3, - column: 4, - }, - end: { - line: 3, - column: 5, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n ", - range: [28, 31], - loc: { - start: { - line: 3, - column: 5, - }, - end: { - line: 4, - column: 2, - }, - }, - parts: [], - }, - { - type: TokenTypes.OpenTagStart, - value: "", - range: [36, 37], - loc: { - start: { - line: 4, - column: 7, - }, - end: { - line: 4, - column: 8, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n ", - range: [37, 42], - loc: { - start: { - line: 4, - column: 8, - }, - end: { - line: 5, - column: 4, - }, - }, - parts: [], - }, - { - type: TokenTypes.CommentOpen, - value: "", - range: [57, 60], - loc: { - start: { - line: 5, - column: 19, - }, - end: { - line: 5, - column: 22, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n ", - range: [60, 63], - loc: { - start: { - line: 5, - column: 22, - }, - end: { - line: 6, - column: 2, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseTag, - value: "", - range: [63, 70], - loc: { - start: { - line: 6, - column: 2, - }, - end: { - line: 6, - column: 9, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n\n ", - range: [70, 74], - loc: { - start: { - line: 6, - column: 9, - }, - end: { - line: 8, - column: 2, - }, - }, - parts: [], - }, - { - type: TokenTypes.CommentOpen, - value: "", - range: [98, 101], - loc: { - start: { - line: 13, - column: 2, - }, - end: { - line: 13, - column: 5, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n", - range: [101, 102], - loc: { - start: { - line: 13, - column: 5, - }, - end: { - line: 14, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseTag, - value: "", - range: [102, 108], - loc: { - start: { - line: 14, - column: 0, - }, - end: { - line: 14, - column: 6, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n\n", - range: [108, 110], - loc: { - start: { - line: 14, - column: 6, - }, - end: { - line: 16, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.CommentOpen, - value: "", - range: [132, 135], - loc: { - start: { - line: 18, - column: 8, - }, - end: { - line: 18, - column: 11, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n\n", - range: [135, 137], - loc: { - start: { - line: 18, - column: 11, - }, - end: { - line: 20, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.CommentOpen, - value: "", - range: [171, 174], - loc: { - start: { - line: 20, - column: 34, - }, - end: { - line: 20, - column: 37, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n", - range: [174, 175], - loc: { - start: { - line: 20, - column: 37, - }, - end: { - line: 21, - column: 0, - }, - }, - parts: [], - }, -]; - -export default OUTPUT; diff --git a/src/tokenizer/__tests__/__output__/custom-elements.ts b/src/tokenizer/__tests__/__output__/custom-elements.ts deleted file mode 100644 index 30adf5a..0000000 --- a/src/tokenizer/__tests__/__output__/custom-elements.ts +++ /dev/null @@ -1,161 +0,0 @@ -import { TokenTypes } from "../../../constants"; -import { AnyToken } from "../../../types"; - -const OUTPUT: AnyToken[] = [ - { - type: TokenTypes.OpenTagStart, - value: "", - range: [11, 12], - loc: { - start: { - line: 1, - column: 11, - }, - end: { - line: 1, - column: 12, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n some text\n\n ", - range: [12, 28], - loc: { - start: { - column: 12, - line: 1, - }, - end: { - line: 4, - column: 2, - }, - }, - parts: [], - }, - { - type: TokenTypes.OpenTagStart, - value: "", - range: [39, 40], - loc: { - start: { - line: 4, - column: 13, - }, - end: { - line: 4, - column: 14, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n another text\n ", - range: [40, 60], - loc: { - start: { - column: 14, - line: 4, - }, - end: { - line: 6, - column: 2, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseTag, - value: "", - range: [60, 73], - loc: { - start: { - line: 6, - column: 2, - }, - end: { - line: 6, - column: 15, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n", - range: [73, 74], - loc: { - start: { - line: 6, - column: 15, - }, - end: { - line: 7, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseTag, - value: "", - range: [74, 87], - loc: { - start: { - column: 0, - line: 7, - }, - end: { - line: 7, - column: 13, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n", - range: [87, 88], - loc: { - start: { - line: 7, - column: 13, - }, - end: { - line: 8, - column: 0, - }, - }, - parts: [], - }, -]; - -export default OUTPUT; diff --git a/src/tokenizer/__tests__/__output__/custom-tag-raw-content.ts b/src/tokenizer/__tests__/__output__/custom-tag-raw-content.ts deleted file mode 100644 index 3bd1882..0000000 --- a/src/tokenizer/__tests__/__output__/custom-tag-raw-content.ts +++ /dev/null @@ -1,161 +0,0 @@ -import { TokenTypes } from "../../../constants"; -import { AnyToken } from "../../../types"; - -const OUTPUT: AnyToken[] = [ - { - type: TokenTypes.OpenTagStart, - value: "", - range: [18, 19], - loc: { - start: { - column: 18, - line: 1, - }, - end: { - line: 1, - column: 19, - }, - }, - }, - { - type: TokenTypes.RawContent, - value: ` -# Hello, world! - -\`\`\`cpp{4-6,9} -#include - -class Example { - Example() { - std::cout << "Hello, world!" << std::endl; - } - - Example(std::string name) { - std::cout << "Hello, " << name << std::endl; - } -}; -\`\`\` -`, - range: [19, 260], - loc: { - start: { - column: 19, - line: 1, - }, - end: { - line: 17, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseTag, - value: "", - range: [260, 271], - loc: { - start: { - column: 0, - line: 17, - }, - end: { - line: 17, - column: 11, - }, - }, - }, -]; - -export default OUTPUT; diff --git a/src/tokenizer/__tests__/__output__/doctypes.ts b/src/tokenizer/__tests__/__output__/doctypes.ts deleted file mode 100644 index 2c0d6fe..0000000 --- a/src/tokenizer/__tests__/__output__/doctypes.ts +++ /dev/null @@ -1,642 +0,0 @@ -import { TokenTypes } from "../../../constants"; -import { AnyToken } from "../../../types"; - -const OUTPUT: AnyToken[] = [ - { - type: TokenTypes.DoctypeOpen, - value: "", - range: [9, 10], - loc: { - start: { - line: 1, - column: 9, - }, - end: { - line: 1, - column: 10, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n\n", - range: [10, 12], - loc: { - start: { - line: 1, - column: 10, - }, - end: { - line: 3, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.DoctypeOpen, - value: "", - range: [21, 22], - loc: { - start: { - line: 3, - column: 9, - }, - end: { - line: 3, - column: 10, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n\n", - range: [22, 24], - loc: { - start: { - line: 3, - column: 10, - }, - end: { - line: 5, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.DoctypeOpen, - value: "", - range: [65, 66], - loc: { - start: { - line: 5, - column: 41, - }, - end: { - line: 5, - column: 42, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n\n", - range: [66, 68], - loc: { - start: { - line: 5, - column: 42, - }, - end: { - line: 7, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.DoctypeOpen, - value: "", - range: [89, 90], - loc: { - start: { - line: 7, - column: 21, - }, - end: { - line: 7, - column: 22, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n\n", - range: [90, 92], - loc: { - start: { - line: 7, - column: 22, - }, - end: { - line: 9, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.DoctypeOpen, - value: "", - range: [192, 193], - loc: { - start: { - line: 9, - column: 100, - }, - end: { - line: 9, - column: 101, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n\n", - range: [193, 195], - loc: { - start: { - line: 9, - column: 101, - }, - end: { - line: 11, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.DoctypeOpen, - value: "", - range: [302, 303], - loc: { - start: { - line: 15, - column: 0, - }, - end: { - line: 15, - column: 1, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n", - range: [303, 304], - loc: { - start: { - line: 15, - column: 1, - }, - end: { - line: 16, - column: 0, - }, - }, - parts: [], - }, -]; -export default OUTPUT; diff --git a/src/tokenizer/__tests__/__output__/empty.ts b/src/tokenizer/__tests__/__output__/empty.ts deleted file mode 100644 index d6d1738..0000000 --- a/src/tokenizer/__tests__/__output__/empty.ts +++ /dev/null @@ -1 +0,0 @@ -export default []; diff --git a/src/tokenizer/__tests__/__output__/nested-tags.ts b/src/tokenizer/__tests__/__output__/nested-tags.ts deleted file mode 100644 index ca92fd7..0000000 --- a/src/tokenizer/__tests__/__output__/nested-tags.ts +++ /dev/null @@ -1,238 +0,0 @@ -import { TokenTypes } from "../../../constants"; -import { AnyToken } from "../../../types"; - -const OUTPUT: AnyToken[] = [ - { - type: TokenTypes.OpenTagStart, - value: "", - range: [4, 5], - loc: { - start: { - line: 1, - column: 4, - }, - end: { - line: 1, - column: 5, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n ", - range: [5, 8], - loc: { - start: { - line: 1, - column: 5, - }, - end: { - line: 2, - column: 2, - }, - }, - parts: [], - }, - { - type: TokenTypes.OpenTagStart, - value: "", - range: [13, 14], - loc: { - start: { - line: 2, - column: 7, - }, - end: { - line: 2, - column: 8, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n some text\n\n ", - range: [14, 34], - loc: { - start: { - line: 2, - column: 8, - }, - end: { - line: 5, - column: 4, - }, - }, - parts: [], - }, - { - type: TokenTypes.OpenTagStart, - value: "", - range: [39, 40], - loc: { - start: { - line: 5, - column: 9, - }, - end: { - line: 5, - column: 10, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n another text\n ", - range: [40, 64], - loc: { - start: { - column: 10, - line: 5, - }, - end: { - line: 7, - column: 4, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseTag, - value: "", - range: [64, 71], - loc: { - start: { - line: 7, - column: 4, - }, - end: { - line: 7, - column: 11, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n ", - range: [71, 74], - loc: { - start: { - line: 7, - column: 11, - }, - end: { - line: 8, - column: 2, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseTag, - value: "", - range: [74, 81], - loc: { - start: { - line: 8, - column: 2, - }, - end: { - line: 8, - column: 9, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n", - range: [81, 82], - loc: { - start: { - line: 8, - column: 9, - }, - end: { - line: 9, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseTag, - value: "", - range: [82, 88], - loc: { - start: { - line: 9, - column: 0, - }, - end: { - line: 9, - column: 6, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n", - range: [88, 89], - loc: { - start: { - line: 9, - column: 6, - }, - end: { - line: 10, - column: 0, - }, - }, - parts: [], - }, -]; - -export default OUTPUT; diff --git a/src/tokenizer/__tests__/__output__/opening-closing-text.ts b/src/tokenizer/__tests__/__output__/opening-closing-text.ts deleted file mode 100644 index 993d998..0000000 --- a/src/tokenizer/__tests__/__output__/opening-closing-text.ts +++ /dev/null @@ -1,84 +0,0 @@ -import { TokenTypes } from "../../../constants"; -import { AnyToken } from "../../../types"; - -const OUTPUT: AnyToken[] = [ - { - type: TokenTypes.Text, - value: "opening text\n\n", - range: [0, 14], - loc: { - start: { - line: 1, - column: 0, - }, - end: { - line: 3, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.OpenTagStart, - value: "", - range: [18, 19], - loc: { - start: { - line: 3, - column: 4, - }, - end: { - line: 3, - column: 5, - }, - }, - }, - { - type: TokenTypes.CloseTag, - value: "", - range: [19, 25], - loc: { - start: { - line: 3, - column: 5, - }, - end: { - line: 3, - column: 11, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n\nclosing text\n", - range: [25, 40], - loc: { - start: { - line: 3, - column: 11, - }, - end: { - line: 6, - column: 0, - }, - }, - parts: [], - }, -]; - -export default OUTPUT; diff --git a/src/tokenizer/__tests__/__output__/script-elements-attributes.ts b/src/tokenizer/__tests__/__output__/script-elements-attributes.ts deleted file mode 100644 index 340e095..0000000 --- a/src/tokenizer/__tests__/__output__/script-elements-attributes.ts +++ /dev/null @@ -1,655 +0,0 @@ -import { TokenTypes } from "../../../constants"; -import { AnyToken } from "../../../types"; - -const OUTPUT: AnyToken[] = [ - { - type: TokenTypes.OpenTagStart, - value: "", - range: [4, 5], - loc: { - start: { - line: 1, - column: 4, - }, - end: { - line: 1, - column: 5, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n dummy content\n\n ", - range: [5, 25], - loc: { - start: { - line: 1, - column: 5, - }, - end: { - line: 4, - column: 2, - }, - }, - parts: [], - }, - { - type: TokenTypes.OpenScriptTagStart, - value: "", - range: [79, 80], - loc: { - start: { - line: 4, - column: 56, - }, - end: { - line: 4, - column: 57, - }, - }, - }, - { - type: TokenTypes.ScriptTagContent, - value: "\n console.log('test 1')\n ", - range: [80, 109], - loc: { - start: { - line: 4, - column: 57, - }, - end: { - line: 6, - column: 2, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseScriptTag, - value: "", - range: [109, 118], - loc: { - start: { - line: 6, - column: 2, - }, - end: { - line: 6, - column: 11, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n\n ", - range: [118, 122], - loc: { - start: { - line: 6, - column: 11, - }, - end: { - line: 8, - column: 2, - }, - }, - parts: [], - }, - { - type: TokenTypes.OpenScriptTagStart, - value: "", - range: [169, 170], - loc: { - start: { - column: 2, - line: 11, - }, - end: { - line: 11, - column: 3, - }, - }, - }, - { - type: TokenTypes.ScriptTagContent, - value: "\n let a = '
'\n console.log(a)\n ", - range: [170, 218], - loc: { - start: { - column: 3, - line: 11, - }, - end: { - line: 14, - column: 2, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseScriptTag, - value: "", - range: [218, 227], - loc: { - start: { - column: 2, - line: 14, - }, - end: { - line: 14, - column: 11, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n", - range: [227, 228], - loc: { - start: { - line: 14, - column: 11, - }, - end: { - line: 15, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseTag, - value: "", - range: [228, 234], - loc: { - start: { - line: 15, - column: 0, - }, - end: { - line: 15, - column: 6, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n\n", - range: [234, 236], - loc: { - start: { - line: 15, - column: 6, - }, - end: { - line: 17, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.OpenScriptTagStart, - value: "", - range: [272, 273], - loc: { - start: { - line: 17, - column: 36, - }, - end: { - line: 17, - column: 37, - }, - }, - }, - { - type: TokenTypes.ScriptTagContent, - value: "\n console.log('test 2')\n", - range: [273, 298], - loc: { - start: { - line: 17, - column: 37, - }, - end: { - line: 19, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseScriptTag, - value: "", - range: [298, 307], - loc: { - start: { - line: 19, - column: 0, - }, - end: { - line: 19, - column: 9, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n", - range: [307, 308], - loc: { - start: { - line: 19, - column: 9, - }, - end: { - line: 20, - column: 0, - }, - }, - parts: [], - }, -]; - -export default OUTPUT; diff --git a/src/tokenizer/__tests__/__output__/script-elements.ts b/src/tokenizer/__tests__/__output__/script-elements.ts deleted file mode 100644 index 2103153..0000000 --- a/src/tokenizer/__tests__/__output__/script-elements.ts +++ /dev/null @@ -1,176 +0,0 @@ -import { TokenTypes } from "../../../constants"; -import { AnyToken } from "../../../types"; - -const OUTPUT: AnyToken[] = [ - { - type: TokenTypes.Text, - value: "opening text\n\n", - range: [0, 14], - loc: { - start: { - line: 1, - column: 0, - }, - end: { - line: 3, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.OpenTagStart, - value: "", - range: [18, 19], - loc: { - start: { - line: 3, - column: 4, - }, - end: { - line: 3, - column: 5, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n ", - range: [19, 22], - loc: { - start: { - line: 3, - column: 5, - }, - end: { - line: 4, - column: 2, - }, - }, - parts: [], - }, - { - type: TokenTypes.OpenScriptTagStart, - value: "", - range: [29, 30], - loc: { - start: { - line: 4, - column: 9, - }, - end: { - line: 4, - column: 10, - }, - }, - }, - { - type: TokenTypes.ScriptTagContent, - value: "\n console.log('')\n ", - range: [30, 53], - loc: { - start: { - line: 4, - column: 10, - }, - end: { - line: 6, - column: 2, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseScriptTag, - value: "", - range: [53, 62], - loc: { - start: { - line: 6, - column: 2, - }, - end: { - line: 6, - column: 11, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n", - range: [62, 63], - loc: { - start: { - line: 6, - column: 11, - }, - end: { - line: 7, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseTag, - value: "", - range: [63, 69], - loc: { - start: { - line: 7, - column: 0, - }, - end: { - line: 7, - column: 6, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n\nclosing text\n", - range: [69, 84], - loc: { - start: { - line: 7, - column: 6, - }, - end: { - line: 10, - column: 0, - }, - }, - parts: [], - }, -]; -export default OUTPUT; diff --git a/src/tokenizer/__tests__/__output__/style-elements-attributes.ts b/src/tokenizer/__tests__/__output__/style-elements-attributes.ts deleted file mode 100644 index fc02295..0000000 --- a/src/tokenizer/__tests__/__output__/style-elements-attributes.ts +++ /dev/null @@ -1,500 +0,0 @@ -import { TokenTypes } from "../../../constants"; -import { AnyToken } from "../../../types"; - -const OUTPUT: AnyToken[] = [ - { - type: TokenTypes.OpenStyleTagStart, - value: "", - range: [41, 42], - loc: { - start: { - line: 1, - column: 41, - }, - end: { - line: 1, - column: 42, - }, - }, - }, - { - type: TokenTypes.StyleTagContent, - value: "\n body {\n background-color: white;\n }\n", - range: [42, 85], - loc: { - start: { - line: 1, - column: 42, - }, - end: { - line: 5, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseStyleTag, - value: "", - range: [85, 93], - loc: { - start: { - line: 5, - column: 0, - }, - end: { - line: 5, - column: 8, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n\n", - range: [93, 95], - loc: { - start: { - column: 8, - line: 5, - }, - end: { - line: 7, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.OpenTagStart, - value: "", - range: [99, 100], - loc: { - start: { - line: 7, - column: 4, - }, - end: { - line: 7, - column: 5, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n ", - range: [100, 103], - loc: { - start: { - column: 5, - line: 7, - }, - end: { - line: 8, - column: 2, - }, - }, - parts: [], - }, - { - type: TokenTypes.OpenStyleTagStart, - value: "", - range: [163, 164], - loc: { - start: { - line: 13, - column: 2, - }, - end: { - line: 13, - column: 3, - }, - }, - }, - { - type: TokenTypes.StyleTagContent, - value: "\n body {\n background-color: red;\n }\n ", - range: [164, 213], - loc: { - start: { - line: 13, - column: 3, - }, - end: { - line: 17, - column: 2, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseStyleTag, - value: "", - range: [213, 221], - loc: { - start: { - line: 17, - column: 2, - }, - end: { - line: 17, - column: 10, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n", - range: [221, 222], - loc: { - start: { - line: 17, - column: 10, - }, - end: { - line: 18, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseTag, - value: "", - range: [222, 228], - loc: { - start: { - line: 18, - column: 0, - }, - end: { - line: 18, - column: 6, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n", - range: [228, 229], - loc: { - start: { - line: 18, - column: 6, - }, - end: { - line: 19, - column: 0, - }, - }, - parts: [], - }, -]; -export default OUTPUT; diff --git a/src/tokenizer/__tests__/__output__/style-elements.ts b/src/tokenizer/__tests__/__output__/style-elements.ts deleted file mode 100644 index c68f288..0000000 --- a/src/tokenizer/__tests__/__output__/style-elements.ts +++ /dev/null @@ -1,254 +0,0 @@ -import { TokenTypes } from "../../../constants"; -import { AnyToken } from "../../../types"; - -const OUTPUT: AnyToken[] = [ - { - type: TokenTypes.Text, - value: "opening text\n\n", - range: [0, 14], - loc: { - start: { - line: 1, - column: 0, - }, - end: { - line: 3, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.OpenStyleTagStart, - value: "", - range: [20, 21], - loc: { - start: { - line: 3, - column: 6, - }, - end: { - line: 3, - column: 7, - }, - }, - }, - { - type: TokenTypes.StyleTagContent, - value: "\n body {\n background-color: white;\n }\n", - range: [21, 64], - loc: { - start: { - column: 7, - line: 3, - }, - end: { - line: 7, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseStyleTag, - value: "", - range: [64, 72], - loc: { - start: { - column: 0, - line: 7, - }, - end: { - column: 8, - line: 7, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n\n", - range: [72, 74], - loc: { - start: { - column: 8, - line: 7, - }, - end: { - line: 9, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.OpenTagStart, - value: "", - range: [78, 79], - loc: { - start: { - column: 4, - line: 9, - }, - end: { - line: 9, - column: 5, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n ", - range: [79, 82], - loc: { - start: { - line: 9, - column: 5, - }, - end: { - line: 10, - column: 2, - }, - }, - parts: [], - }, - { - type: TokenTypes.OpenStyleTagStart, - value: "", - range: [88, 89], - loc: { - start: { - line: 10, - column: 8, - }, - end: { - line: 10, - column: 9, - }, - }, - }, - { - type: TokenTypes.StyleTagContent, - value: "\n body {\n background-color: red;\n }\n ", - range: [89, 138], - loc: { - start: { - column: 9, - line: 10, - }, - end: { - line: 14, - column: 2, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseStyleTag, - value: "", - range: [138, 146], - loc: { - start: { - line: 14, - column: 2, - }, - end: { - line: 14, - column: 10, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n", - range: [146, 147], - loc: { - start: { - line: 14, - column: 10, - }, - end: { - line: 15, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseTag, - value: "", - range: [147, 153], - loc: { - start: { - line: 15, - column: 0, - }, - end: { - line: 15, - column: 6, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n\nclosing text\n", - range: [153, 168], - loc: { - start: { - column: 6, - line: 15, - }, - end: { - line: 18, - column: 0, - }, - }, - parts: [], - }, -]; - -export default OUTPUT; diff --git a/src/tokenizer/__tests__/__output__/svg.ts b/src/tokenizer/__tests__/__output__/svg.ts deleted file mode 100644 index 734ca24..0000000 --- a/src/tokenizer/__tests__/__output__/svg.ts +++ /dev/null @@ -1,159 +0,0 @@ -import { TokenTypes } from "../../../constants"; -import { AnyToken } from "../../../types"; - -const OUTPUT: AnyToken[] = [ - { - type: TokenTypes.OpenTagStart, - value: "", - range: [39, 40], - loc: { - end: { - column: 40, - line: 1, - }, - start: { - column: 39, - line: 1, - }, - }, - }, - { - type: TokenTypes.OpenTagStart, - value: "", - range: [48, 50], - loc: { - end: { - column: 50, - line: 1, - }, - start: { - column: 48, - line: 1, - }, - }, - }, - { - type: TokenTypes.CloseTag, - value: "", - range: [50, 56], - loc: { - end: { - column: 56, - line: 1, - }, - start: { - column: 50, - line: 1, - }, - }, - }, -]; - -export default OUTPUT; diff --git a/src/tokenizer/__tests__/__output__/tags-register.ts b/src/tokenizer/__tests__/__output__/tags-register.ts deleted file mode 100644 index c720254..0000000 --- a/src/tokenizer/__tests__/__output__/tags-register.ts +++ /dev/null @@ -1,818 +0,0 @@ -import { TokenTypes } from "../../../constants"; -import { AnyToken } from "../../../types"; - -const OUTPUT: AnyToken[] = [ - { - type: TokenTypes.OpenTagStart, - value: "", - range: [4, 5], - loc: { - start: { - line: 1, - column: 4, - }, - end: { - line: 1, - column: 5, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n", - range: [5, 6], - loc: { - start: { - line: 1, - column: 5, - }, - end: { - line: 2, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseTag, - value: "", - range: [6, 12], - loc: { - start: { - line: 2, - column: 0, - }, - end: { - line: 2, - column: 6, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n\n", - range: [12, 14], - loc: { - start: { - line: 2, - column: 6, - }, - end: { - line: 4, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.OpenTagStart, - value: "", - range: [18, 19], - loc: { - start: { - line: 4, - column: 4, - }, - end: { - line: 4, - column: 5, - }, - }, - }, - { - type: TokenTypes.CloseTag, - value: "", - range: [19, 25], - loc: { - start: { - line: 4, - column: 5, - }, - end: { - line: 4, - column: 11, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n\n", - range: [25, 27], - loc: { - start: { - line: 4, - column: 11, - }, - end: { - line: 6, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.OpenTagStart, - value: "", - range: [32, 33], - loc: { - start: { - line: 6, - column: 5, - }, - end: { - line: 6, - column: 6, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n", - range: [33, 34], - loc: { - start: { - line: 6, - column: 6, - }, - end: { - line: 7, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseTag, - value: "", - range: [34, 41], - loc: { - start: { - line: 7, - column: 0, - }, - end: { - line: 7, - column: 7, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n\n", - range: [41, 43], - loc: { - start: { - line: 7, - column: 7, - }, - end: { - line: 9, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.OpenTagStart, - value: "", - range: [48, 49], - loc: { - start: { - line: 9, - column: 5, - }, - end: { - line: 9, - column: 6, - }, - }, - }, - { - type: TokenTypes.CloseTag, - value: "", - range: [49, 56], - loc: { - start: { - line: 9, - column: 6, - }, - end: { - line: 9, - column: 13, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n\n", - range: [56, 58], - loc: { - start: { - line: 9, - column: 13, - }, - end: { - line: 11, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.OpenScriptTagStart, - value: "", - range: [65, 66], - loc: { - start: { - line: 11, - column: 7, - }, - end: { - line: 11, - column: 8, - }, - }, - }, - { - type: TokenTypes.CloseScriptTag, - value: "", - range: [66, 75], - loc: { - start: { - column: 8, - line: 11, - }, - end: { - line: 11, - column: 17, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n", - range: [75, 76], - loc: { - start: { - line: 11, - column: 17, - }, - end: { - line: 12, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.OpenScriptTagStart, - value: "", - range: [83, 84], - loc: { - start: { - line: 12, - column: 7, - }, - end: { - line: 12, - column: 8, - }, - }, - }, - { - type: TokenTypes.ScriptTagContent, - value: "\n", - range: [84, 85], - loc: { - start: { - line: 12, - column: 8, - }, - end: { - line: 13, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseScriptTag, - value: "", - range: [85, 94], - loc: { - start: { - line: 13, - column: 0, - }, - end: { - line: 13, - column: 9, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n", - range: [94, 95], - loc: { - start: { - line: 13, - column: 9, - }, - end: { - line: 14, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.OpenScriptTagStart, - value: "", - range: [102, 103], - loc: { - start: { - line: 14, - column: 7, - }, - end: { - line: 14, - column: 8, - }, - }, - }, - { - type: TokenTypes.CloseScriptTag, - value: "", - range: [103, 112], - loc: { - start: { - line: 14, - column: 8, - }, - end: { - line: 14, - column: 17, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n", - range: [112, 113], - loc: { - start: { - column: 17, - line: 14, - }, - end: { - line: 15, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.OpenScriptTagStart, - value: "", - range: [120, 121], - loc: { - start: { - line: 15, - column: 7, - }, - end: { - line: 15, - column: 8, - }, - }, - }, - { - type: TokenTypes.ScriptTagContent, - value: "\n", - range: [121, 122], - loc: { - start: { - line: 15, - column: 8, - }, - end: { - line: 16, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseScriptTag, - value: "", - range: [122, 131], - loc: { - start: { - line: 16, - column: 0, - }, - end: { - line: 16, - column: 9, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n\n", - range: [131, 133], - loc: { - start: { - line: 16, - column: 9, - }, - end: { - line: 18, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.OpenStyleTagStart, - value: "", - range: [139, 140], - loc: { - start: { - line: 18, - column: 6, - }, - end: { - line: 18, - column: 7, - }, - }, - }, - { - type: TokenTypes.CloseStyleTag, - value: "", - range: [140, 148], - loc: { - start: { - line: 18, - column: 7, - }, - end: { - line: 18, - column: 15, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n", - range: [148, 149], - loc: { - start: { - line: 18, - column: 15, - }, - end: { - line: 19, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.OpenStyleTagStart, - value: "", - range: [155, 156], - loc: { - start: { - line: 19, - column: 6, - }, - end: { - line: 19, - column: 7, - }, - }, - }, - { - type: TokenTypes.StyleTagContent, - value: "\n", - range: [156, 157], - loc: { - start: { - line: 19, - column: 7, - }, - end: { - line: 20, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.CloseStyleTag, - value: "", - range: [157, 165], - loc: { - start: { - line: 20, - column: 0, - }, - end: { - line: 20, - column: 8, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n", - range: [165, 166], - loc: { - start: { - line: 20, - column: 8, - }, - end: { - line: 21, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.OpenStyleTagStart, - value: "", - range: [172, 173], - loc: { - start: { - line: 21, - column: 6, - }, - end: { - line: 21, - column: 7, - }, - }, - }, - { - type: TokenTypes.CloseStyleTag, - value: "", - range: [173, 181], - loc: { - start: { - line: 21, - column: 7, - }, - end: { - line: 21, - column: 15, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n", - range: [181, 182], - loc: { - start: { - line: 21, - column: 15, - }, - end: { - line: 22, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.OpenStyleTagStart, - value: "", - range: [188, 189], - loc: { - start: { - line: 22, - column: 6, - }, - end: { - line: 22, - column: 7, - }, - }, - }, - { - type: TokenTypes.CloseStyleTag, - value: "", - range: [189, 197], - loc: { - start: { - line: 22, - column: 7, - }, - end: { - line: 22, - column: 15, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n", - range: [197, 198], - loc: { - start: { - line: 22, - column: 15, - }, - end: { - line: 23, - column: 0, - }, - }, - parts: [], - }, -]; -export default OUTPUT; diff --git a/src/tokenizer/__tests__/__output__/templates-attributes-key-wrapper.ts b/src/tokenizer/__tests__/__output__/templates-attributes-key-wrapper.ts deleted file mode 100644 index 3be53ae..0000000 --- a/src/tokenizer/__tests__/__output__/templates-attributes-key-wrapper.ts +++ /dev/null @@ -1,110 +0,0 @@ -export default [ - { - loc: { - end: { - column: 4, - line: 1, - }, - start: { - column: 0, - line: 1, - }, - }, - range: [0, 4], - type: "OpenTagStart", - value: "", - }, - { - loc: { - end: { - column: 18, - line: 1, - }, - start: { - column: 12, - line: 1, - }, - }, - range: [12, 18], - type: "CloseTag", - value: "", - }, -]; diff --git a/src/tokenizer/__tests__/__output__/templates-attributes-key.ts b/src/tokenizer/__tests__/__output__/templates-attributes-key.ts deleted file mode 100644 index ab6b819..0000000 --- a/src/tokenizer/__tests__/__output__/templates-attributes-key.ts +++ /dev/null @@ -1,82 +0,0 @@ -export default [ - { - loc: { - end: { - column: 4, - line: 1, - }, - start: { - column: 0, - line: 1, - }, - }, - range: [0, 4], - type: "OpenTagStart", - value: "", - }, - { - loc: { - end: { - column: 18, - line: 1, - }, - start: { - column: 12, - line: 1, - }, - }, - range: [12, 18], - type: "CloseTag", - value: "", - }, -]; diff --git a/src/tokenizer/__tests__/__output__/templates-attributes-value-bare.ts b/src/tokenizer/__tests__/__output__/templates-attributes-value-bare.ts deleted file mode 100644 index 729b1d4..0000000 --- a/src/tokenizer/__tests__/__output__/templates-attributes-value-bare.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { TokenTypes } from "../../../constants"; -import { AnyToken } from "../../../types"; - -const OUTPUT: AnyToken[] = [ - { - type: TokenTypes.OpenTagStart, - value: "", - }, - { - type: TokenTypes.CloseTag, - range: [14, 20], - loc: { - start: { line: 1, column: 14 }, - end: { line: 1, column: 20 }, - }, - value: "", - }, -]; - -export default OUTPUT; diff --git a/src/tokenizer/__tests__/__output__/templates-attributes-value-wrapped-2.ts b/src/tokenizer/__tests__/__output__/templates-attributes-value-wrapped-2.ts deleted file mode 100644 index 5a41b4a..0000000 --- a/src/tokenizer/__tests__/__output__/templates-attributes-value-wrapped-2.ts +++ /dev/null @@ -1,122 +0,0 @@ -import { TokenTypes } from "../../../constants"; -import { AnyToken } from "../../../types"; - -const OUTPUT: AnyToken[] = [ - { - type: TokenTypes.OpenTagStart, - value: "", - }, - { - type: TokenTypes.CloseTag, - range: [33, 39], - loc: { - start: { line: 1, column: 33 }, - end: { line: 1, column: 39 }, - }, - value: "", - }, -]; - -export default OUTPUT; diff --git a/src/tokenizer/__tests__/__output__/templates-attributes-value-wrapped.ts b/src/tokenizer/__tests__/__output__/templates-attributes-value-wrapped.ts deleted file mode 100644 index 200fda3..0000000 --- a/src/tokenizer/__tests__/__output__/templates-attributes-value-wrapped.ts +++ /dev/null @@ -1,92 +0,0 @@ -import { TokenTypes } from "../../../constants"; -import { AnyToken } from "../../../types"; - -const OUTPUT: AnyToken[] = [ - { - type: TokenTypes.OpenTagStart, - value: "", - }, - { - type: TokenTypes.CloseTag, - range: [16, 22], - loc: { - start: { line: 1, column: 16 }, - end: { line: 1, column: 22 }, - }, - value: "", - }, -]; - -export default OUTPUT; diff --git a/src/tokenizer/__tests__/__output__/templates-comment.ts b/src/tokenizer/__tests__/__output__/templates-comment.ts deleted file mode 100644 index 2863acc..0000000 --- a/src/tokenizer/__tests__/__output__/templates-comment.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { TokenTypes } from "../../../constants"; -import { AnyToken } from "../../../types"; - -const OUTPUT: AnyToken[] = [ - { - type: TokenTypes.CommentOpen, - value: "", - range: [14, 17], - loc: { - start: { line: 1, column: 14 }, - end: { line: 1, column: 17 }, - }, - }, -]; -export default OUTPUT; diff --git a/src/tokenizer/__tests__/__output__/templates-content-end.ts b/src/tokenizer/__tests__/__output__/templates-content-end.ts deleted file mode 100644 index 4e3272c..0000000 --- a/src/tokenizer/__tests__/__output__/templates-content-end.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { TokenTypes } from "../../../constants"; -import { AnyToken } from "../../../types"; - -const OUTPUT: AnyToken[] = [ - { - loc: { - end: { - column: 10, - line: 1, - }, - start: { - column: 0, - line: 1, - }, - }, - range: [0, 10], - type: TokenTypes.Text, - value: "${content}", - parts: [ - { - loc: { - end: { - column: 10, - line: 1, - }, - start: { - column: 0, - line: 1, - }, - }, - range: [0, 10], - type: TokenTypes.Template, - value: "${content}", - partOf: TokenTypes.Text, - open: undefined, - close: undefined, - }, - ], - }, -]; -export default OUTPUT; diff --git a/src/tokenizer/__tests__/__output__/templates-data.ts b/src/tokenizer/__tests__/__output__/templates-data.ts deleted file mode 100644 index 37a1307..0000000 --- a/src/tokenizer/__tests__/__output__/templates-data.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { TokenTypes } from "../../../constants"; -import { AnyToken } from "../../../types"; - -const OUTPUT: AnyToken[] = [ - { - type: TokenTypes.OpenTagStart, - value: "", - range: [4, 5], - loc: { - start: { line: 1, column: 4 }, - end: { line: 1, column: 5 }, - }, - }, - { - type: TokenTypes.Text, - value: "${children}", - range: [5, 16], - loc: { - start: { line: 1, column: 5 }, - end: { line: 1, column: 16 }, - }, - parts: [ - { - type: TokenTypes.Template, - partOf: TokenTypes.Text, - value: "${children}", - range: [5, 16], - loc: { - start: { line: 1, column: 5 }, - end: { line: 1, column: 16 }, - }, - }, - ], - }, - { - type: TokenTypes.CloseTag, - value: "", - range: [16, 22], - loc: { - start: { line: 1, column: 16 }, - end: { line: 1, column: 22 }, - }, - }, -]; - -export default OUTPUT; diff --git a/src/tokenizer/__tests__/__output__/templates-script-content.ts b/src/tokenizer/__tests__/__output__/templates-script-content.ts deleted file mode 100644 index 9c02cb1..0000000 --- a/src/tokenizer/__tests__/__output__/templates-script-content.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { TokenTypes } from "../../../constants"; -import { AnyToken } from "../../../types"; - -const OUTPUT: AnyToken[] = [ - { - type: TokenTypes.OpenScriptTagStart, - value: "", - range: [7, 8], - loc: { - start: { line: 1, column: 7 }, - end: { line: 1, column: 8 }, - }, - }, - { - type: TokenTypes.ScriptTagContent, - value: "${content}", - range: [8, 18], - loc: { - start: { line: 1, column: 8 }, - end: { line: 1, column: 18 }, - }, - parts: [ - { - type: TokenTypes.Template, - value: "${content}", - range: [8, 18], - loc: { - start: { line: 1, column: 8 }, - end: { line: 1, column: 18 }, - }, - partOf: TokenTypes.ScriptTagContent, - open: undefined, - close: undefined, - }, - ], - }, - { - type: TokenTypes.CloseScriptTag, - value: "", - range: [18, 27], - loc: { - start: { line: 1, column: 18 }, - end: { line: 1, column: 27 }, - }, - }, -]; -export default OUTPUT; diff --git a/src/tokenizer/__tests__/__output__/templates-style-content.ts b/src/tokenizer/__tests__/__output__/templates-style-content.ts deleted file mode 100644 index c69e396..0000000 --- a/src/tokenizer/__tests__/__output__/templates-style-content.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { TokenTypes } from "../../../constants"; -import { AnyToken } from "../../../types"; - -const OUTPUT: AnyToken[] = [ - { - type: TokenTypes.OpenStyleTagStart, - value: "", - range: [6, 7], - loc: { - start: { line: 1, column: 6 }, - end: { line: 1, column: 7 }, - }, - }, - { - type: TokenTypes.StyleTagContent, - value: "${content}", - range: [7, 17], - loc: { - start: { line: 1, column: 7 }, - end: { line: 1, column: 17 }, - }, - parts: [ - { - type: TokenTypes.Template, - value: "${content}", - range: [7, 17], - loc: { - start: { line: 1, column: 7 }, - end: { line: 1, column: 17 }, - }, - partOf: TokenTypes.StyleTagContent, - }, - ], - }, - { - type: TokenTypes.CloseStyleTag, - value: "", - range: [17, 25], - loc: { - start: { line: 1, column: 17 }, - end: { line: 1, column: 25 }, - }, - }, -]; -export default OUTPUT; diff --git a/src/tokenizer/__tests__/__output__/void-tags.ts b/src/tokenizer/__tests__/__output__/void-tags.ts deleted file mode 100644 index c823574..0000000 --- a/src/tokenizer/__tests__/__output__/void-tags.ts +++ /dev/null @@ -1,83 +0,0 @@ -import { TokenTypes } from "../../../constants"; -import { AnyToken } from "../../../types"; - -const OUTPUT: AnyToken[] = [ - { - type: TokenTypes.OpenTagStart, - value: "", - range: [5, 7], - loc: { - start: { - line: 1, - column: 5, - }, - end: { - line: 1, - column: 7, - }, - }, - }, - { - type: TokenTypes.Text, - value: "\n\n", - range: [7, 9], - loc: { - start: { - line: 1, - column: 7, - }, - end: { - line: 3, - column: 0, - }, - }, - parts: [], - }, - { - type: TokenTypes.OpenTagStart, - value: "", - range: [14, 16], - loc: { - start: { - line: 4, - column: 0, - }, - end: { - line: 4, - column: 2, - }, - }, - }, -]; - -export default OUTPUT; diff --git a/src/tokenizer/__tests__/tokenize.spec.ts b/src/tokenizer/__tests__/tokenize.spec.ts deleted file mode 100644 index 91e02a2..0000000 --- a/src/tokenizer/__tests__/tokenize.spec.ts +++ /dev/null @@ -1,233 +0,0 @@ -import * as fs from "fs"; -import * as path from "path"; -import { tokenize, TokenizeOptions } from "../tokenize"; -import OPENING_CLOSING_TEXT from "./__output__/opening-closing-text"; -import NESTED_TAGS from "./__output__/nested-tags"; -import COMMENTS from "./__output__/comments"; -import ATTRIBUTES_EMPTY from "./__output__/attributes-empty"; -import ATTRIBUTES_BARE from "./__output__/attributes-bare"; -import ATTRIBUTES_APOSTROPHE from "./__output__/attributes-apostrophe"; -import ATTRIBUTES_QUOTE from "./__output__/attributes-quote"; -import CUSTOM_ELEMENTS from "./__output__/custom-elements"; -import DOCTYPES from "./__output__/doctypes"; -import SCRIPT_ELEMENTS_ATTRIBUTES from "./__output__/script-elements-attributes"; -import SCRIPT_ELEMENTS from "./__output__/script-elements"; -import STYLE_ELEMENTS_ATTRIBUTES from "./__output__/style-elements-attributes"; -import STYLE_ELEMENTS from "./__output__/style-elements"; -import TAGS_REGISTER from "./__output__/tags-register"; -import VOID_TAGS from "./__output__/void-tags"; -import EMPTY from "./__output__/empty"; -import SVG from "./__output__/svg"; -import ATTRIBUTES_MULTILINE_CRLF from "./__output__/attributes-multiline-crlf"; -import ATTRIBUTES_BARE_WRONG_QUOTE from "./__output__/attributes-bare-wrong-quote"; -import TEMPLATE_ATTRIBUTES_KEY from "./__output__/templates-attributes-key"; -import TEMPLATE_ATTRIBUTES_KEY_WRAPPER from "./__output__/templates-attributes-key-wrapper"; -import TEMPLATE_ATTRIBUTES_VALUE_BARE from "./__output__/templates-attributes-value-bare"; -import TEMPLATE_ATTRIBUTES_VALUE_WRAPPED from "./__output__/templates-attributes-value-wrapped"; -import TEMPLATE_ATTRIBUTES_VALUE_WRAPPED_2 from "./__output__/templates-attributes-value-wrapped-2"; -import TEMPLATE_DATA from "./__output__/templates-data"; -import TEMPLATE_COMMENT from "./__output__/templates-comment"; -import TEMPLATE_SCRIPT_CONTENT from "./__output__/templates-script-content"; -import TEMPLATE_STYLE_CONTENT from "./__output__/templates-style-content"; -import TEMPLATE_CONTENT_END from "./__output__/templates-content-end"; -import CUSTOM_TAG_RAW_CONTENT from "./__output__/custom-tag-raw-content"; -import { defaultTokenAdapter } from "../../token-adapter"; -import { Range, TemplateInfo } from "../../types"; - -describe("tokenize", () => { - test.each([ - [ - "Attributes apostrophe", - "attributes-apostrophe.html", - ATTRIBUTES_APOSTROPHE, - null, - null, - ], - ["Attributes bare", "attributes-bare.html", ATTRIBUTES_BARE, null, null], - [ - "Attributes bare wrong quotes", - "attributes-bare-wrong-quote.html", - ATTRIBUTES_BARE_WRONG_QUOTE, - null, - null, - ], - ["Attributes empty", "attributes-empty.html", ATTRIBUTES_EMPTY, null, null], - ["Attributes quote", "attributes-quote.html", ATTRIBUTES_QUOTE, null, null], - ["Comments", "comments.html", COMMENTS, null, null], - ["Custom elements", "custom-elements.html", CUSTOM_ELEMENTS, null, null], - ["Doctypes", "doctypes.html", DOCTYPES, null, null], - ["Nested tags", "nested-tags.html", NESTED_TAGS, null, null], - [ - "Opening and closing text", - "opening-closing-text.html", - OPENING_CLOSING_TEXT, - null, - null, - ], - [ - "Script elements attributes", - "script-elements-attributes.html", - SCRIPT_ELEMENTS_ATTRIBUTES, - null, - null, - ], - ["Script element", "script-elements.html", SCRIPT_ELEMENTS, null, null], - ["Tags register", "tags-register.html", TAGS_REGISTER, null, null], - [ - "Style elements attributes", - "style-elements-attributes.html", - STYLE_ELEMENTS_ATTRIBUTES, - null, - null, - ], - ["Style elements", "style-elements.html", STYLE_ELEMENTS, null, null], - ["Void tags", "void-tags.html", VOID_TAGS, null, null], - ["Empty", "empty.html", EMPTY, null, null], - ["Svg", "svg.html", SVG, null, null], - [ - "Attributes multiline CRLF", - "attributes-multiline.html", - ATTRIBUTES_MULTILINE_CRLF, - (html: string) => { - return html.replace(/\n/gi, "\r\n"); - }, - null, - ], - [ - "Template Attributes Key", - "templates-attributes-key.html", - TEMPLATE_ATTRIBUTES_KEY, - null, - { - templateInfos: [[5, 11]] as Range[], - }, - ], - [ - "Template Attributes Key (wrapper)", - "templates-attributes-key.html", - TEMPLATE_ATTRIBUTES_KEY_WRAPPER, - null, - { - templateInfos: [ - { - open: [5, 7], - close: [10, 11], - }, - ] as TemplateInfo[], - }, - ], - [ - "Template Attributes Value Bare", - "templates-attributes-value-bare.html", - TEMPLATE_ATTRIBUTES_VALUE_BARE, - null, - { - templateInfos: [[8, 13]] as Range[], - }, - ], - [ - "Template Attributes Value Wrapped", - "templates-attributes-value-wrapped.html", - TEMPLATE_ATTRIBUTES_VALUE_WRAPPED, - null, - { - templateInfos: [[9, 14]] as Range[], - }, - ], - [ - "Template Attributes Value Wrapped 2", - "templates-attributes-value-wrapped-2.html", - TEMPLATE_ATTRIBUTES_VALUE_WRAPPED_2, - null, - { - templateInfos: [ - [16, 22], - [23, 31], - ] as Range[], - }, - ], - [ - "Templates Data", - "templates-data.html", - TEMPLATE_DATA, - null, - { - templateInfos: [[5, 16]] as Range[], - }, - ], - [ - "Templates Comment", - "templates-comment.html", - TEMPLATE_COMMENT, - null, - { - templateInfos: [[4, 14]] as Range[], - }, - ], - [ - "Templates Script Content", - "templates-script-content.html", - TEMPLATE_SCRIPT_CONTENT, - null, - { - templateInfos: [[8, 18]] as Range[], - }, - ], - [ - "Templates Style Content", - "templates-style-content.html", - TEMPLATE_STYLE_CONTENT, - null, - { - templateInfos: [[7, 17]] as Range[], - }, - ], - [ - "Templates Content End", - "templates-content-end.html", - TEMPLATE_CONTENT_END, - null, - { - templateInfos: [[0, 10]] as Range[], - }, - ], - [ - "Custom Tag Raw Content", - "custom-tag-raw-content.html", - CUSTOM_TAG_RAW_CONTENT, - null, - { - rawContentTags: ["markdown"], - }, - ], - ])( - "%s", - ( - name, - input, - output, - process: null | ((html: string) => string) = null, - options: TokenizeOptions | null = null - ) => { - const inputPath = path.join(__dirname, "__input__", input); - let html = fs.readFileSync(inputPath, "utf-8"); - if (process) { - html = process(html); - } - const { tokens } = tokenize(html, defaultTokenAdapter, options || {}); - expect(tokens).toEqual(output); - } - ); - - it("parsing error", () => { - const html = fs.readFileSync( - path.join(__dirname, "__input__", "parsing-error-no-open-end.html"), - "utf-8" - ); - expect(() => - tokenize(html, defaultTokenAdapter) - ).toThrowErrorMatchingInlineSnapshot( - `"Unexpected end of tag. Expected '>' to close the opening tag. (2:2)"` - ); - }); -}); diff --git a/src/tree-constructor/__tests__/construct-tree.spec.ts b/src/tree-constructor/__tests__/construct-tree.spec.ts deleted file mode 100644 index 851dfa6..0000000 --- a/src/tree-constructor/__tests__/construct-tree.spec.ts +++ /dev/null @@ -1,89 +0,0 @@ -import { constructTree } from "../construct-tree"; - -import OPENING_CLOSING_TEXT_INPUT from "../../tokenizer/__tests__/__output__/opening-closing-text"; - -import NESTED_TAGS_INPUT from "../../tokenizer/__tests__/__output__/nested-tags"; - -import VOID_TAGS_INPUT from "../../tokenizer/__tests__/__output__/void-tags"; - -import SCRIPT_ELEMENTS_INPUT from "../../tokenizer/__tests__/__output__/script-elements"; - -import CUSTOM_ELEMENTS_INPUT from "../../tokenizer/__tests__/__output__/custom-elements"; - -import DOCTYPES_INPUT from "../../tokenizer/__tests__/__output__/doctypes"; - -import STYLE_ELEMENTS_INPUT from "../../tokenizer/__tests__/__output__/style-elements"; - -import COMMENTS_INPUT from "../../tokenizer/__tests__/__output__/comments"; - -import STYLE_ELEMENTS_ATTRIBUTES_INPUT from "../../tokenizer/__tests__/__output__/style-elements-attributes"; - -import TAGS_REGISTER_INPUT from "../../tokenizer/__tests__/__output__/tags-register"; - -import ATTRIBUTES_APOSTROPHE_INPUT from "../../tokenizer/__tests__/__output__/attributes-apostrophe"; - -import ATTRIBUTES_EMPTY_INPUT from "../../tokenizer/__tests__/__output__/attributes-empty"; - -import SCRIPT_ELEMENTS_ATTRIBUTES_INPUT from "../../tokenizer/__tests__/__output__/script-elements-attributes"; - -import EMPTY_INPUT from "../../tokenizer/__tests__/__output__/empty"; - -import SVG_INPUT from "../../tokenizer/__tests__/__output__/svg"; - -import ATTRIBUTES_MULTILINE_CRLF_INPUT from "../../tokenizer/__tests__/__output__/attributes-multiline-crlf"; - -import ATTRIBUTES_BARE_WRONG_QUOTE_INPUT from "../../tokenizer/__tests__/__output__/attributes-bare-wrong-quote"; - -import TEMPLATE_ATTRIBUTES_KEY from "../../tokenizer/__tests__/__output__/templates-attributes-key"; -import TEMPLATE_ATTRIBUTES_VALUE_BARE from "../../tokenizer/__tests__/__output__/templates-attributes-value-bare"; -import TEMPLATE_ATTRIBUTES_VALUE_WRAPPED from "../../tokenizer/__tests__/__output__/templates-attributes-value-wrapped"; -import TEMPLATE_ATTRIBUTES_VALUE_WRAPPED_2 from "../../tokenizer/__tests__/__output__/templates-attributes-value-wrapped-2"; -import TEMPLATE_DATA from "../../tokenizer/__tests__/__output__/templates-data"; -import TEMPLATE_COMMENT from "../../tokenizer/__tests__/__output__/templates-comment"; -import TEMPLATE_SCRIPT_CONTENT from "../../tokenizer/__tests__/__output__/templates-script-content"; -import TEMPLATE_STYLE_CONTENT from "../../tokenizer/__tests__/__output__/templates-style-content"; -import TEMPLATE_CONTENT_END from "../../tokenizer/__tests__/__output__/templates-content-end"; -import CUSTOM_TAG_RAW_CONTENT from "../../tokenizer/__tests__/__output__/custom-tag-raw-content"; -import { clearParent } from "../../utils"; -import { toMatchFile } from "jest-file-snapshot"; - -expect.extend({ toMatchFile }); -describe("construct-tree", () => { - test.each([ - ["Attributes apostrophe", ATTRIBUTES_APOSTROPHE_INPUT], - ["Attributes empty", ATTRIBUTES_EMPTY_INPUT], - ["Attributes bare wrong quote", ATTRIBUTES_BARE_WRONG_QUOTE_INPUT], - ["Comments", COMMENTS_INPUT], - ["Opening closing text", OPENING_CLOSING_TEXT_INPUT], - ["Void tags", VOID_TAGS_INPUT], - ["Script elements", SCRIPT_ELEMENTS_INPUT], - ["Script elements attributes", SCRIPT_ELEMENTS_ATTRIBUTES_INPUT], - ["Nested tags", NESTED_TAGS_INPUT], - ["Custom elements", CUSTOM_ELEMENTS_INPUT], - ["Doctypes", DOCTYPES_INPUT], - ["Style elements", STYLE_ELEMENTS_INPUT], - ["Style elements attributes", STYLE_ELEMENTS_ATTRIBUTES_INPUT], - ["Tag register", TAGS_REGISTER_INPUT], - ["Empty", EMPTY_INPUT], - ["Svg", SVG_INPUT], - ["Attributes multiline (CRLF)", ATTRIBUTES_MULTILINE_CRLF_INPUT], - ["Templates Attributes Key", TEMPLATE_ATTRIBUTES_KEY], - ["Templates Attributes Value Bare", TEMPLATE_ATTRIBUTES_VALUE_BARE], - ["Templates Attributes Value Wrapped", TEMPLATE_ATTRIBUTES_VALUE_WRAPPED], - [ - "Templates Attributes Value Wrapped 2", - TEMPLATE_ATTRIBUTES_VALUE_WRAPPED_2, - ], - ["Templates Data", TEMPLATE_DATA], - ["Templates Comment", TEMPLATE_COMMENT], - ["Templates Script Content", TEMPLATE_SCRIPT_CONTENT], - ["Templates Style Content", TEMPLATE_STYLE_CONTENT], - ["Templates Content End", TEMPLATE_CONTENT_END], - ["Custom Tag Raw Content", CUSTOM_TAG_RAW_CONTENT], - ])("%s", (name: string, inputTokens: any) => { - const { ast } = constructTree(inputTokens); - expect(JSON.stringify(clearParent(ast), null, 2)).toMatchFile(undefined, { - fileExtension: ".json", - }); - }); -}); diff --git a/tsconfig.json b/tsconfig.json index 3ca154e..b231ce0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,7 +6,8 @@ "esModuleInterop": true, "forceConsistentCasingInFileNames": true, "rootDir": "src", - "skipLibCheck": true + "skipLibCheck": true, + "resolveJsonModule": true }, "exclude": ["website"] }