Hotreloading of for/if/body, formatted strings, literals, component props, nested rsx, light CLI rewrite, cli TUI (#2258)

Hotreload the contents of for loops, if chains, component bodies, props, attributes, and any literals discovered in rsx!
Add a TUI renderer to the CLI.
Improve the CLI build system to be async and parallel.
Refactor RSX to allow partial expansion of expressions.
Merge autofmt implementations for consistency.
Merge the representation of elements and components under the hood.
Add a diagnostics system for rsx for improved error messages.
Drop interprocess and move to websockets for communication between the CLI and the server.
Assign IDs to nodes and attributes in a stable way to be used in non compiler contexts.
Add hotreloading to any body of component/for loop/if chain/etc.

---------

Co-authored-by: Evan Almloff <evanalmloff@gmail.com>
Co-authored-by: Liam Mitchell <liamkarlmitchell@gmail.com>
This commit is contained in:
authored and GitHub committed 2024-07-17 19:11:18 -07:00
1 parent 176e67e5b7
commit 88af3e7eff
181 files changed
+12755 -10806

No files matched your search

+11 -12
View File
@@ -18,6 +18,7 @@ use crate::{
};
use crate::{Task, VComponent};
use futures_util::StreamExt;
use rustc_hash::FxHashMap;
use slab::Slab;
use std::collections::BTreeSet;
use std::{any::Any, rc::Rc};
@@ -207,13 +208,8 @@ pub struct VirtualDom {
pub(crate) dirty_scopes: BTreeSet<ScopeOrder>,
// Maps a template path to a map of byte indexes to templates
// if hot reload is enabled, we need to keep track of template overrides
#[cfg(debug_assertions)]
pub(crate) templates: rustc_hash::FxHashMap<TemplateId, rustc_hash::FxHashMap<usize, Template>>,
// Otherwise, we just need to keep track of what templates we have registered
#[cfg(not(debug_assertions))]
pub(crate) templates: rustc_hash::FxHashSet<TemplateId>,
// A map of overridden templates?
pub(crate) templates: FxHashMap<TemplateId, Template>,
// Templates changes that are queued for the next render
pub(crate) queued_templates: Vec<Template>,
@@ -576,17 +572,20 @@ impl VirtualDom {
// we only replace templates if hot reloading is enabled
#[cfg(debug_assertions)]
{
self.register_template_first_byte_index(template);
// Save the template ID
self.templates.insert(template.name, template);
// Only queue the template to be written if its not completely dynamic
if !template.is_completely_dynamic() {
self.queued_templates.push(template);
}
// iterating a slab is very inefficient, but this is a rare operation that will only happen during development so it's fine
let mut dirty = Vec::new();
for (id, scope) in self.scopes.iter() {
// Recurse into the dynamic nodes of the existing mounted node to see if the template is alive in the tree
fn check_node_for_templates(node: &crate::VNode, template: Template) -> bool {
let this_template_name = node.template.get().name.rsplit_once(':').unwrap().0;
let other_template_name = template.name.rsplit_once(':').unwrap().0;
if this_template_name == other_template_name {
if node.template.get().name == template.name {
return true;
}