Skip to content

Commit

Permalink
fix: correct the doctest
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenix-ru committed Oct 18, 2023
1 parent c99a8b8 commit 339860e
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions crates/fervid/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,34 @@
//! </p>
//!
//! ```
//! use swc_core::ecma::ast::Expr;
//!
//! let input = r#"
//! <template><div>hello world</div></template>
//! "#;
//!
//! // Parse
//! let (remaining_input, sfc) = fervid::parser::core::parse_sfc(input).unwrap();
//!
//! // Find template block
//! let mut template_block = sfc.template;
//! let Some(ref mut template_block) = template_block else {
//! panic!("No template block");
//! };
//!
//!
//! // Do the necessary transformations
//! let mut scope_helper = fervid_transform::structs::ScopeHelper::default();
//! let module = fervid_transform::script::transform_and_record_scripts(sfc.script_setup, sfc.script_legacy, &mut scope_helper);
//! fervid_transform::template::transform_and_record_template(template_block, &mut scope_helper);
//! let transform_result = fervid_transform::transform_sfc(sfc);
//!
//! // Create the context and generate the template block
//! let mut ctx = fervid_codegen::CodegenContext::default();
//! let template_expr = ctx.generate_sfc_template(&template_block);
//! ctx.used_imports = transform_result.used_vue_imports;
//!
//! let template_expr: Option<Expr> = transform_result.template_block.map(|template_block| {
//! ctx.generate_sfc_template(&template_block)
//! });
//!
//! // Generate the module code
//! let sfc_module = ctx.generate_module(Some(template_expr), module.module, module.export_obj, module.setup_fn);
//! let sfc_module = ctx.generate_module(
//! template_expr,
//! transform_result.module,
//! transform_result.exported_obj,
//! transform_result.setup_fn,
//! transform_result.template_generation_mode
//! );
//!
//! // (Optional) Stringify the code
//! let compiled_code = fervid_codegen::CodegenContext::stringify(input, &sfc_module, false);
Expand Down

0 comments on commit 339860e

Please sign in to comment.