Skip to content

Commit

Permalink
fix: fixed output -css.less missing string ~ and \
Browse files Browse the repository at this point in the history
  • Loading branch information
SolidZORO committed Apr 6, 2022
1 parent 9b0a732 commit 457c365
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
12 changes: 6 additions & 6 deletions __test__/variables-css.less
Expand Up @@ -10,8 +10,8 @@
--safe-area-inset-bottom: env(safe-area-inset-bottom);
--safe-area-inset-left: env(safe-area-inset-left);
--safe-area-inset-right: env(safe-area-inset-right);
--THEME--DARK: theme-dark;
--THEME--TEST: theme-test;
--THEME--DARK: ~'theme-dark';
--THEME--TEST: ~'theme-test';
--container-ext-width: 280px;
--page-body-bg-color: #fff;
--page-border-radius: 5px;
Expand All @@ -38,14 +38,14 @@
--favorite-count-color: ____IS_A_LESS_VAR____;
--login-tips-color: #a1b2c5;
--login-tips-color--dark: #a1b2c5;
--font-chinese: PingFang SC, Hiragino Sans GB, Microsoft YaHei, 5FAE8F6F96C59ED1;
--font-chinese: 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', '\5FAE\8F6F\96C5\9ED1';
--font-family: ____IS_A_LESS_VAR____;
--font-family--android: system, sans-serif;
--style-ui-family: ____IS_A_LESS_VAR____;
--number-family: Avenir Next, Avenir, Segoe UI, Roboto, -apple-system, BlinkMacSystemFont, Helvetica Neue, Helvetica, Arial, sans-serif;
--number-family: 'Avenir Next', 'Avenir', 'Segoe UI', Roboto, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Helvetica, Arial, sans-serif;
--price-family: ____IS_A_LESS_VAR____;
--code-family: Consolas, Liberation Mono, Menlo, Courier, monospace;
--prime-family: CindieMono-D, sans-serif;
--code-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace;
--prime-family: 'CindieMono-D', sans-serif;
--palette-GR01: #d71a1b;
--palette-GR01--dark: #fc0d0e;
--palette-GW01: #fff;
Expand Down
14 changes: 6 additions & 8 deletions src/index.js
Expand Up @@ -91,20 +91,14 @@ const lessVarToCssVar = (opts) => {

let val = `@${item.key}`;

// 过滤掉不需要的符号
item.value = item.value.replace(/\\/g, '');
item.value = item.value.replace(/['|~]/g, '');

// Use real CSS values instead of the --a: @a; mapping
if (opts.useRealValue) {
val = `${item.value}`;
}

// console.log(`K: ${item.key} V: ${item.value}`);

// Replace the string of the less variable
if (opts.useRealValue && opts.useRealValueFilterLessVar) {
val = /[@|~]/.test(item.value)
val = /[@]/.test(item.value)
? opts.useRealValueFilterLessVar
: item.value;
}
Expand Down Expand Up @@ -136,7 +130,11 @@ const lessVarToCssVar = (opts) => {
// --screen-md: @screen-md;
if (!item?.key) return;

const val = /[@|~]/.test(item.value)
// 过滤掉不需要的符号
item.value = item.value.replace(/\\/g, '');
item.value = item.value.replace(/['|~]/g, '');

const val = /[@]/.test(item.value)
? `${opts.useRealValueFilterLessVar}`
: item.value;

Expand Down

0 comments on commit 457c365

Please sign in to comment.