https://github.com/vuejs/rfcs/discussions/369#discussioncomment-1192421
Maybe in the long run we want the whole transform (and even the Vue compiler!) to be implemented in native Go/Rust so performance would no longer be a concern ;)
Future is now!
Design
The original design in vue-next mixes . As we can see, the transform pass will in-place mutate ast nodes, leaving the node with both code generation node and ssr code generation node.
This is typically a sign of leaky abstraction. So in the Rust version I decided to take another approach.
The compilation has several phases:
- Scan (output: Token)
- Parse (output: template AST)
- intermediate representation
- transformation/optimization pass
- output generation
Intended Usage
- Rust library
- CLI binary
- napi based nodejs library
- wasm based npm package
Implementation Detail
- The library seeks minimal allocation by using
&str
,Cow<'_, str>
andsmallvec
. -
Fxhash
is preferred over default hasher since hash collision is not a concern. - The
bitflags
crate is used to represent runtime helper and vnode patch flags. - Use heavily optimized routines for string search primitives.
- Benchmark with criterion.rs.
- Test compiler output by snapshot test.
Reference
- vue-next: ご本家様
- html spec is the definitive guide for parsing HTML-like files.
- Vue Template Explorer gives instant results for code generation and error reporting.
- Nu html checker is the official html validator from W3C. This is the canonical error reporter for html parsing, when there is a discrepancy between the framework and the spec.
- AST explorer can inspect AST nodes interactively.
Performance Related Reference
- https://lise-henry.github.io/articles/optimising_strings.html
Roadmap
Todo tasks grouped by scopes.
[core]
- tokenizer
- parser
- IR converter
- transformer
- code generator
[dom]
- transformer
- code generator
[ssr]
- TODO
[sfc]
- TODO
[test]
- Add unit test
- Add insta snapshot
[bench]
- Add benchmark framework
- Micro benchmarks for compiler components
- Integrated benchmarks using repos like Element-Plus
[infra]
- Add pre-commit hooks.
- Add Github Actions for various checks.
[community]
- TODO. not ready for contribution for now.