Skip to content

Commit

Permalink
[bug fix][add test case] add handle animation short name pattern case (
Browse files Browse the repository at this point in the history
  • Loading branch information
SamXChen authored Oct 13, 2020
1 parent 3f4272c commit 00ead4c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,17 +238,26 @@ const plugin = (options = {}) => {

tokens = tokens.map((token, idx) => {
if (idx === 0 || tokens[idx - 1] === ",") {
let result = token;

const localMatch = /^(\s*):local\s*\((.+?)\)/.exec(token);
const nextLocalMatch = /:local\s*\((.+?)\)/.exec(token);

if (localMatch) {
return (
result =
localMatch[1] +
exportScopedName(localMatch[2]) +
token.substr(localMatch[0].length)
);
token.substr(localMatch[0].length);
} else if (nextLocalMatch) {
const input = nextLocalMatch.input;
const matchPattern = nextLocalMatch[0];
const matchVal = nextLocalMatch[1];
const newVal = exportScopedName(matchVal);
result = input.replace(matchPattern, newVal);
} else {
return token;
// do nothing
}
return result;
} else {
return token;
}
Expand Down
8 changes: 8 additions & 0 deletions test/test-cases/export-keyframes/expected.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
animation-name: _input__fade-in;
}

._input__fadeIn {
animation: 2s _input__fade-in;
}

._input__fadeIn {
animation: _input__fade-in 2s;
}

:export {
fadeIn: _input__fadeIn;
fade-in: _input__fade-in;
Expand Down
8 changes: 8 additions & 0 deletions test/test-cases/export-keyframes/source.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,11 @@
:local(.fadeIn) {
animation-name: _colon_local(fade-in);
}

:local(.fadeIn) {
animation: 2s _colon_local(fade-in);
}

:local(.fadeIn) {
animation: _colon_local(fade-in) 2s;
}

0 comments on commit 00ead4c

Please sign in to comment.