|
|
@@ -1,16 +1,13 @@
|
|
|
-import type { DirectiveTransform, TransformContext } from '../transform'
|
|
|
+import type { DirectiveTransform } from '../transform'
|
|
|
import {
|
|
|
- type DirectiveNode,
|
|
|
type ExpressionNode,
|
|
|
NodeTypes,
|
|
|
- type SimpleExpressionNode,
|
|
|
createObjectProperty,
|
|
|
createSimpleExpression,
|
|
|
} from '../ast'
|
|
|
import { ErrorCodes, createCompilerError } from '../errors'
|
|
|
import { camelize } from '@vue/shared'
|
|
|
import { CAMELIZE } from '../runtimeHelpers'
|
|
|
-import { processExpression } from './transformExpression'
|
|
|
|
|
|
// v-bind without arg is handled directly in ./transformElement.ts due to its affecting
|
|
|
// codegen for the entire props object. This transform here is only for v-bind
|
|
|
@@ -40,27 +37,6 @@ export const transformBind: DirectiveTransform = (dir, _node, context) => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // same-name shorthand - :arg is expanded to :arg="arg"
|
|
|
- if (!exp) {
|
|
|
- if (arg.type !== NodeTypes.SIMPLE_EXPRESSION || !arg.isStatic) {
|
|
|
- // only simple expression is allowed for same-name shorthand
|
|
|
- context.onError(
|
|
|
- createCompilerError(
|
|
|
- ErrorCodes.X_V_BIND_INVALID_SAME_NAME_ARGUMENT,
|
|
|
- arg.loc,
|
|
|
- ),
|
|
|
- )
|
|
|
- return {
|
|
|
- props: [
|
|
|
- createObjectProperty(arg, createSimpleExpression('', true, loc)),
|
|
|
- ],
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- transformBindShorthand(dir, context)
|
|
|
- exp = dir.exp!
|
|
|
- }
|
|
|
-
|
|
|
if (arg.type !== NodeTypes.SIMPLE_EXPRESSION) {
|
|
|
arg.children.unshift(`(`)
|
|
|
arg.children.push(`) || ""`)
|
|
|
@@ -92,20 +68,7 @@ export const transformBind: DirectiveTransform = (dir, _node, context) => {
|
|
|
}
|
|
|
|
|
|
return {
|
|
|
- props: [createObjectProperty(arg, exp)],
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-export const transformBindShorthand = (
|
|
|
- dir: DirectiveNode,
|
|
|
- context: TransformContext,
|
|
|
-): void => {
|
|
|
- const arg = dir.arg!
|
|
|
-
|
|
|
- const propName = camelize((arg as SimpleExpressionNode).content)
|
|
|
- dir.exp = createSimpleExpression(propName, false, arg.loc)
|
|
|
- if (!__BROWSER__) {
|
|
|
- dir.exp = processExpression(dir.exp, context)
|
|
|
+ props: [createObjectProperty(arg, exp!)],
|
|
|
}
|
|
|
}
|
|
|
|