fix(compiler-sfc): make asset url imports stringifiable

This commit is contained in:
Evan You
2021-12-06 01:19:06 +08:00
parent 3e5ed6c1fc
commit 87c73e99d6
7 changed files with 136 additions and 16 deletions

View File

@@ -162,7 +162,12 @@ function getImportsExpressionExp(
exp = context.imports[existingIndex].exp as SimpleExpressionNode
} else {
name = `_imports_${context.imports.length}`
exp = createSimpleExpression(name, false, loc, ConstantTypes.CAN_HOIST)
exp = createSimpleExpression(
name,
false,
loc,
ConstantTypes.CAN_STRINGIFY
)
context.imports.push({ exp, path })
}
@@ -184,13 +189,13 @@ function getImportsExpressionExp(
`_hoisted_${existingHoistIndex + 1}`,
false,
loc,
ConstantTypes.CAN_HOIST
ConstantTypes.CAN_STRINGIFY
)
}
return context.hoist(
createSimpleExpression(hashExp, false, loc, ConstantTypes.CAN_HOIST)
createSimpleExpression(hashExp, false, loc, ConstantTypes.CAN_STRINGIFY)
)
} else {
return createSimpleExpression(`''`, false, loc, ConstantTypes.CAN_HOIST)
return createSimpleExpression(`''`, false, loc, ConstantTypes.CAN_STRINGIFY)
}
}

View File

@@ -113,14 +113,14 @@ export const transformSrcset: NodeTransform = (
`_imports_${existingImportsIndex}`,
false,
attr.loc,
ConstantTypes.CAN_HOIST
ConstantTypes.CAN_STRINGIFY
)
} else {
exp = createSimpleExpression(
`_imports_${context.imports.length}`,
false,
attr.loc,
ConstantTypes.CAN_HOIST
ConstantTypes.CAN_STRINGIFY
)
context.imports.push({ exp, path })
}
@@ -131,7 +131,7 @@ export const transformSrcset: NodeTransform = (
`"${url}"`,
false,
attr.loc,
ConstantTypes.CAN_HOIST
ConstantTypes.CAN_STRINGIFY
)
compoundExpression.children.push(exp)
}
@@ -146,7 +146,7 @@ export const transformSrcset: NodeTransform = (
})
const hoisted = context.hoist(compoundExpression)
hoisted.constType = ConstantTypes.CAN_HOIST
hoisted.constType = ConstantTypes.CAN_STRINGIFY
node.props[index] = {
type: NodeTypes.DIRECTIVE,