8000 feat(compiler-sfc): transform asset url by underfin · Pull Request #500 · vuejs/core · GitHub
[go: up one dir, main page]

Skip to content

feat(compiler-sfc): transform asset url #500

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 1, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update templateTransformAssetUrl.ts
  • Loading branch information
yyx990803 authored Dec 1, 2019
commit 7a81e335f1d49a3e467b94210a6f398e50fba3f1
15 changes: 5 additions & 10 deletions packages/compiler-sfc/src/templateTransformAssetUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,12 @@ function getImportsExpressionExp(
context: TransformContext
): ExpressionNode {
if (path) {
const index = getImportsPathIndex(path, context)
if (index > -1) {
return Array.from(context.imports).map(o => o.exp)[
index
] as ExpressionNode
const importsArray = Array.from(context.imports)
const existing = importsArray.find(i => i.path === path)
if (existing) {
return existing.exp
}
const name = `_imports_${context.imports.size}`
const name = `_imports_${importsArray.length}`
const exp = createSimpleExpression(name, false, loc, true)
context.imports.add({ exp, path })
if (hash && path) {
Expand All @@ -80,7 +79,3 @@ function getImportsExpressionExp(
return createSimpleExpression(`''`, false, loc, true)
}
}

function getImportsPathIndex(path: string, context: TransformContext): number {
return Array.from(context.imports).findIndex(o => o.path === path)
}
0