Преглед на файлове

fix(ssr): support rendering comment (#9128)

Xin Du (Clark) преди 7 години
родител
ревизия
b06c784b81
променени са 2 файла, в които са добавени 18 реда и са изтрити 1 реда
  1. 5 1
      src/server/optimizing-compiler/codegen.js
  2. 13 0
      test/unit/modules/server-compiler/compiler-options.spec.js

+ 5 - 1
src/server/optimizing-compiler/codegen.js

@@ -225,7 +225,11 @@ function nodesToSegments (
     } else if (c.type === 2) {
       segments.push({ type: INTERPOLATION, value: c.expression })
     } else if (c.type === 3) {
-      segments.push({ type: RAW, value: escape(c.text) })
+      let text = escape(c.text)
+      if (c.isComment) {
+        text = '<!--' + text + '-->'
+      }
+      segments.push({ type: RAW, value: text })
     }
   }
   return segments

+ 13 - 0
test/unit/modules/server-compiler/compiler-options.spec.js

@@ -0,0 +1,13 @@
+import { ssrCompile } from 'web/server/compiler'
+
+describe('ssrCompile options', () => {
+  it('comments', () => {
+    const compiled = ssrCompile(`
+      <div>
+        <!-- test comments -->
+      </div>
+    `, { comments: true })
+
+    expect(compiled.render).toContain('<!-- test comments -->')
+  })
+})