findProp,
isCoreComponent,
isBindKey,
- findDir
+ findDir,
+ isStaticExp
} from '../utils'
import { buildSlots } from './vSlot'
import { getStaticType } from './hoistStatic'
const dynamicPropNames: string[] = []
const analyzePatchFlag = ({ key, value }: Property) => {
- if (key.type === NodeTypes.SIMPLE_EXPRESSION && key.isStatic) {
+ if (isStaticExp(key)) {
const name = key.content
if (
!isComponent &&
ElementTypes
} from '../ast'
import { createCompilerError, ErrorCodes } from '../errors'
-import { isMemberExpression, isSimpleIdentifier, hasScopeRef } from '../utils'
+import {
+ isMemberExpression,
+ isSimpleIdentifier,
+ hasScopeRef,
+ isStaticExp
+} from '../utils'
export const transformModel: DirectiveTransform = (dir, node, context) => {
const { exp, arg } = dir
const propName = arg ? arg : createSimpleExpression('modelValue', true)
const eventName = arg
- ? arg.type === NodeTypes.SIMPLE_EXPRESSION && arg.isStatic
+ ? isStaticExp(arg)
? `onUpdate:${arg.content}`
: createCompoundExpression(['"onUpdate:" + ', arg])
: `onUpdate:modelValue`
.map(m => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`)
.join(`, `)
const modifiersKey = arg
- ? arg.type === NodeTypes.SIMPLE_EXPRESSION && arg.isStatic
+ ? isStaticExp(arg)
? `${arg.content}Modifiers`
: createCompoundExpression([arg, ' + "Modifiers"'])
: `modelModifiers`
SourceLocation,
createConditionalExpression,
ConditionalExpression,
- JSChildNode,
SimpleExpressionNode,
FunctionExpression,
CallExpression,
} from '../ast'
import { TransformContext, NodeTransform } from '../transform'
import { createCompilerError, ErrorCodes } from '../errors'
-import { findDir, isTemplateNode, assert, isVSlot, hasScopeRef } from '../utils'
+import {
+ findDir,
+ isTemplateNode,
+ assert,
+ isVSlot,
+ hasScopeRef,
+ isStaticExp
+} from '../utils'
import { CREATE_SLOTS, RENDER_LIST, WITH_CTX } from '../runtimeHelpers'
import { parseForExpression, createForLoopParams } from './vFor'
-const isStaticExp = (p: JSChildNode): p is SimpleExpressionNode =>
- p.type === NodeTypes.SIMPLE_EXPRESSION && p.isStatic
-
const defaultFallback = createSimpleExpression(`undefined`, false)
// A NodeTransform that:
IfBranchNode,
TextNode,
InterpolationNode,
- VNodeCall
+ VNodeCall,
+ SimpleExpressionNode
} from './ast'
import { TransformContext } from './transform'
import {
import { walk } from 'estree-walker'
import { Node } from '@babel/types'
+export const isStaticExp = (p: JSChildNode): p is SimpleExpressionNode =>
+ p.type === NodeTypes.SIMPLE_EXPRESSION && p.isStatic
+
export const isBuiltInType = (tag: string, expected: string): boolean =>
tag === expected || tag === hyphenate(expected)
}
export function isBindKey(arg: DirectiveNode['arg'], name: string): boolean {
- return !!(
- arg &&
- arg.type === NodeTypes.SIMPLE_EXPRESSION &&
- arg.isStatic &&
- arg.content === name
- )
+ return !!(arg && isStaticExp(arg) && arg.content === name)
}
export function hasDynamicKeyVBind(node: ElementNode): boolean {
NodeTypes,
createCompoundExpression,
ExpressionNode,
- SimpleExpressionNode
+ SimpleExpressionNode,
+ isStaticExp
} from '@vue/compiler-core'
import { V_ON_WITH_MODIFIERS, V_ON_WITH_KEYS } from '../runtimeHelpers'
import { makeMap } from '@vue/shared'
)
const resolveModifiers = (key: ExpressionNode, modifiers: string[]) => {
- const isStaticKey = key.type === NodeTypes.SIMPLE_EXPRESSION && key.isStatic
const keyModifiers = []
const nonKeyModifiers = []
const eventOptionModifiers = []
} else {
// runtimeModifiers: modifiers that needs runtime guards
if (maybeKeyModifier(modifier)) {
- if (isStaticKey) {
+ if (isStaticExp(key)) {
if (isKeyboardEvent((key as SimpleExpressionNode).content)) {
keyModifiers.push(modifier)
} else {
const transformClick = (key: ExpressionNode, event: string) => {
const isStaticClick =
- key.type === NodeTypes.SIMPLE_EXPRESSION &&
- key.isStatic &&
- key.content.toLowerCase() === 'onclick'
+ isStaticExp(key) && key.content.toLowerCase() === 'onclick'
return isStaticClick
? createSimpleExpression(event, true)
: key.type !== NodeTypes.SIMPLE_EXPRESSION
if (
keyModifiers.length &&
// if event name is dynamic, always wrap with keys guard
- (key.type === NodeTypes.COMPOUND_EXPRESSION ||
- !key.isStatic ||
- isKeyboardEvent(key.content))
+ (!isStaticExp(key) || isKeyboardEvent(key.content))
) {
handlerExp = createCallExpression(context.helper(V_ON_WITH_KEYS), [
handlerExp,
MERGE_PROPS,
isBindKey,
createSequenceExpression,
- InterpolationNode
+ InterpolationNode,
+ isStaticExp
} from '@vue/compiler-dom'
import {
escapeHtml,
}
for (let j = 0; j < props.length; j++) {
const { key, value } = props[j]
- if (key.type === NodeTypes.SIMPLE_EXPRESSION && key.isStatic) {
+ if (isStaticExp(key)) {
let attrName = key.content
// static key attr
if (attrName === 'class') {