From: edison Date: Fri, 20 Sep 2024 08:45:47 +0000 (+0800) Subject: fix(compile-core): fix v-model with newlines edge case (#11960) X-Git-Tag: v3.5.7~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=62242886d705ece88dbcad45bb78072ecccad0ca;p=thirdparty%2Fvuejs%2Fcore.git fix(compile-core): fix v-model with newlines edge case (#11960) close #8306 --- diff --git a/packages/compiler-core/src/transforms/vModel.ts b/packages/compiler-core/src/transforms/vModel.ts index f168c18180..598c1ea438 100644 --- a/packages/compiler-core/src/transforms/vModel.ts +++ b/packages/compiler-core/src/transforms/vModel.ts @@ -31,7 +31,7 @@ export const transformModel: DirectiveTransform = (dir, node, context) => { // we assume v-model directives are always parsed // (not artificially created by a transform) - const rawExp = exp.loc.source + const rawExp = exp.loc.source.trim() const expString = exp.type === NodeTypes.SIMPLE_EXPRESSION ? exp.content : rawExp diff --git a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap index bf40b0529d..7fcc1d3950 100644 --- a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap +++ b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap @@ -1084,6 +1084,29 @@ return (_ctx, _cache) => { }" `; +exports[`SFC compile + + `, + { inlineTemplate: true }, + ) + expect(content).toMatch(`_isRef(count) ? (count).value = $event : null`) + assertCode(content) + }) + test('v-model should not generate ref assignment code for non-setup bindings', () => { const { content } = compile( `