Skip to content

Commit

Permalink
fix: filter less var string ~ and \
Browse files Browse the repository at this point in the history
  • Loading branch information
SolidZORO committed Apr 6, 2022
1 parent 4ec2e32 commit 3d44a39
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 38 deletions.
2 changes: 1 addition & 1 deletion __test__/kv-variables-css.less
@@ -1,5 +1,5 @@
/*
PLEASE DO NOT MODIFY THIS FILE!
⚠️ PLEASE DO NOT MODIFY THIS FILE!
All code is automatically generated by plugin `less-var-to-css-var`.
*/
Expand Down
2 changes: 1 addition & 1 deletion __test__/kv-variables.js
@@ -1,5 +1,5 @@
/*
PLEASE DO NOT MODIFY THIS FILE!
⚠️ PLEASE DO NOT MODIFY THIS FILE!
All code is automatically generated by plugin `less-var-to-css-var`.
*/
Expand Down
6 changes: 3 additions & 3 deletions __test__/out.js
Expand Up @@ -14,7 +14,7 @@ lessVarToCssVar({
jsheader: "import React, { useEffect } from 'react';",
//
useRealValue: true, // Use real CSS values instead of the --a: @a; mapping
// useRealValueFilterLessVar: '____IS_A_LESS_VAR____', // Replace the string of the less variable
useRealValueFilterLessVar: '____IS_A_LESS_VAR____', // Replace the string of the less variable
});

lessVarToCssVar({
Expand All @@ -28,7 +28,7 @@ lessVarToCssVar({
// jsheader: "import React, { useEffect } from 'react';",
//
useRealValue: true, // Use real CSS values instead of the --a: @a; mapping
// useRealValueFilterLessVar: '____IS_A_LESS_VAR____', // Replace the string of the less variable
useRealValueFilterLessVar: '____IS_A_LESS_VAR____', // Replace the string of the less variable
});

lessVarToCssVar({
Expand All @@ -51,5 +51,5 @@ lessVarToCssVar({
jsValueObjectKv: true,
//
useRealValue: true, // Use real CSS values instead of the --a: @a; mapping
// useRealValueFilterLessVar: '____IS_A_LESS_VAR____', // Replace the string of the less variable
useRealValueFilterLessVar: '____IS_A_LESS_VAR____', // Replace the string of the less variable
});
2 changes: 1 addition & 1 deletion __test__/page-variables-css.less
@@ -1,5 +1,5 @@
/*
PLEASE DO NOT MODIFY THIS FILE!
⚠️ PLEASE DO NOT MODIFY THIS FILE!
All code is automatically generated by plugin `less-var-to-css-var`.
*/
Expand Down
2 changes: 1 addition & 1 deletion __test__/page-variables.js
@@ -1,5 +1,5 @@
/*
PLEASE DO NOT MODIFY THIS FILE!
⚠️ PLEASE DO NOT MODIFY THIS FILE!
All code is automatically generated by plugin `less-var-to-css-var`.
*/
Expand Down
30 changes: 15 additions & 15 deletions __test__/variables-css.less
@@ -1,5 +1,5 @@
/*
PLEASE DO NOT MODIFY THIS FILE!
⚠️ PLEASE DO NOT MODIFY THIS FILE!
All code is automatically generated by plugin `less-var-to-css-var`.
*/
Expand All @@ -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 @@ -35,17 +35,17 @@
--pane-drawer-cancel-button-color--dark: #222;
--comment-count-color: #fd0000;
--charging-count-color: #fca810;
--favorite-count-color: @comment-count-color;
--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', '\5FAE\8F6F\96C5\9ED1';
--font-family: -apple-system, BlinkMacSystemFont, @font-chinese, 'Helvetica Neue', Helvetica, Ubuntu, Roboto, Noto, 'Segoe UI', Arial, sans-serif;
--font-chinese: PingFang SC, Hiragino Sans GB, Microsoft YaHei, 5FAE8F6F96C59ED1;
--font-family: ____IS_A_LESS_VAR____;
--font-family--android: system, sans-serif;
--style-ui-family: -apple-system, BlinkMacSystemFont, @font-chinese, 'helvetica neue', helvetica, ubuntu, roboto, noto, 'segoe ui', Arial, sans-serif;
--number-family: 'Avenir Next', 'Avenir', 'Segoe UI', Roboto, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Helvetica, Arial, sans-serif;
--price-family: @number-family;
--code-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace;
--prime-family: 'CindieMono-D', 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;
--price-family: ____IS_A_LESS_VAR____;
--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 Expand Up @@ -84,12 +84,12 @@
--switch-sm-min-width: 28px;
--text-color: #333;
--text-color--dark: #eee;
--sub-text-color: lighten(@text-color, 50%);
--sub-text-color--dark: lighten(@text-color, 50%);
--sub-text-color: ____IS_A_LESS_VAR____;
--sub-text-color--dark: ____IS_A_LESS_VAR____;
--primary-bg-color: #f2f2f2;
--primary-bg-color--dark: #000;
--primary-color: @palette-GR01;
--primary-color--dark: @palette-GR01--dark;
--primary-color: ____IS_A_LESS_VAR____;
--primary-color--dark: ____IS_A_LESS_VAR____;
--prime-bg-color: #20232c;
--prime-tab-text-color: #63646b;
--prime-tab-bg-color: #0e0e11;
Expand Down
30 changes: 15 additions & 15 deletions __test__/variables.js
@@ -1,5 +1,5 @@
/*
PLEASE DO NOT MODIFY THIS FILE!
⚠️ PLEASE DO NOT MODIFY THIS FILE!
All code is automatically generated by plugin `less-var-to-css-var`.
*/
Expand All @@ -12,8 +12,8 @@ export const CSS_VARS = {
'--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': 'undefined',
'--THEME--TEST': 'undefined',
'--THEME--DARK': 'theme-dark',
'--THEME--TEST': 'theme-test',
'--container-ext-width': '280px',
'--page-body-bg-color': '#fff',
'--page-border-radius': '5px',
Expand All @@ -37,17 +37,17 @@ export const CSS_VARS = {
'--pane-drawer-cancel-button-color--dark': '#222',
'--comment-count-color': '#fd0000',
'--charging-count-color': '#fca810',
'--favorite-count-color': 'undefined',
'--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', '\5FAE\8F6F\96C5\9ED1'`,
'--font-family': 'undefined',
'--font-chinese': `PingFang SC, Hiragino Sans GB, Microsoft YaHei, 5FAE8F6F96C59ED1`,
'--font-family': '____IS_A_LESS_VAR____',
'--font-family--android': `system, sans-serif`,
'--style-ui-family': 'undefined',
'--number-family': `'Avenir Next', 'Avenir', 'Segoe UI', Roboto, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Helvetica, Arial, sans-serif`,
'--price-family': 'undefined',
'--code-family': `Consolas, 'Liberation Mono', Menlo, Courier, monospace`,
'--prime-family': `'CindieMono-D', 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`,
'--price-family': '____IS_A_LESS_VAR____',
'--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 Expand Up @@ -86,12 +86,12 @@ export const CSS_VARS = {
'--switch-sm-min-width': '28px',
'--text-color': '#333',
'--text-color--dark': '#eee',
'--sub-text-color': 'undefined',
'--sub-text-color--dark': 'undefined',
'--sub-text-color': '____IS_A_LESS_VAR____',
'--sub-text-color--dark': '____IS_A_LESS_VAR____',
'--primary-bg-color': '#f2f2f2',
'--primary-bg-color--dark': '#000',
'--primary-color': 'undefined',
'--primary-color--dark': 'undefined',
'--primary-color': '____IS_A_LESS_VAR____',
'--primary-color--dark': '____IS_A_LESS_VAR____',
'--prime-bg-color': '#20232c',
'--prime-tab-text-color': '#63646b',
'--prime-tab-bg-color': '#0e0e11',
Expand Down
8 changes: 7 additions & 1 deletion src/index.js
Expand Up @@ -69,7 +69,7 @@ const lessVarToCssVar = (opts) => {
}
});

const __CODE_GEN_COMMENT__ = `/\*\n PLEASE DO NOT MODIFY THIS FILE!\n\n All code is automatically generated by plugin \`less-var-to-css-var\`.\n*\/`;
const __CODE_GEN_COMMENT__ = `/\*\n ⚠️ PLEASE DO NOT MODIFY THIS FILE!\n\n All code is automatically generated by plugin \`less-var-to-css-var\`.\n*\/`;
const __ESLINT_STR__ = `/\* eslint-disable max-len \*/`;

//
Expand All @@ -91,11 +91,17 @@ 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)
Expand Down

0 comments on commit 3d44a39

Please sign in to comment.