refactor(compiler): extract isStaticExp util

This commit is contained in:
Evan You
2020-07-13 16:48:16 -04:00
parent 8b320cc12f
commit 576344d2c3
6 changed files with 33 additions and 28 deletions

View File

@@ -20,7 +20,8 @@ import {
IfBranchNode,
TextNode,
InterpolationNode,
VNodeCall
VNodeCall,
SimpleExpressionNode
} from './ast'
import { TransformContext } from './transform'
import {
@@ -35,6 +36,9 @@ import { parse } from '@babel/parser'
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)
@@ -196,12 +200,7 @@ export function findProp(
}
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 {