fix: dont choke on emojji n exprs
This commit is contained in:
1 parent
ae1a618aa8
commit
4e4e101eee
5 files changed
+32
-21
No files matched your search
@@ -3,7 +3,7 @@ use std::fmt::{Result, Write};
|
|||||||
|
|
||||||
use proc_macro2::Span;
|
use proc_macro2::Span;
|
||||||
|
|
||||||
use crate::Writer;
|
use crate::{collect_macros::byte_offset, Writer};
|
||||||
|
|
||||||
impl Writer<'_> {
|
impl Writer<'_> {
|
||||||
pub fn write_raw_expr(&mut self, placement: Span) -> Result {
|
pub fn write_raw_expr(&mut self, placement: Span) -> Result {
|
||||||
@@ -16,7 +16,10 @@ impl Writer<'_> {
|
|||||||
|
|
||||||
// if the expr is on one line, just write it directly
|
// if the expr is on one line, just write it directly
|
||||||
if start.line == end.line {
|
if start.line == end.line {
|
||||||
let row = &self.src[start.line - 1][start.column..end.column].trim();
|
// split counting utf8 chars
|
||||||
|
let start = byte_offset(self.raw_src, start);
|
||||||
|
let end = byte_offset(self.raw_src, end);
|
||||||
|
let row = self.raw_src[start..end].trim();
|
||||||
write!(self.out, "{}", row)?;
|
write!(self.out, "{}", row)?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,10 +53,7 @@ pub fn fmt_file(contents: &str) -> Vec<FormattedBlock> {
|
|||||||
return formatted_blocks;
|
return formatted_blocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut writer = Writer {
|
let mut writer = Writer::new(contents);
|
||||||
src: contents.lines().collect::<Vec<_>>(),
|
|
||||||
..Writer::default()
|
|
||||||
};
|
|
||||||
|
|
||||||
// Dont parse nested macros
|
// Dont parse nested macros
|
||||||
let mut end_span = LineColumn { column: 0, line: 0 };
|
let mut end_span = LineColumn { column: 0, line: 0 };
|
||||||
@@ -125,10 +122,7 @@ pub fn fmt_file(contents: &str) -> Vec<FormattedBlock> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_block_out(body: CallBody) -> Option<String> {
|
pub fn write_block_out(body: CallBody) -> Option<String> {
|
||||||
let mut buf = Writer {
|
let mut buf = Writer::new("");
|
||||||
src: vec![""],
|
|
||||||
..Writer::default()
|
|
||||||
};
|
|
||||||
|
|
||||||
write_body(&mut buf, &body);
|
write_body(&mut buf, &body);
|
||||||
|
|
||||||
@@ -157,10 +151,7 @@ fn write_body(buf: &mut Writer, body: &CallBody) {
|
|||||||
pub fn fmt_block_from_expr(raw: &str, expr: ExprMacro) -> Option<String> {
|
pub fn fmt_block_from_expr(raw: &str, expr: ExprMacro) -> Option<String> {
|
||||||
let body = syn::parse2::<CallBody>(expr.mac.tokens).unwrap();
|
let body = syn::parse2::<CallBody>(expr.mac.tokens).unwrap();
|
||||||
|
|
||||||
let mut buf = Writer {
|
let mut buf = Writer::new(raw);
|
||||||
src: raw.lines().collect(),
|
|
||||||
..Writer::default()
|
|
||||||
};
|
|
||||||
|
|
||||||
write_body(&mut buf, &body);
|
write_body(&mut buf, &body);
|
||||||
|
|
||||||
@@ -170,10 +161,7 @@ pub fn fmt_block_from_expr(raw: &str, expr: ExprMacro) -> Option<String> {
|
|||||||
pub fn fmt_block(block: &str, indent_level: usize) -> Option<String> {
|
pub fn fmt_block(block: &str, indent_level: usize) -> Option<String> {
|
||||||
let body = syn::parse_str::<dioxus_rsx::CallBody>(block).unwrap();
|
let body = syn::parse_str::<dioxus_rsx::CallBody>(block).unwrap();
|
||||||
|
|
||||||
let mut buf = Writer {
|
let mut buf = Writer::new(block);
|
||||||
src: block.lines().collect(),
|
|
||||||
..Writer::default()
|
|
||||||
};
|
|
||||||
|
|
||||||
buf.out.indent = indent_level;
|
buf.out.indent = indent_level;
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,9 @@ use syn::{spanned::Spanned, Expr, ExprIf};
|
|||||||
|
|
||||||
use crate::buffer::Buffer;
|
use crate::buffer::Buffer;
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug)]
|
||||||
pub struct Writer<'a> {
|
pub struct Writer<'a> {
|
||||||
|
pub raw_src: &'a str,
|
||||||
pub src: Vec<&'a str>,
|
pub src: Vec<&'a str>,
|
||||||
pub cached_formats: HashMap<Location, String>,
|
pub cached_formats: HashMap<Location, String>,
|
||||||
pub comments: VecDeque<usize>,
|
pub comments: VecDeque<usize>,
|
||||||
@@ -31,7 +32,18 @@ impl Location {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Writer<'_> {
|
impl<'a> Writer<'a> {
|
||||||
|
pub fn new(raw_src: &'a str) -> Self {
|
||||||
|
let src = raw_src.lines().collect();
|
||||||
|
Self {
|
||||||
|
raw_src,
|
||||||
|
src,
|
||||||
|
cached_formats: HashMap::new(),
|
||||||
|
comments: VecDeque::new(),
|
||||||
|
out: Buffer::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Expects to be written directly into place
|
// Expects to be written directly into place
|
||||||
pub fn write_ident(&mut self, node: &BodyNode) -> Result {
|
pub fn write_ident(&mut self, node: &BodyNode) -> Result {
|
||||||
match node {
|
match node {
|
||||||
|
|||||||
@@ -39,5 +39,6 @@ twoway![
|
|||||||
t2,
|
t2,
|
||||||
reallylong,
|
reallylong,
|
||||||
immediate_expr,
|
immediate_expr,
|
||||||
collapse_expr
|
collapse_expr,
|
||||||
|
trailing_expr
|
||||||
];
|
];
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fn it_works() {
|
||||||
|
cx.render(rsx! {
|
||||||
|
div {
|
||||||
|
span { "Description: ", package.description.as_deref().unwrap_or("❌❌❌❌ missing") }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
Reference in new issue
Block a user