From 38a3ae321ffceccd7da838e09f092af86d1b6dc4 Mon Sep 17 00:00:00 2001 From: Andrey Sitnik Date: Tue, 24 Dec 2024 13:16:03 +0100 Subject: [PATCH] fix: Allow to disable animation prefix (#14822) * fix: Allow to disable animation prefix * Apply suggestions from code review --------- Co-authored-by: Paolo Ricciuti --- .changeset/twenty-shoes-peel.md | 5 +++++ .../src/compiler/phases/2-analyze/css/css-analyze.js | 10 +++++++++- .../svelte/tests/css/samples/global-block/expected.css | 4 ++++ .../svelte/tests/css/samples/global-block/input.svelte | 4 ++++ 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 .changeset/twenty-shoes-peel.md diff --git a/.changeset/twenty-shoes-peel.md b/.changeset/twenty-shoes-peel.md new file mode 100644 index 000000000000..e0a8e0701dcc --- /dev/null +++ b/.changeset/twenty-shoes-peel.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: don't include keyframes in global scope in the keyframes to rename diff --git a/packages/svelte/src/compiler/phases/2-analyze/css/css-analyze.js b/packages/svelte/src/compiler/phases/2-analyze/css/css-analyze.js index b8c88a102394..ed228385820a 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/css/css-analyze.js +++ b/packages/svelte/src/compiler/phases/2-analyze/css/css-analyze.js @@ -28,11 +28,19 @@ function is_global_block_selector(simple_selector) { ); } +/** + * + * @param {Array} path + */ +function is_in_global_block(path) { + return path.some((node) => node.type === 'Rule' && node.metadata.is_global_block); +} + /** @type {CssVisitors} */ const css_visitors = { Atrule(node, context) { if (is_keyframes_node(node)) { - if (!node.prelude.startsWith('-global-')) { + if (!node.prelude.startsWith('-global-') && !is_in_global_block(context.path)) { context.state.keyframes.push(node.prelude); } } diff --git a/packages/svelte/tests/css/samples/global-block/expected.css b/packages/svelte/tests/css/samples/global-block/expected.css index 8a7c493d7c90..438749224ba6 100644 --- a/packages/svelte/tests/css/samples/global-block/expected.css +++ b/packages/svelte/tests/css/samples/global-block/expected.css @@ -74,6 +74,10 @@ animation: svelte-xyz-test 1s; } + .y{ + animation: test-in 1s; + } + @keyframes test-in{ to{ opacity: 1; diff --git a/packages/svelte/tests/css/samples/global-block/input.svelte b/packages/svelte/tests/css/samples/global-block/input.svelte index dc1a7540108f..a1833636a13f 100644 --- a/packages/svelte/tests/css/samples/global-block/input.svelte +++ b/packages/svelte/tests/css/samples/global-block/input.svelte @@ -76,6 +76,10 @@ animation: test 1s; } + .y{ + animation: test-in 1s; + } + @keyframes test-in{ to{ opacity: 1;