Просмотр исходного кода

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

Evan You 8 лет назад
Родитель
Сommit
248803146c
2 измененных файлов с 8 добавлено и 4 удалено
  1. 3 0
      flow/compiler.js
  2. 5 4
      src/compiler/parser/index.js

+ 3 - 0
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

+ 5 - 4
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) {