This commit is contained in:
darenhsu
2022-07-17 13:16:16 +08:00
parent 84759556ff
commit befd344ab0
28070 changed files with 4008428 additions and 1 deletions
+71
View File
@@ -0,0 +1,71 @@
const utils = require('eslint-plugin-vue/lib/utils')
module.exports = Object.assign(
{
getProperty (node, name, condition) {
return node.properties.find(
p => p.type === 'Property' && name === utils.getStaticPropertyName(p.key) && condition(p)
)
},
getProperties (node, names) {
return node.properties.filter(
p => p.type === 'Property' && (!names.size || names.has(utils.getStaticPropertyName(p.key)))
)
},
getFunctionWithName (rootNode, name) {
return this.getProperty(
rootNode,
name,
item => item.value.type === 'ArrowFunctionExpression' || item.value.type === 'FunctionExpression'
)
},
isInFunction (func, child) {
if (func.value.type === 'FunctionExpression') {
if (
child &&
child.loc.start.line >= func.value.loc.start.line &&
child.loc.end.line <= func.value.loc.end.line
) {
return true
}
}
},
* getFunctionWithChild (rootNode, funcNames, childNodes) {
const funcNodes = this.getProperties(rootNode, funcNames)
for (const func of funcNodes) {
for (const { name, node: child } of childNodes) {
const funcName = utils.getStaticPropertyName(func.key)
if (!funcName) continue
if (this.isInFunction(func, child)) {
yield { name, node: child, func, funcName }
}
}
}
},
isOpenParen (token) {
return token.type === 'Punctuator' && token.value === '('
},
isCloseParen (token) {
return token.type === 'Punctuator' && token.value === ')'
},
getFirstAndLastTokens (node, sourceCode) {
let first = sourceCode.getFirstToken(node)
let last = sourceCode.getLastToken(node)
// If the value enclosed by parentheses, update the 'first' and 'last' by the parentheses.
while (true) {
const prev = sourceCode.getTokenBefore(first)
const next = sourceCode.getTokenAfter(last)
if (this.isOpenParen(prev) && this.isCloseParen(next)) {
first = prev
last = next
} else {
return { first, last }
}
}
}
},
utils
)
+21
View File
@@ -0,0 +1,21 @@
module.exports = {
__version: undefined,
get version () {
if (this.__version === undefined) {
return this.loadNuxtPkg()
}
return this.__version
},
loadPkg (pkgName) {
try {
return require(`${pkgName}/package.json`)
} catch (e) {
return {}
}
},
loadNuxtPkg () {
const { version } = this.loadPkg('nuxt') || this.loadPkg('nuxt-edge')
this.__version = version || false
return this.__version
}
}