diff --git a/packages/compiler-core/src/codegen.ts b/packages/compiler-core/src/codegen.ts index 939b3b356ad..e3dbbc820fc 100644 --- a/packages/compiler-core/src/codegen.ts +++ b/packages/compiler-core/src/codegen.ts @@ -231,12 +231,12 @@ export function generate( ? args.map(arg => `${arg}: any`).join(',') : args.join(', ') - if (genScopeId) { - if (isSetupInlined) { - push(`${PURE_ANNOTATION}${WITH_ID}(`) - } else { - push(`const ${functionName} = ${PURE_ANNOTATION}${WITH_ID}(`) - } + if (genScopeId && !isSetupInlined) { + // root-level _withId wrapping is no longer necessary after 3.0.8 and is + // a noop, it's only kept so that code compiled with 3.0.8+ can run with + // runtime < 3.0.8. + // TODO: consider removing in 3.1 + push(`const ${functionName} = ${PURE_ANNOTATION}${WITH_ID}(`) } if (isSetupInlined || genScopeId) { push(`(${signature}) => {`) @@ -303,7 +303,7 @@ export function generate( deindent() push(`}`) - if (genScopeId) { + if (genScopeId && !isSetupInlined) { push(`)`) } @@ -438,6 +438,7 @@ function genModulePreamble( // we technically don't need this anymore since `withCtx` already sets the // correct scopeId, but this is necessary for backwards compat + // TODO: consider removing in 3.1 if (genScopeId) { push( `const ${WITH_ID} = ${PURE_ANNOTATION}${helper( diff --git a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap index f648f39e8fa..7397228fb3b 100644 --- a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap +++ b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap @@ -272,6 +272,25 @@ return (_ctx, _cache) => { }" `; +exports[`SFC compile + + + `, + { + inlineTemplate: true + } + ) + expect(content).toMatch(`return (_ctx, _cache`) + expect(content).not.toMatch(`_withId(`) + assertCode(content) + }) }) describe('with TypeScript', () => {