phoenix-ru / fervid Goto Github PK
View Code? Open in Web Editor NEWAll-in-One Vue compiler written in Rust
Home Page: https://phoenix-ru.github.io/fervid/
License: Apache License 2.0
All-in-One Vue compiler written in Rust
Home Page: https://phoenix-ru.github.io/fervid/
License: Apache License 2.0
Features I personally find very desirable:
<template>
{{ 1+1 }}
</template>
<script setup>
import { ref } from 'vue'
const name = ref('fervid')
</script>
Current detection only works for the top-most level. The spec requires nested detection except for functions.
To avoid extra overhead of using unimport in js side, most of the component and directive resolutions can happen in the Rust side.
unimport
works on source code;unimport
gathers the auto-import symbols (across source code and dependencies);import 'x'
-> node_modules/path/to/x/index.js
) in Rust;Lazy
prefixed imports;Make module generator produce getters and setters for certain bindings
I am still not sure how TS is used in the official compiler to generate .d.ts
of .vue
files. It uses defineComponent
in the generated code but I want to find a balance between generating the most optimal code (i.e. omitting defineComponent
) and supporting TS definitions.
At the moment of writing, GitHub CI has no ARM-based hosted runners for public repositories.
As a follow-up from #12, we should add tests for ARM builds using QEMU.
Implement user imports deduplication between two scripts
The possible compilation targets are (excluding DEV/PROD differences):
.d.ts
generation;The compiler needs to be able to efficiently support all the targets with some common layer and target-specific implementations.
name
should be inferred based on file name.
It may also be a good idea to use file paths as part of name (@/foo/bar.vue
-> name: 'FooBar'
, but the spec has no such requirement.
Spec dictates that exports should not be allowed in script setup.
The official Vue parser allows self-closing any HTML, but this is not valid by the spec. For example, this:
<template>
<slot />
<div class="bad" />
</template>
Using Nu HTML Checker by W3 results in a clear error:
The same happens when parsing with swc_html_parser
. The error is being reported and the tag is not being closed:
InvalidHtml(NonVoidHtmlElementStartTagWithTrailingSolidus) <slot />
In addition, this also messes up the DOM Tree stack, which is the actual problem here.
All NonVoidHtmlElementStartTagWithTrailingSolidus
should be considered a hard error.
It would also be nice to do RegEx search-replace as a utility in fervid
.
Another option is to parse the HTML and only apply this fix to where the NonVoidHtmlElementStartTagWithTrailingSolidus
problem is encountered.
Writing SFCs using the default JS compiler and https://github.com/unplugin/unplugin-auto-import produces not-so-optimal code.
Take this for example (playground):
<script setup>
const msg = ref('Hello World!')
</script>
<template>
<h1>{{ msg }}</h1>
<input v-model="msg" />
</template>
Correct binding type of msg
cannot be properly inferred, which leads to compiler generating unref(msg)
, which in turn has runtime cost.
In addition to that, extra build step is needed to properly auto-import the ref
.
A better approach would be to add a ref
/computed
/etc. vue-specific imports whenever their usage is detected. It is much cheaper and more beneficial to do so in the SFC compiler than in any other tool.
Steps:
import { ref } from 'vue'
instead of ref as _ref
);import { ref } from './custom-path'
should not auto-import).Farm is now 1.0 stable, the Rust plugin(https://www.farmfe.org/docs/plugins/writing-plugins/rust-plugin) are available for community plugin developers too.
We want to develop a Rust vue plugin based on this project, can we have a collaboration. Relative issue: farm-fe/farm#125
When using <script setup lang="ts">
we can make assumptions regarding binding types. For instance, we can confidently infer the types of bindings in this example:
<script setup lang="ts">
import { ref, computed } from 'vue'
const foo = ref('Hello')
const bar = ref(1)
const baz = computed<number>(() => bar.value * 2)
</script>
fervid
can trust the user's TypeScript setup to catch type errors. In the future, when stc is mature enough, it will be used for type inference and checking.
Knowing the binding TS type, we can further optimize the generation of Interpolations and SSR attributes:
const msg = ref('') // string
What | Mode | Current generation | Proposal generation |
---|---|---|---|
{{ msg }} | CSR | _toDisplayString(msg.value) | msg.value |
{{ msg }} | SSR | _ssrInterpolate(msg.value) | msg.value |
:value="msg" | SSR | _ssrRenderAttr("value", msg.value) | `value="${msg.value}"` |
By having the knowledge of types we can omit unnecessary runtime checks and also ship less code.
The transformer already detects Vue-specific symbols, such as ref
and computed
. We can extend the analysis to also visit the value (second priority) or the type annotations (first priority) and store this information along with the BindingTypes
.
Considering the fact that TS types are complex and inference may not be trivial, the TS type must be an optional hint for the compiler.
When no such type can be inferred (or when outside TS), the compiler should fall back to default code generation.
hi @phoenix-ru Is support for unplugin already under way? I'd like to be involved if I can.
The project is wonderful.
In other to test and check it more conveniently, I'd like to request a playground, like this one.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.