Browse Source

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

dev
Evan You 7 years ago
parent
commit
248803146c
  1. 3
      flow/compiler.js
  2. 9
      src/compiler/parser/index.js

3
flow/compiler.js

@ -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

9
src/compiler/parser/index.js

@ -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) {

Loading…
Cancel
Save