vue3-yuanma/packages/compiler-core/src/transforms/vBind.ts

30 lines
914 B
TypeScript
Raw Normal View History

import { DirectiveTransform } from '../transform'
import { createObjectProperty, createExpression } from '../ast'
import { createCompilerError, ErrorCodes } from '../errors'
2019-09-25 02:03:28 +00:00
import { camelize } from '@vue/shared'
// v-bind without arg is handled directly in ./element.ts due to it affecting
// codegen for the entire props object. This transform here is only for v-bind
// *with* args.
2019-09-25 02:03:28 +00:00
export const transformBind: DirectiveTransform = (
{ exp, arg, modifiers, loc },
context
) => {
if (!exp) {
context.onError(createCompilerError(ErrorCodes.X_V_BIND_NO_EXPRESSION, loc))
}
// .prop is no longer necessary due to new patch behavior
// .sync is replced by v-model:arg
if (modifiers.includes('camel')) {
arg!.content = camelize(arg!.content)
}
return {
props: createObjectProperty(
2019-09-25 02:03:28 +00:00
arg!,
exp || createExpression('', true, loc),
loc
),
needRuntime: false
}
}