Skip to content

Commit 4af4b9a

Browse files
committed
feat: 增加嵌套拆分逻辑
1 parent feb99c0 commit 4af4b9a

File tree

6 files changed

+212
-97
lines changed

6 files changed

+212
-97
lines changed

__test__/fixure/pesudo.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
.pesudo {
22
height: 400px;
33
width: 400px;
4+
margin-top: calc(100% - 30px);
45
}
56

67
.pesudo:last-child {
78
color: red;
89
}
910

10-
.text {
11+
.a, .a .b {
1112
font-size: 20px;
1213
text-overflow: ellipsis;
1314
}

__test__/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ const fs = require('fs')
22
const path = require('path')
33
process.env.platform = 'arm64'
44
const { parse } = require('../index.js')
5-
const component = fs.readFileSync(path.resolve(__dirname, 'fixure/mod.jsx'), 'utf8')
6-
const css1 = fs.readFileSync(path.resolve(__dirname, 'fixure/Mod.scss'), 'utf8')
5+
const component = fs.readFileSync(path.resolve(__dirname, 'fixure/pesudo.jsx'), 'utf8')
6+
const css1 = fs.readFileSync(path.resolve(__dirname, 'fixure/pesudo.scss'), 'utf8')
77
const code = parse(component, [css1], "Harmony")
88

99
console.log(code)

src/constants.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ pub const CONVERT_STYLE_PREFIX: &'static str = "_";
22
pub const CONVERT_STYLE_PX_FN: &'static str = "convertNumber2VP";
33
pub const INNER_STYLE: &'static str = "__inner_style__";
44
pub const INNER_STYLE_DATA: &'static str = "__inner_style_data__";
5+
pub const NESTING_STYLE: &'static str = "__nesting_style__";
6+
pub const NESTINT_STYLE_DATA: &'static str = "__nesting_style_data__";
57
pub const CALC_DYMAMIC_STYLE: &'static str = "calcDynamicStyle";
68

79
pub const RN_CONVERT_STYLE_PX_FN: &'static str = "scalePx2dp";

src/style_propetries/marin_padding.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ impl ToExpr for MarginPadding {
4242
// 判断self.id是否padding开头
4343
let is_padding = self.id.starts_with("padding");
4444
let key_name = if is_padding { "padding" } else { "margin" };
45+
4546
PropertyTuple::Array(vec![
4647
(format!("{}Top", key_name), generate_expr_by_length_percentage_or_auto!(self.top.as_ref().unwrap(), Platform::Harmony)),
4748
(format!("{}Right", key_name), generate_expr_by_length_percentage_or_auto!(self.right.as_ref().unwrap(), Platform::Harmony)),

src/utils.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,42 @@ pub fn color_string(value: &Property) -> String {
174174
},
175175
..PrinterOptions::default()
176176
}).unwrap()
177+
}
178+
179+
// 分割选择器
180+
pub fn split_selector(selector: &str) -> Vec<String> {
181+
let mut result = Vec::new();
182+
let mut current_word = String::new();
183+
let mut buffer = String::new();
184+
185+
for c in selector.chars() {
186+
if c == ' ' || c == '>' || c == '+' || c == '~' {
187+
if !current_word.is_empty() {
188+
result.push(current_word.clone());
189+
current_word.clear();
190+
}
191+
192+
buffer.push(c);
193+
if buffer == " > " || buffer == " + " || buffer == " ~ " {
194+
result.push(buffer.clone());
195+
buffer.clear();
196+
}
197+
} else {
198+
current_word.push(c);
199+
if buffer == ' '.to_string() {
200+
result.push(buffer.clone());
201+
buffer.clear();
202+
}
203+
}
204+
}
205+
206+
if !current_word.is_empty() {
207+
result.push(current_word.clone());
208+
}
209+
210+
if !buffer.is_empty() {
211+
result.push(buffer.clone());
212+
}
213+
214+
result
177215
}

0 commit comments

Comments
 (0)