Skip to content

Commit

Permalink
enh: add span to Interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenix-ru committed Nov 22, 2023
1 parent b7127fc commit b0b7466
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 29 deletions.
1 change: 1 addition & 0 deletions crates/fervid/src/parser/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ fn parse_interpolation_node(input: &str) -> IResult<&str, Node> {
value: parsed,
template_scope: 0,
patch_flag: false,
span: DUMMY_SP
}),
))
}
Expand Down
1 change: 1 addition & 0 deletions crates/fervid_codegen/src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,7 @@ mod tests {
value: js("one"),
template_scope: 0,
patch_flag: true,
span: DUMMY_SP
}),
],
template_scope: 0,
Expand Down
2 changes: 2 additions & 0 deletions crates/fervid_codegen/src/elements/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ mod tests {
value: js("true"),
template_scope: 0,
patch_flag: false,
span: DUMMY_SP
}),
Node::Text(" bye!".into(), DUMMY_SP),
],
Expand Down Expand Up @@ -557,6 +558,7 @@ mod tests {
value: js("true"),
template_scope: 0,
patch_flag: false,
span: DUMMY_SP
}),
Node::Element(ElementNode {
starting_tag: StartingTag {
Expand Down
32 changes: 3 additions & 29 deletions crates/fervid_codegen/src/interpolation/mod.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,11 @@
use fervid_core::{Interpolation, VueImports};
use swc_core::{
common::DUMMY_SP,
ecma::ast::{CallExpr, Callee, Expr, ExprOrSpread, Ident},
};
use swc_core::ecma::ast::{CallExpr, Callee, Expr, ExprOrSpread, Ident};

use crate::context::CodegenContext;

impl CodegenContext {
pub fn generate_interpolation(
&mut self,
interpolation: &Interpolation
) -> Expr {
// This is using a string with value if transformation failed
// let (transformed, has_js_bindings) =
// // Polyfill
// parse_js(value)
// .and_then(|mut expr| {
// let has_js = transform_scoped(&mut expr, &self.scope_helper, scope_to_use);
// Ok((expr, has_js))
// })
// .unwrap_or_else(|_| {
// (
// Box::new(Expr::Lit(Lit::Str(Str {
// span,
// value: FervidAtom::from(value),
// raw: None,
// }))),
// false,
// )
// });

// TODO Span
let span = DUMMY_SP;
pub fn generate_interpolation(&mut self, interpolation: &Interpolation) -> Expr {
let span = interpolation.span;

// toDisplayString(transformed)
Expr::Call(CallExpr {
Expand Down
1 change: 1 addition & 0 deletions crates/fervid_core/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ pub struct Interpolation {
pub value: Box<Expr>,
pub template_scope: u32,
pub patch_flag: bool,
pub span: Span
}

/// Starting tag represents [`ElementNode`]'s tag name and attributes
Expand Down
1 change: 1 addition & 0 deletions crates/fervid_parser/src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ impl SfcParser<'_, '_, '_> {
value: parsed_interpolation,
template_scope: 0,
patch_flag: false,
span: interpolation_span
})),
Err(expr_err) => self.errors.push(expr_err.into()),
}
Expand Down

0 comments on commit b0b7466

Please sign in to comment.