fix(compiler-ssr): avoid duplicated asset imports merged from component slot client branch
fix vitejs/vite#2034
This commit is contained in:
@@ -153,19 +153,18 @@ function getImportsExpressionExp(
|
||||
context: TransformContext
|
||||
): ExpressionNode {
|
||||
if (path) {
|
||||
const importsArray = Array.from(context.imports)
|
||||
const existing = importsArray.find(i => i.path === path)
|
||||
const existing = context.imports.find(i => i.path === path)
|
||||
if (existing) {
|
||||
return existing.exp as ExpressionNode
|
||||
}
|
||||
const name = `_imports_${importsArray.length}`
|
||||
const name = `_imports_${context.imports.length}`
|
||||
const exp = createSimpleExpression(
|
||||
name,
|
||||
false,
|
||||
loc,
|
||||
ConstantTypes.CAN_HOIST
|
||||
)
|
||||
context.imports.add({ exp, path })
|
||||
context.imports.push({ exp, path })
|
||||
if (hash && path) {
|
||||
return context.hoist(
|
||||
createSimpleExpression(
|
||||
|
||||
@@ -99,8 +99,7 @@ export const transformSrcset: NodeTransform = (
|
||||
const { path } = parseUrl(url)
|
||||
let exp: SimpleExpressionNode
|
||||
if (path) {
|
||||
const importsArray = Array.from(context.imports)
|
||||
const existingImportsIndex = importsArray.findIndex(
|
||||
const existingImportsIndex = context.imports.findIndex(
|
||||
i => i.path === path
|
||||
)
|
||||
if (existingImportsIndex > -1) {
|
||||
@@ -112,12 +111,12 @@ export const transformSrcset: NodeTransform = (
|
||||
)
|
||||
} else {
|
||||
exp = createSimpleExpression(
|
||||
`_imports_${importsArray.length}`,
|
||||
`_imports_${context.imports.length}`,
|
||||
false,
|
||||
attr.loc,
|
||||
ConstantTypes.CAN_HOIST
|
||||
)
|
||||
context.imports.add({ exp, path })
|
||||
context.imports.push({ exp, path })
|
||||
}
|
||||
compoundExpression.children.push(exp)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user