You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, everyone, I have a new idea, I am trying to use rust to parse vue sfc template to ast, how about the performance. However, I attempted to hijack the official parse method in the following way and failed. Could you please tell me how to configure it correctly.
// vite.config.ts fileimport{fileURLToPath,URL}from'node:url'import{defineConfig}from'vite'importvuefrom'@vitejs/plugin-vue'//import {compileTemplate} from 'vue-template-compiler-rs'import{transform,generate}from'@vue/compiler-dom'functioncompileWithRust(template: string,options: any){constast_str=compileTemplate(template)// using Rust compile//console.log(ast_str);letast=JSON.parse(ast_str);//console.log(ast);transform(ast,options)// official transformreturngenerate(ast,options)// official codegen}// simple mocking compilefunctioncompileTemplate(template: string):string{returnJSON.stringify({"type":0,"children":[{"type":1,"tag":"div","tagType":0,"isSelfClosing":false,"props":[],"children":[{"type":2,"content":"msg",}],"ns":0,}]})}// https://vite.dev/config/exportdefaultdefineConfig({plugins: [vue({template:{compiler:{compile: compileWithRust,parse: (template:string,options:any)=>{//console.log(template);constastJson=compileTemplate(template)returnJSON.parse(astJson)}},},}),],resolve: {alias: {'@': fileURLToPath(newURL('./src',import.meta.url))},},})
error info:
13:27:29 [vite] Internal server error: Cannot read properties of undefined (reading 'type')
Plugin: vite:vue
File: /Users/tu6ge/rust/vue-example/src/App.vue
at walk (/Users/tu6ge/rust/vue-example/node_modules/.pnpm/@[email protected]/node_modules/@vue/compiler-core/dist/compiler-core.cjs.js:3031:25)
at cacheStatic (/Users/tu6ge/rust/vue-example/node_modules/.pnpm/@[email protected]/node_modules/@vue/compiler-core/dist/compiler-core.cjs.js:3003:3)
at transform (/Users/tu6ge/rust/vue-example/node_modules/.pnpm/@[email protected]/node_modules/@vue/compiler-core/dist/compiler-core.cjs.js:3478:5)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, everyone, I have a new idea, I am trying to use rust to parse vue sfc template to ast, how about the performance. However, I attempted to hijack the official parse method in the following way and failed. Could you please tell me how to configure it correctly.
error info:
Beta Was this translation helpful? Give feedback.
All reactions