Skip to content

Commit

Permalink
Merge pull request #13 from NervJS/fix/negative-unit
Browse files Browse the repository at this point in the history
fix: 修复px数值单位匹配丢失了负数和小数匹配错误问题
  • Loading branch information
heiazu committed Nov 17, 2023
2 parents e6b4f90 + 8981589 commit 2b14dc2
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions __test__/index.spec.mjs.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ Generated by [AVA](https://avajs.dev).
_flexShrink: 0,␊
_fontSize: convertNumber2PX(12),␊
_margin: {␊
top: convertNumber2PX(12),␊
top: convertNumber2PX(-12),␊
right: convertNumber2PX(10),␊
bottom: convertNumber2PX(12),␊
left: convertNumber2PX(32)␊
Expand Down Expand Up @@ -566,7 +566,7 @@ Generated by [AVA](https://avajs.dev).
_fontWeight: 500,␊
_height: convertNumber2PX(800),␊
_margin: {␊
top: convertNumber2PX(12),␊
top: convertNumber2PX(-12),␊
right: convertNumber2PX(10),␊
bottom: convertNumber2PX(12),␊
left: convertNumber2PX(32)␊
Expand Down Expand Up @@ -644,7 +644,7 @@ Generated by [AVA](https://avajs.dev).
_flexShrink: 0,␊
_fontSize: convertNumber2PX(12),␊
_margin: {␊
top: convertNumber2PX(12),␊
top: convertNumber2PX(-12),␊
right: convertNumber2PX(10),␊
bottom: convertNumber2PX(12),␊
left: convertNumber2PX(32)␊
Expand Down
Binary file modified __test__/index.spec.mjs.snap
Binary file not shown.
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub fn prefix_style_key(s: &str) -> String {

pub fn convert_px_to_units(input: String) -> Expr {
// 定义匹配 '16px' 的正则表达式
let re = Regex::new(r"(\d+)px").unwrap();
let re = Regex::new(r"(-?(\d+(\.\d*)?|\.\d+))px").unwrap();
// 使用正则表达式进行匹配
if let Some(captures) = re.captures(&input) {
// 提取匹配到的数字部分
Expand Down

0 comments on commit 2b14dc2

Please sign in to comment.