fix(compiler-sfc): make asset url imports stringifiable
This commit is contained in:
@@ -38,6 +38,12 @@ export const enum StringifyThresholds {
|
||||
|
||||
type StringifiableNode = PlainElementNode | TextCallNode
|
||||
|
||||
/**
|
||||
* Regex for replacing placeholders for embedded constant variables
|
||||
* (e.g. import URL string constants generated by compiler-sfc)
|
||||
*/
|
||||
const expReplaceRE = /__VUE_EXP_START__(.*?)__VUE_EXP_END__/g
|
||||
|
||||
/**
|
||||
* Turn eligible hoisted static trees into stringified static nodes, e.g.
|
||||
*
|
||||
@@ -80,7 +86,7 @@ export const stringifyStatic: HoistTransform = (children, context, parent) => {
|
||||
const staticCall = createCallExpression(context.helper(CREATE_STATIC), [
|
||||
JSON.stringify(
|
||||
currentChunk.map(node => stringifyNode(node, context)).join('')
|
||||
),
|
||||
).replace(expReplaceRE, `" + $1 + "`),
|
||||
// the 2nd argument indicates the number of DOM nodes this static vnode
|
||||
// will insert / hydrate
|
||||
String(currentChunk.length)
|
||||
@@ -273,8 +279,17 @@ function stringifyElement(
|
||||
res += `="${escapeHtml(p.value.content)}"`
|
||||
}
|
||||
} else if (p.type === NodeTypes.DIRECTIVE && p.name === 'bind') {
|
||||
const exp = p.exp as SimpleExpressionNode
|
||||
if (exp.content[0] === '_') {
|
||||
// internally generated string constant references
|
||||
// e.g. imported URL strings via compiler-sfc transformAssetUrl plugin
|
||||
res += ` ${(p.arg as SimpleExpressionNode).content}="__VUE_EXP_START__${
|
||||
exp.content
|
||||
}__VUE_EXP_END__"`
|
||||
continue
|
||||
}
|
||||
// constant v-bind, e.g. :foo="1"
|
||||
let evaluated = evaluateConstant(p.exp as SimpleExpressionNode)
|
||||
let evaluated = evaluateConstant(exp)
|
||||
if (evaluated != null) {
|
||||
const arg = p.arg && (p.arg as SimpleExpressionNode).content
|
||||
if (arg === 'class') {
|
||||
|
||||
Reference in New Issue
Block a user