first commit
This commit is contained in:
62
app_vue/node_modules/eslint-plugin-vue/lib/utils/style-variables/index.js
generated
vendored
Normal file
62
app_vue/node_modules/eslint-plugin-vue/lib/utils/style-variables/index.js
generated
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
const { isVElement } = require('..')
|
||||
|
||||
class StyleVariablesContext {
|
||||
/**
|
||||
* @param {RuleContext} context
|
||||
* @param {VElement[]} styles
|
||||
*/
|
||||
constructor(context, styles) {
|
||||
this.context = context
|
||||
this.styles = styles
|
||||
/** @type {VReference[]} */
|
||||
this.references = []
|
||||
/** @type {VExpressionContainer[]} */
|
||||
this.vBinds = []
|
||||
for (const style of styles) {
|
||||
for (const node of style.children) {
|
||||
if (node.type === 'VExpressionContainer') {
|
||||
this.vBinds.push(node)
|
||||
for (const ref of node.references.filter(
|
||||
(ref) => ref.variable == null
|
||||
)) {
|
||||
this.references.push(ref)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getStyleVariablesContext,
|
||||
StyleVariablesContext
|
||||
}
|
||||
|
||||
/** @type {WeakMap<VElement, StyleVariablesContext>} */
|
||||
const cache = new WeakMap()
|
||||
/**
|
||||
* 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
|
||||
}
|
Reference in New Issue
Block a user