mirror of https://github.com/vuejs/core.git
refactor: isolatedDeclarations for vapor
This commit is contained in:
parent
4468a2bea8
commit
2ef97fec30
|
@ -6,6 +6,7 @@ on:
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
- minor
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
|
|
|
@ -44,9 +44,8 @@ import { parseExpression } from '@babel/parser'
|
||||||
import { IS_REF, UNREF } from '../runtimeHelpers'
|
import { IS_REF, UNREF } from '../runtimeHelpers'
|
||||||
import { BindingTypes } from '../options'
|
import { BindingTypes } from '../options'
|
||||||
|
|
||||||
export const isLiteralWhitelisted = /*#__PURE__*/ makeMap(
|
export const isLiteralWhitelisted: (key: string) => boolean =
|
||||||
'true,false,null,this',
|
/*#__PURE__*/ makeMap('true,false,null,this')
|
||||||
)
|
|
||||||
|
|
||||||
export const transformExpression: NodeTransform = (node, context) => {
|
export const transformExpression: NodeTransform = (node, context) => {
|
||||||
if (node.type === NodeTypes.INTERPOLATION) {
|
if (node.type === NodeTypes.INTERPOLATION) {
|
||||||
|
|
|
@ -16,7 +16,7 @@ import { validateBrowserExpression } from '../validateExpression'
|
||||||
import { hasScopeRef, isMemberExpression } from '../utils'
|
import { hasScopeRef, isMemberExpression } from '../utils'
|
||||||
import { TO_HANDLER_KEY } from '../runtimeHelpers'
|
import { TO_HANDLER_KEY } from '../runtimeHelpers'
|
||||||
|
|
||||||
export const fnExpRE =
|
export const fnExpRE: RegExp =
|
||||||
/^\s*(async\s*)?(\([^)]*?\)|[\w$_]+)\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/
|
/^\s*(async\s*)?(\([^)]*?\)|[\w$_]+)\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/
|
||||||
|
|
||||||
export interface VOnDirectiveNode extends DirectiveNode {
|
export interface VOnDirectiveNode extends DirectiveNode {
|
||||||
|
|
|
@ -158,7 +158,7 @@ export const isMemberExpressionNode: (
|
||||||
context: Pick<TransformContext, 'expressionPlugins'>,
|
context: Pick<TransformContext, 'expressionPlugins'>,
|
||||||
) => boolean = __BROWSER__
|
) => boolean = __BROWSER__
|
||||||
? (NOOP as any)
|
? (NOOP as any)
|
||||||
: (path, context): boolean => {
|
: (path, context) => {
|
||||||
try {
|
try {
|
||||||
let ret: Expression = parseExpression(path, {
|
let ret: Expression = parseExpression(path, {
|
||||||
plugins: context.expressionPlugins,
|
plugins: context.expressionPlugins,
|
||||||
|
@ -176,7 +176,7 @@ export const isMemberExpressionNode: (
|
||||||
|
|
||||||
export const isMemberExpression: (
|
export const isMemberExpression: (
|
||||||
path: string,
|
path: string,
|
||||||
context: TransformContext,
|
context: Pick<TransformContext, 'expressionPlugins'>,
|
||||||
) => boolean = __BROWSER__ ? isMemberExpressionBrowser : isMemberExpressionNode
|
) => boolean = __BROWSER__ ? isMemberExpressionBrowser : isMemberExpressionNode
|
||||||
|
|
||||||
export function advancePositionWithClone(
|
export function advancePositionWithClone(
|
||||||
|
|
|
@ -37,7 +37,11 @@ export const resolveModifiers = (
|
||||||
modifiers: string[],
|
modifiers: string[],
|
||||||
context: TransformContext | null,
|
context: TransformContext | null,
|
||||||
loc: SourceLocation,
|
loc: SourceLocation,
|
||||||
) => {
|
): {
|
||||||
|
keyModifiers: string[]
|
||||||
|
nonKeyModifiers: string[]
|
||||||
|
eventOptionModifiers: string[]
|
||||||
|
} => {
|
||||||
const keyModifiers = []
|
const keyModifiers = []
|
||||||
const nonKeyModifiers = []
|
const nonKeyModifiers = []
|
||||||
const eventOptionModifiers = []
|
const eventOptionModifiers = []
|
||||||
|
|
|
@ -22,8 +22,8 @@ export type CodegenOptions = Omit<BaseCodegenOptions, 'optimizeImports'>
|
||||||
export class CodegenContext {
|
export class CodegenContext {
|
||||||
options: Required<CodegenOptions>
|
options: Required<CodegenOptions>
|
||||||
|
|
||||||
helpers = new Set<string>([])
|
helpers: Set<string> = new Set<string>([])
|
||||||
vaporHelpers = new Set<string>([])
|
vaporHelpers: Set<string> = new Set<string>([])
|
||||||
helper = (name: string) => {
|
helper = (name: string) => {
|
||||||
this.helpers.add(name)
|
this.helpers.add(name)
|
||||||
return `_${name}`
|
return `_${name}`
|
||||||
|
@ -33,7 +33,7 @@ export class CodegenContext {
|
||||||
return `_${name}`
|
return `_${name}`
|
||||||
}
|
}
|
||||||
|
|
||||||
delegates = new Set<string>()
|
delegates: Set<string> = new Set<string>()
|
||||||
|
|
||||||
identifiers: Record<string, string[]> = Object.create(null)
|
identifiers: Record<string, string[]> = Object.create(null)
|
||||||
|
|
||||||
|
@ -56,11 +56,11 @@ export class CodegenContext {
|
||||||
enterBlock(block: BlockIRNode) {
|
enterBlock(block: BlockIRNode) {
|
||||||
const parent = this.block
|
const parent = this.block
|
||||||
this.block = block
|
this.block = block
|
||||||
return () => (this.block = parent)
|
return (): BlockIRNode => (this.block = parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
scopeLevel: number = 0
|
scopeLevel: number = 0
|
||||||
enterScope() {
|
enterScope(): [level: number, exit: () => number] {
|
||||||
return [this.scopeLevel++, () => this.scopeLevel--] as const
|
return [this.scopeLevel++, () => this.scopeLevel--] as const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,10 @@ export function genCreateComponent(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function genRawProps(props: IRProps[], context: CodegenContext) {
|
export function genRawProps(
|
||||||
|
props: IRProps[],
|
||||||
|
context: CodegenContext,
|
||||||
|
): CodeFragment[] | undefined {
|
||||||
const { vaporHelper } = context
|
const { vaporHelper } = context
|
||||||
const frag = props
|
const frag = props
|
||||||
.map(props => {
|
.map(props => {
|
||||||
|
|
|
@ -20,7 +20,10 @@ import {
|
||||||
type WithDirectiveIRNode,
|
type WithDirectiveIRNode,
|
||||||
} from '../ir'
|
} from '../ir'
|
||||||
|
|
||||||
export function genDirectivesForElement(id: number, context: CodegenContext) {
|
export function genDirectivesForElement(
|
||||||
|
id: number,
|
||||||
|
context: CodegenContext,
|
||||||
|
): CodeFragment[] {
|
||||||
const dirs = filterDirectives(id, context.block.operation)
|
const dirs = filterDirectives(id, context.block.operation)
|
||||||
return dirs.length ? genWithDirective(dirs, context) : []
|
return dirs.length ? genWithDirective(dirs, context) : []
|
||||||
}
|
}
|
||||||
|
@ -78,7 +81,7 @@ export function genWithDirective(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function genDirectiveModifiers(modifiers: string[]) {
|
export function genDirectiveModifiers(modifiers: string[]): string {
|
||||||
return modifiers
|
return modifiers
|
||||||
.map(
|
.map(
|
||||||
value =>
|
value =>
|
||||||
|
|
|
@ -90,7 +90,7 @@ function genArrayExpression(elements: string[]) {
|
||||||
export function genEventHandler(
|
export function genEventHandler(
|
||||||
context: CodegenContext,
|
context: CodegenContext,
|
||||||
value: SimpleExpressionNode | undefined,
|
value: SimpleExpressionNode | undefined,
|
||||||
) {
|
): CodeFragment[] {
|
||||||
if (value && value.content.trim()) {
|
if (value && value.content.trim()) {
|
||||||
const isMemberExp = isMemberExpression(value.content, context.options)
|
const isMemberExp = isMemberExpression(value.content, context.options)
|
||||||
const isInlineStatement = !(isMemberExp || fnExpRE.test(value.content))
|
const isInlineStatement = !(isMemberExp || fnExpRE.test(value.content))
|
||||||
|
|
|
@ -25,7 +25,7 @@ export function genSetModelValue(
|
||||||
export function genModelHandler(
|
export function genModelHandler(
|
||||||
value: SimpleExpressionNode,
|
value: SimpleExpressionNode,
|
||||||
context: CodegenContext,
|
context: CodegenContext,
|
||||||
) {
|
): CodeFragment[] {
|
||||||
const {
|
const {
|
||||||
options: { isTS },
|
options: { isTS },
|
||||||
} = context
|
} = context
|
||||||
|
|
|
@ -19,7 +19,10 @@ import {
|
||||||
import { genCreateComponent } from './component'
|
import { genCreateComponent } from './component'
|
||||||
import { genSlotOutlet } from './slotOutlet'
|
import { genSlotOutlet } from './slotOutlet'
|
||||||
|
|
||||||
export function genOperations(opers: OperationNode[], context: CodegenContext) {
|
export function genOperations(
|
||||||
|
opers: OperationNode[],
|
||||||
|
context: CodegenContext,
|
||||||
|
): CodeFragment[] {
|
||||||
const [frag, push] = buildCodeFragment()
|
const [frag, push] = buildCodeFragment()
|
||||||
for (const operation of opers) {
|
for (const operation of opers) {
|
||||||
push(...genOperation(operation, context))
|
push(...genOperation(operation, context))
|
||||||
|
@ -69,7 +72,10 @@ export function genOperation(
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
export function genEffects(effects: IREffect[], context: CodegenContext) {
|
export function genEffects(
|
||||||
|
effects: IREffect[],
|
||||||
|
context: CodegenContext,
|
||||||
|
): CodeFragment[] {
|
||||||
const [frag, push] = buildCodeFragment()
|
const [frag, push] = buildCodeFragment()
|
||||||
for (const effect of effects) {
|
for (const effect of effects) {
|
||||||
push(...genEffect(effect, context))
|
push(...genEffect(effect, context))
|
||||||
|
@ -77,7 +83,10 @@ export function genEffects(effects: IREffect[], context: CodegenContext) {
|
||||||
return frag
|
return frag
|
||||||
}
|
}
|
||||||
|
|
||||||
export function genEffect({ operations }: IREffect, context: CodegenContext) {
|
export function genEffect(
|
||||||
|
{ operations }: IREffect,
|
||||||
|
context: CodegenContext,
|
||||||
|
): CodeFragment[] {
|
||||||
const { vaporHelper } = context
|
const { vaporHelper } = context
|
||||||
const [frag, push] = buildCodeFragment(
|
const [frag, push] = buildCodeFragment(
|
||||||
NEWLINE,
|
NEWLINE,
|
||||||
|
|
|
@ -5,7 +5,10 @@ import { genExpression } from './expression'
|
||||||
import { type CodeFragment, NEWLINE, buildCodeFragment, genCall } from './utils'
|
import { type CodeFragment, NEWLINE, buildCodeFragment, genCall } from './utils'
|
||||||
import { genRawProps } from './component'
|
import { genRawProps } from './component'
|
||||||
|
|
||||||
export function genSlotOutlet(oper: SlotOutletIRNode, context: CodegenContext) {
|
export function genSlotOutlet(
|
||||||
|
oper: SlotOutletIRNode,
|
||||||
|
context: CodegenContext,
|
||||||
|
): CodeFragment[] {
|
||||||
const { vaporHelper } = context
|
const { vaporHelper } = context
|
||||||
const { id, name, fallback } = oper
|
const { id, name, fallback } = oper
|
||||||
const [frag, push] = buildCodeFragment()
|
const [frag, push] = buildCodeFragment()
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { type CodeFragment, NEWLINE, buildCodeFragment, genCall } from './utils'
|
||||||
export function genTemplates(
|
export function genTemplates(
|
||||||
templates: string[],
|
templates: string[],
|
||||||
{ vaporHelper }: CodegenContext,
|
{ vaporHelper }: CodegenContext,
|
||||||
) {
|
): string {
|
||||||
return templates
|
return templates
|
||||||
.map(
|
.map(
|
||||||
(template, i) =>
|
(template, i) =>
|
||||||
|
|
|
@ -10,11 +10,11 @@ import {
|
||||||
import { isArray, isString } from '@vue/shared'
|
import { isArray, isString } from '@vue/shared'
|
||||||
import type { CodegenContext } from '../generate'
|
import type { CodegenContext } from '../generate'
|
||||||
|
|
||||||
export const NEWLINE = Symbol(__DEV__ ? `newline` : ``)
|
export const NEWLINE: unique symbol = Symbol(__DEV__ ? `newline` : ``)
|
||||||
/** increase offset but don't push actual code */
|
/** increase offset but don't push actual code */
|
||||||
export const LF = Symbol(__DEV__ ? `line feed` : ``)
|
export const LF: unique symbol = Symbol(__DEV__ ? `line feed` : ``)
|
||||||
export const INDENT_START = Symbol(__DEV__ ? `indent start` : ``)
|
export const INDENT_START: unique symbol = Symbol(__DEV__ ? `indent start` : ``)
|
||||||
export const INDENT_END = Symbol(__DEV__ ? `indent end` : ``)
|
export const INDENT_END: unique symbol = Symbol(__DEV__ ? `indent end` : ``)
|
||||||
|
|
||||||
type FalsyValue = false | null | undefined
|
type FalsyValue = false | null | undefined
|
||||||
export type CodeFragment =
|
export type CodeFragment =
|
||||||
|
|
|
@ -113,14 +113,14 @@ export class TransformContext<T extends AllNode = AllNode> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
increaseId = () => this.globalId++
|
increaseId = (): number => this.globalId++
|
||||||
reference() {
|
reference(): number {
|
||||||
if (this.dynamic.id !== undefined) return this.dynamic.id
|
if (this.dynamic.id !== undefined) return this.dynamic.id
|
||||||
this.dynamic.flags |= DynamicFlag.REFERENCED
|
this.dynamic.flags |= DynamicFlag.REFERENCED
|
||||||
return (this.dynamic.id = this.increaseId())
|
return (this.dynamic.id = this.increaseId())
|
||||||
}
|
}
|
||||||
|
|
||||||
pushTemplate(content: string) {
|
pushTemplate(content: string): number {
|
||||||
const existing = this.ir.template.findIndex(
|
const existing = this.ir.template.findIndex(
|
||||||
template => template === content,
|
template => template === content,
|
||||||
)
|
)
|
||||||
|
@ -128,7 +128,7 @@ export class TransformContext<T extends AllNode = AllNode> {
|
||||||
this.ir.template.push(content)
|
this.ir.template.push(content)
|
||||||
return this.ir.template.length - 1
|
return this.ir.template.length - 1
|
||||||
}
|
}
|
||||||
registerTemplate() {
|
registerTemplate(): number {
|
||||||
if (!this.template) return -1
|
if (!this.template) return -1
|
||||||
const id = this.pushTemplate(this.template)
|
const id = this.pushTemplate(this.template)
|
||||||
return (this.dynamic.template = id)
|
return (this.dynamic.template = id)
|
||||||
|
@ -137,7 +137,7 @@ export class TransformContext<T extends AllNode = AllNode> {
|
||||||
registerEffect(
|
registerEffect(
|
||||||
expressions: SimpleExpressionNode[],
|
expressions: SimpleExpressionNode[],
|
||||||
...operations: OperationNode[]
|
...operations: OperationNode[]
|
||||||
) {
|
): void {
|
||||||
expressions = expressions.filter(exp => !isConstantExpression(exp))
|
expressions = expressions.filter(exp => !isConstantExpression(exp))
|
||||||
if (this.inVOnce || expressions.length === 0) {
|
if (this.inVOnce || expressions.length === 0) {
|
||||||
return this.registerOperation(...operations)
|
return this.registerOperation(...operations)
|
||||||
|
@ -162,7 +162,7 @@ export class TransformContext<T extends AllNode = AllNode> {
|
||||||
return a.every((exp, i) => exp.content === b[i].content)
|
return a.every((exp, i) => exp.content === b[i].content)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
registerOperation(...node: OperationNode[]) {
|
registerOperation(...node: OperationNode[]): void {
|
||||||
this.block.operation.push(...node)
|
this.block.operation.push(...node)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,7 +230,7 @@ export function transform(
|
||||||
|
|
||||||
export function transformNode(
|
export function transformNode(
|
||||||
context: TransformContext<RootNode | TemplateChildNode>,
|
context: TransformContext<RootNode | TemplateChildNode>,
|
||||||
) {
|
): void {
|
||||||
let { node } = context
|
let { node } = context
|
||||||
|
|
||||||
// apply transform plugins
|
// apply transform plugins
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import {
|
import {
|
||||||
type CommentNode,
|
type CommentNode,
|
||||||
|
type ElementNode,
|
||||||
NodeTypes,
|
NodeTypes,
|
||||||
type TemplateChildNode,
|
type TemplateChildNode,
|
||||||
} from '@vue/compiler-dom'
|
} from '@vue/compiler-dom'
|
||||||
|
@ -20,7 +21,7 @@ export const transformComment: NodeTransform = (node, context) => {
|
||||||
export function getSiblingIf(
|
export function getSiblingIf(
|
||||||
context: TransformContext<TemplateChildNode>,
|
context: TransformContext<TemplateChildNode>,
|
||||||
reverse?: boolean,
|
reverse?: boolean,
|
||||||
) {
|
): ElementNode | undefined {
|
||||||
const parent = context.parent
|
const parent = context.parent
|
||||||
if (!parent) return
|
if (!parent) return
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ import {
|
||||||
} from '../ir'
|
} from '../ir'
|
||||||
import { EMPTY_EXPRESSION } from './utils'
|
import { EMPTY_EXPRESSION } from './utils'
|
||||||
|
|
||||||
export const isReservedProp = /*#__PURE__*/ makeMap(
|
export const isReservedProp: (key: string) => boolean = /*#__PURE__*/ makeMap(
|
||||||
// the leading comma is intentional so empty string "" is also included
|
// the leading comma is intentional so empty string "" is also included
|
||||||
',key,ref,ref_for,ref_key,',
|
',key,ref,ref_for,ref_key,',
|
||||||
)
|
)
|
||||||
|
|
|
@ -4,6 +4,7 @@ import {
|
||||||
type ElementNode,
|
type ElementNode,
|
||||||
ElementTypes,
|
ElementTypes,
|
||||||
NodeTypes,
|
NodeTypes,
|
||||||
|
type SimpleExpressionNode,
|
||||||
type TemplateChildNode,
|
type TemplateChildNode,
|
||||||
type TemplateNode,
|
type TemplateNode,
|
||||||
createSimpleExpression,
|
createSimpleExpression,
|
||||||
|
@ -54,4 +55,7 @@ export function wrapTemplate(node: ElementNode, dirs: string[]): TemplateNode {
|
||||||
} as Partial<TemplateNode>)
|
} as Partial<TemplateNode>)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const EMPTY_EXPRESSION = createSimpleExpression('', true)
|
export const EMPTY_EXPRESSION: SimpleExpressionNode = createSimpleExpression(
|
||||||
|
'',
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
|
|
@ -5,6 +5,7 @@ import {
|
||||||
createCompilerError,
|
createCompilerError,
|
||||||
} from '@vue/compiler-dom'
|
} from '@vue/compiler-dom'
|
||||||
import {
|
import {
|
||||||
|
type NodeTransform,
|
||||||
type TransformContext,
|
type TransformContext,
|
||||||
createStructuralDirectiveTransform,
|
createStructuralDirectiveTransform,
|
||||||
} from '../transform'
|
} from '../transform'
|
||||||
|
@ -17,7 +18,7 @@ import {
|
||||||
import { findProp, propToExpression } from '../utils'
|
import { findProp, propToExpression } from '../utils'
|
||||||
import { newBlock, wrapTemplate } from './utils'
|
import { newBlock, wrapTemplate } from './utils'
|
||||||
|
|
||||||
export const transformVFor = createStructuralDirectiveTransform(
|
export const transformVFor: NodeTransform = createStructuralDirectiveTransform(
|
||||||
'for',
|
'for',
|
||||||
processFor,
|
processFor,
|
||||||
)
|
)
|
||||||
|
@ -52,7 +53,7 @@ export function processFor(
|
||||||
const exitBlock = context.enterBlock(render, true)
|
const exitBlock = context.enterBlock(render, true)
|
||||||
context.reference()
|
context.reference()
|
||||||
|
|
||||||
return () => {
|
return (): void => {
|
||||||
exitBlock()
|
exitBlock()
|
||||||
context.registerOperation({
|
context.registerOperation({
|
||||||
type: IRNodeTypes.FOR,
|
type: IRNodeTypes.FOR,
|
||||||
|
|
|
@ -5,6 +5,7 @@ import {
|
||||||
createSimpleExpression,
|
createSimpleExpression,
|
||||||
} from '@vue/compiler-dom'
|
} from '@vue/compiler-dom'
|
||||||
import {
|
import {
|
||||||
|
type NodeTransform,
|
||||||
type TransformContext,
|
type TransformContext,
|
||||||
createStructuralDirectiveTransform,
|
createStructuralDirectiveTransform,
|
||||||
} from '../transform'
|
} from '../transform'
|
||||||
|
@ -18,7 +19,7 @@ import { extend } from '@vue/shared'
|
||||||
import { newBlock, wrapTemplate } from './utils'
|
import { newBlock, wrapTemplate } from './utils'
|
||||||
import { getSiblingIf } from './transformComment'
|
import { getSiblingIf } from './transformComment'
|
||||||
|
|
||||||
export const transformVIf = createStructuralDirectiveTransform(
|
export const transformVIf: NodeTransform = createStructuralDirectiveTransform(
|
||||||
['if', 'else', 'else-if'],
|
['if', 'else', 'else-if'],
|
||||||
processIf,
|
processIf,
|
||||||
)
|
)
|
||||||
|
@ -27,7 +28,7 @@ export function processIf(
|
||||||
node: ElementNode,
|
node: ElementNode,
|
||||||
dir: VaporDirectiveNode,
|
dir: VaporDirectiveNode,
|
||||||
context: TransformContext<ElementNode>,
|
context: TransformContext<ElementNode>,
|
||||||
) {
|
): (() => void) | undefined {
|
||||||
if (dir.name !== 'else' && (!dir.exp || !dir.exp.content.trim())) {
|
if (dir.name !== 'else' && (!dir.exp || !dir.exp.content.trim())) {
|
||||||
const loc = dir.exp ? dir.exp.loc : node.loc
|
const loc = dir.exp ? dir.exp.loc : node.loc
|
||||||
context.options.onError(
|
context.options.onError(
|
||||||
|
|
|
@ -27,7 +27,9 @@ export const findDir = _findDir as (
|
||||||
allowEmpty?: boolean,
|
allowEmpty?: boolean,
|
||||||
) => VaporDirectiveNode | undefined
|
) => VaporDirectiveNode | undefined
|
||||||
|
|
||||||
export function propToExpression(prop: AttributeNode | VaporDirectiveNode) {
|
export function propToExpression(
|
||||||
|
prop: AttributeNode | VaporDirectiveNode,
|
||||||
|
): SimpleExpressionNode | undefined {
|
||||||
return prop.type === NodeTypes.ATTRIBUTE
|
return prop.type === NodeTypes.ATTRIBUTE
|
||||||
? prop.value
|
? prop.value
|
||||||
? createSimpleExpression(prop.value.content, true, prop.value.loc)
|
? createSimpleExpression(prop.value.content, true, prop.value.loc)
|
||||||
|
@ -35,7 +37,7 @@ export function propToExpression(prop: AttributeNode | VaporDirectiveNode) {
|
||||||
: prop.exp
|
: prop.exp
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isConstantExpression(exp: SimpleExpressionNode) {
|
export function isConstantExpression(exp: SimpleExpressionNode): boolean {
|
||||||
return (
|
return (
|
||||||
isLiteralWhitelisted(exp.content) ||
|
isLiteralWhitelisted(exp.content) ||
|
||||||
isGloballyAllowed(exp.content) ||
|
isGloballyAllowed(exp.content) ||
|
||||||
|
@ -43,7 +45,9 @@ export function isConstantExpression(exp: SimpleExpressionNode) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resolveExpression(exp: SimpleExpressionNode) {
|
export function resolveExpression(
|
||||||
|
exp: SimpleExpressionNode,
|
||||||
|
): SimpleExpressionNode {
|
||||||
if (!exp.isStatic) {
|
if (!exp.isStatic) {
|
||||||
const value = getLiteralExpressionValue(exp)
|
const value = getLiteralExpressionValue(exp)
|
||||||
if (value !== null) {
|
if (value !== null) {
|
||||||
|
|
|
@ -38,7 +38,7 @@ export class EffectScope {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public detached = false,
|
public detached = false,
|
||||||
parent = activeEffectScope,
|
parent: EffectScope | undefined = activeEffectScope,
|
||||||
) {
|
) {
|
||||||
this.parent = parent
|
this.parent = parent
|
||||||
if (!detached && parent) {
|
if (!detached && parent) {
|
||||||
|
|
|
@ -7,12 +7,13 @@ import {
|
||||||
isReservedProp,
|
isReservedProp,
|
||||||
normalizeClass,
|
normalizeClass,
|
||||||
} from '@vue/shared'
|
} from '@vue/shared'
|
||||||
import type { ComponentInternalInstance, Data } from '../component'
|
import type { ComponentInternalInstance } from '../component'
|
||||||
import type { Slot } from '../componentSlots'
|
import type { Slot } from '../componentSlots'
|
||||||
import { createSlots } from '../helpers/createSlots'
|
import { createSlots } from '../helpers/createSlots'
|
||||||
import { renderSlot } from '../helpers/renderSlot'
|
import { renderSlot } from '../helpers/renderSlot'
|
||||||
import { toHandlers } from '../helpers/toHandlers'
|
import { toHandlers } from '../helpers/toHandlers'
|
||||||
import { type VNode, mergeProps } from '../vnode'
|
import { type VNode, mergeProps } from '../vnode'
|
||||||
|
import type { Data } from '@vue/runtime-shared'
|
||||||
|
|
||||||
function toObject(arr: Array<any>): Object {
|
function toObject(arr: Array<any>): Object {
|
||||||
const res = {}
|
const res = {}
|
||||||
|
|
|
@ -2,4 +2,7 @@ import { toHandlers as _toHandlers } from '@vue/runtime-shared'
|
||||||
import { warn } from '../warning'
|
import { warn } from '../warning'
|
||||||
import { NOOP } from '@vue/shared'
|
import { NOOP } from '@vue/shared'
|
||||||
|
|
||||||
export const toHandlers = _toHandlers.bind(undefined, __DEV__ ? warn : NOOP)
|
export const toHandlers: (
|
||||||
|
obj: Record<string, any>,
|
||||||
|
preserveCaseIfNecessary?: boolean | undefined,
|
||||||
|
) => Record<string, any> = _toHandlers.bind(undefined, __DEV__ ? warn : NOOP)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import {
|
import {
|
||||||
type Component,
|
type Component,
|
||||||
|
type ComponentInternalInstance,
|
||||||
createComponentInstance,
|
createComponentInstance,
|
||||||
currentInstance,
|
currentInstance,
|
||||||
} from './component'
|
} from './component'
|
||||||
|
@ -14,7 +15,7 @@ export function createComponent(
|
||||||
slots: RawSlots | null = null,
|
slots: RawSlots | null = null,
|
||||||
singleRoot: boolean = false,
|
singleRoot: boolean = false,
|
||||||
once: boolean = false,
|
once: boolean = false,
|
||||||
) {
|
): ComponentInternalInstance {
|
||||||
const current = currentInstance!
|
const current = currentInstance!
|
||||||
const instance = createComponentInstance(
|
const instance = createComponentInstance(
|
||||||
comp,
|
comp,
|
||||||
|
|
|
@ -8,7 +8,7 @@ export interface InjectionKey<T> extends Symbol {}
|
||||||
export function provide<T, K = InjectionKey<T> | string | number>(
|
export function provide<T, K = InjectionKey<T> | string | number>(
|
||||||
key: K,
|
key: K,
|
||||||
value: K extends InjectionKey<infer V> ? V : T,
|
value: K extends InjectionKey<infer V> ? V : T,
|
||||||
) {
|
): void {
|
||||||
if (!currentInstance) {
|
if (!currentInstance) {
|
||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
warn(`provide() can only be used inside setup().`)
|
warn(`provide() can only be used inside setup().`)
|
||||||
|
|
|
@ -59,19 +59,29 @@ const createHook =
|
||||||
<T extends Function = () => any>(lifecycle: VaporLifecycleHooks) =>
|
<T extends Function = () => any>(lifecycle: VaporLifecycleHooks) =>
|
||||||
(hook: T, target: ComponentInternalInstance | null = currentInstance) =>
|
(hook: T, target: ComponentInternalInstance | null = currentInstance) =>
|
||||||
injectHook(lifecycle, (...args: unknown[]) => hook(...args), target)
|
injectHook(lifecycle, (...args: unknown[]) => hook(...args), target)
|
||||||
|
type CreateHook<T = any> = (
|
||||||
|
hook: T,
|
||||||
|
target?: ComponentInternalInstance | null,
|
||||||
|
) => void
|
||||||
|
|
||||||
export const onBeforeMount = createHook(VaporLifecycleHooks.BEFORE_MOUNT)
|
export const onBeforeMount: CreateHook = createHook(
|
||||||
export const onMounted = createHook(VaporLifecycleHooks.MOUNTED)
|
VaporLifecycleHooks.BEFORE_MOUNT,
|
||||||
export const onBeforeUpdate = createHook(VaporLifecycleHooks.BEFORE_UPDATE)
|
)
|
||||||
export const onUpdated = createHook(VaporLifecycleHooks.UPDATED)
|
export const onMounted: CreateHook = createHook(VaporLifecycleHooks.MOUNTED)
|
||||||
export const onBeforeUnmount = createHook(VaporLifecycleHooks.BEFORE_UNMOUNT)
|
export const onBeforeUpdate: CreateHook = createHook(
|
||||||
export const onUnmounted = createHook(VaporLifecycleHooks.UNMOUNTED)
|
VaporLifecycleHooks.BEFORE_UPDATE,
|
||||||
|
)
|
||||||
|
export const onUpdated: CreateHook = createHook(VaporLifecycleHooks.UPDATED)
|
||||||
|
export const onBeforeUnmount: CreateHook = createHook(
|
||||||
|
VaporLifecycleHooks.BEFORE_UNMOUNT,
|
||||||
|
)
|
||||||
|
export const onUnmounted: CreateHook = createHook(VaporLifecycleHooks.UNMOUNTED)
|
||||||
|
|
||||||
export type DebuggerHook = (e: DebuggerEvent) => void
|
export type DebuggerHook = (e: DebuggerEvent) => void
|
||||||
export const onRenderTriggered = createHook<DebuggerHook>(
|
export const onRenderTriggered: CreateHook = createHook<DebuggerHook>(
|
||||||
VaporLifecycleHooks.RENDER_TRIGGERED,
|
VaporLifecycleHooks.RENDER_TRIGGERED,
|
||||||
)
|
)
|
||||||
export const onRenderTracked = createHook<DebuggerHook>(
|
export const onRenderTracked: CreateHook = createHook<DebuggerHook>(
|
||||||
VaporLifecycleHooks.RENDER_TRACKED,
|
VaporLifecycleHooks.RENDER_TRACKED,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -84,6 +94,6 @@ export type ErrorCapturedHook<TError = unknown> = (
|
||||||
export function onErrorCaptured<TError = Error>(
|
export function onErrorCaptured<TError = Error>(
|
||||||
hook: ErrorCapturedHook<TError>,
|
hook: ErrorCapturedHook<TError>,
|
||||||
target: ComponentInternalInstance | null = currentInstance,
|
target: ComponentInternalInstance | null = currentInstance,
|
||||||
) {
|
): void {
|
||||||
injectHook(VaporLifecycleHooks.ERROR_CAPTURED, hook, target)
|
injectHook(VaporLifecycleHooks.ERROR_CAPTURED, hook, target)
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ import { VaporErrorCodes, callWithErrorHandling } from './errorHandling'
|
||||||
import { endMeasure, startMeasure } from './profiling'
|
import { endMeasure, startMeasure } from './profiling'
|
||||||
import { devtoolsComponentAdded } from './devtools'
|
import { devtoolsComponentAdded } from './devtools'
|
||||||
|
|
||||||
export const fragmentKey = Symbol(__DEV__ ? `fragmentKey` : ``)
|
export const fragmentKey: unique symbol = Symbol(__DEV__ ? `fragmentKey` : ``)
|
||||||
|
|
||||||
export type Block = Node | Fragment | ComponentInternalInstance | Block[]
|
export type Block = Node | Fragment | ComponentInternalInstance | Block[]
|
||||||
export type Fragment = {
|
export type Fragment = {
|
||||||
|
@ -152,7 +152,7 @@ function mountComponent(
|
||||||
return instance
|
return instance
|
||||||
}
|
}
|
||||||
|
|
||||||
export function unmountComponent(instance: ComponentInternalInstance) {
|
export function unmountComponent(instance: ComponentInternalInstance): void {
|
||||||
const { container, block, scope } = instance
|
const { container, block, scope } = instance
|
||||||
|
|
||||||
// hook: beforeUnmount
|
// hook: beforeUnmount
|
||||||
|
|
|
@ -65,7 +65,7 @@ export function watchEffect(
|
||||||
export function watchPostEffect(
|
export function watchPostEffect(
|
||||||
effect: WatchEffect,
|
effect: WatchEffect,
|
||||||
options?: DebuggerOptions,
|
options?: DebuggerOptions,
|
||||||
) {
|
): WatchStopHandle {
|
||||||
return doWatch(
|
return doWatch(
|
||||||
effect,
|
effect,
|
||||||
null,
|
null,
|
||||||
|
@ -76,7 +76,7 @@ export function watchPostEffect(
|
||||||
export function watchSyncEffect(
|
export function watchSyncEffect(
|
||||||
effect: WatchEffect,
|
effect: WatchEffect,
|
||||||
options?: DebuggerOptions,
|
options?: DebuggerOptions,
|
||||||
) {
|
): WatchStopHandle {
|
||||||
return doWatch(
|
return doWatch(
|
||||||
effect,
|
effect,
|
||||||
null,
|
null,
|
||||||
|
|
|
@ -146,7 +146,7 @@ export interface ComponentInternalOptions {
|
||||||
|
|
||||||
type LifecycleHook<TFn = Function> = TFn[] | null
|
type LifecycleHook<TFn = Function> = TFn[] | null
|
||||||
|
|
||||||
export const componentKey = Symbol(__DEV__ ? `componentKey` : ``)
|
export const componentKey: unique symbol = Symbol(__DEV__ ? `componentKey` : ``)
|
||||||
|
|
||||||
export interface ComponentInternalInstance {
|
export interface ComponentInternalInstance {
|
||||||
[componentKey]: true
|
[componentKey]: true
|
||||||
|
@ -246,12 +246,12 @@ export const getCurrentInstance: () => ComponentInternalInstance | null = () =>
|
||||||
export const setCurrentInstance = (instance: ComponentInternalInstance) => {
|
export const setCurrentInstance = (instance: ComponentInternalInstance) => {
|
||||||
const prev = currentInstance
|
const prev = currentInstance
|
||||||
currentInstance = instance
|
currentInstance = instance
|
||||||
return () => {
|
return (): void => {
|
||||||
currentInstance = prev
|
currentInstance = prev
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const unsetCurrentInstance = () => {
|
export const unsetCurrentInstance = (): void => {
|
||||||
currentInstance && currentInstance.scope.off()
|
currentInstance && currentInstance.scope.off()
|
||||||
currentInstance = null
|
currentInstance = null
|
||||||
}
|
}
|
||||||
|
@ -375,7 +375,7 @@ export function isVaporComponent(
|
||||||
export function validateComponentName(
|
export function validateComponentName(
|
||||||
name: string,
|
name: string,
|
||||||
{ isNativeTag }: AppConfig,
|
{ isNativeTag }: AppConfig,
|
||||||
) {
|
): void {
|
||||||
if (isBuiltInTag(name) || isNativeTag(name)) {
|
if (isBuiltInTag(name) || isNativeTag(name)) {
|
||||||
warn(
|
warn(
|
||||||
'Do not use built-in or reserved HTML elements as component id: ' + name,
|
'Do not use built-in or reserved HTML elements as component id: ' + name,
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { setDynamicProps } from './dom/prop'
|
||||||
import type { RawProps } from './componentProps'
|
import type { RawProps } from './componentProps'
|
||||||
import { renderEffect } from './renderEffect'
|
import { renderEffect } from './renderEffect'
|
||||||
|
|
||||||
export function patchAttrs(instance: ComponentInternalInstance) {
|
export function patchAttrs(instance: ComponentInternalInstance): void {
|
||||||
const {
|
const {
|
||||||
attrs,
|
attrs,
|
||||||
rawProps,
|
rawProps,
|
||||||
|
@ -64,7 +64,7 @@ export function withAttrs(props: RawProps): RawProps {
|
||||||
return [attrsGetter, props]
|
return [attrsGetter, props]
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fallThroughAttrs(instance: ComponentInternalInstance) {
|
export function fallThroughAttrs(instance: ComponentInternalInstance): void {
|
||||||
const {
|
const {
|
||||||
block,
|
block,
|
||||||
type: { inheritAttrs },
|
type: { inheritAttrs },
|
||||||
|
|
|
@ -43,7 +43,7 @@ export function emit(
|
||||||
instance: ComponentInternalInstance,
|
instance: ComponentInternalInstance,
|
||||||
event: string,
|
event: string,
|
||||||
...rawArgs: any[]
|
...rawArgs: any[]
|
||||||
) {
|
): void {
|
||||||
if (instance.isUnmounted) return
|
if (instance.isUnmounted) return
|
||||||
|
|
||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
|
|
|
@ -10,7 +10,7 @@ export function invokeLifecycle(
|
||||||
directive: DirectiveHookName,
|
directive: DirectiveHookName,
|
||||||
cb?: (instance: ComponentInternalInstance) => void,
|
cb?: (instance: ComponentInternalInstance) => void,
|
||||||
post?: boolean,
|
post?: boolean,
|
||||||
) {
|
): void {
|
||||||
invokeArrayFns(post ? [invokeSub, invokeCurrent] : [invokeCurrent, invokeSub])
|
invokeArrayFns(post ? [invokeSub, invokeCurrent] : [invokeCurrent, invokeSub])
|
||||||
|
|
||||||
function invokeCurrent() {
|
function invokeCurrent() {
|
||||||
|
|
|
@ -29,5 +29,5 @@ export function recordEventMetadata(el: Node, key: string, value: any) {
|
||||||
const metadata = getMetadata(el)[MetadataKind.event]
|
const metadata = getMetadata(el)[MetadataKind.event]
|
||||||
const handlers = (metadata[key] ||= [])
|
const handlers = (metadata[key] ||= [])
|
||||||
handlers.push(value)
|
handlers.push(value)
|
||||||
return () => remove(handlers, value)
|
return (): void => remove(handlers, value)
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,7 @@ export function initProps(
|
||||||
rawProps: RawProps,
|
rawProps: RawProps,
|
||||||
isStateful: boolean,
|
isStateful: boolean,
|
||||||
once: boolean,
|
once: boolean,
|
||||||
) {
|
): void {
|
||||||
if (!rawProps) rawProps = []
|
if (!rawProps) rawProps = []
|
||||||
else if (!isArray(rawProps)) rawProps = [rawProps]
|
else if (!isArray(rawProps)) rawProps = [rawProps]
|
||||||
instance.rawProps = rawProps
|
instance.rawProps = rawProps
|
||||||
|
|
|
@ -36,7 +36,7 @@ export const isDynamicSlotFn = isFunction as (
|
||||||
export function initSlots(
|
export function initSlots(
|
||||||
instance: ComponentInternalInstance,
|
instance: ComponentInternalInstance,
|
||||||
rawSlots: RawSlots | null = null,
|
rawSlots: RawSlots | null = null,
|
||||||
) {
|
): void {
|
||||||
if (!rawSlots) return
|
if (!rawSlots) return
|
||||||
if (!isArray(rawSlots)) rawSlots = [rawSlots]
|
if (!isArray(rawSlots)) rawSlots = [rawSlots]
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ function emit(event: string, ...args: any[]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setDevtoolsHook(hook: DevtoolsHook, target: any) {
|
export function setDevtoolsHook(hook: DevtoolsHook, target: any): void {
|
||||||
devtools = hook
|
devtools = hook
|
||||||
if (devtools) {
|
if (devtools) {
|
||||||
devtools.enabled = true
|
devtools.enabled = true
|
||||||
|
@ -86,19 +86,18 @@ export function setDevtoolsHook(hook: DevtoolsHook, target: any) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function devtoolsInitApp(app: App, version: string) {
|
export function devtoolsInitApp(app: App, version: string): void {
|
||||||
emit(DevtoolsHooks.APP_INIT, app, version, {})
|
emit(DevtoolsHooks.APP_INIT, app, version, {})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function devtoolsUnmountApp(app: App) {
|
export function devtoolsUnmountApp(app: App): void {
|
||||||
emit(DevtoolsHooks.APP_UNMOUNT, app)
|
emit(DevtoolsHooks.APP_UNMOUNT, app)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const devtoolsComponentAdded = /*#__PURE__*/ createDevtoolsComponentHook(
|
export const devtoolsComponentAdded: DevtoolsComponentHook =
|
||||||
DevtoolsHooks.COMPONENT_ADDED,
|
/*#__PURE__*/ createDevtoolsComponentHook(DevtoolsHooks.COMPONENT_ADDED)
|
||||||
)
|
|
||||||
|
|
||||||
export const devtoolsComponentUpdated =
|
export const devtoolsComponentUpdated: DevtoolsComponentHook =
|
||||||
/*#__PURE__*/ createDevtoolsComponentHook(DevtoolsHooks.COMPONENT_UPDATED)
|
/*#__PURE__*/ createDevtoolsComponentHook(DevtoolsHooks.COMPONENT_UPDATED)
|
||||||
|
|
||||||
const _devtoolsComponentRemoved = /*#__PURE__*/ createDevtoolsComponentHook(
|
const _devtoolsComponentRemoved = /*#__PURE__*/ createDevtoolsComponentHook(
|
||||||
|
@ -107,7 +106,7 @@ const _devtoolsComponentRemoved = /*#__PURE__*/ createDevtoolsComponentHook(
|
||||||
|
|
||||||
export const devtoolsComponentRemoved = (
|
export const devtoolsComponentRemoved = (
|
||||||
component: ComponentInternalInstance,
|
component: ComponentInternalInstance,
|
||||||
) => {
|
): void => {
|
||||||
if (
|
if (
|
||||||
devtools &&
|
devtools &&
|
||||||
typeof devtools.cleanupBuffer === 'function' &&
|
typeof devtools.cleanupBuffer === 'function' &&
|
||||||
|
@ -118,8 +117,12 @@ export const devtoolsComponentRemoved = (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DevtoolsComponentHook = (component: ComponentInternalInstance) => void
|
||||||
|
|
||||||
/*! #__NO_SIDE_EFFECTS__ */
|
/*! #__NO_SIDE_EFFECTS__ */
|
||||||
function createDevtoolsComponentHook(hook: DevtoolsHooks) {
|
function createDevtoolsComponentHook(
|
||||||
|
hook: DevtoolsHooks,
|
||||||
|
): DevtoolsComponentHook {
|
||||||
return (component: ComponentInternalInstance) => {
|
return (component: ComponentInternalInstance) => {
|
||||||
emit(
|
emit(
|
||||||
hook,
|
hook,
|
||||||
|
@ -131,15 +134,20 @@ function createDevtoolsComponentHook(hook: DevtoolsHooks) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const devtoolsPerfStart = /*#__PURE__*/ createDevtoolsPerformanceHook(
|
export const devtoolsPerfStart: DevtoolsPerformanceHook =
|
||||||
DevtoolsHooks.PERFORMANCE_START,
|
/*#__PURE__*/ createDevtoolsPerformanceHook(DevtoolsHooks.PERFORMANCE_START)
|
||||||
)
|
|
||||||
|
|
||||||
export const devtoolsPerfEnd = /*#__PURE__*/ createDevtoolsPerformanceHook(
|
export const devtoolsPerfEnd: DevtoolsPerformanceHook =
|
||||||
DevtoolsHooks.PERFORMANCE_END,
|
/*#__PURE__*/ createDevtoolsPerformanceHook(DevtoolsHooks.PERFORMANCE_END)
|
||||||
)
|
|
||||||
|
|
||||||
function createDevtoolsPerformanceHook(hook: DevtoolsHooks) {
|
type DevtoolsPerformanceHook = (
|
||||||
|
component: ComponentInternalInstance,
|
||||||
|
type: string,
|
||||||
|
time: number,
|
||||||
|
) => void
|
||||||
|
function createDevtoolsPerformanceHook(
|
||||||
|
hook: DevtoolsHooks,
|
||||||
|
): DevtoolsPerformanceHook {
|
||||||
return (component: ComponentInternalInstance, type: string, time: number) => {
|
return (component: ComponentInternalInstance, type: string, time: number) => {
|
||||||
emit(hook, component.appContext.app, component.uid, component, type, time)
|
emit(hook, component.appContext.app, component.uid, component, type, time)
|
||||||
}
|
}
|
||||||
|
@ -149,7 +157,7 @@ export function devtoolsComponentEmit(
|
||||||
component: ComponentInternalInstance,
|
component: ComponentInternalInstance,
|
||||||
event: string,
|
event: string,
|
||||||
params: any[],
|
params: any[],
|
||||||
) {
|
): void {
|
||||||
emit(
|
emit(
|
||||||
DevtoolsHooks.COMPONENT_EMIT,
|
DevtoolsHooks.COMPONENT_EMIT,
|
||||||
component.appContext.app,
|
component.appContext.app,
|
||||||
|
|
|
@ -72,7 +72,7 @@ export type Directive<T = any, V = any, M extends string = string> =
|
||||||
| ObjectDirective<T, V, M>
|
| ObjectDirective<T, V, M>
|
||||||
| FunctionDirective<T, V, M>
|
| FunctionDirective<T, V, M>
|
||||||
|
|
||||||
export function validateDirectiveName(name: string) {
|
export function validateDirectiveName(name: string): void {
|
||||||
if (isBuiltInDirective(name)) {
|
if (isBuiltInDirective(name)) {
|
||||||
warn('Do not use built-in directive ids as custom directive id: ' + name)
|
warn('Do not use built-in directive ids as custom directive id: ' + name)
|
||||||
}
|
}
|
||||||
|
@ -190,7 +190,7 @@ export function invokeDirectiveHook(
|
||||||
instance: ComponentInternalInstance | null,
|
instance: ComponentInternalInstance | null,
|
||||||
name: DirectiveHookName,
|
name: DirectiveHookName,
|
||||||
scope: BlockEffectScope,
|
scope: BlockEffectScope,
|
||||||
) {
|
): void {
|
||||||
const { dirs } = scope
|
const { dirs } = scope
|
||||||
if (name === 'mounted') scope.im = true
|
if (name === 'mounted') scope.im = true
|
||||||
if (!dirs) return
|
if (!dirs) return
|
||||||
|
|
|
@ -22,7 +22,7 @@ export function createChildFragmentDirectives(
|
||||||
initCallback: (getValue: () => any) => void,
|
initCallback: (getValue: () => any) => void,
|
||||||
effectCallback: (getValue: () => any) => void,
|
effectCallback: (getValue: () => any) => void,
|
||||||
once?: boolean,
|
once?: boolean,
|
||||||
) {
|
): void {
|
||||||
let isTriggered = false
|
let isTriggered = false
|
||||||
const instance = currentInstance!
|
const instance = currentInstance!
|
||||||
const parentScope = getCurrentScope() as BlockEffectScope
|
const parentScope = getCurrentScope() as BlockEffectScope
|
||||||
|
@ -92,7 +92,10 @@ export function createChildFragmentDirectives(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function invokeWithMount(scope: BlockEffectScope, handler?: () => any) {
|
export function invokeWithMount(
|
||||||
|
scope: BlockEffectScope,
|
||||||
|
handler?: () => any,
|
||||||
|
): any {
|
||||||
if (isRenderEffectScope(scope.parent) && !scope.parent.im) {
|
if (isRenderEffectScope(scope.parent) && !scope.parent.im) {
|
||||||
return handler && handler()
|
return handler && handler()
|
||||||
}
|
}
|
||||||
|
@ -102,7 +105,7 @@ export function invokeWithMount(scope: BlockEffectScope, handler?: () => any) {
|
||||||
export function invokeWithUnmount(
|
export function invokeWithUnmount(
|
||||||
scope: BlockEffectScope,
|
scope: BlockEffectScope,
|
||||||
handler?: () => void,
|
handler?: () => void,
|
||||||
) {
|
): any {
|
||||||
try {
|
try {
|
||||||
return invokeWithDirsHooks(scope, 'unmount', handler)
|
return invokeWithDirsHooks(scope, 'unmount', handler)
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -113,7 +116,7 @@ export function invokeWithUnmount(
|
||||||
export function invokeWithUpdate(
|
export function invokeWithUpdate(
|
||||||
scope: BlockEffectScope,
|
scope: BlockEffectScope,
|
||||||
handler?: () => void,
|
handler?: () => void,
|
||||||
) {
|
): any {
|
||||||
return invokeWithDirsHooks(scope, 'update', handler)
|
return invokeWithDirsHooks(scope, 'update', handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,15 +24,15 @@ export function insert(
|
||||||
block: Block,
|
block: Block,
|
||||||
parent: ParentNode,
|
parent: ParentNode,
|
||||||
anchor: Node | null = null,
|
anchor: Node | null = null,
|
||||||
) {
|
): void {
|
||||||
normalizeBlock(block).forEach(node => parent.insertBefore(node, anchor))
|
normalizeBlock(block).forEach(node => parent.insertBefore(node, anchor))
|
||||||
}
|
}
|
||||||
|
|
||||||
export function prepend(parent: ParentNode, ...blocks: Block[]) {
|
export function prepend(parent: ParentNode, ...blocks: Block[]): void {
|
||||||
parent.prepend(...normalizeBlock(blocks))
|
parent.prepend(...normalizeBlock(blocks))
|
||||||
}
|
}
|
||||||
|
|
||||||
export function remove(block: Block, parent: ParentNode) {
|
export function remove(block: Block, parent: ParentNode): void {
|
||||||
normalizeBlock(block).forEach(node => parent.removeChild(node))
|
normalizeBlock(block).forEach(node => parent.removeChild(node))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ export function addEventListener(
|
||||||
options?: AddEventListenerOptions,
|
options?: AddEventListenerOptions,
|
||||||
) {
|
) {
|
||||||
el.addEventListener(event, handler, options)
|
el.addEventListener(event, handler, options)
|
||||||
return () => el.removeEventListener(event, handler, options)
|
return (): void => el.removeEventListener(event, handler, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ModifierOptions {
|
interface ModifierOptions {
|
||||||
|
@ -32,7 +32,7 @@ export function on(
|
||||||
handlerGetter: () => undefined | ((...args: any[]) => any),
|
handlerGetter: () => undefined | ((...args: any[]) => any),
|
||||||
options: AddEventListenerOptions &
|
options: AddEventListenerOptions &
|
||||||
ModifierOptions & { effect?: boolean } = {},
|
ModifierOptions & { effect?: boolean } = {},
|
||||||
) {
|
): void {
|
||||||
const handler: DelegatedHandler = eventHandler(handlerGetter, options)
|
const handler: DelegatedHandler = eventHandler(handlerGetter, options)
|
||||||
let cleanupEvent: (() => void) | undefined
|
let cleanupEvent: (() => void) | undefined
|
||||||
queuePostFlushCb(() => {
|
queuePostFlushCb(() => {
|
||||||
|
@ -60,7 +60,7 @@ export function delegate(
|
||||||
event: string,
|
event: string,
|
||||||
handlerGetter: () => undefined | ((...args: any[]) => any),
|
handlerGetter: () => undefined | ((...args: any[]) => any),
|
||||||
options: ModifierOptions = {},
|
options: ModifierOptions = {},
|
||||||
) {
|
): void {
|
||||||
const handler: DelegatedHandler = eventHandler(handlerGetter, options)
|
const handler: DelegatedHandler = eventHandler(handlerGetter, options)
|
||||||
handler.delegate = true
|
handler.delegate = true
|
||||||
recordEventMetadata(el, event, handler)
|
recordEventMetadata(el, event, handler)
|
||||||
|
@ -85,7 +85,7 @@ function eventHandler(
|
||||||
*/
|
*/
|
||||||
const delegatedEvents = Object.create(null)
|
const delegatedEvents = Object.create(null)
|
||||||
|
|
||||||
export const delegateEvents = (...names: string[]) => {
|
export const delegateEvents = (...names: string[]): void => {
|
||||||
for (const name of names) {
|
for (const name of names) {
|
||||||
if (!delegatedEvents[name]) {
|
if (!delegatedEvents[name]) {
|
||||||
delegatedEvents[name] = true
|
delegatedEvents[name] = true
|
||||||
|
@ -130,7 +130,7 @@ const delegatedEventHandler = (e: Event) => {
|
||||||
export function setDynamicEvents(
|
export function setDynamicEvents(
|
||||||
el: HTMLElement,
|
el: HTMLElement,
|
||||||
events: Record<string, (...args: any[]) => any>,
|
events: Record<string, (...args: any[]) => any>,
|
||||||
) {
|
): void {
|
||||||
for (const name in events) {
|
for (const name in events) {
|
||||||
on(el, name, () => events[name], { effect: true })
|
on(el, name, () => events[name], { effect: true })
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,14 +19,14 @@ import {
|
||||||
import { on } from './event'
|
import { on } from './event'
|
||||||
import type { Data } from '@vue/runtime-shared'
|
import type { Data } from '@vue/runtime-shared'
|
||||||
|
|
||||||
export function setClass(el: Element, value: any) {
|
export function setClass(el: Element, value: any): void {
|
||||||
const prev = recordPropMetadata(el, 'class', (value = normalizeClass(value)))
|
const prev = recordPropMetadata(el, 'class', (value = normalizeClass(value)))
|
||||||
if (value !== prev && (value || prev)) {
|
if (value !== prev && (value || prev)) {
|
||||||
el.className = value
|
el.className = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setAttr(el: Element, key: string, value: any) {
|
export function setAttr(el: Element, key: string, value: any): void {
|
||||||
const oldVal = recordPropMetadata(el, key, value)
|
const oldVal = recordPropMetadata(el, key, value)
|
||||||
if (value !== oldVal) {
|
if (value !== oldVal) {
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
|
@ -37,7 +37,7 @@ export function setAttr(el: Element, key: string, value: any) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setDOMProp(el: any, key: string, value: any) {
|
export function setDOMProp(el: any, key: string, value: any): void {
|
||||||
const oldVal = recordPropMetadata(el, key, value)
|
const oldVal = recordPropMetadata(el, key, value)
|
||||||
if (value === oldVal) return
|
if (value === oldVal) return
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ export function setDOMProp(el: any, key: string, value: any) {
|
||||||
needRemove && el.removeAttribute(key)
|
needRemove && el.removeAttribute(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setDynamicProp(el: Element, key: string, value: any) {
|
export function setDynamicProp(el: Element, key: string, value: any): void {
|
||||||
// TODO
|
// TODO
|
||||||
const isSVG = false
|
const isSVG = false
|
||||||
if (key === 'class') {
|
if (key === 'class') {
|
||||||
|
@ -132,7 +132,7 @@ export function setDynamicProp(el: Element, key: string, value: any) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setDynamicProps(el: Element, ...args: any) {
|
export function setDynamicProps(el: Element, ...args: any): void {
|
||||||
const oldProps = getMetadata(el)[MetadataKind.prop]
|
const oldProps = getMetadata(el)[MetadataKind.prop]
|
||||||
const props = args.length > 1 ? mergeProps(...args) : args[0]
|
const props = args.length > 1 ? mergeProps(...args) : args[0]
|
||||||
|
|
||||||
|
@ -154,7 +154,7 @@ export function setDynamicProps(el: Element, ...args: any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO copied from runtime-core
|
// TODO copied from runtime-core
|
||||||
export function mergeProps(...args: Data[]) {
|
export function mergeProps(...args: Data[]): Data {
|
||||||
const ret: Data = {}
|
const ret: Data = {}
|
||||||
for (let i = 0; i < args.length; i++) {
|
for (let i = 0; i < args.length; i++) {
|
||||||
const toMerge = args[i]
|
const toMerge = args[i]
|
||||||
|
@ -185,7 +185,7 @@ export function mergeProps(...args: Data[]) {
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setText(el: Node, ...values: any[]) {
|
export function setText(el: Node, ...values: any[]): void {
|
||||||
const text = values.map(v => toDisplayString(v)).join('')
|
const text = values.map(v => toDisplayString(v)).join('')
|
||||||
const oldVal = recordPropMetadata(el, 'textContent', text)
|
const oldVal = recordPropMetadata(el, 'textContent', text)
|
||||||
if (text !== oldVal) {
|
if (text !== oldVal) {
|
||||||
|
@ -193,7 +193,7 @@ export function setText(el: Node, ...values: any[]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setHtml(el: Element, value: any) {
|
export function setHtml(el: Element, value: any): void {
|
||||||
const oldVal = recordPropMetadata(el, 'innerHTML', value)
|
const oldVal = recordPropMetadata(el, 'innerHTML', value)
|
||||||
if (value !== oldVal) {
|
if (value !== oldVal) {
|
||||||
el.innerHTML = value
|
el.innerHTML = value
|
||||||
|
|
|
@ -9,7 +9,7 @@ import {
|
||||||
import { warn } from '../warning'
|
import { warn } from '../warning'
|
||||||
import { recordPropMetadata } from '../componentMetadata'
|
import { recordPropMetadata } from '../componentMetadata'
|
||||||
|
|
||||||
export function setStyle(el: HTMLElement, value: any) {
|
export function setStyle(el: HTMLElement, value: any): void {
|
||||||
const prev = recordPropMetadata(el, 'style', (value = normalizeStyle(value)))
|
const prev = recordPropMetadata(el, 'style', (value = normalizeStyle(value)))
|
||||||
patchStyle(el, prev, value)
|
patchStyle(el, prev, value)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ export function template(html: string) {
|
||||||
t.innerHTML = html
|
t.innerHTML = html
|
||||||
return t.content.firstChild!
|
return t.content.firstChild!
|
||||||
}
|
}
|
||||||
return () => (node || (node = create())).cloneNode(true)
|
return (): Node => (node || (node = create())).cloneNode(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! #__NO_SIDE_EFFECTS__ */
|
/*! #__NO_SIDE_EFFECTS__ */
|
||||||
|
|
|
@ -32,7 +32,7 @@ export function setRef(
|
||||||
ref: NodeRef,
|
ref: NodeRef,
|
||||||
oldRef?: NodeRef,
|
oldRef?: NodeRef,
|
||||||
refFor = false,
|
refFor = false,
|
||||||
) {
|
): NodeRef | undefined {
|
||||||
if (!currentInstance) return
|
if (!currentInstance) return
|
||||||
const { setupState, isUnmounted } = currentInstance
|
const { setupState, isUnmounted } = currentInstance
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ export function callWithErrorHandling(
|
||||||
instance: ComponentInternalInstance | null,
|
instance: ComponentInternalInstance | null,
|
||||||
type: ErrorTypes,
|
type: ErrorTypes,
|
||||||
args?: unknown[],
|
args?: unknown[],
|
||||||
) {
|
): any {
|
||||||
let res
|
let res
|
||||||
try {
|
try {
|
||||||
res = args ? fn(...args) : fn()
|
res = args ? fn(...args) : fn()
|
||||||
|
@ -116,7 +116,7 @@ export function handleError(
|
||||||
instance: ComponentInternalInstance | null,
|
instance: ComponentInternalInstance | null,
|
||||||
type: ErrorTypes,
|
type: ErrorTypes,
|
||||||
throwInDev = true,
|
throwInDev = true,
|
||||||
) {
|
): void {
|
||||||
if (instance) {
|
if (instance) {
|
||||||
let cur = instance.parent
|
let cur = instance.parent
|
||||||
// in production the hook receives only the error code
|
// in production the hook receives only the error code
|
||||||
|
|
|
@ -8,11 +8,14 @@ export const DIRECTIVES = 'directives'
|
||||||
|
|
||||||
export type AssetTypes = typeof COMPONENTS | typeof DIRECTIVES
|
export type AssetTypes = typeof COMPONENTS | typeof DIRECTIVES
|
||||||
|
|
||||||
export function resolveComponent(name: string, maybeSelfReference?: boolean) {
|
export function resolveComponent(
|
||||||
|
name: string,
|
||||||
|
maybeSelfReference?: boolean,
|
||||||
|
): string | Component {
|
||||||
return resolveAsset(COMPONENTS, name, true, maybeSelfReference) || name
|
return resolveAsset(COMPONENTS, name, true, maybeSelfReference) || name
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resolveDirective(name: string) {
|
export function resolveDirective(name: string): Directive | undefined {
|
||||||
return resolveAsset(DIRECTIVES, name)
|
return resolveAsset(DIRECTIVES, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,4 +2,7 @@ import { toHandlers as _toHandlers } from '@vue/runtime-shared'
|
||||||
import { warn } from '../warning'
|
import { warn } from '../warning'
|
||||||
import { NOOP } from '@vue/shared'
|
import { NOOP } from '@vue/shared'
|
||||||
|
|
||||||
export const toHandlers = _toHandlers.bind(undefined, __DEV__ ? warn : NOOP)
|
export const toHandlers: (
|
||||||
|
obj: Record<string, any>,
|
||||||
|
preserveCaseIfNecessary?: boolean | undefined,
|
||||||
|
) => Record<string, any> = _toHandlers.bind(undefined, __DEV__ ? warn : NOOP)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Core API ------------------------------------------------------------------
|
// Core API ------------------------------------------------------------------
|
||||||
|
|
||||||
export const version = __VERSION__
|
export const version: string = __VERSION__
|
||||||
export {
|
export {
|
||||||
// core
|
// core
|
||||||
type Ref,
|
type Ref,
|
||||||
|
|
|
@ -11,7 +11,7 @@ let perf: Performance
|
||||||
export function startMeasure(
|
export function startMeasure(
|
||||||
instance: ComponentInternalInstance,
|
instance: ComponentInternalInstance,
|
||||||
type: string,
|
type: string,
|
||||||
) {
|
): void {
|
||||||
if (instance.appContext.config.performance && isSupported()) {
|
if (instance.appContext.config.performance && isSupported()) {
|
||||||
perf.mark(`vue-${type}-${instance.uid}`)
|
perf.mark(`vue-${type}-${instance.uid}`)
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,10 @@ export function startMeasure(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function endMeasure(instance: ComponentInternalInstance, type: string) {
|
export function endMeasure(
|
||||||
|
instance: ComponentInternalInstance,
|
||||||
|
type: string,
|
||||||
|
): void {
|
||||||
if (instance.appContext.config.performance && isSupported()) {
|
if (instance.appContext.config.performance && isSupported()) {
|
||||||
const startTag = `vue-${type}-${instance.uid}`
|
const startTag = `vue-${type}-${instance.uid}`
|
||||||
const endTag = startTag + `:end`
|
const endTag = startTag + `:end`
|
||||||
|
|
|
@ -15,7 +15,7 @@ import { queueJob, queuePostFlushCb } from './scheduler'
|
||||||
import { VaporErrorCodes, callWithAsyncErrorHandling } from './errorHandling'
|
import { VaporErrorCodes, callWithAsyncErrorHandling } from './errorHandling'
|
||||||
import { invokeDirectiveHook } from './directives'
|
import { invokeDirectiveHook } from './directives'
|
||||||
|
|
||||||
export function renderEffect(cb: () => void) {
|
export function renderEffect(cb: () => void): void {
|
||||||
const instance = getCurrentInstance()
|
const instance = getCurrentInstance()
|
||||||
const scope = getCurrentScope()
|
const scope = getCurrentScope()
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ export function renderEffect(cb: () => void) {
|
||||||
export function firstEffect(
|
export function firstEffect(
|
||||||
instance: ComponentInternalInstance,
|
instance: ComponentInternalInstance,
|
||||||
fn: () => void,
|
fn: () => void,
|
||||||
) {
|
): void {
|
||||||
const effect = new ReactiveEffect(fn)
|
const effect = new ReactiveEffect(fn)
|
||||||
const job: SchedulerJob = () => effect.run()
|
const job: SchedulerJob = () => effect.run()
|
||||||
job.flags! |= SchedulerJobFlags.PRE
|
job.flags! |= SchedulerJobFlags.PRE
|
||||||
|
|
|
@ -32,7 +32,7 @@ let postFlushIndex = 0
|
||||||
const resolvedPromise = /*#__PURE__*/ Promise.resolve() as Promise<any>
|
const resolvedPromise = /*#__PURE__*/ Promise.resolve() as Promise<any>
|
||||||
let currentFlushPromise: Promise<void> | null = null
|
let currentFlushPromise: Promise<void> | null = null
|
||||||
|
|
||||||
export function queueJob(job: SchedulerJob) {
|
export function queueJob(job: SchedulerJob): void {
|
||||||
let lastOne: SchedulerJob | undefined
|
let lastOne: SchedulerJob | undefined
|
||||||
if (!(job.flags! & SchedulerJobFlags.QUEUED)) {
|
if (!(job.flags! & SchedulerJobFlags.QUEUED)) {
|
||||||
if (job.id == null) {
|
if (job.id == null) {
|
||||||
|
@ -54,7 +54,7 @@ export function queueJob(job: SchedulerJob) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function queuePostFlushCb(cb: SchedulerJobs) {
|
export function queuePostFlushCb(cb: SchedulerJobs): void {
|
||||||
if (!isArray(cb)) {
|
if (!isArray(cb)) {
|
||||||
if (!(cb.flags! & SchedulerJobFlags.QUEUED)) {
|
if (!(cb.flags! & SchedulerJobFlags.QUEUED)) {
|
||||||
pendingPostFlushCbs.push(cb)
|
pendingPostFlushCbs.push(cb)
|
||||||
|
@ -78,7 +78,7 @@ function queueFlush() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function flushPostFlushCbs() {
|
export function flushPostFlushCbs(): void {
|
||||||
if (!pendingPostFlushCbs.length) return
|
if (!pendingPostFlushCbs.length) return
|
||||||
|
|
||||||
const deduped = [...new Set(pendingPostFlushCbs)]
|
const deduped = [...new Set(pendingPostFlushCbs)]
|
||||||
|
|
|
@ -15,7 +15,7 @@ type TraceEntry = {
|
||||||
|
|
||||||
type ComponentTraceStack = TraceEntry[]
|
type ComponentTraceStack = TraceEntry[]
|
||||||
|
|
||||||
export function warn(msg: string, ...args: any[]) {
|
export function warn(msg: string, ...args: any[]): void {
|
||||||
// avoid props formatting or warn handler tracking deps that might be mutated
|
// avoid props formatting or warn handler tracking deps that might be mutated
|
||||||
// during patch, leading to infinite recursion.
|
// during patch, leading to infinite recursion.
|
||||||
pauseTracking()
|
pauseTracking()
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { initCustomFormatter } from '@vue/runtime-dom'
|
import { initCustomFormatter } from '@vue/runtime-dom'
|
||||||
|
|
||||||
export function initDev() {
|
export function initDev(): void {
|
||||||
if (__BROWSER__) {
|
if (__BROWSER__) {
|
||||||
/* istanbul ignore if */
|
/* istanbul ignore if */
|
||||||
if (!__ESM_BUNDLER__) {
|
if (!__ESM_BUNDLER__) {
|
||||||
|
|
|
@ -10,7 +10,7 @@ if (__DEV__) {
|
||||||
|
|
||||||
export * from '@vue/runtime-vapor'
|
export * from '@vue/runtime-vapor'
|
||||||
|
|
||||||
export const compile = () => {
|
export const compile = (): void => {
|
||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
console.warn(
|
console.warn(
|
||||||
`Runtime compilation is not supported in this build of Vue.` +
|
`Runtime compilation is not supported in this build of Vue.` +
|
||||||
|
|
Loading…
Reference in New Issue