Skip to content

Commit

Permalink
chore: only set slotted flag on sfc descriptor if style is scoped
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Mar 5, 2021
1 parent ff4d4ec commit 540e26f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 6 additions & 4 deletions packages/compiler-sfc/__tests__/parse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,14 @@ h1 { color: red }
.slotted
).toBe(false)
expect(
parse(`<template>hi</template><style>:slotted(h1){color:red;}</style>`)
.descriptor.slotted
parse(
`<template>hi</template><style scoped>:slotted(h1){color:red;}</style>`
).descriptor.slotted
).toBe(true)
expect(
parse(`<template>hi</template><style>::v-slotted(h1){color:red;}</style>`)
.descriptor.slotted
parse(
`<template>hi</template><style scoped>::v-slotted(h1){color:red;}</style>`
).descriptor.slotted
).toBe(true)
})

Expand Down
4 changes: 3 additions & 1 deletion packages/compiler-sfc/src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ export function parse(

// check if the SFC uses :slotted
const slottedRE = /(?:::v-|:)slotted\(/
descriptor.slotted = descriptor.styles.some(s => slottedRE.test(s.content))
descriptor.slotted = descriptor.styles.some(
s => s.scoped && slottedRE.test(s.content)
)

const result = {
descriptor,
Expand Down

0 comments on commit 540e26f

Please sign in to comment.