diff --git a/packages/compiler-sfc/__tests__/__snapshots__/templateTransformSrcset.spec.ts.snap b/packages/compiler-sfc/__tests__/__snapshots__/templateTransformSrcset.spec.ts.snap
index 2f057279..377d6a38 100644
--- a/packages/compiler-sfc/__tests__/__snapshots__/templateTransformSrcset.spec.ts.snap
+++ b/packages/compiler-sfc/__tests__/__snapshots__/templateTransformSrcset.spec.ts.snap
@@ -16,6 +16,10 @@ const _hoisted_8 = \\"/logo.png\\" + ', ' + _imports_0 + '2x'
export function render(_ctx, _cache) {
return (_openBlock(), _createBlock(_Fragment, null, [
+ _createVNode(\\"img\\", {
+ src: \\"./logo.png\\",
+ srcset: \\"\\"
+ }),
_createVNode(\\"img\\", {
src: \\"./logo.png\\",
srcset: _hoisted_1
@@ -69,6 +73,10 @@ exports[`compiler sfc: transform srcset transform srcset w/ base 1`] = `
export function render(_ctx, _cache) {
return (_openBlock(), _createBlock(_Fragment, null, [
+ _createVNode(\\"img\\", {
+ src: \\"./logo.png\\",
+ srcset: \\"\\"
+ }),
_createVNode(\\"img\\", {
src: \\"./logo.png\\",
srcset: \\"/foo/logo.png\\"
@@ -137,6 +145,10 @@ const _hoisted_11 = \\"data:image/png;base64,i\\" + '1x, ' + \\"data:image/png;b
export function render(_ctx, _cache) {
return (_openBlock(), _createBlock(_Fragment, null, [
+ _createVNode(\\"img\\", {
+ src: \\"./logo.png\\",
+ srcset: \\"\\"
+ }),
_createVNode(\\"img\\", {
src: \\"./logo.png\\",
srcset: _hoisted_1
diff --git a/packages/compiler-sfc/__tests__/templateTransformSrcset.spec.ts b/packages/compiler-sfc/__tests__/templateTransformSrcset.spec.ts
index 0874d311..465ca567 100644
--- a/packages/compiler-sfc/__tests__/templateTransformSrcset.spec.ts
+++ b/packages/compiler-sfc/__tests__/templateTransformSrcset.spec.ts
@@ -25,6 +25,7 @@ function compileWithSrcset(template: string, options?: AssetURLOptions) {
}
const src = `
+
diff --git a/packages/compiler-sfc/src/templateTransformSrcset.ts b/packages/compiler-sfc/src/templateTransformSrcset.ts
index a667d984..0018c479 100644
--- a/packages/compiler-sfc/src/templateTransformSrcset.ts
+++ b/packages/compiler-sfc/src/templateTransformSrcset.ts
@@ -46,7 +46,7 @@ export const transformSrcset: NodeTransform = (
if (attr.name === 'srcset' && attr.type === NodeTypes.ATTRIBUTE) {
if (!attr.value) return
const value = attr.value.content
-
+ if (!value) return
const imageCandidates: ImageCandidate[] = value.split(',').map(s => {
// The attribute value arrives here with all whitespace, except
// normal spaces, represented by escape sequences