From deca18fe59657bd217aa55bfc343fbde0674cad3 Mon Sep 17 00:00:00 2001
From: likui <2218301630@qq.com>
Date: Mon, 25 May 2020 18:15:22 +0800
Subject: [PATCH 1/3] fix(compiler-dom): should bail hoisted on break content
with innerHTML (eg.tables related tags)
---
.../__tests__/transforms/stringifyStatic.spec.ts | 14 ++++++++++++++
.../compiler-dom/src/transforms/stringifyStatic.ts | 11 ++++++++++-
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts b/packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts
index b4d96605c0b..912e55582a3 100644
--- a/packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts
+++ b/packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts
@@ -225,4 +225,18 @@ describe('stringify static html', () => {
type: NodeTypes.VNODE_CALL // not CALL_EXPRESSION
})
})
+
+ // https://github.com/vitejs/vite/issues/226
+ test('should bail on break content with innerHTML (eg.tables related tags)', () => {
+ const { ast } = compileWithStringify(
+ `
${repeat(
+ `
foo
`,
+ StringifyThresholds.ELEMENT_WITH_BINDING_COUNT
+ )} `
+ )
+ expect(ast.hoists.length).toBe(1)
+ expect(ast.hoists[0]).toMatchObject({
+ type: NodeTypes.VNODE_CALL // not CALL_EXPRESSION
+ })
+ })
})
diff --git a/packages/compiler-dom/src/transforms/stringifyStatic.ts b/packages/compiler-dom/src/transforms/stringifyStatic.ts
index a354dc2cdd9..c1a80f0e842 100644
--- a/packages/compiler-dom/src/transforms/stringifyStatic.ts
+++ b/packages/compiler-dom/src/transforms/stringifyStatic.ts
@@ -25,7 +25,8 @@ import {
toDisplayString,
normalizeClass,
normalizeStyle,
- stringifyStyle
+ stringifyStyle,
+ makeMap
} from '@vue/shared'
export const enum StringifyThresholds {
@@ -59,6 +60,12 @@ type StringifiableNode = PlainElementNode | TextCallNode
* This optimization is only performed in Node.js.
*/
export const stringifyStatic: HoistTransform = (children, context) => {
+ if (
+ context.parent!.type === NodeTypes.ELEMENT &&
+ canNotStringifiableTag((context.parent as PlainElementNode).tag)
+ ) {
+ return
+ }
let nc = 0 // current node count
let ec = 0 // current element with binding count
const currentChunk: StringifiableNode[] = []
@@ -136,6 +143,8 @@ const isStringifiableAttr = (name: string) => {
return isKnownAttr(name) || dataAriaRE.test(name)
}
+const canNotStringifiableTag = makeMap('p,table,thead,tr,th,tbody,td,colspan')
+
const replaceHoist = (
node: StringifiableNode,
replacement: JSChildNode | null,
From 9e8257bd471e3c9a3bcaf53ceaa683e224640d1a Mon Sep 17 00:00:00 2001
From: Evan You
Date: Tue, 9 Jun 2020 16:29:32 -0400
Subject: [PATCH 2/3] Update stringifyStatic.spec.ts
---
.../transforms/stringifyStatic.spec.ts | 22 +++++++++----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts b/packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts
index e7029e1b898..0ff9fc7c627 100644
--- a/packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts
+++ b/packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts
@@ -237,6 +237,17 @@ describe('stringify static html', () => {
expect(ast.hoists[0]).toMatchObject({
type: NodeTypes.VNODE_CALL // not CALL_EXPRESSION
})
+
+ const { ast: ast2 } = compileWithStringify(
+ ``
+ )
+ expect(ast2.hoists.length).toBe(1)
+ expect(ast2.hoists[0]).toMatchObject({
+ type: NodeTypes.VNODE_CALL // not CALL_EXPRESSION
+ })
})
// https://github.com/vitejs/vite/issues/226
@@ -251,16 +262,5 @@ describe('stringify static html', () => {
expect(ast.hoists[0]).toMatchObject({
type: NodeTypes.VNODE_CALL // not CALL_EXPRESSION
})
-
- const { ast: ast2 } = compileWithStringify(
- ``
- )
- expect(ast2.hoists.length).toBe(1)
- expect(ast2.hoists[0]).toMatchObject({
- type: NodeTypes.VNODE_CALL // not CALL_EXPRESSION
- })
})
})
From e616998324e2687cbad2a4be77dd11b729a3d0fc Mon Sep 17 00:00:00 2001
From: Evan You
Date: Tue, 9 Jun 2020 16:29:52 -0400
Subject: [PATCH 3/3] Update stringifyStatic.spec.ts
---
.../compiler-dom/__tests__/transforms/stringifyStatic.spec.ts | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts b/packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts
index 0ff9fc7c627..adc10f9becf 100644
--- a/packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts
+++ b/packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts
@@ -225,7 +225,7 @@ describe('stringify static html', () => {
type: NodeTypes.VNODE_CALL // not CALL_EXPRESSION
})
})
-
+
test('should bail on non attribute bindings', () => {
const { ast } = compileWithStringify(
`${repeat(
@@ -237,7 +237,7 @@ describe('stringify static html', () => {
expect(ast.hoists[0]).toMatchObject({
type: NodeTypes.VNODE_CALL // not CALL_EXPRESSION
})
-
+
const { ast: ast2 } = compileWithStringify(
`