Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug fix][add test case] add handle animation short name pattern case #16

Merged
merged 2 commits into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}