Skip to content

Commit

Permalink
fix(compiler-dom): bail stringification on table elements
Browse files Browse the repository at this point in the history
close #1230, close #1268
  • Loading branch information
yyx990803 committed Jun 9, 2020
1 parent 64ec8bf commit a938b61
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
9 changes: 8 additions & 1 deletion packages/compiler-dom/src/transforms/stringifyStatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import {
toDisplayString,
normalizeClass,
normalizeStyle,
stringifyStyle
stringifyStyle,
makeMap
} from '@vue/shared'

export const enum StringifyThresholds {
Expand Down Expand Up @@ -145,6 +146,8 @@ const replaceHoist = (
context.hoists[context.hoists.indexOf(hoistToReplace)] = replacement
}

const isNonStringifiable = /*#__PURE__*/ makeMap(`thead,tr,th,tbody,td`)

/**
* for a hoisted node, analyze it and return:
* - false: bailed (contains runtime constant)
Expand All @@ -153,6 +156,10 @@ const replaceHoist = (
* - ec is the number of element with bindings inside
*/
function analyzeNode(node: StringifiableNode): [number, number] | false {
if (node.type === NodeTypes.ELEMENT && isNonStringifiable(node.tag)) {
return false
}

if (node.type === NodeTypes.TEXT_CALL) {
return [1, 0]
}
Expand Down
12 changes: 7 additions & 5 deletions packages/shared/src/makeMap.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Make a map and return a function for checking if a key
// is in that map.
//
// IMPORTANT: all calls of this function must be prefixed with /*#__PURE__*/
// So that rollup can tree-shake them if necessary.
/**
* Make a map and return a function for checking if a key
* is in that map.
* IMPORTANT: all calls of this function must be prefixed with
* \/\*#\_\_PURE\_\_\*\/
* So that rollup can tree-shake them if necessary.
*/
export function makeMap(
str: string,
expectsLowerCase?: boolean
Expand Down

0 comments on commit a938b61

Please sign in to comment.