Skip to content

Commit

Permalink
refactor(compiler-core): move return statement from transformBindShor…
Browse files Browse the repository at this point in the history
…thand to transformBind
  • Loading branch information
Vadim Kruglov committed May 20, 2024
1 parent b3c2410 commit 85827ac
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions packages/compiler-core/src/transforms/vBind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,23 @@ export const transformBind: DirectiveTransform = (dir, _node, context) => {

// same-name shorthand - :arg is expanded to :arg="arg"
if (!exp) {
const returned = transformBindShorthand(dir, context)
if (returned) return returned
const { loc } = dir
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!
}

Expand Down Expand Up @@ -88,19 +102,6 @@ export const transformBindShorthand = (
context: TransformContext,
) => {
const arg = dir.arg!
const { loc } = dir
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))],
}
}

const propName = camelize((arg as SimpleExpressionNode).content)
dir.exp = createSimpleExpression(propName, false, arg.loc)
Expand Down

0 comments on commit 85827ac

Please sign in to comment.