refactor: applyDirectives -> withDirectives
This commit is contained in:
parent
cba34453db
commit
e98a85f3cb
@ -15,7 +15,7 @@ import {
|
|||||||
CREATE_BLOCK,
|
CREATE_BLOCK,
|
||||||
FRAGMENT,
|
FRAGMENT,
|
||||||
RENDER_SLOT,
|
RENDER_SLOT,
|
||||||
APPLY_DIRECTIVES
|
WITH_DIRECTIVES
|
||||||
} from '../src/runtimeHelpers'
|
} from '../src/runtimeHelpers'
|
||||||
import { transformIf } from '../src/transforms/vIf'
|
import { transformIf } from '../src/transforms/vIf'
|
||||||
import { transformFor } from '../src/transforms/vFor'
|
import { transformFor } from '../src/transforms/vFor'
|
||||||
@ -314,7 +314,7 @@ describe('compiler: transform', () => {
|
|||||||
{
|
{
|
||||||
type: NodeTypes.JS_CALL_EXPRESSION,
|
type: NodeTypes.JS_CALL_EXPRESSION,
|
||||||
// should wrap applyDirectives() around createBlock()
|
// should wrap applyDirectives() around createBlock()
|
||||||
callee: APPLY_DIRECTIVES,
|
callee: WITH_DIRECTIVES,
|
||||||
arguments: [
|
arguments: [
|
||||||
{ callee: CREATE_BLOCK },
|
{ callee: CREATE_BLOCK },
|
||||||
{ type: NodeTypes.JS_ARRAY_EXPRESSION }
|
{ type: NodeTypes.JS_ARRAY_EXPRESSION }
|
||||||
|
@ -101,12 +101,12 @@ const _hoisted_1 = { id: \\"foo\\" }
|
|||||||
|
|
||||||
return function render() {
|
return function render() {
|
||||||
with (this) {
|
with (this) {
|
||||||
const { createVNode: _createVNode, applyDirectives: _applyDirectives, resolveDirective: _resolveDirective, createBlock: _createBlock, openBlock: _openBlock } = _Vue
|
const { createVNode: _createVNode, withDirectives: _withDirectives, resolveDirective: _resolveDirective, createBlock: _createBlock, openBlock: _openBlock } = _Vue
|
||||||
|
|
||||||
const _directive_foo = _resolveDirective(\\"foo\\")
|
const _directive_foo = _resolveDirective(\\"foo\\")
|
||||||
|
|
||||||
return (_openBlock(), _createBlock(\\"div\\", null, [
|
return (_openBlock(), _createBlock(\\"div\\", null, [
|
||||||
_applyDirectives(_createVNode(\\"div\\", _hoisted_1, null, 32 /* NEED_PATCH */), [
|
_withDirectives(_createVNode(\\"div\\", _hoisted_1, null, 32 /* NEED_PATCH */), [
|
||||||
[_directive_foo]
|
[_directive_foo]
|
||||||
])
|
])
|
||||||
]))
|
]))
|
||||||
|
@ -137,12 +137,12 @@ exports[`compiler: v-for codegen v-for on element with custom directive 1`] = `
|
|||||||
|
|
||||||
return function render() {
|
return function render() {
|
||||||
with (this) {
|
with (this) {
|
||||||
const { renderList: _renderList, openBlock: _openBlock, createBlock: _createBlock, Fragment: _Fragment, createVNode: _createVNode, applyDirectives: _applyDirectives, resolveDirective: _resolveDirective } = _Vue
|
const { renderList: _renderList, openBlock: _openBlock, createBlock: _createBlock, Fragment: _Fragment, createVNode: _createVNode, withDirectives: _withDirectives, resolveDirective: _resolveDirective } = _Vue
|
||||||
|
|
||||||
const _directive_foo = _resolveDirective(\\"foo\\")
|
const _directive_foo = _resolveDirective(\\"foo\\")
|
||||||
|
|
||||||
return (_openBlock(), _createBlock(_Fragment, null, _renderList(list, (i) => {
|
return (_openBlock(), _createBlock(_Fragment, null, _renderList(list, (i) => {
|
||||||
return (_openBlock(), _applyDirectives(_createBlock(\\"div\\", null, null, 32 /* NEED_PATCH */), [
|
return (_openBlock(), _withDirectives(_createBlock(\\"div\\", null, null, 32 /* NEED_PATCH */), [
|
||||||
[_directive_foo]
|
[_directive_foo]
|
||||||
]))
|
]))
|
||||||
}), 128 /* UNKEYED_FRAGMENT */))
|
}), 128 /* UNKEYED_FRAGMENT */))
|
||||||
|
@ -9,7 +9,7 @@ import {
|
|||||||
OPEN_BLOCK,
|
OPEN_BLOCK,
|
||||||
CREATE_BLOCK,
|
CREATE_BLOCK,
|
||||||
CREATE_VNODE,
|
CREATE_VNODE,
|
||||||
APPLY_DIRECTIVES,
|
WITH_DIRECTIVES,
|
||||||
FRAGMENT,
|
FRAGMENT,
|
||||||
RENDER_LIST
|
RENDER_LIST
|
||||||
} from '../../src/runtimeHelpers'
|
} from '../../src/runtimeHelpers'
|
||||||
@ -304,7 +304,7 @@ describe('compiler: hoistStatic transform', () => {
|
|||||||
{
|
{
|
||||||
type: NodeTypes.ELEMENT,
|
type: NodeTypes.ELEMENT,
|
||||||
codegenNode: {
|
codegenNode: {
|
||||||
callee: APPLY_DIRECTIVES,
|
callee: WITH_DIRECTIVES,
|
||||||
arguments: [
|
arguments: [
|
||||||
{
|
{
|
||||||
callee: CREATE_VNODE,
|
callee: CREATE_VNODE,
|
||||||
|
@ -4,7 +4,7 @@ import {
|
|||||||
CREATE_VNODE,
|
CREATE_VNODE,
|
||||||
MERGE_PROPS,
|
MERGE_PROPS,
|
||||||
RESOLVE_DIRECTIVE,
|
RESOLVE_DIRECTIVE,
|
||||||
APPLY_DIRECTIVES,
|
WITH_DIRECTIVES,
|
||||||
TO_HANDLERS,
|
TO_HANDLERS,
|
||||||
helperNameMap,
|
helperNameMap,
|
||||||
PORTAL,
|
PORTAL,
|
||||||
@ -368,7 +368,7 @@ describe('compiler: element transform', () => {
|
|||||||
expect(root.helpers).toContain(RESOLVE_DIRECTIVE)
|
expect(root.helpers).toContain(RESOLVE_DIRECTIVE)
|
||||||
expect(root.directives).toContain(`foo`)
|
expect(root.directives).toContain(`foo`)
|
||||||
|
|
||||||
expect(node.callee).toBe(APPLY_DIRECTIVES)
|
expect(node.callee).toBe(WITH_DIRECTIVES)
|
||||||
expect(node.arguments).toMatchObject([
|
expect(node.arguments).toMatchObject([
|
||||||
{
|
{
|
||||||
type: NodeTypes.JS_CALL_EXPRESSION,
|
type: NodeTypes.JS_CALL_EXPRESSION,
|
||||||
@ -438,7 +438,7 @@ describe('compiler: element transform', () => {
|
|||||||
expect(root.directives).toContain(`bar`)
|
expect(root.directives).toContain(`bar`)
|
||||||
expect(root.directives).toContain(`baz`)
|
expect(root.directives).toContain(`baz`)
|
||||||
|
|
||||||
expect(node.callee).toBe(APPLY_DIRECTIVES)
|
expect(node.callee).toBe(WITH_DIRECTIVES)
|
||||||
expect(node.arguments).toMatchObject([
|
expect(node.arguments).toMatchObject([
|
||||||
{
|
{
|
||||||
type: NodeTypes.JS_CALL_EXPRESSION
|
type: NodeTypes.JS_CALL_EXPRESSION
|
||||||
|
@ -23,7 +23,7 @@ import {
|
|||||||
FRAGMENT,
|
FRAGMENT,
|
||||||
RENDER_LIST,
|
RENDER_LIST,
|
||||||
RENDER_SLOT,
|
RENDER_SLOT,
|
||||||
APPLY_DIRECTIVES
|
WITH_DIRECTIVES
|
||||||
} from '../../src/runtimeHelpers'
|
} from '../../src/runtimeHelpers'
|
||||||
import { PatchFlags } from '@vue/runtime-dom'
|
import { PatchFlags } from '@vue/runtime-dom'
|
||||||
import { createObjectMatcher, genFlagText } from '../testUtils'
|
import { createObjectMatcher, genFlagText } from '../testUtils'
|
||||||
@ -859,7 +859,7 @@ describe('compiler: v-for', () => {
|
|||||||
{ callee: OPEN_BLOCK },
|
{ callee: OPEN_BLOCK },
|
||||||
// should wrap applyDirectives() around createBlock()
|
// should wrap applyDirectives() around createBlock()
|
||||||
{
|
{
|
||||||
callee: APPLY_DIRECTIVES,
|
callee: WITH_DIRECTIVES,
|
||||||
arguments: [
|
arguments: [
|
||||||
{ callee: CREATE_BLOCK },
|
{ callee: CREATE_BLOCK },
|
||||||
{ type: NodeTypes.JS_ARRAY_EXPRESSION }
|
{ type: NodeTypes.JS_ARRAY_EXPRESSION }
|
||||||
|
@ -22,7 +22,7 @@ import {
|
|||||||
COMMENT,
|
COMMENT,
|
||||||
FRAGMENT,
|
FRAGMENT,
|
||||||
MERGE_PROPS,
|
MERGE_PROPS,
|
||||||
APPLY_DIRECTIVES,
|
WITH_DIRECTIVES,
|
||||||
RENDER_SLOT
|
RENDER_SLOT
|
||||||
} from '../../src/runtimeHelpers'
|
} from '../../src/runtimeHelpers'
|
||||||
import { createObjectMatcher } from '../testUtils'
|
import { createObjectMatcher } from '../testUtils'
|
||||||
@ -513,7 +513,7 @@ describe('compiler: v-if', () => {
|
|||||||
} = parseWithIfTransform(`<div v-if="ok" v-foo />`)
|
} = parseWithIfTransform(`<div v-if="ok" v-foo />`)
|
||||||
const branch1 = (codegenNode.expressions[1] as ConditionalExpression)
|
const branch1 = (codegenNode.expressions[1] as ConditionalExpression)
|
||||||
.consequent as CallExpression
|
.consequent as CallExpression
|
||||||
expect(branch1.callee).toBe(APPLY_DIRECTIVES)
|
expect(branch1.callee).toBe(WITH_DIRECTIVES)
|
||||||
const realBranch = branch1.arguments[0] as CallExpression
|
const realBranch = branch1.arguments[0] as CallExpression
|
||||||
expect(realBranch.arguments[1]).toMatchObject(
|
expect(realBranch.arguments[1]).toMatchObject(
|
||||||
createObjectMatcher({ key: `[0]` })
|
createObjectMatcher({ key: `[0]` })
|
||||||
|
@ -2,7 +2,7 @@ import { isString } from '@vue/shared'
|
|||||||
import { ForParseResult } from './transforms/vFor'
|
import { ForParseResult } from './transforms/vFor'
|
||||||
import {
|
import {
|
||||||
CREATE_VNODE,
|
CREATE_VNODE,
|
||||||
APPLY_DIRECTIVES,
|
WITH_DIRECTIVES,
|
||||||
RENDER_SLOT,
|
RENDER_SLOT,
|
||||||
CREATE_SLOTS,
|
CREATE_SLOTS,
|
||||||
RENDER_LIST,
|
RENDER_LIST,
|
||||||
@ -393,7 +393,7 @@ export interface DynamicSlotFnProperty extends Property {
|
|||||||
// ])
|
// ])
|
||||||
export interface CodegenNodeWithDirective<T extends CallExpression>
|
export interface CodegenNodeWithDirective<T extends CallExpression>
|
||||||
extends CallExpression {
|
extends CallExpression {
|
||||||
callee: typeof APPLY_DIRECTIVES
|
callee: typeof WITH_DIRECTIVES
|
||||||
arguments: [T, DirectiveArguments]
|
arguments: [T, DirectiveArguments]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -548,7 +548,7 @@ type InferCodegenNodeType<T> = T extends
|
|||||||
| typeof CREATE_VNODE
|
| typeof CREATE_VNODE
|
||||||
| typeof CREATE_BLOCK
|
| typeof CREATE_BLOCK
|
||||||
? PlainElementCodegenNode | PlainComponentCodegenNode
|
? PlainElementCodegenNode | PlainComponentCodegenNode
|
||||||
: T extends typeof APPLY_DIRECTIVES
|
: T extends typeof WITH_DIRECTIVES
|
||||||
?
|
?
|
||||||
| CodegenNodeWithDirective<PlainElementCodegenNode>
|
| CodegenNodeWithDirective<PlainElementCodegenNode>
|
||||||
| CodegenNodeWithDirective<PlainComponentCodegenNode>
|
| CodegenNodeWithDirective<PlainComponentCodegenNode>
|
||||||
|
@ -11,7 +11,7 @@ export const RESOLVE_DYNAMIC_COMPONENT = Symbol(
|
|||||||
__DEV__ ? `resolveDynamicComponent` : ``
|
__DEV__ ? `resolveDynamicComponent` : ``
|
||||||
)
|
)
|
||||||
export const RESOLVE_DIRECTIVE = Symbol(__DEV__ ? `resolveDirective` : ``)
|
export const RESOLVE_DIRECTIVE = Symbol(__DEV__ ? `resolveDirective` : ``)
|
||||||
export const APPLY_DIRECTIVES = Symbol(__DEV__ ? `applyDirectives` : ``)
|
export const WITH_DIRECTIVES = Symbol(__DEV__ ? `withDirectives` : ``)
|
||||||
export const RENDER_LIST = Symbol(__DEV__ ? `renderList` : ``)
|
export const RENDER_LIST = Symbol(__DEV__ ? `renderList` : ``)
|
||||||
export const RENDER_SLOT = Symbol(__DEV__ ? `renderSlot` : ``)
|
export const RENDER_SLOT = Symbol(__DEV__ ? `renderSlot` : ``)
|
||||||
export const CREATE_SLOTS = Symbol(__DEV__ ? `createSlots` : ``)
|
export const CREATE_SLOTS = Symbol(__DEV__ ? `createSlots` : ``)
|
||||||
@ -35,7 +35,7 @@ export const helperNameMap: any = {
|
|||||||
[RESOLVE_COMPONENT]: `resolveComponent`,
|
[RESOLVE_COMPONENT]: `resolveComponent`,
|
||||||
[RESOLVE_DYNAMIC_COMPONENT]: `resolveDynamicComponent`,
|
[RESOLVE_DYNAMIC_COMPONENT]: `resolveDynamicComponent`,
|
||||||
[RESOLVE_DIRECTIVE]: `resolveDirective`,
|
[RESOLVE_DIRECTIVE]: `resolveDirective`,
|
||||||
[APPLY_DIRECTIVES]: `applyDirectives`,
|
[WITH_DIRECTIVES]: `withDirectives`,
|
||||||
[RENDER_LIST]: `renderList`,
|
[RENDER_LIST]: `renderList`,
|
||||||
[RENDER_SLOT]: `renderSlot`,
|
[RENDER_SLOT]: `renderSlot`,
|
||||||
[CREATE_SLOTS]: `createSlots`,
|
[CREATE_SLOTS]: `createSlots`,
|
||||||
|
@ -23,7 +23,7 @@ import {
|
|||||||
CREATE_VNODE,
|
CREATE_VNODE,
|
||||||
FRAGMENT,
|
FRAGMENT,
|
||||||
helperNameMap,
|
helperNameMap,
|
||||||
APPLY_DIRECTIVES,
|
WITH_DIRECTIVES,
|
||||||
CREATE_BLOCK
|
CREATE_BLOCK
|
||||||
} from './runtimeHelpers'
|
} from './runtimeHelpers'
|
||||||
import { isVSlot, createBlockExpression } from './utils'
|
import { isVSlot, createBlockExpression } from './utils'
|
||||||
@ -243,7 +243,7 @@ function finalizeRoot(root: RootNode, context: TransformContext) {
|
|||||||
const codegenNode = child.codegenNode as
|
const codegenNode = child.codegenNode as
|
||||||
| ElementCodegenNode
|
| ElementCodegenNode
|
||||||
| ComponentCodegenNode
|
| ComponentCodegenNode
|
||||||
if (codegenNode.callee === APPLY_DIRECTIVES) {
|
if (codegenNode.callee === WITH_DIRECTIVES) {
|
||||||
codegenNode.arguments[0].callee = helper(CREATE_BLOCK)
|
codegenNode.arguments[0].callee = helper(CREATE_BLOCK)
|
||||||
} else {
|
} else {
|
||||||
codegenNode.callee = helper(CREATE_BLOCK)
|
codegenNode.callee = helper(CREATE_BLOCK)
|
||||||
|
@ -11,7 +11,7 @@ import {
|
|||||||
ElementNode
|
ElementNode
|
||||||
} from '../ast'
|
} from '../ast'
|
||||||
import { TransformContext } from '../transform'
|
import { TransformContext } from '../transform'
|
||||||
import { APPLY_DIRECTIVES } from '../runtimeHelpers'
|
import { WITH_DIRECTIVES } from '../runtimeHelpers'
|
||||||
import { PatchFlags, isString, isSymbol } from '@vue/shared'
|
import { PatchFlags, isString, isSymbol } from '@vue/shared'
|
||||||
import { isSlotOutlet, findProp } from '../utils'
|
import { isSlotOutlet, findProp } from '../utils'
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ function walk(
|
|||||||
!hasDynamicKeyOrRef(child)
|
!hasDynamicKeyOrRef(child)
|
||||||
) {
|
) {
|
||||||
let codegenNode = child.codegenNode as ElementCodegenNode
|
let codegenNode = child.codegenNode as ElementCodegenNode
|
||||||
if (codegenNode.callee === APPLY_DIRECTIVES) {
|
if (codegenNode.callee === WITH_DIRECTIVES) {
|
||||||
codegenNode = codegenNode.arguments[0]
|
codegenNode = codegenNode.arguments[0]
|
||||||
}
|
}
|
||||||
const props = codegenNode.arguments[1]
|
const props = codegenNode.arguments[1]
|
||||||
@ -99,7 +99,7 @@ function walk(
|
|||||||
|
|
||||||
function getPatchFlag(node: PlainElementNode): number | undefined {
|
function getPatchFlag(node: PlainElementNode): number | undefined {
|
||||||
let codegenNode = node.codegenNode as ElementCodegenNode
|
let codegenNode = node.codegenNode as ElementCodegenNode
|
||||||
if (codegenNode.callee === APPLY_DIRECTIVES) {
|
if (codegenNode.callee === WITH_DIRECTIVES) {
|
||||||
codegenNode = codegenNode.arguments[0]
|
codegenNode = codegenNode.arguments[0]
|
||||||
}
|
}
|
||||||
const flag = codegenNode.arguments[3]
|
const flag = codegenNode.arguments[3]
|
||||||
|
@ -19,7 +19,7 @@ import { PatchFlags, PatchFlagNames, isSymbol } from '@vue/shared'
|
|||||||
import { createCompilerError, ErrorCodes } from '../errors'
|
import { createCompilerError, ErrorCodes } from '../errors'
|
||||||
import {
|
import {
|
||||||
CREATE_VNODE,
|
CREATE_VNODE,
|
||||||
APPLY_DIRECTIVES,
|
WITH_DIRECTIVES,
|
||||||
RESOLVE_DIRECTIVE,
|
RESOLVE_DIRECTIVE,
|
||||||
RESOLVE_COMPONENT,
|
RESOLVE_COMPONENT,
|
||||||
RESOLVE_DYNAMIC_COMPONENT,
|
RESOLVE_DYNAMIC_COMPONENT,
|
||||||
@ -177,7 +177,7 @@ export const transformElement: NodeTransform = (node, context) => {
|
|||||||
|
|
||||||
if (runtimeDirectives && runtimeDirectives.length) {
|
if (runtimeDirectives && runtimeDirectives.length) {
|
||||||
node.codegenNode = createCallExpression(
|
node.codegenNode = createCallExpression(
|
||||||
context.helper(APPLY_DIRECTIVES),
|
context.helper(WITH_DIRECTIVES),
|
||||||
[
|
[
|
||||||
vnode,
|
vnode,
|
||||||
createArrayExpression(
|
createArrayExpression(
|
||||||
|
@ -31,7 +31,7 @@ import {
|
|||||||
OPEN_BLOCK,
|
OPEN_BLOCK,
|
||||||
CREATE_BLOCK,
|
CREATE_BLOCK,
|
||||||
FRAGMENT,
|
FRAGMENT,
|
||||||
APPLY_DIRECTIVES
|
WITH_DIRECTIVES
|
||||||
} from '../runtimeHelpers'
|
} from '../runtimeHelpers'
|
||||||
import { processExpression } from './transformExpression'
|
import { processExpression } from './transformExpression'
|
||||||
import { PatchFlags, PatchFlagNames } from '@vue/shared'
|
import { PatchFlags, PatchFlagNames } from '@vue/shared'
|
||||||
@ -151,7 +151,7 @@ export const transformFor = createStructuralDirectiveTransform(
|
|||||||
// Normal element v-for. Directly use the child's codegenNode
|
// Normal element v-for. Directly use the child's codegenNode
|
||||||
// arguments, but replace createVNode() with createBlock()
|
// arguments, but replace createVNode() with createBlock()
|
||||||
let codegenNode = node.codegenNode as ElementCodegenNode
|
let codegenNode = node.codegenNode as ElementCodegenNode
|
||||||
if (codegenNode.callee === APPLY_DIRECTIVES) {
|
if (codegenNode.callee === WITH_DIRECTIVES) {
|
||||||
codegenNode.arguments[0].callee = helper(CREATE_BLOCK)
|
codegenNode.arguments[0].callee = helper(CREATE_BLOCK)
|
||||||
} else {
|
} else {
|
||||||
codegenNode.callee = helper(CREATE_BLOCK)
|
codegenNode.callee = helper(CREATE_BLOCK)
|
||||||
|
@ -32,7 +32,7 @@ import {
|
|||||||
CREATE_BLOCK,
|
CREATE_BLOCK,
|
||||||
COMMENT,
|
COMMENT,
|
||||||
FRAGMENT,
|
FRAGMENT,
|
||||||
APPLY_DIRECTIVES,
|
WITH_DIRECTIVES,
|
||||||
CREATE_VNODE
|
CREATE_VNODE
|
||||||
} from '../runtimeHelpers'
|
} from '../runtimeHelpers'
|
||||||
import { injectProp } from '../utils'
|
import { injectProp } from '../utils'
|
||||||
@ -196,7 +196,7 @@ function createChildrenCodegenNode(
|
|||||||
| SlotOutletCodegenNode
|
| SlotOutletCodegenNode
|
||||||
let vnodeCall = childCodegen
|
let vnodeCall = childCodegen
|
||||||
// Element with custom directives. Locate the actual createVNode() call.
|
// Element with custom directives. Locate the actual createVNode() call.
|
||||||
if (vnodeCall.callee === APPLY_DIRECTIVES) {
|
if (vnodeCall.callee === WITH_DIRECTIVES) {
|
||||||
vnodeCall = vnodeCall.arguments[0]
|
vnodeCall = vnodeCall.arguments[0]
|
||||||
}
|
}
|
||||||
// Change createVNode to createBlock.
|
// Change createVNode to createBlock.
|
||||||
|
@ -5,9 +5,9 @@ exports[`compiler: transform v-model modifiers .lazy 1`] = `
|
|||||||
|
|
||||||
return function render() {
|
return function render() {
|
||||||
with (this) {
|
with (this) {
|
||||||
const { vModelText: _vModelText, createVNode: _createVNode, applyDirectives: _applyDirectives, createBlock: _createBlock, openBlock: _openBlock } = _Vue
|
const { vModelText: _vModelText, createVNode: _createVNode, withDirectives: _withDirectives, createBlock: _createBlock, openBlock: _openBlock } = _Vue
|
||||||
|
|
||||||
return (_openBlock(), _applyDirectives(_createBlock(\\"input\\", {
|
return (_openBlock(), _withDirectives(_createBlock(\\"input\\", {
|
||||||
modelValue: model,
|
modelValue: model,
|
||||||
\\"onUpdate:modelValue\\": $event => (model = $event)
|
\\"onUpdate:modelValue\\": $event => (model = $event)
|
||||||
}, null, 8 /* PROPS */, [\\"modelValue\\", \\"onUpdate:modelValue\\"]), [
|
}, null, 8 /* PROPS */, [\\"modelValue\\", \\"onUpdate:modelValue\\"]), [
|
||||||
@ -27,9 +27,9 @@ exports[`compiler: transform v-model modifiers .number 1`] = `
|
|||||||
|
|
||||||
return function render() {
|
return function render() {
|
||||||
with (this) {
|
with (this) {
|
||||||
const { vModelText: _vModelText, createVNode: _createVNode, applyDirectives: _applyDirectives, createBlock: _createBlock, openBlock: _openBlock } = _Vue
|
const { vModelText: _vModelText, createVNode: _createVNode, withDirectives: _withDirectives, createBlock: _createBlock, openBlock: _openBlock } = _Vue
|
||||||
|
|
||||||
return (_openBlock(), _applyDirectives(_createBlock(\\"input\\", {
|
return (_openBlock(), _withDirectives(_createBlock(\\"input\\", {
|
||||||
modelValue: model,
|
modelValue: model,
|
||||||
\\"onUpdate:modelValue\\": $event => (model = $event)
|
\\"onUpdate:modelValue\\": $event => (model = $event)
|
||||||
}, null, 8 /* PROPS */, [\\"modelValue\\", \\"onUpdate:modelValue\\"]), [
|
}, null, 8 /* PROPS */, [\\"modelValue\\", \\"onUpdate:modelValue\\"]), [
|
||||||
@ -49,9 +49,9 @@ exports[`compiler: transform v-model modifiers .trim 1`] = `
|
|||||||
|
|
||||||
return function render() {
|
return function render() {
|
||||||
with (this) {
|
with (this) {
|
||||||
const { vModelText: _vModelText, createVNode: _createVNode, applyDirectives: _applyDirectives, createBlock: _createBlock, openBlock: _openBlock } = _Vue
|
const { vModelText: _vModelText, createVNode: _createVNode, withDirectives: _withDirectives, createBlock: _createBlock, openBlock: _openBlock } = _Vue
|
||||||
|
|
||||||
return (_openBlock(), _applyDirectives(_createBlock(\\"input\\", {
|
return (_openBlock(), _withDirectives(_createBlock(\\"input\\", {
|
||||||
modelValue: model,
|
modelValue: model,
|
||||||
\\"onUpdate:modelValue\\": $event => (model = $event)
|
\\"onUpdate:modelValue\\": $event => (model = $event)
|
||||||
}, null, 8 /* PROPS */, [\\"modelValue\\", \\"onUpdate:modelValue\\"]), [
|
}, null, 8 /* PROPS */, [\\"modelValue\\", \\"onUpdate:modelValue\\"]), [
|
||||||
@ -71,9 +71,9 @@ exports[`compiler: transform v-model simple expression 1`] = `
|
|||||||
|
|
||||||
return function render() {
|
return function render() {
|
||||||
with (this) {
|
with (this) {
|
||||||
const { vModelText: _vModelText, createVNode: _createVNode, applyDirectives: _applyDirectives, createBlock: _createBlock, openBlock: _openBlock } = _Vue
|
const { vModelText: _vModelText, createVNode: _createVNode, withDirectives: _withDirectives, createBlock: _createBlock, openBlock: _openBlock } = _Vue
|
||||||
|
|
||||||
return (_openBlock(), _applyDirectives(_createBlock(\\"input\\", {
|
return (_openBlock(), _withDirectives(_createBlock(\\"input\\", {
|
||||||
modelValue: model,
|
modelValue: model,
|
||||||
\\"onUpdate:modelValue\\": $event => (model = $event)
|
\\"onUpdate:modelValue\\": $event => (model = $event)
|
||||||
}, null, 8 /* PROPS */, [\\"modelValue\\", \\"onUpdate:modelValue\\"]), [
|
}, null, 8 /* PROPS */, [\\"modelValue\\", \\"onUpdate:modelValue\\"]), [
|
||||||
@ -88,9 +88,9 @@ exports[`compiler: transform v-model simple expression for input (checkbox) 1`]
|
|||||||
|
|
||||||
return function render() {
|
return function render() {
|
||||||
with (this) {
|
with (this) {
|
||||||
const { vModelCheckbox: _vModelCheckbox, createVNode: _createVNode, applyDirectives: _applyDirectives, createBlock: _createBlock, openBlock: _openBlock } = _Vue
|
const { vModelCheckbox: _vModelCheckbox, createVNode: _createVNode, withDirectives: _withDirectives, createBlock: _createBlock, openBlock: _openBlock } = _Vue
|
||||||
|
|
||||||
return (_openBlock(), _applyDirectives(_createBlock(\\"input\\", {
|
return (_openBlock(), _withDirectives(_createBlock(\\"input\\", {
|
||||||
type: \\"checkbox\\",
|
type: \\"checkbox\\",
|
||||||
modelValue: model,
|
modelValue: model,
|
||||||
\\"onUpdate:modelValue\\": $event => (model = $event)
|
\\"onUpdate:modelValue\\": $event => (model = $event)
|
||||||
@ -106,11 +106,11 @@ exports[`compiler: transform v-model simple expression for input (dynamic type)
|
|||||||
|
|
||||||
return function render() {
|
return function render() {
|
||||||
with (this) {
|
with (this) {
|
||||||
const { vModelDynamic: _vModelDynamic, createVNode: _createVNode, applyDirectives: _applyDirectives, resolveDirective: _resolveDirective, createBlock: _createBlock, openBlock: _openBlock } = _Vue
|
const { vModelDynamic: _vModelDynamic, createVNode: _createVNode, withDirectives: _withDirectives, resolveDirective: _resolveDirective, createBlock: _createBlock, openBlock: _openBlock } = _Vue
|
||||||
|
|
||||||
const _directive_bind = _resolveDirective(\\"bind\\")
|
const _directive_bind = _resolveDirective(\\"bind\\")
|
||||||
|
|
||||||
return (_openBlock(), _applyDirectives(_createBlock(\\"input\\", {
|
return (_openBlock(), _withDirectives(_createBlock(\\"input\\", {
|
||||||
modelValue: model,
|
modelValue: model,
|
||||||
\\"onUpdate:modelValue\\": $event => (model = $event)
|
\\"onUpdate:modelValue\\": $event => (model = $event)
|
||||||
}, null, 8 /* PROPS */, [\\"modelValue\\", \\"onUpdate:modelValue\\"]), [
|
}, null, 8 /* PROPS */, [\\"modelValue\\", \\"onUpdate:modelValue\\"]), [
|
||||||
@ -126,9 +126,9 @@ exports[`compiler: transform v-model simple expression for input (radio) 1`] = `
|
|||||||
|
|
||||||
return function render() {
|
return function render() {
|
||||||
with (this) {
|
with (this) {
|
||||||
const { vModelRadio: _vModelRadio, createVNode: _createVNode, applyDirectives: _applyDirectives, createBlock: _createBlock, openBlock: _openBlock } = _Vue
|
const { vModelRadio: _vModelRadio, createVNode: _createVNode, withDirectives: _withDirectives, createBlock: _createBlock, openBlock: _openBlock } = _Vue
|
||||||
|
|
||||||
return (_openBlock(), _applyDirectives(_createBlock(\\"input\\", {
|
return (_openBlock(), _withDirectives(_createBlock(\\"input\\", {
|
||||||
type: \\"radio\\",
|
type: \\"radio\\",
|
||||||
modelValue: model,
|
modelValue: model,
|
||||||
\\"onUpdate:modelValue\\": $event => (model = $event)
|
\\"onUpdate:modelValue\\": $event => (model = $event)
|
||||||
@ -144,9 +144,9 @@ exports[`compiler: transform v-model simple expression for input (text) 1`] = `
|
|||||||
|
|
||||||
return function render() {
|
return function render() {
|
||||||
with (this) {
|
with (this) {
|
||||||
const { vModelText: _vModelText, createVNode: _createVNode, applyDirectives: _applyDirectives, createBlock: _createBlock, openBlock: _openBlock } = _Vue
|
const { vModelText: _vModelText, createVNode: _createVNode, withDirectives: _withDirectives, createBlock: _createBlock, openBlock: _openBlock } = _Vue
|
||||||
|
|
||||||
return (_openBlock(), _applyDirectives(_createBlock(\\"input\\", {
|
return (_openBlock(), _withDirectives(_createBlock(\\"input\\", {
|
||||||
type: \\"text\\",
|
type: \\"text\\",
|
||||||
modelValue: model,
|
modelValue: model,
|
||||||
\\"onUpdate:modelValue\\": $event => (model = $event)
|
\\"onUpdate:modelValue\\": $event => (model = $event)
|
||||||
@ -162,9 +162,9 @@ exports[`compiler: transform v-model simple expression for select 1`] = `
|
|||||||
|
|
||||||
return function render() {
|
return function render() {
|
||||||
with (this) {
|
with (this) {
|
||||||
const { vModelSelect: _vModelSelect, createVNode: _createVNode, applyDirectives: _applyDirectives, createBlock: _createBlock, openBlock: _openBlock } = _Vue
|
const { vModelSelect: _vModelSelect, createVNode: _createVNode, withDirectives: _withDirectives, createBlock: _createBlock, openBlock: _openBlock } = _Vue
|
||||||
|
|
||||||
return (_openBlock(), _applyDirectives(_createBlock(\\"select\\", {
|
return (_openBlock(), _withDirectives(_createBlock(\\"select\\", {
|
||||||
modelValue: model,
|
modelValue: model,
|
||||||
\\"onUpdate:modelValue\\": $event => (model = $event)
|
\\"onUpdate:modelValue\\": $event => (model = $event)
|
||||||
}, null, 8 /* PROPS */, [\\"modelValue\\", \\"onUpdate:modelValue\\"]), [
|
}, null, 8 /* PROPS */, [\\"modelValue\\", \\"onUpdate:modelValue\\"]), [
|
||||||
@ -179,9 +179,9 @@ exports[`compiler: transform v-model simple expression for textarea 1`] = `
|
|||||||
|
|
||||||
return function render() {
|
return function render() {
|
||||||
with (this) {
|
with (this) {
|
||||||
const { vModelText: _vModelText, createVNode: _createVNode, applyDirectives: _applyDirectives, createBlock: _createBlock, openBlock: _openBlock } = _Vue
|
const { vModelText: _vModelText, createVNode: _createVNode, withDirectives: _withDirectives, createBlock: _createBlock, openBlock: _openBlock } = _Vue
|
||||||
|
|
||||||
return (_openBlock(), _applyDirectives(_createBlock(\\"textarea\\", {
|
return (_openBlock(), _withDirectives(_createBlock(\\"textarea\\", {
|
||||||
modelValue: model,
|
modelValue: model,
|
||||||
\\"onUpdate:modelValue\\": $event => (model = $event)
|
\\"onUpdate:modelValue\\": $event => (model = $event)
|
||||||
}, null, 8 /* PROPS */, [\\"modelValue\\", \\"onUpdate:modelValue\\"]), [
|
}, null, 8 /* PROPS */, [\\"modelValue\\", \\"onUpdate:modelValue\\"]), [
|
||||||
|
@ -8,7 +8,7 @@ import {
|
|||||||
inject,
|
inject,
|
||||||
resolveComponent,
|
resolveComponent,
|
||||||
resolveDirective,
|
resolveDirective,
|
||||||
applyDirectives,
|
withDirectives,
|
||||||
Plugin,
|
Plugin,
|
||||||
ref,
|
ref,
|
||||||
getCurrentInstance
|
getCurrentInstance
|
||||||
@ -128,7 +128,7 @@ describe('api: createApp', () => {
|
|||||||
return () => {
|
return () => {
|
||||||
// resolve in render
|
// resolve in render
|
||||||
const BarBaz = resolveDirective('bar-baz')!
|
const BarBaz = resolveDirective('bar-baz')!
|
||||||
return applyDirectives(h('div'), [[FooBar], [BarBaz]])
|
return withDirectives(h('div'), [[FooBar], [BarBaz]])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
h,
|
h,
|
||||||
applyDirectives,
|
withDirectives,
|
||||||
ref,
|
ref,
|
||||||
render,
|
render,
|
||||||
nodeOps,
|
nodeOps,
|
||||||
@ -107,7 +107,7 @@ describe('directives', () => {
|
|||||||
},
|
},
|
||||||
render() {
|
render() {
|
||||||
_prevVnode = _vnode
|
_prevVnode = _vnode
|
||||||
_vnode = applyDirectives(h('div', count.value), [
|
_vnode = withDirectives(h('div', count.value), [
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
beforeMount,
|
beforeMount,
|
||||||
@ -174,7 +174,7 @@ describe('directives', () => {
|
|||||||
},
|
},
|
||||||
render() {
|
render() {
|
||||||
_prevVnode = _vnode
|
_prevVnode = _vnode
|
||||||
_vnode = applyDirectives(h('div', count.value), [
|
_vnode = withDirectives(h('div', count.value), [
|
||||||
[
|
[
|
||||||
fn,
|
fn,
|
||||||
// value
|
// value
|
||||||
|
@ -11,8 +11,8 @@ return applyDirectives(h(comp), [
|
|||||||
])
|
])
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { VNode, cloneVNode } from './vnode'
|
import { VNode } from './vnode'
|
||||||
import { extend, isArray, isFunction, EMPTY_OBJ, makeMap } from '@vue/shared'
|
import { isArray, isFunction, EMPTY_OBJ, makeMap } from '@vue/shared'
|
||||||
import { warn } from './warning'
|
import { warn } from './warning'
|
||||||
import { ComponentInternalInstance } from './component'
|
import { ComponentInternalInstance } from './component'
|
||||||
import { currentRenderingInstance } from './componentRenderUtils'
|
import { currentRenderingInstance } from './componentRenderUtils'
|
||||||
@ -120,11 +120,10 @@ export type DirectiveArguments = Array<
|
|||||||
| [Directive, any, string, DirectiveModifiers]
|
| [Directive, any, string, DirectiveModifiers]
|
||||||
>
|
>
|
||||||
|
|
||||||
export function applyDirectives(vnode: VNode, directives: DirectiveArguments) {
|
export function withDirectives(vnode: VNode, directives: DirectiveArguments) {
|
||||||
const instance = currentRenderingInstance
|
const instance = currentRenderingInstance
|
||||||
if (instance !== null) {
|
if (instance !== null) {
|
||||||
vnode = cloneVNode(vnode)
|
vnode.props = vnode.props || {}
|
||||||
vnode.props = vnode.props != null ? extend({}, vnode.props) : {}
|
|
||||||
for (let i = 0; i < directives.length; i++) {
|
for (let i = 0; i < directives.length; i++) {
|
||||||
const [dir, value, arg, modifiers] = directives[i]
|
const [dir, value, arg, modifiers] = directives[i]
|
||||||
applyDirective(vnode.props, instance, dir, value, arg, modifiers)
|
applyDirective(vnode.props, instance, dir, value, arg, modifiers)
|
||||||
|
@ -38,7 +38,7 @@ export {
|
|||||||
|
|
||||||
// Internal, for compiler generated code
|
// Internal, for compiler generated code
|
||||||
// should sync with '@vue/compiler-core/src/runtimeConstants.ts'
|
// should sync with '@vue/compiler-core/src/runtimeConstants.ts'
|
||||||
export { applyDirectives } from './directives'
|
export { withDirectives } from './directives'
|
||||||
export {
|
export {
|
||||||
resolveComponent,
|
resolveComponent,
|
||||||
resolveDirective,
|
resolveDirective,
|
||||||
|
@ -4,7 +4,7 @@ import {
|
|||||||
nextTick,
|
nextTick,
|
||||||
createComponent,
|
createComponent,
|
||||||
vModelDynamic,
|
vModelDynamic,
|
||||||
applyDirectives,
|
withDirectives,
|
||||||
VNode
|
VNode
|
||||||
} from '@vue/runtime-dom'
|
} from '@vue/runtime-dom'
|
||||||
|
|
||||||
@ -14,7 +14,7 @@ const triggerEvent = (type: string, el: Element) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const withVModel = (node: VNode, arg: any, mods?: any) =>
|
const withVModel = (node: VNode, arg: any, mods?: any) =>
|
||||||
applyDirectives(node, [[vModelDynamic, arg, '', mods]])
|
withDirectives(node, [[vModelDynamic, arg, '', mods]])
|
||||||
|
|
||||||
const setValue = function(this: any, value: any) {
|
const setValue = function(this: any, value: any) {
|
||||||
this.value = value
|
this.value = value
|
||||||
|
Loading…
Reference in New Issue
Block a user