diff --git a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap index 79d598ae..e0bdd298 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 7defa480..0e60d0d9 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 =