]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-ssr): keep the order of imports expression for the fallback branch of...
authorHcySunYang <HcySunYang@outlook.com>
Thu, 25 Mar 2021 15:10:25 +0000 (23:10 +0800)
committerGitHub <noreply@github.com>
Thu, 25 Mar 2021 15:10:25 +0000 (11:10 -0400)
fix #3447

packages/compiler-sfc/__tests__/compileTemplate.spec.ts
packages/compiler-ssr/src/transforms/ssrTransformComponent.ts

index 576240b5e1d81dbc8aad1b156e541ca415053920..af0f66007c71c16b8876567d3e754a4611fdd49b 100644 (file)
@@ -137,3 +137,19 @@ test('preprocessor errors', () => {
     `The end of the string reached with no closing bracket ) found.`
   )
 })
+
+// #3447
+test('should generate the correct imports expression', () => {
+  const { code } = compile({
+    filename: 'example.vue',
+    source: `
+      <img src="./foo.svg"/>
+      <Comp>
+        <img src="./bar.svg"/>
+      </Comp>
+    `,
+    ssr: true
+  })
+  expect(code).toMatch(`_ssrRenderAttr(\"src\", _imports_1)`)
+  expect(code).toMatch(`_createVNode(\"img\", { src: _imports_1 })`)
+})
index de96b7efc677d0515eadbbedfb4f36f2737ff459..dc53aaf982c337cc9ba77a0f2ca5447248c164db 100644 (file)
@@ -293,6 +293,7 @@ function subTransform(
   // inherit parent scope analysis state
   childContext.scopes = { ...parentContext.scopes }
   childContext.identifiers = { ...parentContext.identifiers }
+  childContext.imports = parentContext.imports
   // traverse
   traverseNode(childRoot, childContext)
   // merge helpers/components/directives into parent context