Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = (tree, position) => {
const babylonPos = positionUtils.vsCodeToBabylon(position)
let currentToken
let currentTokenLength = tree.program.end
try {
traverse.cheap(tree.program, (node) => {
const {start, end} = node.loc
if (start.line === babylonPos.line && start.column < babylonPos.column && end.column >= babylonPos.column) {
const nodeLength = node.end - node.start
if (nodeLength < currentTokenLength) {
currentToken = node
currentTokenLength = nodeLength
}
}
})
} catch (err) {
// current text in the editor might not be parseable, but this is not an error we'd need to throw outside of this function
}
return currentToken
}
module.exports = (tree, documentOffset) => {
let currentNode
let paramsNodes = []
let attributeNamesNodes = []
let propertyNodes = []
try {
traverse.cheap(tree.program, (node, parent) => {
const { start, end, params, attributes, property, properties } = node
if (start <= documentOffset && end >= documentOffset) {
if (params) {
paramsNodes = paramsNodes.concat(params)
}
if (attributes) {
attributeNamesNodes = attributeNamesNodes.concat(
attributes.map(({ name }) => name)
)
}
if (property) {
propertyNodes.push(property)
}
if (properties) {
propertyNodes = propertyNodes.concat(properties.map(({ key }) => key))
}