]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-dom): handle newlines when evaluating constants during stringification...
author白雾三语 <32354856+baiwusanyu-c@users.noreply.github.com>
Fri, 31 Mar 2023 08:33:00 +0000 (16:33 +0800)
committerGitHub <noreply@github.com>
Fri, 31 Mar 2023 08:33:00 +0000 (16:33 +0800)
fix #7994

packages/compiler-dom/__tests__/transforms/__snapshots__/stringifyStatic.spec.ts.snap
packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts
packages/compiler-dom/src/transforms/stringifyStatic.ts

index da24c26551ee34ee8ea598be6cd795dca99f343e..b671d3252e534677b289299b2d577fd777858a48 100644 (file)
@@ -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(\\"<pre data-type=\\\\\\"js\\\\\\"><code>text1</code></pre><div class><span class>1</span><span class>2</span></div>\\", 2)
+
+return function render(_ctx, _cache) {
+  return _hoisted_1
+}"
+`;
index bedec9fc00a9b8ba163fb489a69f57cc2d007202..85efeafb8c9d20b631bf797507629069e7d902de 100644 (file)
@@ -477,4 +477,15 @@ describe('stringify static html', () => {
     expect(code).toMatch(`<code>&lt;span&gt;show-it &lt;/span&gt;</code>`)
     expect(code).toMatchSnapshot()
   })
+
+  test('stringify v-text with escape', () => {
+    const { code } = compileWithStringify(`
+      <pre  data-type="js"><code v-text="
+                \`text1\`"></code></pre>
+      <div class>
+        <span class>1</span><span class>2</span>
+      </div>`)
+    expect(code).toMatch(`<code>text1</code>`)
+    expect(code).toMatchSnapshot()
+  })
 })
index d3f58bdb9dae75ce315381615e5f32710782a7fe..0b47cb435b01eedf26fd1e56499ef00ece9a1682 100644 (file)
@@ -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 = ``