From d812bf159e4001ad65e2706495a2063a524d17d4 Mon Sep 17 00:00:00 2001 From: navorite Date: Wed, 13 Dec 2023 07:23:17 +0200 Subject: [PATCH 01/18] check for snippet block --- packages/svelte/src/compiler/phases/2-analyze/validation.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/svelte/src/compiler/phases/2-analyze/validation.js b/packages/svelte/src/compiler/phases/2-analyze/validation.js index 8dad40e2386e..08402009abd5 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/validation.js +++ b/packages/svelte/src/compiler/phases/2-analyze/validation.js @@ -476,6 +476,7 @@ export const validation = { grand_parent?.type !== 'SvelteComponent' && grand_parent?.type !== 'EachBlock' && grand_parent?.type !== 'AwaitBlock' && + grand_parent?.type !== 'SnippetBlock' && ((grand_parent?.type !== 'RegularElement' && grand_parent?.type !== 'SvelteElement') || !grand_parent.attributes.some((a) => a.type === 'Attribute' && a.name === 'slot'))) ) { From b721b1f44270dcc3b154706507cf33d408ac63af Mon Sep 17 00:00:00 2001 From: navorite Date: Wed, 13 Dec 2023 07:22:52 +0200 Subject: [PATCH 02/18] change the error msg --- packages/svelte/src/compiler/errors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/svelte/src/compiler/errors.js b/packages/svelte/src/compiler/errors.js index 73b6f2e86d1d..c083604b87c1 100644 --- a/packages/svelte/src/compiler/errors.js +++ b/packages/svelte/src/compiler/errors.js @@ -333,7 +333,7 @@ const compiler_options = { /** @satisfies {Errors} */ const const_tag = { 'invalid-const-placement': () => - `{@const} must be the immediate child of {#if}, {:else if}, {:else}, {#each}, {:then}, {:catch}, or ` + `{@const} must be the immediate child of {#snippet}, {#if}, {:else if}, {:else}, {#each}, {:then}, {:catch}, or ` }; /** @satisfies {Errors} */ From 9493c9142cd558d2bb94af4c7b7b092feb36206b Mon Sep 17 00:00:00 2001 From: navorite Date: Wed, 13 Dec 2023 07:25:36 +0200 Subject: [PATCH 03/18] edit tests --- .../tests/validator/samples/const-tag-placement-1/errors.json | 2 +- .../tests/validator/samples/const-tag-placement-2/errors.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/svelte/tests/validator/samples/const-tag-placement-1/errors.json b/packages/svelte/tests/validator/samples/const-tag-placement-1/errors.json index f90fcf80ab47..66ff86663f6d 100644 --- a/packages/svelte/tests/validator/samples/const-tag-placement-1/errors.json +++ b/packages/svelte/tests/validator/samples/const-tag-placement-1/errors.json @@ -1,7 +1,7 @@ [ { "code": "invalid-const-placement", - "message": "{@const} must be the immediate child of {#if}, {:else if}, {:else}, {#each}, {:then}, {:catch}, or ", + "message": "{@const} must be the immediate child of {#snippet}, {#if}, {:else if}, {:else}, {#each}, {:then}, {:catch}, or ", "start": { "line": 5, "column": 0 }, "end": { "line": 5, "column": 18 } } diff --git a/packages/svelte/tests/validator/samples/const-tag-placement-2/errors.json b/packages/svelte/tests/validator/samples/const-tag-placement-2/errors.json index 1124d0b4f869..6c14fdbaf728 100644 --- a/packages/svelte/tests/validator/samples/const-tag-placement-2/errors.json +++ b/packages/svelte/tests/validator/samples/const-tag-placement-2/errors.json @@ -1,7 +1,7 @@ [ { "code": "invalid-const-placement", - "message": "{@const} must be the immediate child of {#if}, {:else if}, {:else}, {#each}, {:then}, {:catch}, or ", + "message": "{@const} must be the immediate child of {#snippet}, {#if}, {:else if}, {:else}, {#each}, {:then}, {:catch}, or ", "start": { "line": 7, "column": 4 }, "end": { "line": 7, "column": 18 } } From 139395a893d9eba0335d4d1db08a46b16d3b341b Mon Sep 17 00:00:00 2001 From: navorite Date: Wed, 13 Dec 2023 07:47:58 +0200 Subject: [PATCH 04/18] changeset --- .changeset/chatty-cups-drop.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/chatty-cups-drop.md diff --git a/.changeset/chatty-cups-drop.md b/.changeset/chatty-cups-drop.md new file mode 100644 index 000000000000..282a9b25ded2 --- /dev/null +++ b/.changeset/chatty-cups-drop.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +feat: add support for `{@const}` inside snippet block From ed7d5e410ef830c5065ac4138c02696f8c514bc0 Mon Sep 17 00:00:00 2001 From: navorite Date: Wed, 13 Dec 2023 15:57:46 +0200 Subject: [PATCH 05/18] test --- .../samples/snippet-const/_config.js | 16 ++++++++++++++++ .../samples/snippet-const/main.svelte | 10 ++++++++++ 2 files changed, 26 insertions(+) create mode 100644 packages/svelte/tests/runtime-runes/samples/snippet-const/_config.js create mode 100644 packages/svelte/tests/runtime-runes/samples/snippet-const/main.svelte diff --git a/packages/svelte/tests/runtime-runes/samples/snippet-const/_config.js b/packages/svelte/tests/runtime-runes/samples/snippet-const/_config.js new file mode 100644 index 000000000000..8867993dbbc5 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/snippet-const/_config.js @@ -0,0 +1,16 @@ +import { test } from '../../test'; + +export default test({ + html: ``, + async test({ assert, target }) { + const btn = target.querySelector('button'); + + assert.htmlEqual(target.innerHTML, ''); + + await btn?.click(); + assert.htmlEqual(target.innerHTML, ''); + + await btn?.click(); + assert.htmlEqual(target.innerHTML, ''); + } +}); diff --git a/packages/svelte/tests/runtime-runes/samples/snippet-const/main.svelte b/packages/svelte/tests/runtime-runes/samples/snippet-const/main.svelte new file mode 100644 index 000000000000..cad63519bf75 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/snippet-const/main.svelte @@ -0,0 +1,10 @@ + + +{#snippet counter()} + {@const doubled = count * 2} + +{/snippet} + +{@render counter()} From 77c1fd3aec79c4dc9961f43d16c4e104cc178cd8 Mon Sep 17 00:00:00 2001 From: navorite Date: Wed, 20 Dec 2023 17:03:22 +0200 Subject: [PATCH 06/18] fix regex --- packages/svelte/src/compiler/phases/1-parse/read/style.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/svelte/src/compiler/phases/1-parse/read/style.js b/packages/svelte/src/compiler/phases/1-parse/read/style.js index 8b1d78544636..99ebf7054f6c 100644 --- a/packages/svelte/src/compiler/phases/1-parse/read/style.js +++ b/packages/svelte/src/compiler/phases/1-parse/read/style.js @@ -6,7 +6,7 @@ const REGEX_ATTRIBUTE_FLAGS = /^[a-zA-Z]+/; // only `i` and `s` are valid today, const REGEX_COMBINATOR_WHITESPACE = /^\s*(\+|~|>|\|\|)\s*/; const REGEX_COMBINATOR = /^(\+|~|>|\|\|)/; const REGEX_PERCENTAGE = /^\d+(\.\d+)?%/; -const REGEX_NTH_OF = /^\s*(even|odd|(-?[0-9]?n?(\s*\+\s*[0-9]+)?))(\s*(?=[,)])|\s+of\s+)/; +const REGEX_NTH_OF = /^\s*(even|odd|(-?[0-9]*n?(\s*\+\s*[0-9]+)?))(\s*(?=[,)])|\s+of\s+)/; const REGEX_WHITESPACE_OR_COLON = /[\s:]/; const REGEX_BRACE_OR_SEMICOLON = /[{;]/; const REGEX_LEADING_HYPHEN_OR_DIGIT = /-?\d/; From dadb77cbcee8fd4f9cd363fe2f51a3d74bcc0202 Mon Sep 17 00:00:00 2001 From: navorite Date: Wed, 20 Dec 2023 17:13:52 +0200 Subject: [PATCH 07/18] changeset --- .changeset/three-suits-grin.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/three-suits-grin.md diff --git a/.changeset/three-suits-grin.md b/.changeset/three-suits-grin.md new file mode 100644 index 000000000000..4b9598c70057 --- /dev/null +++ b/.changeset/three-suits-grin.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: adjust regex to match more than one digit inside `:nth-of-type(xn+y)` From 9474aba827adee3f2d4ba232d8f5e07a97340d25 Mon Sep 17 00:00:00 2001 From: navorite Date: Thu, 21 Dec 2023 03:36:07 +0200 Subject: [PATCH 08/18] better matcher --- packages/svelte/src/compiler/phases/1-parse/read/style.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/svelte/src/compiler/phases/1-parse/read/style.js b/packages/svelte/src/compiler/phases/1-parse/read/style.js index 99ebf7054f6c..d4d75cd60107 100644 --- a/packages/svelte/src/compiler/phases/1-parse/read/style.js +++ b/packages/svelte/src/compiler/phases/1-parse/read/style.js @@ -6,7 +6,8 @@ const REGEX_ATTRIBUTE_FLAGS = /^[a-zA-Z]+/; // only `i` and `s` are valid today, const REGEX_COMBINATOR_WHITESPACE = /^\s*(\+|~|>|\|\|)\s*/; const REGEX_COMBINATOR = /^(\+|~|>|\|\|)/; const REGEX_PERCENTAGE = /^\d+(\.\d+)?%/; -const REGEX_NTH_OF = /^\s*(even|odd|(-?[0-9]*n?(\s*\+\s*[0-9]+)?))(\s*(?=[,)])|\s+of\s+)/; +const REGEX_NTH_OF = + /^\s*(even|odd|(\d+|\+?\d*n(\s*[+-]\d+)?)|\-\d*n(\s*\+\d+))(\s*(?=[,)])|\s+of\s+)/; const REGEX_WHITESPACE_OR_COLON = /[\s:]/; const REGEX_BRACE_OR_SEMICOLON = /[{;]/; const REGEX_LEADING_HYPHEN_OR_DIGIT = /-?\d/; From b9da8329d4cc881974af9c9b5166fe67132dd08b Mon Sep 17 00:00:00 2001 From: navorite Date: Thu, 21 Dec 2023 04:02:30 +0200 Subject: [PATCH 09/18] whitespaces --- packages/svelte/src/compiler/phases/1-parse/read/style.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/svelte/src/compiler/phases/1-parse/read/style.js b/packages/svelte/src/compiler/phases/1-parse/read/style.js index d4d75cd60107..9b7f4770e065 100644 --- a/packages/svelte/src/compiler/phases/1-parse/read/style.js +++ b/packages/svelte/src/compiler/phases/1-parse/read/style.js @@ -7,7 +7,7 @@ const REGEX_COMBINATOR_WHITESPACE = /^\s*(\+|~|>|\|\|)\s*/; const REGEX_COMBINATOR = /^(\+|~|>|\|\|)/; const REGEX_PERCENTAGE = /^\d+(\.\d+)?%/; const REGEX_NTH_OF = - /^\s*(even|odd|(\d+|\+?\d*n(\s*[+-]\d+)?)|\-\d*n(\s*\+\d+))(\s*(?=[,)])|\s+of\s+)/; + /^\s*(even|odd|(\d+|\+?\d*n(\s*[+-]\s*\d+)?)|\-\d*n(\s*\+\s*\d+))(\s*(?=[,)])|\s+of\s+)/; const REGEX_WHITESPACE_OR_COLON = /[\s:]/; const REGEX_BRACE_OR_SEMICOLON = /[{;]/; const REGEX_LEADING_HYPHEN_OR_DIGIT = /-?\d/; From 7fc218cb8526e6392b12903d5dc0c98fbdf8ba2a Mon Sep 17 00:00:00 2001 From: navorite Date: Thu, 21 Dec 2023 04:05:16 +0200 Subject: [PATCH 10/18] lint --- packages/svelte/src/compiler/phases/1-parse/read/style.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/svelte/src/compiler/phases/1-parse/read/style.js b/packages/svelte/src/compiler/phases/1-parse/read/style.js index 9b7f4770e065..c7bff3211448 100644 --- a/packages/svelte/src/compiler/phases/1-parse/read/style.js +++ b/packages/svelte/src/compiler/phases/1-parse/read/style.js @@ -7,7 +7,7 @@ const REGEX_COMBINATOR_WHITESPACE = /^\s*(\+|~|>|\|\|)\s*/; const REGEX_COMBINATOR = /^(\+|~|>|\|\|)/; const REGEX_PERCENTAGE = /^\d+(\.\d+)?%/; const REGEX_NTH_OF = - /^\s*(even|odd|(\d+|\+?\d*n(\s*[+-]\s*\d+)?)|\-\d*n(\s*\+\s*\d+))(\s*(?=[,)])|\s+of\s+)/; + /^\s*(even|odd|(\d+|\+?\d*n(\s*[+-]\s*\d+)?)|-\d*n(\s*\+\s*\d+))(\s*(?=[,)])|\s+of\s+)/; const REGEX_WHITESPACE_OR_COLON = /[\s:]/; const REGEX_BRACE_OR_SEMICOLON = /[{;]/; const REGEX_LEADING_HYPHEN_OR_DIGIT = /-?\d/; From 7655c6ecf3e1010cc7ac512c505922ca1eaea111 Mon Sep 17 00:00:00 2001 From: navorite Date: Wed, 20 Dec 2023 17:03:22 +0200 Subject: [PATCH 11/18] fix regex --- packages/svelte/src/compiler/phases/1-parse/read/style.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/svelte/src/compiler/phases/1-parse/read/style.js b/packages/svelte/src/compiler/phases/1-parse/read/style.js index 8b1d78544636..99ebf7054f6c 100644 --- a/packages/svelte/src/compiler/phases/1-parse/read/style.js +++ b/packages/svelte/src/compiler/phases/1-parse/read/style.js @@ -6,7 +6,7 @@ const REGEX_ATTRIBUTE_FLAGS = /^[a-zA-Z]+/; // only `i` and `s` are valid today, const REGEX_COMBINATOR_WHITESPACE = /^\s*(\+|~|>|\|\|)\s*/; const REGEX_COMBINATOR = /^(\+|~|>|\|\|)/; const REGEX_PERCENTAGE = /^\d+(\.\d+)?%/; -const REGEX_NTH_OF = /^\s*(even|odd|(-?[0-9]?n?(\s*\+\s*[0-9]+)?))(\s*(?=[,)])|\s+of\s+)/; +const REGEX_NTH_OF = /^\s*(even|odd|(-?[0-9]*n?(\s*\+\s*[0-9]+)?))(\s*(?=[,)])|\s+of\s+)/; const REGEX_WHITESPACE_OR_COLON = /[\s:]/; const REGEX_BRACE_OR_SEMICOLON = /[{;]/; const REGEX_LEADING_HYPHEN_OR_DIGIT = /-?\d/; From bb3943fcf95eb3024f593c706f1783e41d661e32 Mon Sep 17 00:00:00 2001 From: navorite Date: Wed, 20 Dec 2023 17:13:52 +0200 Subject: [PATCH 12/18] changeset --- .changeset/three-suits-grin.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/three-suits-grin.md diff --git a/.changeset/three-suits-grin.md b/.changeset/three-suits-grin.md new file mode 100644 index 000000000000..4b9598c70057 --- /dev/null +++ b/.changeset/three-suits-grin.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: adjust regex to match more than one digit inside `:nth-of-type(xn+y)` From 2bc4a555bfbe4a76ae72c839ce7fa34e750f3b91 Mon Sep 17 00:00:00 2001 From: navorite Date: Thu, 21 Dec 2023 03:36:07 +0200 Subject: [PATCH 13/18] better matcher --- packages/svelte/src/compiler/phases/1-parse/read/style.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/svelte/src/compiler/phases/1-parse/read/style.js b/packages/svelte/src/compiler/phases/1-parse/read/style.js index 99ebf7054f6c..d4d75cd60107 100644 --- a/packages/svelte/src/compiler/phases/1-parse/read/style.js +++ b/packages/svelte/src/compiler/phases/1-parse/read/style.js @@ -6,7 +6,8 @@ const REGEX_ATTRIBUTE_FLAGS = /^[a-zA-Z]+/; // only `i` and `s` are valid today, const REGEX_COMBINATOR_WHITESPACE = /^\s*(\+|~|>|\|\|)\s*/; const REGEX_COMBINATOR = /^(\+|~|>|\|\|)/; const REGEX_PERCENTAGE = /^\d+(\.\d+)?%/; -const REGEX_NTH_OF = /^\s*(even|odd|(-?[0-9]*n?(\s*\+\s*[0-9]+)?))(\s*(?=[,)])|\s+of\s+)/; +const REGEX_NTH_OF = + /^\s*(even|odd|(\d+|\+?\d*n(\s*[+-]\d+)?)|\-\d*n(\s*\+\d+))(\s*(?=[,)])|\s+of\s+)/; const REGEX_WHITESPACE_OR_COLON = /[\s:]/; const REGEX_BRACE_OR_SEMICOLON = /[{;]/; const REGEX_LEADING_HYPHEN_OR_DIGIT = /-?\d/; From 0396af888b4d327995f3235babf62ac9e62dbac5 Mon Sep 17 00:00:00 2001 From: navorite Date: Thu, 21 Dec 2023 04:02:30 +0200 Subject: [PATCH 14/18] whitespaces --- packages/svelte/src/compiler/phases/1-parse/read/style.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/svelte/src/compiler/phases/1-parse/read/style.js b/packages/svelte/src/compiler/phases/1-parse/read/style.js index d4d75cd60107..9b7f4770e065 100644 --- a/packages/svelte/src/compiler/phases/1-parse/read/style.js +++ b/packages/svelte/src/compiler/phases/1-parse/read/style.js @@ -7,7 +7,7 @@ const REGEX_COMBINATOR_WHITESPACE = /^\s*(\+|~|>|\|\|)\s*/; const REGEX_COMBINATOR = /^(\+|~|>|\|\|)/; const REGEX_PERCENTAGE = /^\d+(\.\d+)?%/; const REGEX_NTH_OF = - /^\s*(even|odd|(\d+|\+?\d*n(\s*[+-]\d+)?)|\-\d*n(\s*\+\d+))(\s*(?=[,)])|\s+of\s+)/; + /^\s*(even|odd|(\d+|\+?\d*n(\s*[+-]\s*\d+)?)|\-\d*n(\s*\+\s*\d+))(\s*(?=[,)])|\s+of\s+)/; const REGEX_WHITESPACE_OR_COLON = /[\s:]/; const REGEX_BRACE_OR_SEMICOLON = /[{;]/; const REGEX_LEADING_HYPHEN_OR_DIGIT = /-?\d/; From 643357c0468dbe0af0665b08668a8df694e56477 Mon Sep 17 00:00:00 2001 From: navorite Date: Thu, 21 Dec 2023 04:05:16 +0200 Subject: [PATCH 15/18] lint --- packages/svelte/src/compiler/phases/1-parse/read/style.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/svelte/src/compiler/phases/1-parse/read/style.js b/packages/svelte/src/compiler/phases/1-parse/read/style.js index 9b7f4770e065..c7bff3211448 100644 --- a/packages/svelte/src/compiler/phases/1-parse/read/style.js +++ b/packages/svelte/src/compiler/phases/1-parse/read/style.js @@ -7,7 +7,7 @@ const REGEX_COMBINATOR_WHITESPACE = /^\s*(\+|~|>|\|\|)\s*/; const REGEX_COMBINATOR = /^(\+|~|>|\|\|)/; const REGEX_PERCENTAGE = /^\d+(\.\d+)?%/; const REGEX_NTH_OF = - /^\s*(even|odd|(\d+|\+?\d*n(\s*[+-]\s*\d+)?)|\-\d*n(\s*\+\s*\d+))(\s*(?=[,)])|\s+of\s+)/; + /^\s*(even|odd|(\d+|\+?\d*n(\s*[+-]\s*\d+)?)|-\d*n(\s*\+\s*\d+))(\s*(?=[,)])|\s+of\s+)/; const REGEX_WHITESPACE_OR_COLON = /[\s:]/; const REGEX_BRACE_OR_SEMICOLON = /[{;]/; const REGEX_LEADING_HYPHEN_OR_DIGIT = /-?\d/; From 45ce4c2189ab05b4244f886194e753e046f94a31 Mon Sep 17 00:00:00 2001 From: navorite Date: Fri, 29 Dec 2023 09:49:36 +0200 Subject: [PATCH 16/18] fix parsing order --- .../src/compiler/phases/1-parse/read/style.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/svelte/src/compiler/phases/1-parse/read/style.js b/packages/svelte/src/compiler/phases/1-parse/read/style.js index c7bff3211448..4d1777638dba 100644 --- a/packages/svelte/src/compiler/phases/1-parse/read/style.js +++ b/packages/svelte/src/compiler/phases/1-parse/read/style.js @@ -7,7 +7,7 @@ const REGEX_COMBINATOR_WHITESPACE = /^\s*(\+|~|>|\|\|)\s*/; const REGEX_COMBINATOR = /^(\+|~|>|\|\|)/; const REGEX_PERCENTAGE = /^\d+(\.\d+)?%/; const REGEX_NTH_OF = - /^\s*(even|odd|(\d+|\+?\d*n(\s*[+-]\s*\d+)?)|-\d*n(\s*\+\s*\d+))(\s*(?=[,)])|\s+of\s+)/; + /^\s*(even|odd|\+?(\d+|\d*n(\s*[+-]\s*\d+)?)|-\d*n(\s*\+\s*\d+))(\s*(?=[,)])|\s+of\s+)/; const REGEX_WHITESPACE_OR_COLON = /[\s:]/; const REGEX_BRACE_OR_SEMICOLON = /[{;]/; const REGEX_LEADING_HYPHEN_OR_DIGIT = /-?\d/; @@ -278,6 +278,14 @@ function read_selector(parser, inside_pseudo_class = false) { value, flags }); + } else if (inside_pseudo_class && parser.match_regex(REGEX_NTH_OF)) { + // nth of matcher must come before combinator matcher to prevent collision else the '+' in '+2n-1' would be parsed as a combinator + children.push({ + type: 'Nth', + value: /** @type {string} */ (parser.read(REGEX_NTH_OF)), + start, + end: parser.index + }); } else if (parser.match_regex(REGEX_COMBINATOR_WHITESPACE)) { parser.allow_whitespace(); const start = parser.index; @@ -295,13 +303,6 @@ function read_selector(parser, inside_pseudo_class = false) { start, end: parser.index }); - } else if (inside_pseudo_class && parser.match_regex(REGEX_NTH_OF)) { - children.push({ - type: 'Nth', - value: /** @type {string} */ (parser.read(REGEX_NTH_OF)), - start, - end: parser.index - }); } else { let name = read_identifier(parser); if (parser.match('|')) { From fcf208f32cf774225750d714099f850ab569aeb7 Mon Sep 17 00:00:00 2001 From: navorite Date: Fri, 29 Dec 2023 10:01:08 +0200 Subject: [PATCH 17/18] tests --- .../samples/css-nth-syntax/input.svelte | 12 + .../samples/css-nth-syntax/output.json | 284 +++++++++++++++++- 2 files changed, 284 insertions(+), 12 deletions(-) diff --git a/packages/svelte/tests/parser-modern/samples/css-nth-syntax/input.svelte b/packages/svelte/tests/parser-modern/samples/css-nth-syntax/input.svelte index 5668a7799ada..ce3813f3adef 100644 --- a/packages/svelte/tests/parser-modern/samples/css-nth-syntax/input.svelte +++ b/packages/svelte/tests/parser-modern/samples/css-nth-syntax/input.svelte @@ -28,6 +28,18 @@ } h1:global(nav) { background: red; + } + h1:nth-of-type(10n+1){ + background: red; + } + h1:nth-of-type(-2n+3){ + background: red; + } + h1:nth-of-type(+12){ + background: red; + } + h1:nth-of-type(+3n){ + background: red; } diff --git a/packages/svelte/tests/parser-modern/samples/css-nth-syntax/output.json b/packages/svelte/tests/parser-modern/samples/css-nth-syntax/output.json index 3716981b3727..6893091b8f71 100644 --- a/packages/svelte/tests/parser-modern/samples/css-nth-syntax/output.json +++ b/packages/svelte/tests/parser-modern/samples/css-nth-syntax/output.json @@ -2,7 +2,7 @@ "css": { "type": "Style", "start": 0, - "end": 586, + "end": 806, "attributes": [], "children": [ { @@ -601,32 +601,292 @@ }, "start": 530, "end": 577 + }, + { + "type": "Rule", + "prelude": { + "type": "SelectorList", + "start": 580, + "end": 601, + "children": [ + { + "type": "Selector", + "start": 580, + "end": 601, + "children": [ + { + "type": "TypeSelector", + "name": "h1", + "start": 580, + "end": 582 + }, + { + "type": "PseudoClassSelector", + "name": "nth-of-type", + "args": { + "type": "SelectorList", + "start": 595, + "end": 600, + "children": [ + { + "type": "Selector", + "start": 595, + "end": 600, + "children": [ + { + "type": "Nth", + "value": "10n+1", + "start": 595, + "end": 600 + } + ] + } + ] + }, + "start": 582, + "end": 601 + } + ] + } + ] + }, + "block": { + "type": "Block", + "start": 601, + "end": 633, + "children": [ + { + "type": "Declaration", + "start": 611, + "end": 626, + "property": "background", + "value": "red" + } + ] + }, + "start": 580, + "end": 633 + }, + { + "type": "Rule", + "prelude": { + "type": "SelectorList", + "start": 636, + "end": 657, + "children": [ + { + "type": "Selector", + "start": 636, + "end": 657, + "children": [ + { + "type": "TypeSelector", + "name": "h1", + "start": 636, + "end": 638 + }, + { + "type": "PseudoClassSelector", + "name": "nth-of-type", + "args": { + "type": "SelectorList", + "start": 651, + "end": 656, + "children": [ + { + "type": "Selector", + "start": 651, + "end": 656, + "children": [ + { + "type": "Nth", + "value": "-2n+3", + "start": 651, + "end": 656 + } + ] + } + ] + }, + "start": 638, + "end": 657 + } + ] + } + ] + }, + "block": { + "type": "Block", + "start": 657, + "end": 689, + "children": [ + { + "type": "Declaration", + "start": 667, + "end": 682, + "property": "background", + "value": "red" + } + ] + }, + "start": 636, + "end": 689 + }, + { + "type": "Rule", + "prelude": { + "type": "SelectorList", + "start": 692, + "end": 711, + "children": [ + { + "type": "Selector", + "start": 692, + "end": 711, + "children": [ + { + "type": "TypeSelector", + "name": "h1", + "start": 692, + "end": 694 + }, + { + "type": "PseudoClassSelector", + "name": "nth-of-type", + "args": { + "type": "SelectorList", + "start": 707, + "end": 710, + "children": [ + { + "type": "Selector", + "start": 707, + "end": 710, + "children": [ + { + "type": "Nth", + "value": "+12", + "start": 707, + "end": 710 + } + ] + } + ] + }, + "start": 694, + "end": 711 + } + ] + } + ] + }, + "block": { + "type": "Block", + "start": 711, + "end": 743, + "children": [ + { + "type": "Declaration", + "start": 721, + "end": 736, + "property": "background", + "value": "red" + } + ] + }, + "start": 692, + "end": 743 + }, + { + "type": "Rule", + "prelude": { + "type": "SelectorList", + "start": 746, + "end": 765, + "children": [ + { + "type": "Selector", + "start": 746, + "end": 765, + "children": [ + { + "type": "TypeSelector", + "name": "h1", + "start": 746, + "end": 748 + }, + { + "type": "PseudoClassSelector", + "name": "nth-of-type", + "args": { + "type": "SelectorList", + "start": 761, + "end": 764, + "children": [ + { + "type": "Selector", + "start": 761, + "end": 764, + "children": [ + { + "type": "Nth", + "value": "+3n", + "start": 761, + "end": 764 + } + ] + } + ] + }, + "start": 748, + "end": 765 + } + ] + } + ] + }, + "block": { + "type": "Block", + "start": 765, + "end": 797, + "children": [ + { + "type": "Declaration", + "start": 775, + "end": 790, + "property": "background", + "value": "red" + } + ] + }, + "start": 746, + "end": 797 } ], "content": { "start": 7, - "end": 578, - "styles": "\n /* test that all these are parsed correctly */\n\th1:nth-of-type(2n+1){\n background: red;\n }\n h1:nth-child(-n + 3 of li.important) {\n background: red;\n }\n h1:nth-child(1) {\n background: red;\n }\n h1:nth-child(p) {\n background: red;\n }\n h1:nth-child(n+7) {\n background: red;\n }\n h1:nth-child(even) {\n background: red;\n }\n h1:nth-child(odd) {\n background: red;\n }\n h1:nth-child(\n n\n ) {\n background: red;\n }\n h1:global(nav) {\n background: red;\n }\n" + "end": 798, + "styles": "\n /* test that all these are parsed correctly */\n\th1:nth-of-type(2n+1){\n background: red;\n }\n h1:nth-child(-n + 3 of li.important) {\n background: red;\n }\n h1:nth-child(1) {\n background: red;\n }\n h1:nth-child(p) {\n background: red;\n }\n h1:nth-child(n+7) {\n background: red;\n }\n h1:nth-child(even) {\n background: red;\n }\n h1:nth-child(odd) {\n background: red;\n }\n h1:nth-child(\n n\n ) {\n background: red;\n }\n h1:global(nav) {\n background: red;\n }\n\t\th1:nth-of-type(10n+1){\n background: red;\n }\n\t\th1:nth-of-type(-2n+3){\n background: red;\n }\n\t\th1:nth-of-type(+12){\n background: red;\n }\n\t\th1:nth-of-type(+3n){\n background: red;\n }\n" } }, "js": [], - "start": 588, - "end": 600, + "start": 808, + "end": 820, "type": "Root", "fragment": { "type": "Fragment", "nodes": [ { "type": "Text", - "start": 586, - "end": 588, + "start": 806, + "end": 808, "raw": "\n\n", "data": "\n\n" }, { "type": "RegularElement", - "start": 588, - "end": 600, + "start": 808, + "end": 820, "name": "h1", "attributes": [], "fragment": { @@ -634,8 +894,8 @@ "nodes": [ { "type": "Text", - "start": 592, - "end": 595, + "start": 812, + "end": 815, "raw": "Foo", "data": "Foo" } @@ -647,4 +907,4 @@ "transparent": false }, "options": null -} +} \ No newline at end of file From 9402b642449519082b1ed685e014aa508c86855b Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Tue, 2 Jan 2024 14:43:28 +0100 Subject: [PATCH 18/18] Update packages/svelte/tests/parser-modern/samples/css-nth-syntax/output.json --- .../tests/parser-modern/samples/css-nth-syntax/output.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/svelte/tests/parser-modern/samples/css-nth-syntax/output.json b/packages/svelte/tests/parser-modern/samples/css-nth-syntax/output.json index 6893091b8f71..87ab7c02eb2e 100644 --- a/packages/svelte/tests/parser-modern/samples/css-nth-syntax/output.json +++ b/packages/svelte/tests/parser-modern/samples/css-nth-syntax/output.json @@ -907,4 +907,4 @@ "transparent": false }, "options": null -} \ No newline at end of file +}