Giter VIP home page Giter VIP logo

vue3-compiler-learn's Introduction

vue3-compiler-learn

以代码实践 深入学习模板编译原理

Edit on StackBlitz ⚡️


由于 vue3 修改和移除了 vue2 的部分特性

比如:

  • 移除了 .sync 修饰符
  • v-slot 只能用于 组件<template> 标签
  • v-if 优先级比 v-for
  • v-model 默认变成了 v-model:modelValue

为了更好的深入 vue3 模板编译原理,我尝试在编译时对 AST 进行转换,以解决上面问题为目标来 👉练练手👈

目标:

  • 实现对 sync 修饰符的支持
  • v-slot 指令可用于 div 等普通元素
  • v-forv-if 回调到和 vue2 一样的优先级
  • v-model 默认绑定到 value 属性



.sync 转化为 @update:xxx [演示]

<my-component :value.sync="count" />

转换后

<my-component :value="count" @update:value="count = $event" />

v-slot 支持到普通元素 [演示]

<my-component>
  <div #footer></div>
</my-component>

转换后

<my-component>
  <template #footer>
    <div></div>
  </template>
</my-component>

v-for 优先级高于 v-if [演示]

<span v-for="i in 10" v-if="i % 2">{{ i }}</span>

转换后

<template v-for="i in 10">
  <template v-if="i % 2">
    <span>{{ i }}</span>
  </template>
</template>

v-model 默认为 v-model:value [演示]

<my-component v-model="value" />

转换后

<my-component v-model:value="value" />

更多内容持续更新中……

如果你有更多想法,欢迎给我 PR


👍 点个赞吧 ✨ 👈

vue3-compiler-learn's People

Contributors

huodoushigemi avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.