-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
Closed
Labels
Description
What problem does this feature solve?
It may sounds awkward when using the modified AST to generate render function instead of using template files as input. But, in the following cases, it might be useful:
What if:
- people want to do some optimized operations on AST like what the
optimizer.jsdoes before jump into the codegen method in the baseCompile function. - a pre-disposed component can be loaded via webpack loader which implements the exposed generate function to get the new render function. In this case, I can initially load some customized vue components with new added dom elements, attributes, events and etc.
- I can visually edit the rendered components by modifying the ASTs instead of the original template which is considered to be much easier.
- After the previous step, I can even generate the new template file like the reverse way of template -> AST -> render function.
I'm not sure whether there is an alternative way of doing the things above, but it might be helpful when it comes to something like visualized vue components development IDE.
What does the proposed API look like?
Maybe in the createCompilerCreator function, we can add a function as property in compile method like:
compile.fromAST = function fromAST(
ast
) {
return generate(ast, baseOptions)
};
in line 49, src/compiler/create-compiler.js
OEvgeny, cottom and whq731