From: Evan You Date: Tue, 21 Nov 2023 10:37:47 +0000 (+0800) Subject: refactor: fix v-bind no-exp shorthand for new parser X-Git-Tag: v3.4.0-alpha.2~30 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=94c86269d09259bda4bbeaa4cb98e9c8ded5b0a6;p=thirdparty%2Fvuejs%2Fcore.git refactor: fix v-bind no-exp shorthand for new parser --- diff --git a/packages/compiler-core/__tests__/transforms/vBind.spec.ts b/packages/compiler-core/__tests__/transforms/vBind.spec.ts index 2e94dc1f7d..0ae247c2f5 100644 --- a/packages/compiler-core/__tests__/transforms/vBind.spec.ts +++ b/packages/compiler-core/__tests__/transforms/vBind.spec.ts @@ -80,32 +80,16 @@ describe('compiler: transform v-bind', () => { content: `id`, isStatic: true, loc: { - start: { - line: 1, - column: 13, - offset: 12 - }, - end: { - line: 1, - column: 15, - offset: 14 - } + start: { line: 1, column: 13, offset: 12 }, + end: { line: 1, column: 15, offset: 14 } } }, value: { content: `id`, isStatic: false, loc: { - start: { - line: 1, - column: 1, - offset: 0 - }, - end: { - line: 1, - column: 1, - offset: 0 - } + start: { line: 1, column: 13, offset: 12 }, + end: { line: 1, column: 15, offset: 14 } } } }) diff --git a/packages/compiler-core/src/transforms/vBind.ts b/packages/compiler-core/src/transforms/vBind.ts index 9f85d6b3d6..eba95727bd 100644 --- a/packages/compiler-core/src/transforms/vBind.ts +++ b/packages/compiler-core/src/transforms/vBind.ts @@ -3,7 +3,6 @@ import { createObjectProperty, createSimpleExpression, ExpressionNode, - locStub, NodeTypes } from '../ast' import { createCompilerError, ErrorCodes } from '../errors' @@ -18,6 +17,16 @@ export const transformBind: DirectiveTransform = (dir, _node, context) => { const { modifiers, loc } = dir const arg = dir.arg! + // :arg is replaced by :arg="arg" + let { exp } = dir + if (!exp && arg.type === NodeTypes.SIMPLE_EXPRESSION) { + const propName = camelize(arg.content) + exp = dir.exp = createSimpleExpression(propName, false, arg.loc) + if (!__BROWSER__) { + exp = dir.exp = processExpression(exp, context) + } + } + if (arg.type !== NodeTypes.SIMPLE_EXPRESSION) { arg.children.unshift(`(`) arg.children.push(`) || ""`) @@ -48,18 +57,6 @@ export const transformBind: DirectiveTransform = (dir, _node, context) => { } } - // :arg is replaced by :arg="arg" - let { exp } = dir - if (!exp && arg.type === NodeTypes.SIMPLE_EXPRESSION) { - const propName = camelize(arg.loc.source) - const simpleExpression = createSimpleExpression(propName, false, { - ...locStub, - source: propName - }) - - exp = dir.exp = processExpression(simpleExpression, context) - } - if ( !exp || (exp.type === NodeTypes.SIMPLE_EXPRESSION && !exp.content.trim())