From 945a20ee93946bc83bfc92de32b2498656303594 Mon Sep 17 00:00:00 2001 From: LastLeaf Date: Tue, 25 Jun 2024 12:33:13 +0800 Subject: [PATCH] optimize: sourcemap name output --- .../src/stringify/expr.rs | 104 ++++++++-------- .../src/stringify/mod.rs | 12 +- .../src/stringify/tag.rs | 116 +++++++++--------- 3 files changed, 116 insertions(+), 116 deletions(-) diff --git a/glass-easel-template-compiler/src/stringify/expr.rs b/glass-easel-template-compiler/src/stringify/expr.rs index 3df4b46..61ccc6c 100644 --- a/glass-easel-template-compiler/src/stringify/expr.rs +++ b/glass-easel-template-compiler/src/stringify/expr.rs @@ -93,39 +93,39 @@ fn expression_strigify_write<'s, W: FmtWrite>( stringifier.write_scope_name(*index, location)?; } Expression::DataField { name, location } => { - stringifier.write_token(name, name, location)?; + stringifier.write_token(name, Some(name), location)?; } Expression::ToStringWithoutUndefined { .. } => { panic!("illegal expression"); } Expression::LitUndefined { location } => { - stringifier.write_token("undefined", "undefined", location)?; + stringifier.write_token("undefined", None, location)?; } Expression::LitNull { location } => { - stringifier.write_token("null", "null", location)?; + stringifier.write_token("null", None, location)?; } Expression::LitStr { value, location } => { let quoted = gen_lit_str(&value); - stringifier.write_token(&format!(r#"{}"#, quoted), &value, &location)?; + stringifier.write_token(&format!(r#"{}"#, quoted), None, &location)?; } Expression::LitInt { value, location } => { let value = value.to_string(); - stringifier.write_token(&value, &value, location)?; + stringifier.write_token(&value, None, location)?; } Expression::LitFloat { value, location } => { let value = value.to_string(); - stringifier.write_token(&value, &value, location)?; + stringifier.write_token(&value, None, location)?; } Expression::LitBool { value, location } => { let value = if *value { "true" } else { "false" }; - stringifier.write_token(value, value, location)?; + stringifier.write_token(value, None, location)?; } Expression::LitObj { fields, brace_location, } => { - stringifier.write_token("{", "{", &brace_location.0)?; + stringifier.write_token("{", None, &brace_location.0)?; for (index, field) in fields.iter().enumerate() { if index > 0 { stringifier.write_str(",")?; @@ -144,29 +144,29 @@ fn expression_strigify_write<'s, W: FmtWrite>( Expression::DataField { name: x, .. } => x == name, _ => false, }; - stringifier.write_token(name, name, location)?; + stringifier.write_token(name, None, location)?; if !is_shortcut { stringifier.write_token( ":", - ":", + None, colon_location.as_ref().unwrap_or(location), )?; expression_strigify_write(value, stringifier, ExpressionLevel::Cond)?; } } ObjectFieldKind::Spread { location, value } => { - stringifier.write_token("...", "...", location)?; + stringifier.write_token("...", None, location)?; expression_strigify_write(value, stringifier, ExpressionLevel::Cond)?; } } } - stringifier.write_token("}", "}", &brace_location.1)?; + stringifier.write_token("}", None, &brace_location.1)?; } Expression::LitArr { fields, bracket_location, } => { - stringifier.write_token("[", "[", &bracket_location.0)?; + stringifier.write_token("[", None, &bracket_location.0)?; for (index, field) in fields.iter().enumerate() { if index > 0 { stringifier.write_str(",")?; @@ -176,7 +176,7 @@ fn expression_strigify_write<'s, W: FmtWrite>( expression_strigify_write(value, stringifier, ExpressionLevel::Cond)?; } ArrayFieldKind::Spread { location, value } => { - stringifier.write_token("...", "...", location)?; + stringifier.write_token("...", None, location)?; expression_strigify_write(value, stringifier, ExpressionLevel::Cond)?; } ArrayFieldKind::EmptySlot => { @@ -186,7 +186,7 @@ fn expression_strigify_write<'s, W: FmtWrite>( } } } - stringifier.write_token("]", "]", &bracket_location.1)?; + stringifier.write_token("]", None, &bracket_location.1)?; } Expression::StaticMember { @@ -196,8 +196,8 @@ fn expression_strigify_write<'s, W: FmtWrite>( field_location, } => { expression_strigify_write(obj, stringifier, ExpressionLevel::Member)?; - stringifier.write_token(".", ".", dot_location)?; - stringifier.write_token(&field_name, &field_name, field_location)?; + stringifier.write_token(".", None, dot_location)?; + stringifier.write_token(&field_name, Some(&field_name), field_location)?; } Expression::DynamicMember { obj, @@ -205,9 +205,9 @@ fn expression_strigify_write<'s, W: FmtWrite>( bracket_location, } => { expression_strigify_write(obj, stringifier, ExpressionLevel::Member)?; - stringifier.write_token("[", "[", &bracket_location.0)?; + stringifier.write_token("[", None, &bracket_location.0)?; expression_strigify_write(&field_name, stringifier, ExpressionLevel::Cond)?; - stringifier.write_token("]", "]", &bracket_location.1)?; + stringifier.write_token("]", None, &bracket_location.1)?; } Expression::FuncCall { func, @@ -215,38 +215,38 @@ fn expression_strigify_write<'s, W: FmtWrite>( paren_location, } => { expression_strigify_write(func, stringifier, ExpressionLevel::Member)?; - stringifier.write_token("(", "(", &paren_location.0)?; + stringifier.write_token("(", None, &paren_location.0)?; for (index, arg) in args.iter().enumerate() { if index > 0 { stringifier.write_str(",")?; } expression_strigify_write(&arg, stringifier, ExpressionLevel::Cond)?; } - stringifier.write_token(")", ")", &paren_location.1)?; + stringifier.write_token(")", None, &paren_location.1)?; } Expression::Reverse { value, location } => { - stringifier.write_token("!", "!", location)?; + stringifier.write_token("!", None, location)?; expression_strigify_write(&value, stringifier, ExpressionLevel::Unary)?; } Expression::BitReverse { value, location } => { - stringifier.write_token("~", "~", location)?; + stringifier.write_token("~", None, location)?; expression_strigify_write(&value, stringifier, ExpressionLevel::Unary)?; } Expression::Positive { value, location } => { - stringifier.write_token(" +", " +", location)?; + stringifier.write_token(" +", None, location)?; expression_strigify_write(&value, stringifier, ExpressionLevel::Unary)?; } Expression::Negative { value, location } => { - stringifier.write_token(" -", " -", location)?; + stringifier.write_token(" -", None, location)?; expression_strigify_write(&value, stringifier, ExpressionLevel::Unary)?; } Expression::TypeOf { value, location } => { - stringifier.write_token(" typeof ", " typeof ", location)?; + stringifier.write_token(" typeof ", None, location)?; expression_strigify_write(&value, stringifier, ExpressionLevel::Unary)?; } Expression::Void { value, location } => { - stringifier.write_token(" void ", " void ", location)?; + stringifier.write_token(" void ", None, location)?; expression_strigify_write(&value, stringifier, ExpressionLevel::Unary)?; } @@ -256,7 +256,7 @@ fn expression_strigify_write<'s, W: FmtWrite>( location, } => { expression_strigify_write(&left, stringifier, ExpressionLevel::Multiply)?; - stringifier.write_token("*", "*", location)?; + stringifier.write_token("*", None, location)?; expression_strigify_write(&right, stringifier, ExpressionLevel::Unary)?; } Expression::Divide { @@ -265,7 +265,7 @@ fn expression_strigify_write<'s, W: FmtWrite>( location, } => { expression_strigify_write(&left, stringifier, ExpressionLevel::Multiply)?; - stringifier.write_token("/", "/", location)?; + stringifier.write_token("/", None, location)?; expression_strigify_write(&right, stringifier, ExpressionLevel::Unary)?; } Expression::Remainer { @@ -274,7 +274,7 @@ fn expression_strigify_write<'s, W: FmtWrite>( location, } => { expression_strigify_write(&left, stringifier, ExpressionLevel::Multiply)?; - stringifier.write_token("%", "%", location)?; + stringifier.write_token("%", None, location)?; expression_strigify_write(&right, stringifier, ExpressionLevel::Unary)?; } @@ -284,7 +284,7 @@ fn expression_strigify_write<'s, W: FmtWrite>( location, } => { expression_strigify_write(&left, stringifier, ExpressionLevel::Plus)?; - stringifier.write_token("+", "+", location)?; + stringifier.write_token("+", None, location)?; expression_strigify_write(&right, stringifier, ExpressionLevel::Multiply)?; } Expression::Minus { @@ -293,7 +293,7 @@ fn expression_strigify_write<'s, W: FmtWrite>( location, } => { expression_strigify_write(&left, stringifier, ExpressionLevel::Plus)?; - stringifier.write_token("-", "-", location)?; + stringifier.write_token("-", None, location)?; expression_strigify_write(&right, stringifier, ExpressionLevel::Multiply)?; } @@ -303,7 +303,7 @@ fn expression_strigify_write<'s, W: FmtWrite>( location, } => { expression_strigify_write(&left, stringifier, ExpressionLevel::Shift)?; - stringifier.write_token("<<", "<<", location)?; + stringifier.write_token("<<", None, location)?; expression_strigify_write(&right, stringifier, ExpressionLevel::Plus)?; } Expression::RightShift { @@ -312,7 +312,7 @@ fn expression_strigify_write<'s, W: FmtWrite>( location, } => { expression_strigify_write(&left, stringifier, ExpressionLevel::Shift)?; - stringifier.write_token(">>", ">>", location)?; + stringifier.write_token(">>", None, location)?; expression_strigify_write(&right, stringifier, ExpressionLevel::Plus)?; } Expression::UnsignedRightShift { @@ -321,7 +321,7 @@ fn expression_strigify_write<'s, W: FmtWrite>( location, } => { expression_strigify_write(&left, stringifier, ExpressionLevel::Shift)?; - stringifier.write_token(">>>", ">>>", location)?; + stringifier.write_token(">>>", None, location)?; expression_strigify_write(&right, stringifier, ExpressionLevel::Plus)?; } @@ -331,7 +331,7 @@ fn expression_strigify_write<'s, W: FmtWrite>( location, } => { expression_strigify_write(&left, stringifier, ExpressionLevel::Comparison)?; - stringifier.write_token("<", "<", location)?; + stringifier.write_token("<", None, location)?; expression_strigify_write(&right, stringifier, ExpressionLevel::Shift)?; } Expression::Lte { @@ -340,7 +340,7 @@ fn expression_strigify_write<'s, W: FmtWrite>( location, } => { expression_strigify_write(&left, stringifier, ExpressionLevel::Comparison)?; - stringifier.write_token("<=", "<=", location)?; + stringifier.write_token("<=", None, location)?; expression_strigify_write(&right, stringifier, ExpressionLevel::Shift)?; } Expression::Gt { @@ -349,7 +349,7 @@ fn expression_strigify_write<'s, W: FmtWrite>( location, } => { expression_strigify_write(&left, stringifier, ExpressionLevel::Comparison)?; - stringifier.write_token(">", ">", location)?; + stringifier.write_token(">", None, location)?; expression_strigify_write(&right, stringifier, ExpressionLevel::Shift)?; } Expression::Gte { @@ -358,7 +358,7 @@ fn expression_strigify_write<'s, W: FmtWrite>( location, } => { expression_strigify_write(&left, stringifier, ExpressionLevel::Comparison)?; - stringifier.write_token(">=", ">=", location)?; + stringifier.write_token(">=", None, location)?; expression_strigify_write(&right, stringifier, ExpressionLevel::Shift)?; } Expression::InstanceOf { @@ -367,7 +367,7 @@ fn expression_strigify_write<'s, W: FmtWrite>( location, } => { expression_strigify_write(&left, stringifier, ExpressionLevel::Comparison)?; - stringifier.write_token(" instanceof ", " instanceof ", location)?; + stringifier.write_token(" instanceof ", None, location)?; expression_strigify_write(&right, stringifier, ExpressionLevel::Shift)?; } @@ -377,7 +377,7 @@ fn expression_strigify_write<'s, W: FmtWrite>( location, } => { expression_strigify_write(&left, stringifier, ExpressionLevel::Eq)?; - stringifier.write_token("==", "==", location)?; + stringifier.write_token("==", None, location)?; expression_strigify_write(&right, stringifier, ExpressionLevel::Comparison)?; } Expression::Ne { @@ -386,7 +386,7 @@ fn expression_strigify_write<'s, W: FmtWrite>( location, } => { expression_strigify_write(&left, stringifier, ExpressionLevel::Eq)?; - stringifier.write_token("!=", "!=", location)?; + stringifier.write_token("!=", None, location)?; expression_strigify_write(&right, stringifier, ExpressionLevel::Comparison)?; } Expression::EqFull { @@ -395,7 +395,7 @@ fn expression_strigify_write<'s, W: FmtWrite>( location, } => { expression_strigify_write(&left, stringifier, ExpressionLevel::Eq)?; - stringifier.write_token("===", "===", location)?; + stringifier.write_token("===", None, location)?; expression_strigify_write(&right, stringifier, ExpressionLevel::Comparison)?; } Expression::NeFull { @@ -404,7 +404,7 @@ fn expression_strigify_write<'s, W: FmtWrite>( location, } => { expression_strigify_write(&left, stringifier, ExpressionLevel::Eq)?; - stringifier.write_token("!==", "!==", location)?; + stringifier.write_token("!==", None, location)?; expression_strigify_write(&right, stringifier, ExpressionLevel::Comparison)?; } @@ -414,7 +414,7 @@ fn expression_strigify_write<'s, W: FmtWrite>( location, } => { expression_strigify_write(&left, stringifier, ExpressionLevel::BitAnd)?; - stringifier.write_token("&", "&", location)?; + stringifier.write_token("&", None, location)?; expression_strigify_write(&right, stringifier, ExpressionLevel::Eq)?; } @@ -424,7 +424,7 @@ fn expression_strigify_write<'s, W: FmtWrite>( location, } => { expression_strigify_write(&left, stringifier, ExpressionLevel::BitXor)?; - stringifier.write_token("^", "^", location)?; + stringifier.write_token("^", None, location)?; expression_strigify_write(&right, stringifier, ExpressionLevel::BitAnd)?; } @@ -434,7 +434,7 @@ fn expression_strigify_write<'s, W: FmtWrite>( location, } => { expression_strigify_write(&left, stringifier, ExpressionLevel::BitOr)?; - stringifier.write_token("|", "|", location)?; + stringifier.write_token("|", None, location)?; expression_strigify_write(&right, stringifier, ExpressionLevel::BitXor)?; } @@ -444,7 +444,7 @@ fn expression_strigify_write<'s, W: FmtWrite>( location, } => { expression_strigify_write(&left, stringifier, ExpressionLevel::LogicAnd)?; - stringifier.write_token("&&", "&&", location)?; + stringifier.write_token("&&", None, location)?; expression_strigify_write(&right, stringifier, ExpressionLevel::BitOr)?; } @@ -454,7 +454,7 @@ fn expression_strigify_write<'s, W: FmtWrite>( location, } => { expression_strigify_write(&left, stringifier, ExpressionLevel::LogicOr)?; - stringifier.write_token("||", "||", location)?; + stringifier.write_token("||", None, location)?; expression_strigify_write(&right, stringifier, ExpressionLevel::LogicAnd)?; } Expression::NullishCoalescing { @@ -463,7 +463,7 @@ fn expression_strigify_write<'s, W: FmtWrite>( location, } => { expression_strigify_write(&left, stringifier, ExpressionLevel::LogicOr)?; - stringifier.write_token("??", "??", location)?; + stringifier.write_token("??", None, location)?; expression_strigify_write(&right, stringifier, ExpressionLevel::LogicAnd)?; } @@ -475,9 +475,9 @@ fn expression_strigify_write<'s, W: FmtWrite>( colon_location, } => { expression_strigify_write(&cond, stringifier, ExpressionLevel::LogicOr)?; - stringifier.write_token("?", "?", question_location)?; + stringifier.write_token("?", None, question_location)?; expression_strigify_write(&true_br, stringifier, ExpressionLevel::Cond)?; - stringifier.write_token(":", ":", colon_location)?; + stringifier.write_token(":", None, colon_location)?; expression_strigify_write(&false_br, stringifier, ExpressionLevel::Cond)?; } } diff --git a/glass-easel-template-compiler/src/stringify/mod.rs b/glass-easel-template-compiler/src/stringify/mod.rs index 8550164..4df3d0c 100644 --- a/glass-easel-template-compiler/src/stringify/mod.rs +++ b/glass-easel-template-compiler/src/stringify/mod.rs @@ -72,7 +72,7 @@ impl<'s, W: FmtWrite> Stringifier<'s, W> { fn write_scope_name(&mut self, index: usize, location: &Range) -> FmtResult { let name = self.get_scope_name(index).to_string(); - self.write_token(&name, &name, location) + self.write_token(&name, Some(&name), location) } fn write_str(&mut self, s: &str) -> FmtResult { @@ -91,7 +91,7 @@ impl<'s, W: FmtWrite> Stringifier<'s, W> { fn write_token( &mut self, dest_text: &str, - source_text: &str, + source_text: Option<&str>, location: &Range, ) -> FmtResult { self.smb.add( @@ -100,7 +100,7 @@ impl<'s, W: FmtWrite> Stringifier<'s, W> { location.start.line, location.start.utf16_col, Some(self.source_path), - Some(source_text), + source_text, ); self.write_str(dest_text)?; Ok(()) @@ -109,13 +109,13 @@ impl<'s, W: FmtWrite> Stringifier<'s, W> { fn write_str_name_quoted(&mut self, n: &StrName) -> FmtResult { let quoted = escape_html_quote(&n.name); self.write_str("\"")?; - self.write_token("ed, &n.name, &n.location())?; + self.write_token("ed, Some(&n.name), &n.location())?; self.write_str("\"")?; Ok(()) } - fn write_ident(&mut self, n: &Ident) -> FmtResult { - self.write_token(&n.name, &n.name, &n.location()) + fn write_ident(&mut self, n: &Ident, need_name: bool) -> FmtResult { + self.write_token(&n.name, need_name.then_some(&n.name), &n.location()) } } diff --git a/glass-easel-template-compiler/src/stringify/tag.rs b/glass-easel-template-compiler/src/stringify/tag.rs index 5dc2559..6545698 100644 --- a/glass-easel-template-compiler/src/stringify/tag.rs +++ b/glass-easel-template-compiler/src/stringify/tag.rs @@ -42,7 +42,7 @@ impl Stringify for Template { stringifier.write_str(r#">"#)?; stringifier.write_token( &content.replace(""#)?; @@ -87,12 +87,12 @@ impl Stringify for Node { Node::Element(element) => element.stringify_write(stringifier)?, Node::Comment(s, location) => { stringifier.write_str(r#"", "-- >"), &s, &location)?; + stringifier.write_token(&s.replace("-->", "-- >"), None, &location)?; stringifier.write_str(r#"-->"#)?; } Node::UnknownMetaTag(s, location) => { stringifier.write_str(r#""#)?; } } @@ -116,10 +116,10 @@ impl Stringify for Element { -> FmtResult { stringifier.write_str(" ")?; if let Some((p, loc)) = prefix { - stringifier.write_token(p, p, loc)?; + stringifier.write_token(p, None, loc)?; stringifier.write_str(":")?; } - stringifier.write_ident(name)?; + stringifier.write_ident(name, true)?; if !is_empty_value(value) { stringifier.write_str(r#"=""#)?; value.stringify_write(stringifier)?; @@ -134,10 +134,10 @@ impl Stringify for Element { -> FmtResult { stringifier.write_str(" ")?; if let Some((p, loc)) = prefix { - stringifier.write_token(p, p, loc)?; + stringifier.write_token(p, None, loc)?; stringifier.write_str(":")?; } - stringifier.write_ident(name)?; + stringifier.write_ident(name, true)?; if value.name.len() > 0 { stringifier.write_str(r#"="#)?; stringifier.write_str_name_quoted(value)?; @@ -150,7 +150,7 @@ impl Stringify for Element { value: &Value| -> FmtResult { stringifier.write_str(" ")?; - stringifier.write_token(name, name, location)?; + stringifier.write_token(name, Some(name), location)?; if !is_empty_value(value) { stringifier.write_str(r#"=""#)?; value.stringify_write(stringifier)?; @@ -164,7 +164,7 @@ impl Stringify for Element { value: &StrName| -> FmtResult { stringifier.write_str(" ")?; - stringifier.write_token(name, name, location)?; + stringifier.write_token(name, Some(name), location)?; if value.name.len() > 0 { stringifier.write_str(r#"="#)?; stringifier.write_str_name_quoted(value)?; @@ -180,11 +180,11 @@ impl Stringify for Element { stringifier.write_str(" ")?; stringifier.write_token( "slot", - "slot", + None, attr.prefix_location.as_ref().unwrap_or(&attr.name.location), )?; stringifier.write_str(":")?; - stringifier.write_token(&attr.name.name, &attr.name.name, &attr.name.location)?; + stringifier.write_token(&attr.name.name, Some(&attr.name.name), &attr.name.location)?; if value != &attr.name.name { stringifier.write_str(r#"="#)?; stringifier.write_str_name_quoted(&StrName { @@ -255,7 +255,7 @@ impl Stringify for Element { { let mut is_first = true; for (loc, value, children) in branches { - stringifier.write_token("<", "<", &self.start_tag_location.0)?; + stringifier.write_token("<", None, &self.start_tag_location.0)?; stringifier.write_str("block")?; let name = if is_first { is_first = false; @@ -265,24 +265,24 @@ impl Stringify for Element { }; write_named_attr(stringifier, name, loc, value)?; if children.len() > 0 { - stringifier.write_token(">", ">", &self.start_tag_location.1)?; + stringifier.write_token(">", None, &self.start_tag_location.1)?; for child in children { child.stringify_write(stringifier)?; } stringifier.write_token( "<", - "<", + None, &self .end_tag_location .as_ref() .unwrap_or(&self.start_tag_location) .0, )?; - stringifier.write_token("/", "/", &self.close_location)?; + stringifier.write_token("/", None, &self.close_location)?; stringifier.write_str("block")?; stringifier.write_token( ">", - ">", + None, &self .end_tag_location .as_ref() @@ -290,34 +290,34 @@ impl Stringify for Element { .1, )?; } else { - stringifier.write_token("/", "/", &self.close_location)?; - stringifier.write_token(">", ">", &self.start_tag_location.1)?; + stringifier.write_token("/", None, &self.close_location)?; + stringifier.write_token(">", None, &self.start_tag_location.1)?; } } if let Some((loc, children)) = else_branch.as_ref() { - stringifier.write_token("<", "<", &self.start_tag_location.0)?; + stringifier.write_token("<", None, &self.start_tag_location.0)?; stringifier.write_str("block")?; stringifier.write_str(" ")?; - stringifier.write_token("wx:else", "wx:else", loc)?; + stringifier.write_token("wx:else", None, loc)?; if children.len() > 0 { - stringifier.write_token(">", ">", &self.start_tag_location.1)?; + stringifier.write_token(">", None, &self.start_tag_location.1)?; for child in children { child.stringify_write(stringifier)?; } stringifier.write_token( "<", - "<", + None, &self .end_tag_location .as_ref() .unwrap_or(&self.start_tag_location) .0, )?; - stringifier.write_token("/", "/", &self.close_location)?; + stringifier.write_token("/", None, &self.close_location)?; stringifier.write_str("block")?; stringifier.write_token( ">", - ">", + None, &self .end_tag_location .as_ref() @@ -325,8 +325,8 @@ impl Stringify for Element { .1, )?; } else { - stringifier.write_token("/", "/", &self.close_location)?; - stringifier.write_token(">", ">", &self.start_tag_location.1)?; + stringifier.write_token("/", None, &self.close_location)?; + stringifier.write_token(">", None, &self.start_tag_location.1)?; } } return Ok(()); @@ -334,7 +334,7 @@ impl Stringify for Element { // write tag start let prev_scopes_count = stringifier.scope_names.len(); - stringifier.write_token("<", "<", &self.start_tag_location.0)?; + stringifier.write_token("<", None, &self.start_tag_location.0)?; match &self.kind { ElementKind::Normal { tag_name, @@ -349,7 +349,7 @@ impl Stringify for Element { extra_attr, common, } => { - stringifier.write_ident(&tag_name)?; + stringifier.write_ident(&tag_name, true)?; write_slot_and_slot_values(stringifier, &common.slot, &common.slot_value_refs)?; match class { ClassAttribute::None => {} @@ -513,23 +513,23 @@ impl Stringify for Element { let empty_children = vec![]; let children = self.children().unwrap_or(&empty_children); if children.len() > 0 { - stringifier.write_token(">", ">", &self.start_tag_location.1)?; + stringifier.write_token(">", None, &self.start_tag_location.1)?; for child in children { child.stringify_write(stringifier)?; } stringifier.write_token( "<", - "<", + None, &self .end_tag_location .as_ref() .unwrap_or(&self.start_tag_location) .0, )?; - stringifier.write_token("/", "/", &self.close_location)?; + stringifier.write_token("/", None, &self.close_location)?; match &self.kind { ElementKind::Normal { tag_name, .. } => { - stringifier.write_ident(&tag_name)?; + stringifier.write_ident(&tag_name, false)?; } ElementKind::Pure { .. } | ElementKind::For { .. } => { stringifier.write_str("block")?; @@ -547,7 +547,7 @@ impl Stringify for Element { } stringifier.write_token( ">", - ">", + None, &self .end_tag_location .as_ref() @@ -555,8 +555,8 @@ impl Stringify for Element { .1, )?; } else { - stringifier.write_token("/", "/", &self.close_location)?; - stringifier.write_token(">", ">", &self.start_tag_location.1)?; + stringifier.write_token("/", None, &self.close_location)?; + stringifier.write_token(">", None, &self.start_tag_location.1)?; } // reset scopes @@ -571,7 +571,7 @@ impl Stringify for Value { match self { Self::Static { value, location } => { let quoted = escape_html_body(&value); - stringifier.write_token(&format!("{}", quoted), &value, &location)?; + stringifier.write_token(&format!("{}", quoted), None, &location)?; } Self::Dynamic { expression, @@ -586,13 +586,13 @@ impl Stringify for Value { ) -> FmtResult { match expr { Expression::LitStr { value, location } => { - stringifier.write_token(&escape_html_body(value), value, location)?; + stringifier.write_token(&escape_html_body(value), None, location)?; return Ok(()); } Expression::ToStringWithoutUndefined { value, location } => { - stringifier.write_token("{{", "{{", &start_location)?; + stringifier.write_token("{{", None, &start_location)?; value.stringify_write(stringifier)?; - stringifier.write_token("}}", "}}", &location)?; + stringifier.write_token("}}", None, &location)?; return Ok(()); } Expression::Plus { @@ -619,9 +619,9 @@ impl Stringify for Value { } _ => {} } - stringifier.write_token("{{", "{{", &start_location)?; + stringifier.write_token("{{", None, &start_location)?; expr.stringify_write(stringifier)?; - stringifier.write_token("}}", "}}", &end_location)?; + stringifier.write_token("}}", None, &end_location)?; Ok(()) } split_expression( @@ -657,22 +657,22 @@ mod test { r#"