Skip to content

Commit ba09c7f

Browse files
committed
[bug fix][add test case] add handle animation short name pattern case
fix a bug in animation short name pattern like "animation: 2s _colon_local(fade-in);"
1 parent 3f4272c commit ba09c7f

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

src/index.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,17 +238,29 @@ const plugin = (options = {}) => {
238238

239239
tokens = tokens.map((token, idx) => {
240240
if (idx === 0 || tokens[idx - 1] === ",") {
241+
242+
let result = token;
243+
241244
const localMatch = /^(\s*):local\s*\((.+?)\)/.exec(token);
245+
const nextLocalMatch = /:local\s*\((.+?)\)/.exec(token);
242246

243247
if (localMatch) {
244-
return (
248+
result = (
245249
localMatch[1] +
246250
exportScopedName(localMatch[2]) +
247251
token.substr(localMatch[0].length)
248252
);
253+
} else if (nextLocalMatch) {
254+
255+
const input = nextLocalMatch.input;
256+
const matchPattern = nextLocalMatch[0];
257+
const matchVal = nextLocalMatch[1];
258+
const newVal = exportScopedName(matchVal);
259+
result = input.replace(matchPattern, newVal);
249260
} else {
250-
return token;
261+
// do nothing
251262
}
263+
return result;
252264
} else {
253265
return token;
254266
}

test/test-cases/export-keyframes/expected.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717
animation-name: _input__fade-in;
1818
}
1919

20+
._input__fadeIn {
21+
animation: 2s _input__fade-in;
22+
}
23+
24+
._input__fadeIn {
25+
animation: _input__fade-in 2s;
26+
}
27+
2028
:export {
2129
fadeIn: _input__fadeIn;
2230
fade-in: _input__fade-in;

test/test-cases/export-keyframes/source.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,11 @@
1616
:local(.fadeIn) {
1717
animation-name: _colon_local(fade-in);
1818
}
19+
20+
:local(.fadeIn) {
21+
animation: 2s _colon_local(fade-in);
22+
}
23+
24+
:local(.fadeIn) {
25+
animation: _colon_local(fade-in) 2s;
26+
}

0 commit comments

Comments
 (0)