Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update
vue/no-unused-properties
and vue/script-setup-uses-vars
ru…
…le to support style CSS vars
- Loading branch information
Showing
5 changed files
with
151 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
const { isVElement } = require('..') | ||
|
||
module.exports = { | ||
getStyleVariablesContext | ||
} | ||
|
||
class StyleVariablesContext { | ||
/** | ||
* @param {RuleContext} context | ||
* @param {VElement[]} styles | ||
*/ | ||
constructor(context, styles) { | ||
this.context = context | ||
this.styles = styles | ||
/** @type {VReference[]} */ | ||
this.references = [] | ||
for (const style of styles) { | ||
for (const node of style.children) { | ||
if (node.type === 'VExpressionContainer') { | ||
for (const ref of node.references.filter( | ||
(ref) => ref.variable == null | ||
)) { | ||
this.references.push(ref) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** @type {Map<VElement, StyleVariablesContext} */ | ||
const cache = new Map() | ||
/** | ||
* Get the style vars context | ||
* @param {RuleContext} context | ||
* @returns {StyleVariablesContext | null} | ||
*/ | ||
function getStyleVariablesContext(context) { | ||
const df = | ||
context.parserServices.getDocumentFragment && | ||
context.parserServices.getDocumentFragment() | ||
if (!df) { | ||
return null | ||
} | ||
const styles = df.children | ||
.filter(isVElement) | ||
.filter((e) => e.name === 'style') | ||
if (!styles.length) { | ||
return null | ||
} | ||
let ctx = cache.get(styles[0]) | ||
if (ctx) { | ||
return ctx | ||
} | ||
ctx = new StyleVariablesContext(context, styles) | ||
cache.set(styles[0], ctx) | ||
return ctx | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters