fix(ssr): should not hoist transformed asset urls in ssr compile

fix #3874
This commit is contained in:
Evan You
2022-05-11 12:43:44 +08:00
parent fec12d7dcc
commit 57bb37bd64
8 changed files with 277 additions and 154 deletions

View File

@@ -176,6 +176,17 @@ function getImportsExpressionExp(
}
const hashExp = `${name} + '${hash}'`
const finalExp = createSimpleExpression(
hashExp,
false,
loc,
ConstantTypes.CAN_STRINGIFY
)
if (!context.hoistStatic) {
return finalExp
}
const existingHoistIndex = context.hoists.findIndex(h => {
return (
h &&
@@ -192,9 +203,7 @@ function getImportsExpressionExp(
ConstantTypes.CAN_STRINGIFY
)
}
return context.hoist(
createSimpleExpression(hashExp, false, loc, ConstantTypes.CAN_STRINGIFY)
)
return context.hoist(finalExp)
} else {
return createSimpleExpression(`''`, false, loc, ConstantTypes.CAN_STRINGIFY)
}

View File

@@ -3,6 +3,7 @@ import {
ConstantTypes,
createCompoundExpression,
createSimpleExpression,
ExpressionNode,
NodeTransform,
NodeTypes,
SimpleExpressionNode
@@ -145,14 +146,17 @@ export const transformSrcset: NodeTransform = (
}
})
const hoisted = context.hoist(compoundExpression)
hoisted.constType = ConstantTypes.CAN_STRINGIFY
let exp: ExpressionNode = compoundExpression
if (context.hoistStatic) {
exp = context.hoist(compoundExpression)
exp.constType = ConstantTypes.CAN_STRINGIFY
}
node.props[index] = {
type: NodeTypes.DIRECTIVE,
name: 'bind',
arg: createSimpleExpression('srcset', true, attr.loc),
exp: hoisted,
exp,
modifiers: [],
loc: attr.loc
}