Skip to content

Commit

Permalink
fix(compiler-sfc): vuejs#4581 getImportsExpressionExp with hash
Browse files Browse the repository at this point in the history
Subsequent calls with an url already in the import cache
and with a hash returns the correct expression including each time the
hash if one.
  • Loading branch information
hl037 committed Sep 14, 2021
1 parent a6e5f82 commit a53dff4
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions packages/compiler-sfc/src/templateTransformAssetUrl.ts
Expand Up @@ -2,6 +2,7 @@ import path from 'path'
import {
ConstantTypes,
createSimpleExpression,
SimpleExpressionNode,
ExpressionNode,
NodeTransform,
NodeTypes,
Expand Down Expand Up @@ -154,17 +155,17 @@ function getImportsExpressionExp(
): ExpressionNode {
if (path) {
const existing = context.imports.find(i => i.path === path)
let exp: SimpleExpressionNode
let name: string
if (existing) {
return existing.exp as ExpressionNode
exp = existing.exp as SimpleExpressionNode
name = exp.content
} else {
name = `_imports_${context.imports.length}`
exp = createSimpleExpression(name, false, loc, ConstantTypes.CAN_HOIST)
context.imports.push({ exp, path })
}
const name = `_imports_${context.imports.length}`
const exp = createSimpleExpression(
name,
false,
loc,
ConstantTypes.CAN_HOIST
)
context.imports.push({ exp, path })

if (hash && path) {
return context.hoist(
createSimpleExpression(
Expand Down

0 comments on commit a53dff4

Please sign in to comment.