refactor(compiler): move postTransforms to after children are processed

This commit is contained in:
Evan You 2017-09-06 03:01:54 -04:00
parent 996eb00a0a
commit 248803146c
2 changed files with 8 additions and 4 deletions

View File

@ -37,9 +37,12 @@ declare type CompiledResult = {
};
declare type ModuleOptions = {
// transform an AST node before any attributes are processed
// returning an ASTElement from pre/transforms replaces the element
preTransformNode: (el: ASTElement) => ?ASTElement;
// transform an AST node after built-ins like v-if, v-for are processed
transformNode: (el: ASTElement) => ?ASTElement;
// transform an AST node after its children have been processed
// cannot return replacement in postTransform because tree is already finalized
postTransformNode: (el: ASTElement) => void;
genData: (el: ASTElement) => string; // generate extra data string for an element

View File

@ -221,10 +221,6 @@ export function parse (
} else {
endPre(element)
}
// apply post-transforms
for (let i = 0; i < postTransforms.length; i++) {
postTransforms[i](element, options)
}
},
end () {
@ -238,6 +234,11 @@ export function parse (
stack.length -= 1
currentParent = stack[stack.length - 1]
endPre(element)
// apply post-transforms
for (let i = 0; i < postTransforms.length; i++) {
postTransforms[i](element, options)
}
},
chars (text: string) {