Skip to content

Commit cdfc4c1

Browse files
committed
fix(compiler-sfc): expose src on custom blocks as well
1 parent 8f5817a commit cdfc4c1

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

packages/compiler-sfc/src/parseComponent.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ export function parseComponent(
125125
return cumulated
126126
}, {})
127127
}
128+
129+
if (typeof currentBlock.attrs.src === 'string') {
130+
currentBlock.src = currentBlock.attrs.src
131+
}
132+
128133
if (isSpecialTag(tag)) {
129134
checkAttrs(currentBlock, attrs)
130135
if (tag === 'script') {
@@ -162,9 +167,6 @@ export function parseComponent(
162167
if (attr.name === 'module') {
163168
block.module = attr.value || true
164169
}
165-
if (attr.name === 'src') {
166-
block.src = attr.value
167-
}
168170
}
169171
}
170172

packages/compiler-sfc/test/parseComponent.spec.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,11 @@ describe('Single File Component parser', () => {
202202
}))
203203
}
204204
</test>
205+
<custom src="./x.json"></custom>
205206
`,
206207
{ deindent: true }
207208
)
208-
expect(res.customBlocks.length).toBe(3)
209+
expect(res.customBlocks.length).toBe(4)
209210

210211
const simpleExample = res.customBlocks[0]
211212
expect(simpleExample.type).toBe('example')
@@ -233,6 +234,9 @@ describe('Single File Component parser', () => {
233234
}`)
234235
expect(simpleTest.attrs.name).toBe('simple')
235236
expect(simpleTest.attrs.foo).toBe('bar')
237+
238+
const customWithSrc = res.customBlocks[3]
239+
expect(customWithSrc.src).toBe('./x.json')
236240
})
237241

238242
// Regression #4289

0 commit comments

Comments
 (0)