Skip to content
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

fix(compiler-sfc): Show location of >>> / /deep/ in the ...combinators have been deprecated message #8596

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion packages/compiler-sfc/src/compileStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export function doCompileStyle(
plugins.push(trimPlugin())
}
if (scoped) {
plugins.push(scopedPlugin(longId))
plugins.push(scopedPlugin({ id: longId, filename: filename }))
}
let cssModules: Record<string, string> | undefined
if (modules) {
Expand Down
29 changes: 20 additions & 9 deletions packages/compiler-sfc/src/style/pluginScoped.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ import { warn } from '../warn'

const animationNameRE = /^(-\w+-)?animation-name$/
const animationRE = /^(-\w+-)?animation$/
type pluginParam = { id: string; filename?: string }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type names usually begin with uppercase letters.


const scopedPlugin: PluginCreator<string> = (id = '') => {
const scopedPlugin: PluginCreator<pluginParam> = (
params: pluginParam | undefined
) => {
const keyframes = Object.create(null)
const shortId = id.replace(/^data-v-/, '')
const shortId = params!.id.replace(/^data-v-/, '')

return {
postcssPlugin: 'vue-sfc-scoped',
Rule(rule) {
processRule(id, rule)
processRule(params!.id, rule, params!.filename)
},
AtRule(node) {
if (
Expand Down Expand Up @@ -61,7 +64,7 @@ const scopedPlugin: PluginCreator<string> = (id = '') => {

const processedRules = new WeakSet<Rule>()

function processRule(id: string, rule: Rule) {
function processRule(id: string, rule: Rule, filename = '') {
if (
processedRules.has(rule) ||
(rule.parent &&
Expand All @@ -73,7 +76,7 @@ function processRule(id: string, rule: Rule) {
processedRules.add(rule)
rule.selector = selectorParser(selectorRoot => {
selectorRoot.each(selector => {
rewriteSelector(id, selector, selectorRoot)
rewriteSelector(id, selector, selectorRoot, filename)
})
}).processSync(rule.selector)
}
Expand All @@ -82,22 +85,24 @@ function rewriteSelector(
id: string,
selector: selectorParser.Selector,
selectorRoot: selectorParser.Root,
filename = '',
slotted = false
) {
let node: selectorParser.Node | null = null
let shouldInject = true
// find the last child node to insert attribute selector
selector.each(n => {
// DEPRECATED ">>>" and "/deep/" combinator

if (
n.type === 'combinator' &&
(n.value === '>>>' || n.value === '/deep/')
) {
n.value = ' '
n.spaces.before = n.spaces.after = ''
warn(
`the >>> and /deep/ combinators have been deprecated. ` +
`Use :deep() instead.`
`the >>> and /deep/ combinators have been deprecated. ` +
`Use :deep() instead.(${filename}(${n.source?.start?.line} : ${n.source?.start?.column}))`
Comment on lines +104 to +105
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spacing of this message seems a bit off, as does the nested bracketing. I also wonder whether the column is really that useful in this context. Perhaps something like this instead?

Suggested change
`the >>> and /deep/ combinators have been deprecated. ` +
`Use :deep() instead.(${filename}(${n.source?.start?.line} : ${n.source?.start?.column}))`
`the >>> and /deep/ combinators have been deprecated. ` +
`Use :deep() instead. Line ${n.source?.start?.line}, ${filename}`,

)
return false
}
Expand Down Expand Up @@ -131,7 +136,7 @@ function rewriteSelector(
// .foo ::v-deep .bar -> .foo[xxxxxxx] .bar
warn(
`${value} usage as a combinator has been deprecated. ` +
`Use :deep(<inner-selector>) instead of ${value} <inner-selector>.`
`Use :deep(<inner-selector>) instead of ${value} <inner-selector>.(${filename}(${n.source?.start?.line} : ${n.source?.start?.column}))`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the other message, perhaps something like this?

Suggested change
`Use :deep(<inner-selector>) instead of ${value} <inner-selector>.(${filename}(${n.source?.start?.line} : ${n.source?.start?.column}))`
`Use :deep(<inner-selector>) instead of ${value} <inner-selector>. Line ${n.source?.start?.line}, ${filename}`,

)

const prev = selector.at(selector.index(n) - 1)
Expand All @@ -147,7 +152,13 @@ function rewriteSelector(
// instead.
// ::v-slotted(.foo) -> .foo[xxxxxxx-s]
if (value === ':slotted' || value === '::v-slotted') {
rewriteSelector(id, n.nodes[0], selectorRoot, true /* slotted */)
rewriteSelector(
id,
n.nodes[0],
selectorRoot,
filename,
true /* slotted */
)
let last: selectorParser.Selector['nodes'][0] = n
n.nodes[0].each(ss => {
selector.insertAfter(last, ss)
Expand Down