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
fix a bug in animation short name pattern like "animation: 2s _colon_local(fade-in);"
  • Loading branch information
SamXChen committed Jul 31, 2019
1 parent 5e4d69d commit fa5449d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,21 +224,35 @@ const processor = postcss.plugin('postcss-modules-scope', function(options) {
});

rule.walkDecls(decl => {

let tokens = decl.value.split(/(,|'[^']*'|"[^"]*")/);

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)
);
} 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 fa5449d

Please sign in to comment.