Skip to content

Commit 5d785cf

Browse files
committed
feat: 支持跨组件传递class和style
1 parent 717ad64 commit 5d785cf

File tree

6 files changed

+356
-286
lines changed

6 files changed

+356
-286
lines changed

__test__/index.spec.mjs.md

Lines changed: 94 additions & 141 deletions
Large diffs are not rendered by default.

__test__/index.spec.mjs.snap

-89 Bytes
Binary file not shown.

src/document.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ use crate::{
2121
pub struct JSXDocument {
2222
pub program: Option<Program>,
2323
pub jsx_record: Option<JSXRecord>,
24+
pub taro_components: Vec<String>,
2425
}
2526

2627
impl JSXDocument {
2728
pub fn new() -> Self {
2829
JSXDocument {
2930
program: None,
3031
jsx_record: None,
32+
taro_components: Vec::new(),
3133
}
3234
}
3335

@@ -70,6 +72,7 @@ impl JSXDocument {
7072
// 收集使用的 Taro Component
7173
let mut visitor = CollectVisitor::new();
7274
program.visit_with(&mut visitor);
75+
self.taro_components = visitor.taro_components.to_vec();
7376
let mut visitor = AstVisitor::new(&mut jsx_record, &visitor.taro_components);
7477
program.visit_all_with(&mut visitor);
7578
self.program = Some(program);

src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ pub fn parse(component: String, styles: Vec<String>, options: ParseOptions) -> S
4141
_ => Platform::Harmony
4242
};
4343

44-
let mut is_enable_nesting = options.is_enable_nesting.map_or(false, |item| item);
44+
// let mut is_enable_nesting = options.is_enable_nesting.map_or(false, |item| item);
45+
let mut is_enable_nesting = true;
4546

4647
// 解析组件文件
4748
let cm: Lrc<SourceMap> = Default::default();
@@ -69,7 +70,7 @@ pub fn parse(component: String, styles: Vec<String>, options: ParseOptions) -> S
6970
style_data.all_style.clone(),
7071
is_enable_nesting,
7172
);
72-
style_write.write(platform);
73+
style_write.write(platform, document.taro_components.clone());
7374

7475
// ast 转代码
7576
let mut buf = Vec::new();

src/style_write.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@ impl<'i> StyleWrite<'i> {
3333
}
3434
}
3535

36-
pub fn write(&mut self, platform: Platform) {
36+
pub fn write(&mut self, platform: Platform, taro_components: Vec<String>) {
3737
// 插入到jsx的style里
3838
{
3939
let mut jsx_mut_visitor =
4040
JSXMutVisitor::new(
4141
self.jsx_record.clone(),
4242
self.pesudo_style_record.clone(),
43+
taro_components.clone(),
4344
platform.clone()
4445
);
4546
self

0 commit comments

Comments
 (0)