From 6df2aca070abe622fedb8caa36ca1ff9f6cc1864 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 14 Feb 2020 01:36:42 -0500 Subject: [PATCH] refactor(types): move shapeFlags to shared --- .../runtime-core/__tests__/rendererFragment.spec.ts | 2 +- packages/runtime-core/__tests__/vnode.spec.ts | 3 +-- packages/runtime-core/src/component.ts | 4 ++-- packages/runtime-core/src/componentRenderUtils.ts | 3 +-- packages/runtime-core/src/componentSlots.ts | 3 +-- .../runtime-core/src/components/BaseTransition.ts | 2 +- packages/runtime-core/src/components/KeepAlive.ts | 3 +-- packages/runtime-core/src/components/Suspense.ts | 3 +-- packages/runtime-core/src/hydration.ts | 3 +-- packages/runtime-core/src/index.ts | 2 -- packages/runtime-core/src/renderer.ts | 6 +++--- packages/runtime-core/src/vnode.ts | 4 ++-- packages/server-renderer/src/renderToString.ts | 2 +- packages/shared/src/index.ts | 1 + packages/shared/src/shapeFlags.ts | 12 ++++++++++++ packages/vue/examples/__tests__/markdown.spec.ts | 2 +- 16 files changed, 30 insertions(+), 25 deletions(-) create mode 100644 packages/shared/src/shapeFlags.ts diff --git a/packages/runtime-core/__tests__/rendererFragment.spec.ts b/packages/runtime-core/__tests__/rendererFragment.spec.ts index dd3a27b7..091ef7a2 100644 --- a/packages/runtime-core/__tests__/rendererFragment.spec.ts +++ b/packages/runtime-core/__tests__/rendererFragment.spec.ts @@ -6,13 +6,13 @@ import { NodeTypes, TestElement, Fragment, - PatchFlags, resetOps, dumpOps, NodeOpTypes, serializeInner, createTextVNode } from '@vue/runtime-test' +import { PatchFlags } from '@vue/shared' describe('renderer: fragment', () => { it('should allow returning multiple component root nodes', () => { diff --git a/packages/runtime-core/__tests__/vnode.spec.ts b/packages/runtime-core/__tests__/vnode.spec.ts index a3555a10..1a500ac7 100644 --- a/packages/runtime-core/__tests__/vnode.spec.ts +++ b/packages/runtime-core/__tests__/vnode.spec.ts @@ -9,9 +9,8 @@ import { mergeProps, normalizeVNode } from '../src/vnode' -import { ShapeFlags } from '../src/shapeFlags' import { Data } from '../src/component' -import { PatchFlags } from '@vue/shared' +import { ShapeFlags, PatchFlags } from '@vue/shared' describe('vnode', () => { test('create with just tag', () => { diff --git a/packages/runtime-core/src/component.ts b/packages/runtime-core/src/component.ts index 15b3edc0..538ca470 100644 --- a/packages/runtime-core/src/component.ts +++ b/packages/runtime-core/src/component.ts @@ -26,7 +26,8 @@ import { makeMap, isPromise, isArray, - hyphenate + hyphenate, + ShapeFlags } from '@vue/shared' import { SuspenseBoundary } from './components/Suspense' import { CompilerOptions } from '@vue/compiler-core' @@ -34,7 +35,6 @@ import { currentRenderingInstance, markAttrsAccessed } from './componentRenderUtils' -import { ShapeFlags } from './shapeFlags' export type Data = { [key: string]: unknown } diff --git a/packages/runtime-core/src/componentRenderUtils.ts b/packages/runtime-core/src/componentRenderUtils.ts index fb71728d..145a3697 100644 --- a/packages/runtime-core/src/componentRenderUtils.ts +++ b/packages/runtime-core/src/componentRenderUtils.ts @@ -10,9 +10,8 @@ import { Comment, cloneVNode } from './vnode' -import { ShapeFlags } from './shapeFlags' import { handleError, ErrorCodes } from './errorHandling' -import { PatchFlags, EMPTY_OBJ } from '@vue/shared' +import { PatchFlags, ShapeFlags, EMPTY_OBJ } from '@vue/shared' import { warn } from './warning' // mark the current rendering instance for asset resolution (e.g. diff --git a/packages/runtime-core/src/componentSlots.ts b/packages/runtime-core/src/componentSlots.ts index 4f7e82a5..79c8f9d4 100644 --- a/packages/runtime-core/src/componentSlots.ts +++ b/packages/runtime-core/src/componentSlots.ts @@ -5,8 +5,7 @@ import { normalizeVNode, VNodeChild } from './vnode' -import { isArray, isFunction, EMPTY_OBJ } from '@vue/shared' -import { ShapeFlags } from './shapeFlags' +import { isArray, isFunction, EMPTY_OBJ, ShapeFlags } from '@vue/shared' import { warn } from './warning' import { isKeepAlive } from './components/KeepAlive' diff --git a/packages/runtime-core/src/components/BaseTransition.ts b/packages/runtime-core/src/components/BaseTransition.ts index bcc2a4bd..ffe5597a 100644 --- a/packages/runtime-core/src/components/BaseTransition.ts +++ b/packages/runtime-core/src/components/BaseTransition.ts @@ -15,7 +15,7 @@ import { warn } from '../warning' import { isKeepAlive } from './KeepAlive' import { toRaw } from '@vue/reactivity' import { callWithAsyncErrorHandling, ErrorCodes } from '../errorHandling' -import { ShapeFlags } from '../shapeFlags' +import { ShapeFlags } from '@vue/shared' import { onBeforeUnmount, onMounted } from '../apiLifecycle' export interface BaseTransitionProps { diff --git a/packages/runtime-core/src/components/KeepAlive.ts b/packages/runtime-core/src/components/KeepAlive.ts index 18105efa..4125131d 100644 --- a/packages/runtime-core/src/components/KeepAlive.ts +++ b/packages/runtime-core/src/components/KeepAlive.ts @@ -10,9 +10,8 @@ import { import { VNode, cloneVNode, isVNode } from '../vnode' import { warn } from '../warning' import { onBeforeUnmount, injectHook, onUnmounted } from '../apiLifecycle' -import { isString, isArray } from '@vue/shared' +import { isString, isArray, ShapeFlags } from '@vue/shared' import { watch } from '../apiWatch' -import { ShapeFlags } from '../shapeFlags' import { SuspenseBoundary } from './Suspense' import { RendererInternals, diff --git a/packages/runtime-core/src/components/Suspense.ts b/packages/runtime-core/src/components/Suspense.ts index 8cbf7a1d..211e5f30 100644 --- a/packages/runtime-core/src/components/Suspense.ts +++ b/packages/runtime-core/src/components/Suspense.ts @@ -1,6 +1,5 @@ import { VNode, normalizeVNode, VNodeChild } from '../vnode' -import { ShapeFlags } from '../shapeFlags' -import { isFunction, isArray } from '@vue/shared' +import { isFunction, isArray, ShapeFlags } from '@vue/shared' import { ComponentInternalInstance, handleSetupResult } from '../component' import { Slots } from '../componentSlots' import { RendererInternals, MoveType } from '../renderer' diff --git a/packages/runtime-core/src/hydration.ts b/packages/runtime-core/src/hydration.ts index 3318001f..d451d752 100644 --- a/packages/runtime-core/src/hydration.ts +++ b/packages/runtime-core/src/hydration.ts @@ -10,9 +10,8 @@ import { import { queuePostFlushCb, flushPostFlushCbs } from './scheduler' import { ComponentInternalInstance } from './component' import { invokeDirectiveHook } from './directives' -import { ShapeFlags } from './shapeFlags' import { warn } from './warning' -import { PatchFlags, isReservedProp, isOn } from '@vue/shared' +import { PatchFlags, ShapeFlags, isReservedProp, isOn } from '@vue/shared' // Note: hydration is DOM-specific // But we have to place it in core due to tight coupling with core - splitting diff --git a/packages/runtime-core/src/index.ts b/packages/runtime-core/src/index.ts index 09a3ac2d..25f1939f 100644 --- a/packages/runtime-core/src/index.ts +++ b/packages/runtime-core/src/index.ts @@ -56,8 +56,6 @@ export { BaseTransition, BaseTransitionProps } from './components/BaseTransition' -export { PatchFlags } from '@vue/shared' -export { ShapeFlags } from './shapeFlags' // SFC CSS Modules export { useCSSModule } from './helpers/useCssModule' diff --git a/packages/runtime-core/src/renderer.ts b/packages/runtime-core/src/renderer.ts index ab8a29d4..c5b38b3b 100644 --- a/packages/runtime-core/src/renderer.ts +++ b/packages/runtime-core/src/renderer.ts @@ -30,6 +30,7 @@ import { isReservedProp, isFunction, PatchFlags, + ShapeFlags, NOOP } from '@vue/shared' import { @@ -49,11 +50,10 @@ import { } from '@vue/reactivity' import { resolveProps } from './componentProps' import { resolveSlots } from './componentSlots' -import { ShapeFlags } from './shapeFlags' import { pushWarningContext, popWarningContext, warn } from './warning' import { invokeDirectiveHook } from './directives' import { ComponentPublicInstance } from './componentProxy' -import { createAppAPI } from './apiCreateApp' +import { createAppAPI, CreateAppFunction } from './apiCreateApp' import { SuspenseBoundary, queueEffectWithSuspense, @@ -1858,7 +1858,7 @@ function baseCreateRenderer< return { render, hydrate, - createApp: createAppAPI(render, hydrate) + createApp: createAppAPI(render, hydrate) as CreateAppFunction } } diff --git a/packages/runtime-core/src/vnode.ts b/packages/runtime-core/src/vnode.ts index 623f51d3..440eb270 100644 --- a/packages/runtime-core/src/vnode.ts +++ b/packages/runtime-core/src/vnode.ts @@ -7,7 +7,8 @@ import { extend, normalizeClass, normalizeStyle, - PatchFlags + PatchFlags, + ShapeFlags } from '@vue/shared' import { ComponentInternalInstance, @@ -16,7 +17,6 @@ import { Component } from './component' import { RawSlots } from './componentSlots' -import { ShapeFlags } from './shapeFlags' import { isReactive, Ref } from '@vue/reactivity' import { AppContext } from './apiCreateApp' import { SuspenseBoundary } from './components/Suspense' diff --git a/packages/server-renderer/src/renderToString.ts b/packages/server-renderer/src/renderToString.ts index 074d98b0..265fb2c6 100644 --- a/packages/server-renderer/src/renderToString.ts +++ b/packages/server-renderer/src/renderToString.ts @@ -9,12 +9,12 @@ import { Comment, Fragment, Portal, - ShapeFlags, ssrUtils, Slots, warn } from 'vue' import { + ShapeFlags, isString, isPromise, isArray, diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts index 4ec5d8d9..68daa4b2 100644 --- a/packages/shared/src/index.ts +++ b/packages/shared/src/index.ts @@ -2,6 +2,7 @@ import { makeMap } from './makeMap' export { makeMap } export * from './patchFlags' +export * from './shapeFlags' export * from './globalsWhitelist' export * from './codeframe' export * from './mockWarn' diff --git a/packages/shared/src/shapeFlags.ts b/packages/shared/src/shapeFlags.ts new file mode 100644 index 00000000..c5d4f6f8 --- /dev/null +++ b/packages/shared/src/shapeFlags.ts @@ -0,0 +1,12 @@ +export const enum ShapeFlags { + ELEMENT = 1, + FUNCTIONAL_COMPONENT = 1 << 1, + STATEFUL_COMPONENT = 1 << 2, + TEXT_CHILDREN = 1 << 3, + ARRAY_CHILDREN = 1 << 4, + SLOTS_CHILDREN = 1 << 5, + SUSPENSE = 1 << 6, + COMPONENT_SHOULD_KEEP_ALIVE = 1 << 7, + COMPONENT_KEPT_ALIVE = 1 << 8, + COMPONENT = ShapeFlags.STATEFUL_COMPONENT | ShapeFlags.FUNCTIONAL_COMPONENT +} diff --git a/packages/vue/examples/__tests__/markdown.spec.ts b/packages/vue/examples/__tests__/markdown.spec.ts index 3f257015..cc9f4e87 100644 --- a/packages/vue/examples/__tests__/markdown.spec.ts +++ b/packages/vue/examples/__tests__/markdown.spec.ts @@ -18,7 +18,7 @@ describe('e2e: markdown', () => { await page().type('textarea', '\n## foo\n\n- bar\n- baz') // assert the output is not updated yet because of debounce expect(await html('#editor div')).toBe('

hello

\n') - await page().waitFor(16) + await page().waitFor(30) expect(await html('#editor div')).toBe( '

hello

\n' + '

foo

\n' +