Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
refactor: use isStaticArgOf
  • Loading branch information
yyx990803 committed May 1, 2024
commit 8a9c50eeb6775edefd89421f57d20931b4b00eea
15 changes: 7 additions & 8 deletions packages/compiler-dom/src/transforms/stringifyStatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
type TextCallNode,
type TransformContext,
createCallExpression,
isStaticArgOf,
} from '@vue/compiler-core'
import {
escapeHtml,
Expand Down Expand Up @@ -200,6 +201,7 @@ function analyzeNode(node: StringifiableNode): [number, number] | false {
// probably only need to check for most common case
// i.e. non-phrasing-content tags inside `<p>`
function walk(node: ElementNode): boolean {
const isOptionTag = node.tag === 'option' && node.ns === Namespaces.HTML
for (let i = 0; i < node.props.length; i++) {
const p = node.props[i]
// bail on non-attr bindings
Expand All @@ -225,18 +227,15 @@ function analyzeNode(node: StringifiableNode): [number, number] | false {
) {
return bail()
}
// <option :value="1"> cannot be safely stringified
if (
p.arg &&
p.arg.isStatic &&
isOptionTag &&
isStaticArgOf(p.arg, 'value') &&
p.exp &&
p.exp.ast &&
p.exp.ast.type !== 'StringLiteral' &&
node.ns === Namespaces.HTML
p.exp.ast.type !== 'StringLiteral'
) {
// <option :value="1"> cannot be safely stringified
if (node.tag === 'option' && p.arg.content === 'value') {
return bail()
}
return bail()
}
}
}
Expand Down