From: 白雾三语 <32354856+baiwusanyu-c@users.noreply.github.com> Date: Fri, 31 Mar 2023 08:33:00 +0000 (+0800) Subject: fix(compiler-dom): handle newlines when evaluating constants during stringification... X-Git-Tag: v3.3.0-alpha.7~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=52610851137b9c5f6f57d771fd604fba309b3c97;p=thirdparty%2Fvuejs%2Fcore.git fix(compiler-dom): handle newlines when evaluating constants during stringification (#7995) fix #7994 --- diff --git a/packages/compiler-dom/__tests__/transforms/__snapshots__/stringifyStatic.spec.ts.snap b/packages/compiler-dom/__tests__/transforms/__snapshots__/stringifyStatic.spec.ts.snap index da24c26551..b671d3252e 100644 --- a/packages/compiler-dom/__tests__/transforms/__snapshots__/stringifyStatic.spec.ts.snap +++ b/packages/compiler-dom/__tests__/transforms/__snapshots__/stringifyStatic.spec.ts.snap @@ -52,3 +52,13 @@ return function render(_ctx, _cache) { return _hoisted_1 }" `; + +exports[`stringify static html > stringify v-text with escape 1`] = ` +"const { createElementVNode: _createElementVNode, createStaticVNode: _createStaticVNode } = Vue + +const _hoisted_1 = /*#__PURE__*/_createStaticVNode(\\"
text1<span>show-it </span>`)
expect(code).toMatchSnapshot()
})
+
+ test('stringify v-text with escape', () => {
+ const { code } = compileWithStringify(`
+
+ text1`)
+ expect(code).toMatchSnapshot()
+ })
})
diff --git a/packages/compiler-dom/src/transforms/stringifyStatic.ts b/packages/compiler-dom/src/transforms/stringifyStatic.ts
index d3f58bdb9d..0b47cb435b 100644
--- a/packages/compiler-dom/src/transforms/stringifyStatic.ts
+++ b/packages/compiler-dom/src/transforms/stringifyStatic.ts
@@ -356,7 +356,7 @@ function stringifyElement(
// (see compiler-core/src/transforms/transformExpression)
function evaluateConstant(exp: ExpressionNode): string {
if (exp.type === NodeTypes.SIMPLE_EXPRESSION) {
- return new Function(`return ${exp.content}`)()
+ return new Function(`return (${exp.content})`)()
} else {
// compound
let res = ``