From ba09c7fa8b893b61fc6820ac3e44103cfc85a3e0 Mon Sep 17 00:00:00 2001 From: Sam X Chen <739263563@qq.com> Date: Wed, 31 Jul 2019 16:58:28 +0800 Subject: [PATCH 1/2] [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);" --- src/index.js | 16 ++++++++++++++-- test/test-cases/export-keyframes/expected.css | 8 ++++++++ test/test-cases/export-keyframes/source.css | 8 ++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 5fce099..32ae0c3 100644 --- a/src/index.js +++ b/src/index.js @@ -238,17 +238,29 @@ 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) ); + } 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; } diff --git a/test/test-cases/export-keyframes/expected.css b/test/test-cases/export-keyframes/expected.css index 546a3fb..c22e307 100644 --- a/test/test-cases/export-keyframes/expected.css +++ b/test/test-cases/export-keyframes/expected.css @@ -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; diff --git a/test/test-cases/export-keyframes/source.css b/test/test-cases/export-keyframes/source.css index f07f7c9..65ff571 100644 --- a/test/test-cases/export-keyframes/source.css +++ b/test/test-cases/export-keyframes/source.css @@ -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; +} \ No newline at end of file From 331386a4d53fbd73c0cf70b4655c50c50d9455cb Mon Sep 17 00:00:00 2001 From: Sam X Chen <739263563@qq.com> Date: Sat, 10 Oct 2020 20:25:36 +0800 Subject: [PATCH 2/2] fix: fix code style problem --- src/index.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index 32ae0c3..70eeabf 100644 --- a/src/index.js +++ b/src/index.js @@ -238,20 +238,17 @@ 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) { - result = ( + 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];