Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/fervid/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ license = "Apache-2.0"
[features]
default = []
dbg_print = []
new-pipeline = ["fervid_transform/new-pipeline", "fervid_codegen/new-pipeline"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
5 changes: 5 additions & 0 deletions crates/fervid/benches/codegen_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ fn codegen_benchmark(c: &mut Criterion) {
let filename = "anonymous.vue".to_string();
let mut ctx = TransformSfcContext {
filename: filename.to_owned(),
self_name: None,
bindings_helper: BindingsHelper::default(),
is_ce: false,
props_destructure: PropsDestructureConfig::default(),
Expand All @@ -33,6 +34,10 @@ fn codegen_benchmark(c: &mut Criterion) {
transform_asset_urls: TransformAssetUrlsConfig::default(),
errors: vec![],
warnings: vec![],
directive_scopes: Default::default(),
current_template_scope: 0,
directive_transforms: Default::default(),
node_transforms: Default::default(),
};

fervid_transform::template::transform_and_record_template(template_block, &mut ctx);
Expand Down
11 changes: 11 additions & 0 deletions crates/fervid/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
//! scope_id: "filehash",
//! filename: "input.vue",
//! transform_asset_urls: fervid_transform::TransformAssetUrlsConfig::default(),
//! directive_transforms: Default::default(),
//! node_transforms: Default::default(),
//! };
//! let transform_result = fervid_transform::transform_sfc(sfc, transform_options, &mut transform_errors);
//!
Expand Down Expand Up @@ -147,6 +149,11 @@ pub fn compile(source: &str, options: CompileOptions) -> Result<CompileResult, C
// TODO Research if it's better to compute that on the caller site or here
let file_hash = compute_scope_id(source);

// Get the correct transforms
// TODO
let directive_transforms = Default::default();
let node_transforms = Default::default();

// Transform
let mut transform_errors = Vec::new();
let transform_options = TransformSfcOptions {
Expand All @@ -156,6 +163,8 @@ pub fn compile(source: &str, options: CompileOptions) -> Result<CompileResult, C
scope_id: &file_hash,
filename: &options.filename,
transform_asset_urls: options.transform_asset_urls.unwrap_or_default(),
directive_transforms,
node_transforms,
};
let transform_result = transform_sfc(sfc, transform_options, &mut transform_errors);
all_errors.extend(transform_errors.into_iter().map(From::from));
Expand Down Expand Up @@ -248,6 +257,8 @@ pub fn compile_sync_naive(source: &str, is_prod: bool) -> Result<String, String>
scope_id: &file_hash,
filename: "anonymous.vue",
transform_asset_urls: TransformAssetUrlsConfig::default(),
directive_transforms: Default::default(),
node_transforms: Default::default(),
};
let transform_result = transform_sfc(sfc, transform_options, &mut transform_errors);

Expand Down
6 changes: 4 additions & 2 deletions crates/fervid/src/parser_old/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,10 @@ pub fn parse_element_node(input: &str) -> IResult<&str, Node> {
starting_tag,
children: vec![],
template_scope: 0,
kind: ElementKind::Element,
tag_type: ElementKind::Element,
patch_hints: Default::default(),
span: DUMMY_SP, // TODO
codegen_node: None,
}),
));
}
Expand All @@ -346,9 +347,10 @@ pub fn parse_element_node(input: &str) -> IResult<&str, Node> {
starting_tag,
children,
template_scope: 0,
kind: ElementKind::Element,
tag_type: ElementKind::Element,
patch_hints: Default::default(),
span: DUMMY_SP, // TODO
codegen_node: None,
}),
))
}
Expand Down
4 changes: 4 additions & 0 deletions crates/fervid_codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ flagset = "0.4.3"
[dev-dependencies]
panic-message = "0.3.0"
swc_ecma_parser = { workspace = true }

[features]
default = []
new-pipeline = ["fervid_transform/new-pipeline"]
113 changes: 42 additions & 71 deletions crates/fervid_codegen/src/builtins/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,15 @@ mod tests {
|| {
// <component></component>
test_out(
ElementNode {
kind: ElementKind::Builtin(BuiltinType::Component),
starting_tag: StartingTag {
ElementNode::new_with_children_and_type(
StartingTag {
tag_name: "component".into(),
attributes: vec![],
directives: None,
},
children: vec![],
template_scope: 0,
patch_hints: Default::default(),
span: DUMMY_SP,
},
vec![],
ElementKind::Builtin(BuiltinType::Component),
),
r#""#,
);
},
Expand All @@ -136,18 +133,15 @@ mod tests {
fn it_generates_component_is_static() {
// <component is="div"></component>
test_out(
ElementNode {
kind: ElementKind::Builtin(BuiltinType::Component),
starting_tag: StartingTag {
ElementNode::new_with_children_and_type(
StartingTag {
tag_name: "component".into(),
attributes: vec![regular_attribute("is", "div")],
directives: None,
},
children: vec![],
template_scope: 0,
patch_hints: Default::default(),
span: DUMMY_SP,
},
vec![],
ElementKind::Builtin(BuiltinType::Component),
),
r#"(_openBlock(),_createBlock(_resolveDynamicComponent("div")))"#,
);
}
Expand All @@ -156,18 +150,15 @@ mod tests {
fn it_generates_component_is_binding() {
// <component :is="foo"></component>
test_out(
ElementNode {
kind: ElementKind::Builtin(BuiltinType::Component),
starting_tag: StartingTag {
ElementNode::new_with_children_and_type(
StartingTag {
tag_name: "component".into(),
attributes: vec![v_bind_attribute("is", "foo")],
directives: None,
},
children: vec![],
template_scope: 0,
patch_hints: Default::default(),
span: DUMMY_SP,
},
vec![],
ElementKind::Builtin(BuiltinType::Component),
),
r#"(_openBlock(),_createBlock(_resolveDynamicComponent(foo)))"#,
);
}
Expand All @@ -176,9 +167,8 @@ mod tests {
fn it_generates_component_builtin_attrs() {
// <component is="div" foo="bar" :baz="qux"></component>
test_out(
ElementNode {
kind: ElementKind::Builtin(BuiltinType::Component),
starting_tag: StartingTag {
ElementNode::new_with_children_and_type(
StartingTag {
tag_name: "component".into(),
attributes: vec![
regular_attribute("is", "div"),
Expand All @@ -187,11 +177,9 @@ mod tests {
],
directives: None,
},
children: vec![],
template_scope: 0,
patch_hints: Default::default(),
span: DUMMY_SP,
},
vec![],
ElementKind::Builtin(BuiltinType::Component),
),
r#"(_openBlock(),_createBlock(_resolveDynamicComponent("div"),{foo:"bar",baz:qux}))"#,
)
}
Expand All @@ -200,18 +188,15 @@ mod tests {
fn it_generates_component_builtin_default_slot() {
// <component is="div">foobar</component>
test_out(
ElementNode {
kind: ElementKind::Builtin(BuiltinType::Component),
starting_tag: StartingTag {
ElementNode::new_with_children_and_type(
StartingTag {
tag_name: "component".into(),
attributes: vec![regular_attribute("is", "div")],
directives: None,
},
children: vec![Node::Text("foobar".into(), DUMMY_SP)],
template_scope: 0,
patch_hints: Default::default(),
span: DUMMY_SP,
},
vec![Node::Text("foobar".into(), DUMMY_SP)],
ElementKind::Builtin(BuiltinType::Component),
),
r#"(_openBlock(),_createBlock(_resolveDynamicComponent("div"),null,{default:_withCtx(()=>[_createTextVNode("foobar")]),_:1}))"#,
)
}
Expand All @@ -222,16 +207,14 @@ mod tests {
// <template v-slot:named>foobar</template>
// </component>
test_out(
ElementNode {
kind: ElementKind::Builtin(BuiltinType::Component),
starting_tag: StartingTag {
ElementNode::new_with_children_and_type(
StartingTag {
tag_name: "component".into(),
attributes: vec![regular_attribute("is", "div")],
directives: None,
},
children: vec![Node::Element(ElementNode {
kind: ElementKind::Element,
starting_tag: StartingTag {
vec![Node::Element(ElementNode::new_with_children(
StartingTag {
tag_name: "template".into(),
attributes: vec![],
directives: Some(Box::new(VueDirectives {
Expand All @@ -242,15 +225,10 @@ mod tests {
..Default::default()
})),
},
children: vec![Node::Text("foobar".into(), DUMMY_SP)],
template_scope: 0,
patch_hints: Default::default(),
span: DUMMY_SP,
})],
template_scope: 0,
patch_hints: Default::default(),
span: DUMMY_SP,
},
vec![Node::Text("foobar".into(), DUMMY_SP)],
))],
ElementKind::Builtin(BuiltinType::Component),
),
r#"(_openBlock(),_createBlock(_resolveDynamicComponent("div"),null,{named:_withCtx(()=>[_createTextVNode("foobar")]),_:1}))"#,
)
}
Expand All @@ -264,9 +242,8 @@ mod tests {
// </template>
// </component>
test_out(
ElementNode {
kind: ElementKind::Builtin(BuiltinType::Component),
starting_tag: StartingTag {
ElementNode::new_with_children_and_type(
StartingTag {
tag_name: "component".into(),
attributes: vec![
regular_attribute("is", "div"),
Expand All @@ -275,11 +252,10 @@ mod tests {
],
directives: None,
},
children: vec![
vec![
Node::Text("foobar".into(), DUMMY_SP),
Node::Element(ElementNode {
kind: ElementKind::Element,
starting_tag: StartingTag {
Node::Element(ElementNode::new_with_children(
StartingTag {
tag_name: "template".into(),
attributes: vec![],
directives: Some(Box::new(VueDirectives {
Expand All @@ -290,16 +266,11 @@ mod tests {
..Default::default()
})),
},
children: vec![Node::Text("bazqux".into(), DUMMY_SP)],
template_scope: 0,
patch_hints: Default::default(),
span: DUMMY_SP,
}),
vec![Node::Text("bazqux".into(), DUMMY_SP)],
)),
],
template_scope: 0,
patch_hints: Default::default(),
span: DUMMY_SP,
},
ElementKind::Builtin(BuiltinType::Component),
),
r#"(_openBlock(),_createBlock(_resolveDynamicComponent("div"),{foo:"bar",baz:qux},{named:_withCtx(()=>[_createTextVNode("bazqux")]),default:_withCtx(()=>[_createTextVNode("foobar")]),_:1}))"#,
)
}
Expand Down
Loading
Loading