Browse Source

fix(compiler-vapor): add newline after effect body

三咲智子 Kevin Deng 2 years ago
parent
commit
126796edb9

+ 6 - 3
packages/compiler-vapor/__tests__/transforms/__snapshots__/vOn.spec.ts.snap

@@ -340,7 +340,8 @@ export function render(_ctx) {
   _renderEffect(() => {
     _on(n1, (_ctx.event) === "click" ? "mouseup" : (_ctx.event), () => _ctx.test, undefined, {
       modifiers: ["middle"]
-    })})
+    })
+  })
   return n0
 }"
 `;
@@ -370,7 +371,8 @@ export function render(_ctx) {
     _on(n1, (_ctx.event) === "click" ? "contextmenu" : (_ctx.event), () => _ctx.test, undefined, {
       modifiers: ["right"],
       keys: ["right"]
-    })})
+    })
+  })
   return n0
 }"
 `;
@@ -398,7 +400,8 @@ export function render(_ctx) {
     _on(n1, _ctx.e, () => _ctx.test, undefined, {
       modifiers: ["left"],
       keys: ["left"]
-    })})
+    })
+  })
   return n0
 }"
 `;

+ 4 - 4
packages/compiler-vapor/src/generators/operation.ts

@@ -76,14 +76,14 @@ export function genEffect({ operations }: IREffect, context: CodegenContext) {
     `${vaporHelper('renderEffect')}(() => `,
   )
 
-  const [fragOps, pushOps] = buildCodeFragment()
+  const [operationsExps, pushOps] = buildCodeFragment()
   operations.forEach(op => pushOps(...genOperation(op, context)))
 
-  const newlineCount = fragOps.filter(frag => frag === NEWLINE).length
+  const newlineCount = operationsExps.filter(frag => frag === NEWLINE).length
   if (newlineCount > 1) {
-    push('{', INDENT_START, ...fragOps, INDENT_END, '})')
+    push('{', INDENT_START, ...operationsExps, INDENT_END, NEWLINE, '})')
   } else {
-    push(...fragOps.filter(frag => frag !== NEWLINE), ')')
+    push(...operationsExps.filter(frag => frag !== NEWLINE), ')')
   }
 
   return frag