Skip to content

Commit 00ead4c

Browse files
authored
[bug fix][add test case] add handle animation short name pattern case (css-modules#16)
1 parent 3f4272c commit 00ead4c

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

src/index.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -238,17 +238,26 @@ const plugin = (options = {}) => {
238238

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

243246
if (localMatch) {
244-
return (
247+
result =
245248
localMatch[1] +
246249
exportScopedName(localMatch[2]) +
247-
token.substr(localMatch[0].length)
248-
);
250+
token.substr(localMatch[0].length);
251+
} else if (nextLocalMatch) {
252+
const input = nextLocalMatch.input;
253+
const matchPattern = nextLocalMatch[0];
254+
const matchVal = nextLocalMatch[1];
255+
const newVal = exportScopedName(matchVal);
256+
result = input.replace(matchPattern, newVal);
249257
} else {
250-
return token;
258+
// do nothing
251259
}
260+
return result;
252261
} else {
253262
return token;
254263
}

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

+8
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

+8
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)