Skip to content

Commit 6c3a86b

Browse files
committed
add global for animations
1 parent f1c05a5 commit 6c3a86b

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

src/index.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,17 @@ function localizeDeclarationValues(localize, declaration, context) {
328328
return false;
329329
}
330330

331+
// replace `animation-name: global(example)` with `animation-name: example`
332+
if (
333+
node.type === "function" &&
334+
node.value.toLowerCase() === "global" &&
335+
/animation(-name)$/i.test(declaration.prop) &&
336+
node.nodes.length === 1
337+
) {
338+
Object.assign(node, node.nodes[0]);
339+
return;
340+
}
341+
331342
if (
332343
node.type === "word" &&
333344
specialKeywords.includes(node.value.toLowerCase())
@@ -414,9 +425,13 @@ function localizeDeclaration(declaration, context) {
414425
parsedAnimationKeywords = {};
415426

416427
return;
417-
}
418-
// Do not handle nested functions
419-
else if (node.type === "function") {
428+
} else if (node.type === "function") {
429+
// replace `animation: global(example)` with `animation-name: example`
430+
if (node.value.toLowerCase() === "global" && node.nodes.length === 1) {
431+
Object.assign(node, node.nodes[0]);
432+
return false;
433+
}
434+
// Do not handle nested functions
420435
return false;
421436
}
422437
// Ignore all except word

test/index.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,21 @@ const tests = [
179179
input: ".foo { animation-name: env(bar); }",
180180
expected: ":local(.foo) { animation-name: env(bar); }",
181181
},
182+
{
183+
name: "not localize animation-name in an global function",
184+
input: ".foo { animation-name: global(bar); }",
185+
expected: ":local(.foo) { animation-name: bar; }",
186+
},
187+
{
188+
name: "not localize animation in an global function",
189+
input: ".foo { animation: global(bar); }",
190+
expected: ":local(.foo) { animation: bar; }",
191+
},
192+
{
193+
name: "not localize a certain animation in an global function",
194+
input: ".foo { animation: global(bar), foo; }",
195+
expected: ":local(.foo) { animation: bar, :local(foo); }",
196+
},
182197
{
183198
name: "not localize animation-name in an env function #2",
184199
input: ".foo { animation-name: eNv(bar); }",

0 commit comments

Comments
 (0)