Skip to content

Commit

Permalink
fix(compiler-sfc): expose src on custom blocks as well
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jun 17, 2022
1 parent 8f5817a commit cdfc4c1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 5 additions & 3 deletions packages/compiler-sfc/src/parseComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ export function parseComponent(
return cumulated
}, {})
}

if (typeof currentBlock.attrs.src === 'string') {
currentBlock.src = currentBlock.attrs.src
}

if (isSpecialTag(tag)) {
checkAttrs(currentBlock, attrs)
if (tag === 'script') {
Expand Down Expand Up @@ -162,9 +167,6 @@ export function parseComponent(
if (attr.name === 'module') {
block.module = attr.value || true
}
if (attr.name === 'src') {
block.src = attr.value
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion packages/compiler-sfc/test/parseComponent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,11 @@ describe('Single File Component parser', () => {
}))
}
</test>
<custom src="./x.json"></custom>
`,
{ deindent: true }
)
expect(res.customBlocks.length).toBe(3)
expect(res.customBlocks.length).toBe(4)

const simpleExample = res.customBlocks[0]
expect(simpleExample.type).toBe('example')
Expand Down Expand Up @@ -233,6 +234,9 @@ describe('Single File Component parser', () => {
}`)
expect(simpleTest.attrs.name).toBe('simple')
expect(simpleTest.attrs.foo).toBe('bar')

const customWithSrc = res.customBlocks[3]
expect(customWithSrc.src).toBe('./x.json')
})

// Regression #4289
Expand Down

0 comments on commit cdfc4c1

Please sign in to comment.