refactor: applyDirectives -> withDirectives
This commit is contained in:
@@ -15,7 +15,7 @@ import {
|
||||
CREATE_BLOCK,
|
||||
FRAGMENT,
|
||||
RENDER_SLOT,
|
||||
APPLY_DIRECTIVES
|
||||
WITH_DIRECTIVES
|
||||
} from '../src/runtimeHelpers'
|
||||
import { transformIf } from '../src/transforms/vIf'
|
||||
import { transformFor } from '../src/transforms/vFor'
|
||||
@@ -314,7 +314,7 @@ describe('compiler: transform', () => {
|
||||
{
|
||||
type: NodeTypes.JS_CALL_EXPRESSION,
|
||||
// should wrap applyDirectives() around createBlock()
|
||||
callee: APPLY_DIRECTIVES,
|
||||
callee: WITH_DIRECTIVES,
|
||||
arguments: [
|
||||
{ callee: CREATE_BLOCK },
|
||||
{ type: NodeTypes.JS_ARRAY_EXPRESSION }
|
||||
|
||||
@@ -101,12 +101,12 @@ const _hoisted_1 = { id: \\"foo\\" }
|
||||
|
||||
return function render() {
|
||||
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\\")
|
||||
|
||||
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]
|
||||
])
|
||||
]))
|
||||
|
||||
@@ -137,12 +137,12 @@ exports[`compiler: v-for codegen v-for on element with custom directive 1`] = `
|
||||
|
||||
return function render() {
|
||||
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\\")
|
||||
|
||||
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]
|
||||
]))
|
||||
}), 128 /* UNKEYED_FRAGMENT */))
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
OPEN_BLOCK,
|
||||
CREATE_BLOCK,
|
||||
CREATE_VNODE,
|
||||
APPLY_DIRECTIVES,
|
||||
WITH_DIRECTIVES,
|
||||
FRAGMENT,
|
||||
RENDER_LIST
|
||||
} from '../../src/runtimeHelpers'
|
||||
@@ -304,7 +304,7 @@ describe('compiler: hoistStatic transform', () => {
|
||||
{
|
||||
type: NodeTypes.ELEMENT,
|
||||
codegenNode: {
|
||||
callee: APPLY_DIRECTIVES,
|
||||
callee: WITH_DIRECTIVES,
|
||||
arguments: [
|
||||
{
|
||||
callee: CREATE_VNODE,
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
CREATE_VNODE,
|
||||
MERGE_PROPS,
|
||||
RESOLVE_DIRECTIVE,
|
||||
APPLY_DIRECTIVES,
|
||||
WITH_DIRECTIVES,
|
||||
TO_HANDLERS,
|
||||
helperNameMap,
|
||||
PORTAL,
|
||||
@@ -368,7 +368,7 @@ describe('compiler: element transform', () => {
|
||||
expect(root.helpers).toContain(RESOLVE_DIRECTIVE)
|
||||
expect(root.directives).toContain(`foo`)
|
||||
|
||||
expect(node.callee).toBe(APPLY_DIRECTIVES)
|
||||
expect(node.callee).toBe(WITH_DIRECTIVES)
|
||||
expect(node.arguments).toMatchObject([
|
||||
{
|
||||
type: NodeTypes.JS_CALL_EXPRESSION,
|
||||
@@ -438,7 +438,7 @@ describe('compiler: element transform', () => {
|
||||
expect(root.directives).toContain(`bar`)
|
||||
expect(root.directives).toContain(`baz`)
|
||||
|
||||
expect(node.callee).toBe(APPLY_DIRECTIVES)
|
||||
expect(node.callee).toBe(WITH_DIRECTIVES)
|
||||
expect(node.arguments).toMatchObject([
|
||||
{
|
||||
type: NodeTypes.JS_CALL_EXPRESSION
|
||||
|
||||
@@ -23,7 +23,7 @@ import {
|
||||
FRAGMENT,
|
||||
RENDER_LIST,
|
||||
RENDER_SLOT,
|
||||
APPLY_DIRECTIVES
|
||||
WITH_DIRECTIVES
|
||||
} from '../../src/runtimeHelpers'
|
||||
import { PatchFlags } from '@vue/runtime-dom'
|
||||
import { createObjectMatcher, genFlagText } from '../testUtils'
|
||||
@@ -859,7 +859,7 @@ describe('compiler: v-for', () => {
|
||||
{ callee: OPEN_BLOCK },
|
||||
// should wrap applyDirectives() around createBlock()
|
||||
{
|
||||
callee: APPLY_DIRECTIVES,
|
||||
callee: WITH_DIRECTIVES,
|
||||
arguments: [
|
||||
{ callee: CREATE_BLOCK },
|
||||
{ type: NodeTypes.JS_ARRAY_EXPRESSION }
|
||||
|
||||
@@ -22,7 +22,7 @@ import {
|
||||
COMMENT,
|
||||
FRAGMENT,
|
||||
MERGE_PROPS,
|
||||
APPLY_DIRECTIVES,
|
||||
WITH_DIRECTIVES,
|
||||
RENDER_SLOT
|
||||
} from '../../src/runtimeHelpers'
|
||||
import { createObjectMatcher } from '../testUtils'
|
||||
@@ -513,7 +513,7 @@ describe('compiler: v-if', () => {
|
||||
} = parseWithIfTransform(`<div v-if="ok" v-foo />`)
|
||||
const branch1 = (codegenNode.expressions[1] as ConditionalExpression)
|
||||
.consequent as CallExpression
|
||||
expect(branch1.callee).toBe(APPLY_DIRECTIVES)
|
||||
expect(branch1.callee).toBe(WITH_DIRECTIVES)
|
||||
const realBranch = branch1.arguments[0] as CallExpression
|
||||
expect(realBranch.arguments[1]).toMatchObject(
|
||||
createObjectMatcher({ key: `[0]` })
|
||||
|
||||
@@ -2,7 +2,7 @@ import { isString } from '@vue/shared'
|
||||
import { ForParseResult } from './transforms/vFor'
|
||||
import {
|
||||
CREATE_VNODE,
|
||||
APPLY_DIRECTIVES,
|
||||
WITH_DIRECTIVES,
|
||||
RENDER_SLOT,
|
||||
CREATE_SLOTS,
|
||||
RENDER_LIST,
|
||||
@@ -393,7 +393,7 @@ export interface DynamicSlotFnProperty extends Property {
|
||||
// ])
|
||||
export interface CodegenNodeWithDirective<T extends CallExpression>
|
||||
extends CallExpression {
|
||||
callee: typeof APPLY_DIRECTIVES
|
||||
callee: typeof WITH_DIRECTIVES
|
||||
arguments: [T, DirectiveArguments]
|
||||
}
|
||||
|
||||
@@ -548,7 +548,7 @@ type InferCodegenNodeType<T> = T extends
|
||||
| typeof CREATE_VNODE
|
||||
| typeof CREATE_BLOCK
|
||||
? PlainElementCodegenNode | PlainComponentCodegenNode
|
||||
: T extends typeof APPLY_DIRECTIVES
|
||||
: T extends typeof WITH_DIRECTIVES
|
||||
?
|
||||
| CodegenNodeWithDirective<PlainElementCodegenNode>
|
||||
| CodegenNodeWithDirective<PlainComponentCodegenNode>
|
||||
|
||||
@@ -11,7 +11,7 @@ export const RESOLVE_DYNAMIC_COMPONENT = Symbol(
|
||||
__DEV__ ? `resolveDynamicComponent` : ``
|
||||
)
|
||||
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_SLOT = Symbol(__DEV__ ? `renderSlot` : ``)
|
||||
export const CREATE_SLOTS = Symbol(__DEV__ ? `createSlots` : ``)
|
||||
@@ -35,7 +35,7 @@ export const helperNameMap: any = {
|
||||
[RESOLVE_COMPONENT]: `resolveComponent`,
|
||||
[RESOLVE_DYNAMIC_COMPONENT]: `resolveDynamicComponent`,
|
||||
[RESOLVE_DIRECTIVE]: `resolveDirective`,
|
||||
[APPLY_DIRECTIVES]: `applyDirectives`,
|
||||
[WITH_DIRECTIVES]: `withDirectives`,
|
||||
[RENDER_LIST]: `renderList`,
|
||||
[RENDER_SLOT]: `renderSlot`,
|
||||
[CREATE_SLOTS]: `createSlots`,
|
||||
|
||||
@@ -23,7 +23,7 @@ import {
|
||||
CREATE_VNODE,
|
||||
FRAGMENT,
|
||||
helperNameMap,
|
||||
APPLY_DIRECTIVES,
|
||||
WITH_DIRECTIVES,
|
||||
CREATE_BLOCK
|
||||
} from './runtimeHelpers'
|
||||
import { isVSlot, createBlockExpression } from './utils'
|
||||
@@ -243,7 +243,7 @@ function finalizeRoot(root: RootNode, context: TransformContext) {
|
||||
const codegenNode = child.codegenNode as
|
||||
| ElementCodegenNode
|
||||
| ComponentCodegenNode
|
||||
if (codegenNode.callee === APPLY_DIRECTIVES) {
|
||||
if (codegenNode.callee === WITH_DIRECTIVES) {
|
||||
codegenNode.arguments[0].callee = helper(CREATE_BLOCK)
|
||||
} else {
|
||||
codegenNode.callee = helper(CREATE_BLOCK)
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
ElementNode
|
||||
} from '../ast'
|
||||
import { TransformContext } from '../transform'
|
||||
import { APPLY_DIRECTIVES } from '../runtimeHelpers'
|
||||
import { WITH_DIRECTIVES } from '../runtimeHelpers'
|
||||
import { PatchFlags, isString, isSymbol } from '@vue/shared'
|
||||
import { isSlotOutlet, findProp } from '../utils'
|
||||
|
||||
@@ -72,7 +72,7 @@ function walk(
|
||||
!hasDynamicKeyOrRef(child)
|
||||
) {
|
||||
let codegenNode = child.codegenNode as ElementCodegenNode
|
||||
if (codegenNode.callee === APPLY_DIRECTIVES) {
|
||||
if (codegenNode.callee === WITH_DIRECTIVES) {
|
||||
codegenNode = codegenNode.arguments[0]
|
||||
}
|
||||
const props = codegenNode.arguments[1]
|
||||
@@ -99,7 +99,7 @@ function walk(
|
||||
|
||||
function getPatchFlag(node: PlainElementNode): number | undefined {
|
||||
let codegenNode = node.codegenNode as ElementCodegenNode
|
||||
if (codegenNode.callee === APPLY_DIRECTIVES) {
|
||||
if (codegenNode.callee === WITH_DIRECTIVES) {
|
||||
codegenNode = codegenNode.arguments[0]
|
||||
}
|
||||
const flag = codegenNode.arguments[3]
|
||||
|
||||
@@ -19,7 +19,7 @@ import { PatchFlags, PatchFlagNames, isSymbol } from '@vue/shared'
|
||||
import { createCompilerError, ErrorCodes } from '../errors'
|
||||
import {
|
||||
CREATE_VNODE,
|
||||
APPLY_DIRECTIVES,
|
||||
WITH_DIRECTIVES,
|
||||
RESOLVE_DIRECTIVE,
|
||||
RESOLVE_COMPONENT,
|
||||
RESOLVE_DYNAMIC_COMPONENT,
|
||||
@@ -177,7 +177,7 @@ export const transformElement: NodeTransform = (node, context) => {
|
||||
|
||||
if (runtimeDirectives && runtimeDirectives.length) {
|
||||
node.codegenNode = createCallExpression(
|
||||
context.helper(APPLY_DIRECTIVES),
|
||||
context.helper(WITH_DIRECTIVES),
|
||||
[
|
||||
vnode,
|
||||
createArrayExpression(
|
||||
|
||||
@@ -31,7 +31,7 @@ import {
|
||||
OPEN_BLOCK,
|
||||
CREATE_BLOCK,
|
||||
FRAGMENT,
|
||||
APPLY_DIRECTIVES
|
||||
WITH_DIRECTIVES
|
||||
} from '../runtimeHelpers'
|
||||
import { processExpression } from './transformExpression'
|
||||
import { PatchFlags, PatchFlagNames } from '@vue/shared'
|
||||
@@ -151,7 +151,7 @@ export const transformFor = createStructuralDirectiveTransform(
|
||||
// Normal element v-for. Directly use the child's codegenNode
|
||||
// arguments, but replace createVNode() with createBlock()
|
||||
let codegenNode = node.codegenNode as ElementCodegenNode
|
||||
if (codegenNode.callee === APPLY_DIRECTIVES) {
|
||||
if (codegenNode.callee === WITH_DIRECTIVES) {
|
||||
codegenNode.arguments[0].callee = helper(CREATE_BLOCK)
|
||||
} else {
|
||||
codegenNode.callee = helper(CREATE_BLOCK)
|
||||
|
||||
@@ -32,7 +32,7 @@ import {
|
||||
CREATE_BLOCK,
|
||||
COMMENT,
|
||||
FRAGMENT,
|
||||
APPLY_DIRECTIVES,
|
||||
WITH_DIRECTIVES,
|
||||
CREATE_VNODE
|
||||
} from '../runtimeHelpers'
|
||||
import { injectProp } from '../utils'
|
||||
@@ -196,7 +196,7 @@ function createChildrenCodegenNode(
|
||||
| SlotOutletCodegenNode
|
||||
let vnodeCall = childCodegen
|
||||
// Element with custom directives. Locate the actual createVNode() call.
|
||||
if (vnodeCall.callee === APPLY_DIRECTIVES) {
|
||||
if (vnodeCall.callee === WITH_DIRECTIVES) {
|
||||
vnodeCall = vnodeCall.arguments[0]
|
||||
}
|
||||
// Change createVNode to createBlock.
|
||||
|
||||
Reference in New Issue
Block a user