From: Evan You Date: Fri, 8 Oct 2021 16:52:48 +0000 (-0400) Subject: fix(compiler-sfc): fix props codegen w/ leading import X-Git-Tag: v3.2.20~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d4c04e979934b81a30467aa4b1e717175b9b2d80;p=thirdparty%2Fvuejs%2Fcore.git fix(compiler-sfc): fix props codegen w/ leading import fix #4764 --- diff --git a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap index 79d598ae6f..e0bdd298f4 100644 --- a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap +++ b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap @@ -58,7 +58,7 @@ exports[`SFC compile + `) + // props declaration should be inside setup, not moved along with the import + expect(content).not.toMatch(`const props = __props\nimport`) + assertCode(content) + }) + test('defineEmits()', () => { const { content, bindings } = compile(` @@ -181,7 +193,7 @@ defineExpose({ foo: 123 }) const { content } = compile(` @@ -549,7 +561,7 @@ defineExpose({ foo: 123 })
diff --git a/packages/compiler-sfc/src/compileScript.ts b/packages/compiler-sfc/src/compileScript.ts index 7defa480a9..0e60d0d9e3 100644 --- a/packages/compiler-sfc/src/compileScript.ts +++ b/packages/compiler-sfc/src/compileScript.ts @@ -1205,25 +1205,25 @@ export function compileScript( // we use a default __props so that template expressions referencing props // can use it directly if (propsIdentifier) { - s.prependRight( + s.prependLeft( startOffset, `\nconst ${propsIdentifier} = __props${ propsTypeDecl ? ` as ${genSetupPropsType(propsTypeDecl)}` : `` - }` + }\n` ) } if (propsDestructureRestId) { - s.prependRight( + s.prependLeft( startOffset, `\nconst ${propsDestructureRestId} = ${helper( `createPropsRestProxy` - )}(__props, ${JSON.stringify(Object.keys(propsDestructuredBindings))})` + )}(__props, ${JSON.stringify(Object.keys(propsDestructuredBindings))})\n` ) } // inject temp variables for async context preservation if (hasAwait) { const any = isTS ? `: any` : `` - s.prependRight(startOffset, `\nlet __temp${any}, __restore${any}\n`) + s.prependLeft(startOffset, `\nlet __temp${any}, __restore${any}\n`) } const destructureElements =