From 935b4e221041c8ae34c5821d90db90f07e622a9f Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 1 Sep 2021 11:30:34 -0400 Subject: [PATCH] fix(compiler-core): remove no longer necessary withScopeId import in generated code --- .../__tests__/__snapshots__/scopeId.spec.ts.snap | 8 ++++---- packages/compiler-core/src/codegen.ts | 8 ++------ packages/compiler-core/src/runtimeHelpers.ts | 2 -- packages/compiler-ssr/__tests__/ssrScopeId.spec.ts | 9 ++++----- 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/packages/compiler-core/__tests__/__snapshots__/scopeId.spec.ts.snap b/packages/compiler-core/__tests__/__snapshots__/scopeId.spec.ts.snap index 5372c5dbd81..0b6816a08f4 100644 --- a/packages/compiler-core/__tests__/__snapshots__/scopeId.spec.ts.snap +++ b/packages/compiler-core/__tests__/__snapshots__/scopeId.spec.ts.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`scopeId compiler support should push scopeId for hoisted nodes 1`] = ` -"import { createElementVNode as _createElementVNode, toDisplayString as _toDisplayString, createTextVNode as _createTextVNode, openBlock as _openBlock, createElementBlock as _createElementBlock, withScopeId as _withScopeId, pushScopeId as _pushScopeId, popScopeId as _popScopeId } from \\"vue\\" +"import { createElementVNode as _createElementVNode, toDisplayString as _toDisplayString, createTextVNode as _createTextVNode, openBlock as _openBlock, createElementBlock as _createElementBlock, pushScopeId as _pushScopeId, popScopeId as _popScopeId } from \\"vue\\" _pushScopeId(\\"test\\") const _hoisted_1 = /*#__PURE__*/_createElementVNode(\\"div\\", null, \\"hello\\", -1 /* HOISTED */) @@ -18,7 +18,7 @@ export function render(_ctx, _cache) { `; exports[`scopeId compiler support should wrap default slot 1`] = ` -"import { createElementVNode as _createElementVNode, resolveComponent as _resolveComponent, withCtx as _withCtx, openBlock as _openBlock, createBlock as _createBlock, withScopeId as _withScopeId } from \\"vue\\" +"import { createElementVNode as _createElementVNode, resolveComponent as _resolveComponent, withCtx as _withCtx, openBlock as _openBlock, createBlock as _createBlock } from \\"vue\\" export function render(_ctx, _cache) { const _component_Child = _resolveComponent(\\"Child\\") @@ -33,7 +33,7 @@ export function render(_ctx, _cache) { `; exports[`scopeId compiler support should wrap dynamic slots 1`] = ` -"import { createElementVNode as _createElementVNode, resolveComponent as _resolveComponent, withCtx as _withCtx, renderList as _renderList, createSlots as _createSlots, openBlock as _openBlock, createBlock as _createBlock, withScopeId as _withScopeId } from \\"vue\\" +"import { createElementVNode as _createElementVNode, resolveComponent as _resolveComponent, withCtx as _withCtx, renderList as _renderList, createSlots as _createSlots, openBlock as _openBlock, createBlock as _createBlock } from \\"vue\\" export function render(_ctx, _cache) { const _component_Child = _resolveComponent(\\"Child\\") @@ -60,7 +60,7 @@ export function render(_ctx, _cache) { `; exports[`scopeId compiler support should wrap named slots 1`] = ` -"import { toDisplayString as _toDisplayString, createTextVNode as _createTextVNode, createElementVNode as _createElementVNode, resolveComponent as _resolveComponent, withCtx as _withCtx, openBlock as _openBlock, createBlock as _createBlock, withScopeId as _withScopeId } from \\"vue\\" +"import { toDisplayString as _toDisplayString, createTextVNode as _createTextVNode, createElementVNode as _createElementVNode, resolveComponent as _resolveComponent, withCtx as _withCtx, openBlock as _openBlock, createBlock as _createBlock } from \\"vue\\" export function render(_ctx, _cache) { const _component_Child = _resolveComponent(\\"Child\\") diff --git a/packages/compiler-core/src/codegen.ts b/packages/compiler-core/src/codegen.ts index 56774e31b84..0cc5e105ec6 100644 --- a/packages/compiler-core/src/codegen.ts +++ b/packages/compiler-core/src/codegen.ts @@ -47,7 +47,6 @@ import { CREATE_TEXT, PUSH_SCOPE_ID, POP_SCOPE_ID, - WITH_SCOPE_ID, WITH_DIRECTIVES, CREATE_ELEMENT_VNODE, OPEN_BLOCK, @@ -380,11 +379,8 @@ function genModulePreamble( ) { const { push, newline, optimizeImports, runtimeModuleName } = context - if (genScopeId) { - ast.helpers.push(WITH_SCOPE_ID) - if (ast.hoists.length) { - ast.helpers.push(PUSH_SCOPE_ID, POP_SCOPE_ID) - } + if (genScopeId && ast.hoists.length) { + ast.helpers.push(PUSH_SCOPE_ID, POP_SCOPE_ID) } // generate import statements for helpers diff --git a/packages/compiler-core/src/runtimeHelpers.ts b/packages/compiler-core/src/runtimeHelpers.ts index eab67534331..3bfe73935b8 100644 --- a/packages/compiler-core/src/runtimeHelpers.ts +++ b/packages/compiler-core/src/runtimeHelpers.ts @@ -34,7 +34,6 @@ export const TO_HANDLER_KEY = Symbol(__DEV__ ? `toHandlerKey` : ``) export const SET_BLOCK_TRACKING = Symbol(__DEV__ ? `setBlockTracking` : ``) export const PUSH_SCOPE_ID = Symbol(__DEV__ ? `pushScopeId` : ``) export const POP_SCOPE_ID = Symbol(__DEV__ ? `popScopeId` : ``) -export const WITH_SCOPE_ID = Symbol(__DEV__ ? `withScopeId` : ``) export const WITH_CTX = Symbol(__DEV__ ? `withCtx` : ``) export const UNREF = Symbol(__DEV__ ? `unref` : ``) export const IS_REF = Symbol(__DEV__ ? `isRef` : ``) @@ -79,7 +78,6 @@ export const helperNameMap: any = { [SET_BLOCK_TRACKING]: `setBlockTracking`, [PUSH_SCOPE_ID]: `pushScopeId`, [POP_SCOPE_ID]: `popScopeId`, - [WITH_SCOPE_ID]: `withScopeId`, [WITH_CTX]: `withCtx`, [UNREF]: `unref`, [IS_REF]: `isRef`, diff --git a/packages/compiler-ssr/__tests__/ssrScopeId.spec.ts b/packages/compiler-ssr/__tests__/ssrScopeId.spec.ts index 09ff183ef8f..954a7d44fbd 100644 --- a/packages/compiler-ssr/__tests__/ssrScopeId.spec.ts +++ b/packages/compiler-ssr/__tests__/ssrScopeId.spec.ts @@ -10,8 +10,7 @@ describe('ssr: scopeId', () => { mode: 'module' }).code ).toMatchInlineSnapshot(` - "import { withScopeId as _withScopeId } from \\"vue\\" - import { ssrRenderAttrs as _ssrRenderAttrs } from \\"@vue/server-renderer\\" + "import { ssrRenderAttrs as _ssrRenderAttrs } from \\"@vue/server-renderer\\" export function ssrRender(_ctx, _push, _parent, _attrs) { _push(\`hello\`) @@ -27,7 +26,7 @@ describe('ssr: scopeId', () => { mode: 'module' }).code ).toMatchInlineSnapshot(` - "import { resolveComponent as _resolveComponent, withCtx as _withCtx, createTextVNode as _createTextVNode, withScopeId as _withScopeId } from \\"vue\\" + "import { resolveComponent as _resolveComponent, withCtx as _withCtx, createTextVNode as _createTextVNode } from \\"vue\\" import { ssrRenderComponent as _ssrRenderComponent } from \\"@vue/server-renderer\\" export function ssrRender(_ctx, _push, _parent, _attrs) { @@ -56,7 +55,7 @@ describe('ssr: scopeId', () => { mode: 'module' }).code ).toMatchInlineSnapshot(` - "import { resolveComponent as _resolveComponent, withCtx as _withCtx, createVNode as _createVNode, withScopeId as _withScopeId } from \\"vue\\" + "import { resolveComponent as _resolveComponent, withCtx as _withCtx, createVNode as _createVNode } from \\"vue\\" import { ssrRenderComponent as _ssrRenderComponent } from \\"@vue/server-renderer\\" export function ssrRender(_ctx, _push, _parent, _attrs) { @@ -85,7 +84,7 @@ describe('ssr: scopeId', () => { mode: 'module' }).code ).toMatchInlineSnapshot(` - "import { resolveComponent as _resolveComponent, withCtx as _withCtx, createVNode as _createVNode, withScopeId as _withScopeId } from \\"vue\\" + "import { resolveComponent as _resolveComponent, withCtx as _withCtx, createVNode as _createVNode } from \\"vue\\" import { ssrRenderComponent as _ssrRenderComponent } from \\"@vue/server-renderer\\" export function ssrRender(_ctx, _push, _parent, _attrs) {