From: HcySunYang Date: Thu, 25 Mar 2021 15:10:25 +0000 (+0800) Subject: fix(compiler-ssr): keep the order of imports expression for the fallback branch of... X-Git-Tag: v3.0.8~36 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=49f4072c83c06a66e2b7a334d8dedabd1b433ca9;p=thirdparty%2Fvuejs%2Fcore.git fix(compiler-ssr): keep the order of imports expression for the fallback branch of SSR (#3448) fix #3447 --- diff --git a/packages/compiler-sfc/__tests__/compileTemplate.spec.ts b/packages/compiler-sfc/__tests__/compileTemplate.spec.ts index 576240b5e1..af0f66007c 100644 --- a/packages/compiler-sfc/__tests__/compileTemplate.spec.ts +++ b/packages/compiler-sfc/__tests__/compileTemplate.spec.ts @@ -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: ` + + + + + `, + ssr: true + }) + expect(code).toMatch(`_ssrRenderAttr(\"src\", _imports_1)`) + expect(code).toMatch(`_createVNode(\"img\", { src: _imports_1 })`) +}) diff --git a/packages/compiler-ssr/src/transforms/ssrTransformComponent.ts b/packages/compiler-ssr/src/transforms/ssrTransformComponent.ts index de96b7efc6..dc53aaf982 100644 --- a/packages/compiler-ssr/src/transforms/ssrTransformComponent.ts +++ b/packages/compiler-ssr/src/transforms/ssrTransformComponent.ts @@ -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