From 928af5fe2f5f366b5c28b8549c3728735c8d8318 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20Deng=20=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90?= Date: Thu, 8 Aug 2024 23:05:21 +0800 Subject: [PATCH] refactor(types): enable `isolatedDeclarations` (#11178) --- packages/compiler-core/src/ast.ts | 14 ++- packages/compiler-core/src/babelUtils.ts | 12 +- .../compiler-core/src/compat/compatConfig.ts | 4 +- packages/compiler-core/src/errors.ts | 4 +- packages/compiler-core/src/runtimeHelpers.ts | 114 ++++++++++++------ packages/compiler-core/src/tokenizer.ts | 20 ++- packages/compiler-core/src/transform.ts | 6 +- .../src/transforms/cacheStatic.ts | 2 +- .../src/transforms/transformElement.ts | 4 +- .../compiler-core/src/transforms/vBind.ts | 2 +- packages/compiler-core/src/transforms/vFor.ts | 7 +- packages/compiler-core/src/transforms/vIf.ts | 5 +- packages/compiler-core/src/utils.ts | 24 ++-- .../compiler-core/src/validateExpression.ts | 2 +- packages/compiler-dom/src/runtimeHelpers.ts | 32 +++-- packages/compiler-sfc/src/index.ts | 4 +- packages/compiler-sfc/src/parse.ts | 5 +- packages/compiler-sfc/src/script/context.ts | 13 +- .../compiler-sfc/src/script/defineProps.ts | 2 +- .../src/script/definePropsDestructure.ts | 4 +- .../compiler-sfc/src/script/normalScript.ts | 3 +- .../compiler-sfc/src/script/resolveType.ts | 8 +- .../compiler-sfc/src/script/topLevelAwait.ts | 2 +- packages/compiler-sfc/src/script/utils.ts | 37 ++++-- packages/compiler-sfc/src/warn.ts | 4 +- packages/compiler-ssr/src/runtimeHelpers.ts | 48 +++++--- .../compiler-ssr/src/ssrCodegenTransform.ts | 29 +++-- .../src/transforms/ssrTransformComponent.ts | 7 +- .../src/transforms/ssrTransformElement.ts | 2 +- .../src/transforms/ssrTransformSlotOutlet.ts | 2 +- .../src/transforms/ssrTransformSuspense.ts | 4 +- .../src/transforms/ssrTransformTeleport.ts | 2 +- .../src/transforms/ssrTransformTransition.ts | 4 +- .../transforms/ssrTransformTransitionGroup.ts | 4 +- .../compiler-ssr/src/transforms/ssrVFor.ts | 9 +- .../compiler-ssr/src/transforms/ssrVIf.ts | 5 +- packages/reactivity/src/baseHandlers.ts | 9 +- packages/reactivity/src/computed.ts | 18 +-- packages/reactivity/src/dep.ts | 27 +++-- packages/reactivity/src/effect.ts | 32 ++--- packages/reactivity/src/effectScope.ts | 18 +-- packages/reactivity/src/reactive.ts | 18 ++- packages/reactivity/src/ref.ts | 2 +- packages/reactivity/src/warning.ts | 2 +- packages/runtime-core/src/apiInject.ts | 2 +- packages/runtime-core/src/apiLifecycle.ts | 43 ++++--- packages/runtime-core/src/apiSetupHelpers.ts | 8 +- packages/runtime-core/src/apiWatch.ts | 10 +- .../runtime-core/src/compat/compatConfig.ts | 16 +-- .../runtime-core/src/compat/componentAsync.ts | 4 +- .../src/compat/componentFunctional.ts | 4 +- .../src/compat/componentVModel.ts | 4 +- packages/runtime-core/src/compat/data.ts | 2 +- packages/runtime-core/src/compat/global.ts | 2 +- .../runtime-core/src/compat/globalConfig.ts | 4 +- packages/runtime-core/src/compat/instance.ts | 4 +- .../src/compat/instanceEventEmitter.ts | 9 +- .../src/compat/instanceListeners.ts | 4 +- packages/runtime-core/src/compat/props.ts | 2 +- packages/runtime-core/src/compat/renderFn.ts | 6 +- .../runtime-core/src/compat/renderHelpers.ts | 20 +-- packages/runtime-core/src/component.ts | 24 ++-- packages/runtime-core/src/componentEmits.ts | 3 +- packages/runtime-core/src/componentOptions.ts | 8 +- packages/runtime-core/src/componentProps.ts | 4 +- .../src/componentPublicInstance.ts | 16 ++- .../src/componentRenderContext.ts | 8 +- .../runtime-core/src/componentRenderUtils.ts | 4 +- packages/runtime-core/src/componentSlots.ts | 4 +- .../src/components/BaseTransition.ts | 8 +- .../runtime-core/src/components/KeepAlive.ts | 4 +- .../runtime-core/src/components/Suspense.ts | 10 +- .../runtime-core/src/components/Teleport.ts | 12 +- packages/runtime-core/src/customFormatter.ts | 2 +- packages/runtime-core/src/devtools.ts | 42 ++++--- packages/runtime-core/src/directives.ts | 4 +- packages/runtime-core/src/errorHandling.ts | 4 +- packages/runtime-core/src/featureFlags.ts | 2 +- .../runtime-core/src/helpers/renderSlot.ts | 4 +- .../runtime-core/src/helpers/resolveAssets.ts | 2 +- packages/runtime-core/src/helpers/useId.ts | 4 +- .../runtime-core/src/helpers/useSsrContext.ts | 4 +- packages/runtime-core/src/helpers/withMemo.ts | 4 +- packages/runtime-core/src/hmr.ts | 12 +- packages/runtime-core/src/hydration.ts | 14 ++- .../runtime-core/src/hydrationStrategies.ts | 2 +- packages/runtime-core/src/index.ts | 27 ++++- packages/runtime-core/src/internalObject.ts | 5 +- packages/runtime-core/src/profiling.ts | 7 +- packages/runtime-core/src/renderer.ts | 20 ++- .../runtime-core/src/rendererTemplateRef.ts | 2 +- packages/runtime-core/src/scheduler.ts | 12 +- packages/runtime-core/src/vnode.ts | 32 ++--- packages/runtime-core/src/warning.ts | 8 +- packages/runtime-dom/src/apiCustomElement.ts | 19 +-- .../runtime-dom/src/components/Transition.ts | 10 +- packages/runtime-dom/src/directives/vModel.ts | 4 +- packages/runtime-dom/src/directives/vOn.ts | 37 ++++-- packages/runtime-dom/src/directives/vShow.ts | 6 +- .../runtime-dom/src/helpers/useCssVars.ts | 4 +- packages/runtime-dom/src/modules/attrs.ts | 4 +- packages/runtime-dom/src/modules/class.ts | 6 +- packages/runtime-dom/src/modules/events.ts | 8 +- packages/runtime-dom/src/modules/props.ts | 2 +- packages/runtime-dom/src/modules/style.ts | 2 +- .../src/helpers/ssrRenderList.ts | 2 +- .../src/helpers/ssrRenderSlot.ts | 4 +- .../src/helpers/ssrRenderSuspense.ts | 2 +- .../src/helpers/ssrRenderTeleport.ts | 2 +- .../src/helpers/ssrVModelHelpers.ts | 4 +- packages/server-renderer/src/render.ts | 6 +- .../server-renderer/src/renderToStream.ts | 6 +- .../server-renderer/src/renderToString.ts | 2 +- packages/shared/src/codeframe.ts | 2 +- packages/shared/src/domAttrConfig.ts | 9 +- packages/shared/src/domTagConfig.ts | 12 +- packages/shared/src/escapeHtml.ts | 2 +- packages/shared/src/general.ts | 66 +++++----- packages/shared/src/globalsAllowList.ts | 5 +- packages/shared/src/normalizeProp.ts | 4 +- packages/shared/src/slotFlags.ts | 2 +- packages/vue-compat/src/createCompatVue.ts | 3 +- packages/vue-compat/src/dev.ts | 2 +- packages/vue-compat/src/esm-index.ts | 2 +- packages/vue-compat/src/esm-runtime.ts | 2 +- packages/vue-compat/src/index.ts | 3 +- packages/vue-compat/src/runtime.ts | 4 +- packages/vue/src/dev.ts | 2 +- packages/vue/src/runtime.ts | 2 +- tsconfig.build-browser.json | 3 +- tsconfig.build-node.json | 3 +- tsconfig.json | 6 +- 132 files changed, 776 insertions(+), 526 deletions(-) diff --git a/packages/compiler-core/src/ast.ts b/packages/compiler-core/src/ast.ts index 3d2ef05dcfb..8116f532b79 100644 --- a/packages/compiler-core/src/ast.ts +++ b/packages/compiler-core/src/ast.ts @@ -618,7 +618,7 @@ export function createVNodeCall( isBlock: VNodeCall['isBlock'] = false, disableTracking: VNodeCall['disableTracking'] = false, isComponent: VNodeCall['isComponent'] = false, - loc = locStub, + loc: SourceLocation = locStub, ): VNodeCall { if (context) { if (isBlock) { @@ -851,18 +851,24 @@ export function createReturnStatement( } } -export function getVNodeHelper(ssr: boolean, isComponent: boolean) { +export function getVNodeHelper( + ssr: boolean, + isComponent: boolean, +): typeof CREATE_VNODE | typeof CREATE_ELEMENT_VNODE { return ssr || isComponent ? CREATE_VNODE : CREATE_ELEMENT_VNODE } -export function getVNodeBlockHelper(ssr: boolean, isComponent: boolean) { +export function getVNodeBlockHelper( + ssr: boolean, + isComponent: boolean, +): typeof CREATE_BLOCK | typeof CREATE_ELEMENT_BLOCK { return ssr || isComponent ? CREATE_BLOCK : CREATE_ELEMENT_BLOCK } export function convertToBlock( node: VNodeCall, { helper, removeHelper, inSSR }: TransformContext, -) { +): void { if (!node.isBlock) { node.isBlock = true removeHelper(getVNodeHelper(inSSR, node.isComponent)) diff --git a/packages/compiler-core/src/babelUtils.ts b/packages/compiler-core/src/babelUtils.ts index 9b0a5ede60d..52fabeea896 100644 --- a/packages/compiler-core/src/babelUtils.ts +++ b/packages/compiler-core/src/babelUtils.ts @@ -28,7 +28,7 @@ export function walkIdentifiers( includeAll = false, parentStack: Node[] = [], knownIds: Record = Object.create(null), -) { +): void { if (__BROWSER__) { return } @@ -108,7 +108,7 @@ export function isReferencedIdentifier( id: Identifier, parent: Node | null, parentStack: Node[], -) { +): boolean { if (__BROWSER__) { return false } @@ -177,7 +177,7 @@ export function isInNewExpression(parentStack: Node[]): boolean { export function walkFunctionParams( node: Function, onIdent: (id: Identifier) => void, -) { +): void { for (const p of node.params) { for (const id of extractIdentifiers(p)) { onIdent(id) @@ -188,7 +188,7 @@ export function walkFunctionParams( export function walkBlockDeclarations( block: BlockStatement | Program, onIdent: (node: Identifier) => void, -) { +): void { for (const stmt of block.body) { if (stmt.type === 'VariableDeclaration') { if (stmt.declare) continue @@ -313,7 +313,7 @@ export const isStaticProperty = (node: Node): node is ObjectProperty => (node.type === 'ObjectProperty' || node.type === 'ObjectMethod') && !node.computed -export const isStaticPropertyKey = (node: Node, parent: Node) => +export const isStaticPropertyKey = (node: Node, parent: Node): boolean => isStaticProperty(parent) && parent.key === node /** @@ -495,7 +495,7 @@ function isReferenced(node: Node, parent: Node, grandparent?: Node): boolean { return true } -export const TS_NODE_TYPES = [ +export const TS_NODE_TYPES: string[] = [ 'TSAsExpression', // foo as number 'TSTypeAssertion', // (foo) 'TSNonNullExpression', // foo! diff --git a/packages/compiler-core/src/compat/compatConfig.ts b/packages/compiler-core/src/compat/compatConfig.ts index bf06f4aae0f..58c5d9611f2 100644 --- a/packages/compiler-core/src/compat/compatConfig.ts +++ b/packages/compiler-core/src/compat/compatConfig.ts @@ -106,7 +106,7 @@ function getCompatValue( export function isCompatEnabled( key: CompilerDeprecationTypes, context: MergedParserOptions | TransformContext, -) { +): boolean { const mode = getCompatValue('MODE', context) const value = getCompatValue(key, context) // in v3 mode, only enable if explicitly set to true @@ -132,7 +132,7 @@ export function warnDeprecation( context: MergedParserOptions | TransformContext, loc: SourceLocation | null, ...args: any[] -) { +): void { const val = getCompatValue(key, context) if (val === 'suppress-warning') { return diff --git a/packages/compiler-core/src/errors.ts b/packages/compiler-core/src/errors.ts index a536392b9a3..58e113ab19e 100644 --- a/packages/compiler-core/src/errors.ts +++ b/packages/compiler-core/src/errors.ts @@ -9,11 +9,11 @@ export interface CoreCompilerError extends CompilerError { code: ErrorCodes } -export function defaultOnError(error: CompilerError) { +export function defaultOnError(error: CompilerError): never { throw error } -export function defaultOnWarn(msg: CompilerError) { +export function defaultOnWarn(msg: CompilerError): void { __DEV__ && console.warn(`[Vue warn] ${msg.message}`) } diff --git a/packages/compiler-core/src/runtimeHelpers.ts b/packages/compiler-core/src/runtimeHelpers.ts index ded149e59b7..7cf3757b249 100644 --- a/packages/compiler-core/src/runtimeHelpers.ts +++ b/packages/compiler-core/src/runtimeHelpers.ts @@ -1,51 +1,85 @@ -export const FRAGMENT = Symbol(__DEV__ ? `Fragment` : ``) -export const TELEPORT = Symbol(__DEV__ ? `Teleport` : ``) -export const SUSPENSE = Symbol(__DEV__ ? `Suspense` : ``) -export const KEEP_ALIVE = Symbol(__DEV__ ? `KeepAlive` : ``) -export const BASE_TRANSITION = Symbol(__DEV__ ? `BaseTransition` : ``) -export const OPEN_BLOCK = Symbol(__DEV__ ? `openBlock` : ``) -export const CREATE_BLOCK = Symbol(__DEV__ ? `createBlock` : ``) -export const CREATE_ELEMENT_BLOCK = Symbol(__DEV__ ? `createElementBlock` : ``) -export const CREATE_VNODE = Symbol(__DEV__ ? `createVNode` : ``) -export const CREATE_ELEMENT_VNODE = Symbol(__DEV__ ? `createElementVNode` : ``) -export const CREATE_COMMENT = Symbol(__DEV__ ? `createCommentVNode` : ``) -export const CREATE_TEXT = Symbol(__DEV__ ? `createTextVNode` : ``) -export const CREATE_STATIC = Symbol(__DEV__ ? `createStaticVNode` : ``) -export const RESOLVE_COMPONENT = Symbol(__DEV__ ? `resolveComponent` : ``) -export const RESOLVE_DYNAMIC_COMPONENT = Symbol( +export const FRAGMENT: unique symbol = Symbol(__DEV__ ? `Fragment` : ``) +export const TELEPORT: unique symbol = Symbol(__DEV__ ? `Teleport` : ``) +export const SUSPENSE: unique symbol = Symbol(__DEV__ ? `Suspense` : ``) +export const KEEP_ALIVE: unique symbol = Symbol(__DEV__ ? `KeepAlive` : ``) +export const BASE_TRANSITION: unique symbol = Symbol( + __DEV__ ? `BaseTransition` : ``, +) +export const OPEN_BLOCK: unique symbol = Symbol(__DEV__ ? `openBlock` : ``) +export const CREATE_BLOCK: unique symbol = Symbol(__DEV__ ? `createBlock` : ``) +export const CREATE_ELEMENT_BLOCK: unique symbol = Symbol( + __DEV__ ? `createElementBlock` : ``, +) +export const CREATE_VNODE: unique symbol = Symbol(__DEV__ ? `createVNode` : ``) +export const CREATE_ELEMENT_VNODE: unique symbol = Symbol( + __DEV__ ? `createElementVNode` : ``, +) +export const CREATE_COMMENT: unique symbol = Symbol( + __DEV__ ? `createCommentVNode` : ``, +) +export const CREATE_TEXT: unique symbol = Symbol( + __DEV__ ? `createTextVNode` : ``, +) +export const CREATE_STATIC: unique symbol = Symbol( + __DEV__ ? `createStaticVNode` : ``, +) +export const RESOLVE_COMPONENT: unique symbol = Symbol( + __DEV__ ? `resolveComponent` : ``, +) +export const RESOLVE_DYNAMIC_COMPONENT: unique symbol = Symbol( __DEV__ ? `resolveDynamicComponent` : ``, ) -export const RESOLVE_DIRECTIVE = Symbol(__DEV__ ? `resolveDirective` : ``) -export const RESOLVE_FILTER = Symbol(__DEV__ ? `resolveFilter` : ``) -export const WITH_DIRECTIVES = Symbol(__DEV__ ? `withDirectives` : ``) -export const RENDER_LIST = Symbol(__DEV__ ? `renderList` : ``) -export const RENDER_SLOT = Symbol(__DEV__ ? `renderSlot` : ``) -export const CREATE_SLOTS = Symbol(__DEV__ ? `createSlots` : ``) -export const TO_DISPLAY_STRING = Symbol(__DEV__ ? `toDisplayString` : ``) -export const MERGE_PROPS = Symbol(__DEV__ ? `mergeProps` : ``) -export const NORMALIZE_CLASS = Symbol(__DEV__ ? `normalizeClass` : ``) -export const NORMALIZE_STYLE = Symbol(__DEV__ ? `normalizeStyle` : ``) -export const NORMALIZE_PROPS = Symbol(__DEV__ ? `normalizeProps` : ``) -export const GUARD_REACTIVE_PROPS = Symbol(__DEV__ ? `guardReactiveProps` : ``) -export const TO_HANDLERS = Symbol(__DEV__ ? `toHandlers` : ``) -export const CAMELIZE = Symbol(__DEV__ ? `camelize` : ``) -export const CAPITALIZE = Symbol(__DEV__ ? `capitalize` : ``) -export const TO_HANDLER_KEY = Symbol(__DEV__ ? `toHandlerKey` : ``) -export const SET_BLOCK_TRACKING = Symbol(__DEV__ ? `setBlockTracking` : ``) +export const RESOLVE_DIRECTIVE: unique symbol = Symbol( + __DEV__ ? `resolveDirective` : ``, +) +export const RESOLVE_FILTER: unique symbol = Symbol( + __DEV__ ? `resolveFilter` : ``, +) +export const WITH_DIRECTIVES: unique symbol = Symbol( + __DEV__ ? `withDirectives` : ``, +) +export const RENDER_LIST: unique symbol = Symbol(__DEV__ ? `renderList` : ``) +export const RENDER_SLOT: unique symbol = Symbol(__DEV__ ? `renderSlot` : ``) +export const CREATE_SLOTS: unique symbol = Symbol(__DEV__ ? `createSlots` : ``) +export const TO_DISPLAY_STRING: unique symbol = Symbol( + __DEV__ ? `toDisplayString` : ``, +) +export const MERGE_PROPS: unique symbol = Symbol(__DEV__ ? `mergeProps` : ``) +export const NORMALIZE_CLASS: unique symbol = Symbol( + __DEV__ ? `normalizeClass` : ``, +) +export const NORMALIZE_STYLE: unique symbol = Symbol( + __DEV__ ? `normalizeStyle` : ``, +) +export const NORMALIZE_PROPS: unique symbol = Symbol( + __DEV__ ? `normalizeProps` : ``, +) +export const GUARD_REACTIVE_PROPS: unique symbol = Symbol( + __DEV__ ? `guardReactiveProps` : ``, +) +export const TO_HANDLERS: unique symbol = Symbol(__DEV__ ? `toHandlers` : ``) +export const CAMELIZE: unique symbol = Symbol(__DEV__ ? `camelize` : ``) +export const CAPITALIZE: unique symbol = Symbol(__DEV__ ? `capitalize` : ``) +export const TO_HANDLER_KEY: unique symbol = Symbol( + __DEV__ ? `toHandlerKey` : ``, +) +export const SET_BLOCK_TRACKING: unique symbol = Symbol( + __DEV__ ? `setBlockTracking` : ``, +) /** * @deprecated no longer needed in 3.5+ because we no longer hoist element nodes * but kept for backwards compat */ -export const PUSH_SCOPE_ID = Symbol(__DEV__ ? `pushScopeId` : ``) +export const PUSH_SCOPE_ID: unique symbol = Symbol(__DEV__ ? `pushScopeId` : ``) /** * @deprecated kept for backwards compat */ -export const POP_SCOPE_ID = Symbol(__DEV__ ? `popScopeId` : ``) -export const WITH_CTX = Symbol(__DEV__ ? `withCtx` : ``) -export const UNREF = Symbol(__DEV__ ? `unref` : ``) -export const IS_REF = Symbol(__DEV__ ? `isRef` : ``) -export const WITH_MEMO = Symbol(__DEV__ ? `withMemo` : ``) -export const IS_MEMO_SAME = Symbol(__DEV__ ? `isMemoSame` : ``) +export const POP_SCOPE_ID: unique symbol = Symbol(__DEV__ ? `popScopeId` : ``) +export const WITH_CTX: unique symbol = Symbol(__DEV__ ? `withCtx` : ``) +export const UNREF: unique symbol = Symbol(__DEV__ ? `unref` : ``) +export const IS_REF: unique symbol = Symbol(__DEV__ ? `isRef` : ``) +export const WITH_MEMO: unique symbol = Symbol(__DEV__ ? `withMemo` : ``) +export const IS_MEMO_SAME: unique symbol = Symbol(__DEV__ ? `isMemoSame` : ``) // Name mapping for runtime helpers that need to be imported from 'vue' in // generated code. Make sure these are correctly exported in the runtime! @@ -91,7 +125,7 @@ export const helperNameMap: Record = { [IS_MEMO_SAME]: `isMemoSame`, } -export function registerRuntimeHelpers(helpers: Record) { +export function registerRuntimeHelpers(helpers: Record): void { Object.getOwnPropertySymbols(helpers).forEach(s => { helperNameMap[s] = helpers[s] }) diff --git a/packages/compiler-core/src/tokenizer.ts b/packages/compiler-core/src/tokenizer.ts index 72f548fa28c..7e93cdf5878 100644 --- a/packages/compiler-core/src/tokenizer.ts +++ b/packages/compiler-core/src/tokenizer.ts @@ -213,7 +213,15 @@ export interface Callbacks { * We don't have `Script`, `Style`, or `Title` here. Instead, we re-use the *End * sequences with an increased offset. */ -export const Sequences = { +export const Sequences: { + Cdata: Uint8Array + CdataEnd: Uint8Array + CommentEnd: Uint8Array + ScriptEnd: Uint8Array + StyleEnd: Uint8Array + TitleEnd: Uint8Array + TextareaEnd: Uint8Array +} = { Cdata: new Uint8Array([0x43, 0x44, 0x41, 0x54, 0x41, 0x5b]), // CDATA[ CdataEnd: new Uint8Array([0x5d, 0x5d, 0x3e]), // ]]> CommentEnd: new Uint8Array([0x2d, 0x2d, 0x3e]), // `-->` @@ -227,7 +235,7 @@ export const Sequences = { export default class Tokenizer { /** The current state the tokenizer is in. */ - public state = State.Text + public state: State = State.Text /** The read buffer. */ private buffer = '' /** The beginning of the section that is currently being read. */ @@ -249,8 +257,8 @@ export default class Tokenizer { private readonly entityDecoder?: EntityDecoder - public mode = ParseMode.BASE - public get inSFCRoot() { + public mode: ParseMode = ParseMode.BASE + public get inSFCRoot(): boolean { return this.mode === ParseMode.SFC && this.stack.length === 0 } @@ -526,7 +534,7 @@ export default class Tokenizer { this.state = State.SpecialStartSequence } - public enterRCDATA(sequence: Uint8Array, offset: number) { + public enterRCDATA(sequence: Uint8Array, offset: number): void { this.inRCDATA = true this.currentSequence = sequence this.sequenceIndex = offset @@ -917,7 +925,7 @@ export default class Tokenizer { * * States that are more likely to be hit are higher up, as a performance improvement. */ - public parse(input: string) { + public parse(input: string): void { this.buffer = input while (this.index < this.buffer.length) { const c = this.buffer.charCodeAt(this.index) diff --git a/packages/compiler-core/src/transform.ts b/packages/compiler-core/src/transform.ts index 381015c9997..5e8cfee3f50 100644 --- a/packages/compiler-core/src/transform.ts +++ b/packages/compiler-core/src/transform.ts @@ -326,7 +326,7 @@ export function createTransformContext( return context } -export function transform(root: RootNode, options: TransformOptions) { +export function transform(root: RootNode, options: TransformOptions): void { const context = createTransformContext(root, options) traverseNode(root, context) if (options.hoistStatic) { @@ -403,7 +403,7 @@ function createRootCodegen(root: RootNode, context: TransformContext) { export function traverseChildren( parent: ParentNode, context: TransformContext, -) { +): void { let i = 0 const nodeRemoved = () => { i-- @@ -422,7 +422,7 @@ export function traverseChildren( export function traverseNode( node: RootNode | TemplateChildNode, context: TransformContext, -) { +): void { context.currentNode = node // apply transform plugins const { nodeTransforms } = context diff --git a/packages/compiler-core/src/transforms/cacheStatic.ts b/packages/compiler-core/src/transforms/cacheStatic.ts index 6ffd624ff53..8d5961643c1 100644 --- a/packages/compiler-core/src/transforms/cacheStatic.ts +++ b/packages/compiler-core/src/transforms/cacheStatic.ts @@ -31,7 +31,7 @@ import { OPEN_BLOCK, } from '../runtimeHelpers' -export function cacheStatic(root: RootNode, context: TransformContext) { +export function cacheStatic(root: RootNode, context: TransformContext): void { walk( root, undefined, diff --git a/packages/compiler-core/src/transforms/transformElement.ts b/packages/compiler-core/src/transforms/transformElement.ts index 9445a61077b..ca53c4785ba 100644 --- a/packages/compiler-core/src/transforms/transformElement.ts +++ b/packages/compiler-core/src/transforms/transformElement.ts @@ -228,7 +228,7 @@ export function resolveComponentType( node: ComponentNode, context: TransformContext, ssr = false, -) { +): string | symbol | CallExpression { let { tag } = node // 1. dynamic component @@ -374,7 +374,7 @@ export type PropsExpression = ObjectExpression | CallExpression | ExpressionNode export function buildProps( node: ElementNode, context: TransformContext, - props: ElementNode['props'] = node.props, + props: ElementNode['props'] | undefined = node.props, isComponent: boolean, isDynamicComponent: boolean, ssr = false, diff --git a/packages/compiler-core/src/transforms/vBind.ts b/packages/compiler-core/src/transforms/vBind.ts index cec444a5a1a..76a36145c06 100644 --- a/packages/compiler-core/src/transforms/vBind.ts +++ b/packages/compiler-core/src/transforms/vBind.ts @@ -99,7 +99,7 @@ export const transformBind: DirectiveTransform = (dir, _node, context) => { export const transformBindShorthand = ( dir: DirectiveNode, context: TransformContext, -) => { +): void => { const arg = dir.arg! const propName = camelize((arg as SimpleExpressionNode).content) diff --git a/packages/compiler-core/src/transforms/vFor.ts b/packages/compiler-core/src/transforms/vFor.ts index 84b9b2d642a..ec1c21ff88b 100644 --- a/packages/compiler-core/src/transforms/vFor.ts +++ b/packages/compiler-core/src/transforms/vFor.ts @@ -1,4 +1,5 @@ import { + type NodeTransform, type TransformContext, createStructuralDirectiveTransform, } from '../transform' @@ -49,7 +50,7 @@ import { validateBrowserExpression } from '../validateExpression' import { PatchFlags } from '@vue/shared' import { transformBindShorthand } from './vBind' -export const transformFor = createStructuralDirectiveTransform( +export const transformFor: NodeTransform = createStructuralDirectiveTransform( 'for', (node, dir, context) => { const { helper, removeHelper } = context @@ -299,7 +300,7 @@ export function processFor( const onExit = processCodegen && processCodegen(forNode) - return () => { + return (): void => { scopes.vFor-- if (!__BROWSER__ && context.prefixIdentifiers) { value && removeIdentifiers(value) @@ -313,7 +314,7 @@ export function processFor( export function finalizeForParseResult( result: ForParseResult, context: TransformContext, -) { +): void { if (result.finalized) return if (!__BROWSER__ && context.prefixIdentifiers) { diff --git a/packages/compiler-core/src/transforms/vIf.ts b/packages/compiler-core/src/transforms/vIf.ts index cb2d9856f24..c3dc8d4ecd0 100644 --- a/packages/compiler-core/src/transforms/vIf.ts +++ b/packages/compiler-core/src/transforms/vIf.ts @@ -1,4 +1,5 @@ import { + type NodeTransform, type TransformContext, createStructuralDirectiveTransform, traverseNode, @@ -33,7 +34,7 @@ import { CREATE_COMMENT, FRAGMENT } from '../runtimeHelpers' import { findDir, findProp, getMemoedVNodeCall, injectProp } from '../utils' import { PatchFlagNames, PatchFlags } from '@vue/shared' -export const transformIf = createStructuralDirectiveTransform( +export const transformIf: NodeTransform = createStructuralDirectiveTransform( /^(if|else|else-if)$/, (node, dir, context) => { return processIf(node, dir, context, (ifNode, branch, isRoot) => { @@ -83,7 +84,7 @@ export function processIf( branch: IfBranchNode, isRoot: boolean, ) => (() => void) | undefined, -) { +): (() => void) | undefined { if ( dir.name !== 'else' && (!dir.exp || !(dir.exp as SimpleExpressionNode).content.trim()) diff --git a/packages/compiler-core/src/utils.ts b/packages/compiler-core/src/utils.ts index 83618f8ade0..54a3a845737 100644 --- a/packages/compiler-core/src/utils.ts +++ b/packages/compiler-core/src/utils.ts @@ -153,8 +153,11 @@ export const isMemberExpressionBrowser = (path: string): boolean => { return !currentOpenBracketCount && !currentOpenParensCount } -export const isMemberExpressionNode = __BROWSER__ - ? (NOOP as any as (path: string, context: TransformContext) => boolean) +export const isMemberExpressionNode: ( + path: string, + context: TransformContext, +) => boolean = __BROWSER__ + ? (NOOP as any) : (path: string, context: TransformContext): boolean => { try { let ret: Expression = parseExpression(path, { @@ -171,9 +174,10 @@ export const isMemberExpressionNode = __BROWSER__ } } -export const isMemberExpression = __BROWSER__ - ? isMemberExpressionBrowser - : isMemberExpressionNode +export const isMemberExpression: ( + path: string, + context: TransformContext, +) => boolean = __BROWSER__ ? isMemberExpressionBrowser : isMemberExpressionNode export function advancePositionWithClone( pos: Position, @@ -217,7 +221,7 @@ export function advancePositionWithMutation( return pos } -export function assert(condition: boolean, msg?: string) { +export function assert(condition: boolean, msg?: string): void { /* istanbul ignore if */ if (!condition) { throw new Error(msg || `unexpected compiler condition`) @@ -331,7 +335,7 @@ export function injectProp( node: VNodeCall | RenderSlotCall, prop: Property, context: TransformContext, -) { +): void { let propsWithInjection: ObjectExpression | CallExpression | undefined /** * 1. mergeProps(...) @@ -498,7 +502,9 @@ export function hasScopeRef( } } -export function getMemoedVNodeCall(node: BlockCodegenNode | MemoExpression) { +export function getMemoedVNodeCall( + node: BlockCodegenNode | MemoExpression, +): VNodeCall | RenderSlotCall { if (node.type === NodeTypes.JS_CALL_EXPRESSION && node.callee === WITH_MEMO) { return node.arguments[1].returns as VNodeCall } else { @@ -506,4 +512,4 @@ export function getMemoedVNodeCall(node: BlockCodegenNode | MemoExpression) { } } -export const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+(\S[\s\S]*)/ +export const forAliasRE: RegExp = /([\s\S]*?)\s+(?:in|of)\s+(\S[\s\S]*)/ diff --git a/packages/compiler-core/src/validateExpression.ts b/packages/compiler-core/src/validateExpression.ts index dca90ddd3f1..a8b7a4fd337 100644 --- a/packages/compiler-core/src/validateExpression.ts +++ b/packages/compiler-core/src/validateExpression.ts @@ -30,7 +30,7 @@ export function validateBrowserExpression( context: TransformContext, asParams = false, asRawStatements = false, -) { +): void { const exp = node.content // empty expressions are validated per-directive since some directives diff --git a/packages/compiler-dom/src/runtimeHelpers.ts b/packages/compiler-dom/src/runtimeHelpers.ts index db829096cb8..c5349ad7940 100644 --- a/packages/compiler-dom/src/runtimeHelpers.ts +++ b/packages/compiler-dom/src/runtimeHelpers.ts @@ -1,18 +1,30 @@ import { registerRuntimeHelpers } from '@vue/compiler-core' -export const V_MODEL_RADIO = Symbol(__DEV__ ? `vModelRadio` : ``) -export const V_MODEL_CHECKBOX = Symbol(__DEV__ ? `vModelCheckbox` : ``) -export const V_MODEL_TEXT = Symbol(__DEV__ ? `vModelText` : ``) -export const V_MODEL_SELECT = Symbol(__DEV__ ? `vModelSelect` : ``) -export const V_MODEL_DYNAMIC = Symbol(__DEV__ ? `vModelDynamic` : ``) +export const V_MODEL_RADIO: unique symbol = Symbol(__DEV__ ? `vModelRadio` : ``) +export const V_MODEL_CHECKBOX: unique symbol = Symbol( + __DEV__ ? `vModelCheckbox` : ``, +) +export const V_MODEL_TEXT: unique symbol = Symbol(__DEV__ ? `vModelText` : ``) +export const V_MODEL_SELECT: unique symbol = Symbol( + __DEV__ ? `vModelSelect` : ``, +) +export const V_MODEL_DYNAMIC: unique symbol = Symbol( + __DEV__ ? `vModelDynamic` : ``, +) -export const V_ON_WITH_MODIFIERS = Symbol(__DEV__ ? `vOnModifiersGuard` : ``) -export const V_ON_WITH_KEYS = Symbol(__DEV__ ? `vOnKeysGuard` : ``) +export const V_ON_WITH_MODIFIERS: unique symbol = Symbol( + __DEV__ ? `vOnModifiersGuard` : ``, +) +export const V_ON_WITH_KEYS: unique symbol = Symbol( + __DEV__ ? `vOnKeysGuard` : ``, +) -export const V_SHOW = Symbol(__DEV__ ? `vShow` : ``) +export const V_SHOW: unique symbol = Symbol(__DEV__ ? `vShow` : ``) -export const TRANSITION = Symbol(__DEV__ ? `Transition` : ``) -export const TRANSITION_GROUP = Symbol(__DEV__ ? `TransitionGroup` : ``) +export const TRANSITION: unique symbol = Symbol(__DEV__ ? `Transition` : ``) +export const TRANSITION_GROUP: unique symbol = Symbol( + __DEV__ ? `TransitionGroup` : ``, +) registerRuntimeHelpers({ [V_MODEL_RADIO]: `vModelRadio`, diff --git a/packages/compiler-sfc/src/index.ts b/packages/compiler-sfc/src/index.ts index 9661b7f7963..5123a908976 100644 --- a/packages/compiler-sfc/src/index.ts +++ b/packages/compiler-sfc/src/index.ts @@ -1,4 +1,4 @@ -export const version = __VERSION__ +export const version: string = __VERSION__ // API export { parse } from './parse' @@ -18,7 +18,7 @@ import { errorMessages as coreErrorMessages, } from '@vue/compiler-dom' -export const errorMessages = { +export const errorMessages: Record = { ...coreErrorMessages, ...DOMErrorMessages, } diff --git a/packages/compiler-sfc/src/parse.ts b/packages/compiler-sfc/src/parse.ts index f0ec926d1b9..e10d4cc84db 100644 --- a/packages/compiler-sfc/src/parse.ts +++ b/packages/compiler-sfc/src/parse.ts @@ -17,6 +17,7 @@ import { parseCssVars } from './style/cssVars' import { createCache } from './cache' import type { ImportBinding } from './compileScript' import { isImportUsed } from './script/importUsageCheck' +import type { LRUCache } from 'lru-cache' export const DEFAULT_FILENAME = 'anonymous.vue' @@ -103,7 +104,9 @@ export interface SFCParseResult { errors: (CompilerError | SyntaxError)[] } -export const parseCache = createCache() +export const parseCache: + | Map + | LRUCache = createCache() function genCacheKey(source: string, options: SFCParseOptions): string { return ( diff --git a/packages/compiler-sfc/src/script/context.ts b/packages/compiler-sfc/src/script/context.ts index 43209d4a0de..91ba0d74884 100644 --- a/packages/compiler-sfc/src/script/context.ts +++ b/packages/compiler-sfc/src/script/context.ts @@ -17,11 +17,12 @@ export class ScriptCompileContext { scriptAst: Program | null scriptSetupAst: Program | null - source = this.descriptor.source - filename = this.descriptor.filename - s = new MagicString(this.source) - startOffset = this.descriptor.scriptSetup?.loc.start.offset - endOffset = this.descriptor.scriptSetup?.loc.end.offset + source: string = this.descriptor.source + filename: string = this.descriptor.filename + s: MagicString = new MagicString(this.source) + startOffset: number | undefined = + this.descriptor.scriptSetup?.loc.start.offset + endOffset: number | undefined = this.descriptor.scriptSetup?.loc.end.offset // import / type analysis scope?: TypeScope @@ -162,7 +163,7 @@ export function resolveParserPlugins( lang: string, userPlugins?: ParserPlugin[], dts = false, -) { +): ParserPlugin[] { const plugins: ParserPlugin[] = [] if ( !userPlugins || diff --git a/packages/compiler-sfc/src/script/defineProps.ts b/packages/compiler-sfc/src/script/defineProps.ts index 4c8a34aa616..9e6b0d86d64 100644 --- a/packages/compiler-sfc/src/script/defineProps.ts +++ b/packages/compiler-sfc/src/script/defineProps.ts @@ -48,7 +48,7 @@ export function processDefineProps( ctx: ScriptCompileContext, node: Node, declId?: LVal, -) { +): boolean { if (!isCallOf(node, DEFINE_PROPS)) { return processWithDefaults(ctx, node, declId) } diff --git a/packages/compiler-sfc/src/script/definePropsDestructure.ts b/packages/compiler-sfc/src/script/definePropsDestructure.ts index 8c527a87bd2..7d848bfecee 100644 --- a/packages/compiler-sfc/src/script/definePropsDestructure.ts +++ b/packages/compiler-sfc/src/script/definePropsDestructure.ts @@ -26,7 +26,7 @@ import { DEFINE_PROPS } from './defineProps' export function processPropsDestructure( ctx: ScriptCompileContext, declId: ObjectPattern, -) { +): void { if (ctx.options.propsDestructure === 'error') { ctx.error(`Props destructure is explicitly prohibited via config.`, declId) } else if (ctx.options.propsDestructure === false) { @@ -97,7 +97,7 @@ type Scope = Record export function transformDestructuredProps( ctx: ScriptCompileContext, vueImportAliases: Record, -) { +): void { if (ctx.options.propsDestructure === false) { return } diff --git a/packages/compiler-sfc/src/script/normalScript.ts b/packages/compiler-sfc/src/script/normalScript.ts index 3b2f21d4863..7fd859290b1 100644 --- a/packages/compiler-sfc/src/script/normalScript.ts +++ b/packages/compiler-sfc/src/script/normalScript.ts @@ -3,13 +3,14 @@ import type { ScriptCompileContext } from './context' import MagicString from 'magic-string' import { rewriteDefaultAST } from '../rewriteDefault' import { genNormalScriptCssVarsCode } from '../style/cssVars' +import type { SFCScriptBlock } from '../parse' export const normalScriptDefaultVar = `__default__` export function processNormalScript( ctx: ScriptCompileContext, scopeId: string, -) { +): SFCScriptBlock { const script = ctx.descriptor.script! if (script.lang && !ctx.isJS && !ctx.isTS) { // do not process non js/ts script blocks diff --git a/packages/compiler-sfc/src/script/resolveType.ts b/packages/compiler-sfc/src/script/resolveType.ts index 398d3ba9f42..4f2d29e036c 100644 --- a/packages/compiler-sfc/src/script/resolveType.ts +++ b/packages/compiler-sfc/src/script/resolveType.ts @@ -823,7 +823,7 @@ let loadTS: (() => typeof TS) | undefined /** * @private */ -export function registerTS(_loadTS: () => typeof TS) { +export function registerTS(_loadTS: () => typeof TS): void { loadTS = () => { try { return _loadTS() @@ -1107,7 +1107,7 @@ const fileToScopeCache = createCache() /** * @private */ -export function invalidateTypeCache(filename: string) { +export function invalidateTypeCache(filename: string): void { filename = normalizePath(filename) fileToScopeCache.delete(filename) tsConfigCache.delete(filename) @@ -1439,7 +1439,7 @@ function attachNamespace( } } -export function recordImports(body: Statement[]) { +export function recordImports(body: Statement[]): Record { const imports: TypeScope['imports'] = Object.create(null) for (const s of body) { recordImport(s, imports) @@ -1462,7 +1462,7 @@ function recordImport(node: Node, imports: TypeScope['imports']) { export function inferRuntimeType( ctx: TypeResolveContext, node: Node & MaybeWithScope, - scope = node._ownerScope || ctxToScope(ctx), + scope: TypeScope = node._ownerScope || ctxToScope(ctx), isKeyOf = false, ): string[] { try { diff --git a/packages/compiler-sfc/src/script/topLevelAwait.ts b/packages/compiler-sfc/src/script/topLevelAwait.ts index 09955ac54e4..c0e00e615f7 100644 --- a/packages/compiler-sfc/src/script/topLevelAwait.ts +++ b/packages/compiler-sfc/src/script/topLevelAwait.ts @@ -39,7 +39,7 @@ export function processAwait( node: AwaitExpression, needSemi: boolean, isStatement: boolean, -) { +): void { const argumentStart = node.argument.extra && node.argument.extra.parenthesized ? (node.argument.extra.parenStart as number) diff --git a/packages/compiler-sfc/src/script/utils.ts b/packages/compiler-sfc/src/script/utils.ts index 38e6bf93750..f9b4ad68625 100644 --- a/packages/compiler-sfc/src/script/utils.ts +++ b/packages/compiler-sfc/src/script/utils.ts @@ -12,7 +12,10 @@ import path from 'path' export const UNKNOWN_TYPE = 'Unknown' -export function resolveObjectKey(node: Node, computed: boolean) { +export function resolveObjectKey( + node: Node, + computed: boolean, +): string | undefined { switch (node.type) { case 'StringLiteral': case 'NumericLiteral': @@ -23,11 +26,13 @@ export function resolveObjectKey(node: Node, computed: boolean) { return undefined } -export function concatStrings(strs: Array) { +export function concatStrings( + strs: Array, +): string { return strs.filter((s): s is string => !!s).join(', ') } -export function isLiteralNode(node: Node) { +export function isLiteralNode(node: Node): boolean { return node.type.endsWith('Literal') } @@ -46,7 +51,7 @@ export function isCallOf( ) } -export function toRuntimeTypeString(types: string[]) { +export function toRuntimeTypeString(types: string[]): string { return types.length > 1 ? `[${types.join(', ')}]` : types[0] } @@ -55,7 +60,7 @@ export function getImportedName( | ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier, -) { +): string { if (specifier.type === 'ImportSpecifier') return specifier.imported.type === 'Identifier' ? specifier.imported.name @@ -89,7 +94,9 @@ function toFileNameLowerCase(x: string) { * but TS does not expose it directly. This implementation is repllicated from * the TS source code. */ -export function createGetCanonicalFileName(useCaseSensitiveFileNames: boolean) { +export function createGetCanonicalFileName( + useCaseSensitiveFileNames: boolean, +): (str: string) => string { return useCaseSensitiveFileNames ? identity : toFileNameLowerCase } @@ -97,25 +104,31 @@ export function createGetCanonicalFileName(useCaseSensitiveFileNames: boolean) { // posix behavior. const normalize = (path.posix || path).normalize const windowsSlashRE = /\\/g -export function normalizePath(p: string) { +export function normalizePath(p: string): string { return normalize(p.replace(windowsSlashRE, '/')) } -export const joinPaths = (path.posix || path).join +export const joinPaths: (...paths: string[]) => string = (path.posix || path) + .join /** * key may contain symbols * e.g. onUpdate:modelValue -> "onUpdate:modelValue" */ -export const propNameEscapeSymbolsRE = /[ !"#$%&'()*+,./:;<=>?@[\\\]^`{|}~\-]/ +export const propNameEscapeSymbolsRE: RegExp = + /[ !"#$%&'()*+,./:;<=>?@[\\\]^`{|}~\-]/ -export function getEscapedPropName(key: string) { +export function getEscapedPropName(key: string): string { return propNameEscapeSymbolsRE.test(key) ? JSON.stringify(key) : key } -export const cssVarNameEscapeSymbolsRE = /[ !"#$%&'()*+,./:;<=>?@[\\\]^`{|}~]/g +export const cssVarNameEscapeSymbolsRE: RegExp = + /[ !"#$%&'()*+,./:;<=>?@[\\\]^`{|}~]/g -export function getEscapedCssVarName(key: string, doubleEscape: boolean) { +export function getEscapedCssVarName( + key: string, + doubleEscape: boolean, +): string { return key.replace(cssVarNameEscapeSymbolsRE, s => doubleEscape ? `\\\\${s}` : `\\${s}`, ) diff --git a/packages/compiler-sfc/src/warn.ts b/packages/compiler-sfc/src/warn.ts index 29bed4dc509..486f4572c16 100644 --- a/packages/compiler-sfc/src/warn.ts +++ b/packages/compiler-sfc/src/warn.ts @@ -1,6 +1,6 @@ const hasWarned: Record = {} -export function warnOnce(msg: string) { +export function warnOnce(msg: string): void { const isNodeProd = typeof process !== 'undefined' && process.env.NODE_ENV === 'production' if (!isNodeProd && !__TEST__ && !hasWarned[msg]) { @@ -9,7 +9,7 @@ export function warnOnce(msg: string) { } } -export function warn(msg: string) { +export function warn(msg: string): void { console.warn( `\x1b[1m\x1b[33m[@vue/compiler-sfc]\x1b[0m\x1b[33m ${msg}\x1b[0m\n`, ) diff --git a/packages/compiler-ssr/src/runtimeHelpers.ts b/packages/compiler-ssr/src/runtimeHelpers.ts index 1420ef64fbe..0e2c8c67bed 100644 --- a/packages/compiler-ssr/src/runtimeHelpers.ts +++ b/packages/compiler-ssr/src/runtimeHelpers.ts @@ -1,26 +1,34 @@ import { registerRuntimeHelpers } from '@vue/compiler-dom' -export const SSR_INTERPOLATE = Symbol(`ssrInterpolate`) -export const SSR_RENDER_VNODE = Symbol(`ssrRenderVNode`) -export const SSR_RENDER_COMPONENT = Symbol(`ssrRenderComponent`) -export const SSR_RENDER_SLOT = Symbol(`ssrRenderSlot`) -export const SSR_RENDER_SLOT_INNER = Symbol(`ssrRenderSlotInner`) -export const SSR_RENDER_CLASS = Symbol(`ssrRenderClass`) -export const SSR_RENDER_STYLE = Symbol(`ssrRenderStyle`) -export const SSR_RENDER_ATTRS = Symbol(`ssrRenderAttrs`) -export const SSR_RENDER_ATTR = Symbol(`ssrRenderAttr`) -export const SSR_RENDER_DYNAMIC_ATTR = Symbol(`ssrRenderDynamicAttr`) -export const SSR_RENDER_LIST = Symbol(`ssrRenderList`) -export const SSR_INCLUDE_BOOLEAN_ATTR = Symbol(`ssrIncludeBooleanAttr`) -export const SSR_LOOSE_EQUAL = Symbol(`ssrLooseEqual`) -export const SSR_LOOSE_CONTAIN = Symbol(`ssrLooseContain`) -export const SSR_RENDER_DYNAMIC_MODEL = Symbol(`ssrRenderDynamicModel`) -export const SSR_GET_DYNAMIC_MODEL_PROPS = Symbol(`ssrGetDynamicModelProps`) -export const SSR_RENDER_TELEPORT = Symbol(`ssrRenderTeleport`) -export const SSR_RENDER_SUSPENSE = Symbol(`ssrRenderSuspense`) -export const SSR_GET_DIRECTIVE_PROPS = Symbol(`ssrGetDirectiveProps`) +export const SSR_INTERPOLATE: unique symbol = Symbol(`ssrInterpolate`) +export const SSR_RENDER_VNODE: unique symbol = Symbol(`ssrRenderVNode`) +export const SSR_RENDER_COMPONENT: unique symbol = Symbol(`ssrRenderComponent`) +export const SSR_RENDER_SLOT: unique symbol = Symbol(`ssrRenderSlot`) +export const SSR_RENDER_SLOT_INNER: unique symbol = Symbol(`ssrRenderSlotInner`) +export const SSR_RENDER_CLASS: unique symbol = Symbol(`ssrRenderClass`) +export const SSR_RENDER_STYLE: unique symbol = Symbol(`ssrRenderStyle`) +export const SSR_RENDER_ATTRS: unique symbol = Symbol(`ssrRenderAttrs`) +export const SSR_RENDER_ATTR: unique symbol = Symbol(`ssrRenderAttr`) +export const SSR_RENDER_DYNAMIC_ATTR: unique symbol = + Symbol(`ssrRenderDynamicAttr`) +export const SSR_RENDER_LIST: unique symbol = Symbol(`ssrRenderList`) +export const SSR_INCLUDE_BOOLEAN_ATTR: unique symbol = Symbol( + `ssrIncludeBooleanAttr`, +) +export const SSR_LOOSE_EQUAL: unique symbol = Symbol(`ssrLooseEqual`) +export const SSR_LOOSE_CONTAIN: unique symbol = Symbol(`ssrLooseContain`) +export const SSR_RENDER_DYNAMIC_MODEL: unique symbol = Symbol( + `ssrRenderDynamicModel`, +) +export const SSR_GET_DYNAMIC_MODEL_PROPS: unique symbol = Symbol( + `ssrGetDynamicModelProps`, +) +export const SSR_RENDER_TELEPORT: unique symbol = Symbol(`ssrRenderTeleport`) +export const SSR_RENDER_SUSPENSE: unique symbol = Symbol(`ssrRenderSuspense`) +export const SSR_GET_DIRECTIVE_PROPS: unique symbol = + Symbol(`ssrGetDirectiveProps`) -export const ssrHelpers = { +export const ssrHelpers: Record = { [SSR_INTERPOLATE]: `ssrInterpolate`, [SSR_RENDER_VNODE]: `ssrRenderVNode`, [SSR_RENDER_COMPONENT]: `ssrRenderComponent`, diff --git a/packages/compiler-ssr/src/ssrCodegenTransform.ts b/packages/compiler-ssr/src/ssrCodegenTransform.ts index 53a7a060510..c093898ec3e 100644 --- a/packages/compiler-ssr/src/ssrCodegenTransform.ts +++ b/packages/compiler-ssr/src/ssrCodegenTransform.ts @@ -1,9 +1,11 @@ import { type BlockStatement, type CallExpression, + type CompilerError, type CompilerOptions, ElementTypes, type IfStatement, + type JSChildNode, NodeTypes, type RootNode, type TemplateChildNode, @@ -33,7 +35,10 @@ import { SSRErrorCodes, createSSRCompilerError } from './errors' // transform pass to convert the template AST into a fresh JS AST before // passing it to codegen. -export function ssrCodegenTransform(ast: RootNode, options: CompilerOptions) { +export function ssrCodegenTransform( + ast: RootNode, + options: CompilerOptions, +): void { const context = createSSRTransformContext(ast, options) // inject SFC