Skip to content

Commit a938b61

Browse files
committed
fix(compiler-dom): bail stringification on table elements
close #1230, close #1268
1 parent 64ec8bf commit a938b61

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

packages/compiler-dom/src/transforms/stringifyStatic.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ import {
2525
toDisplayString,
2626
normalizeClass,
2727
normalizeStyle,
28-
stringifyStyle
28+
stringifyStyle,
29+
makeMap
2930
} from '@vue/shared'
3031

3132
export const enum StringifyThresholds {
@@ -145,6 +146,8 @@ const replaceHoist = (
145146
context.hoists[context.hoists.indexOf(hoistToReplace)] = replacement
146147
}
147148

149+
const isNonStringifiable = /*#__PURE__*/ makeMap(`thead,tr,th,tbody,td`)
150+
148151
/**
149152
* for a hoisted node, analyze it and return:
150153
* - false: bailed (contains runtime constant)
@@ -153,6 +156,10 @@ const replaceHoist = (
153156
* - ec is the number of element with bindings inside
154157
*/
155158
function analyzeNode(node: StringifiableNode): [number, number] | false {
159+
if (node.type === NodeTypes.ELEMENT && isNonStringifiable(node.tag)) {
160+
return false
161+
}
162+
156163
if (node.type === NodeTypes.TEXT_CALL) {
157164
return [1, 0]
158165
}

packages/shared/src/makeMap.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
// Make a map and return a function for checking if a key
2-
// is in that map.
3-
//
4-
// IMPORTANT: all calls of this function must be prefixed with /*#__PURE__*/
5-
// So that rollup can tree-shake them if necessary.
1+
/**
2+
* Make a map and return a function for checking if a key
3+
* is in that map.
4+
* IMPORTANT: all calls of this function must be prefixed with
5+
* \/\*#\_\_PURE\_\_\*\/
6+
* So that rollup can tree-shake them if necessary.
7+
*/
68
export function makeMap(
79
str: string,
810
expectsLowerCase?: boolean

0 commit comments

Comments
 (0)