Skip to content

Commit

Permalink
fix(jsx): match
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon-He95 committed Mar 2, 2024
1 parent e5a2724 commit 4c16683
Showing 1 changed file with 40 additions and 18 deletions.
58 changes: 40 additions & 18 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,24 +253,46 @@ function jsxDfs(children: any, parent: any, position: vscode.Position) {
if (type === 'JSXElement' || type === 'Element' || (type === 'ReturnStatement' && (argument.type === 'JSXElement' || argument.type === 'JSXFragment')))
isInTemplate = true

if (child.children)
children = child.children
else if (type === 'ExportNamedDeclaration')
children = child.declaration
else if (type === 'ObjectExpression')
children = child.properties
else if (type === 'Property' && child.value.type === 'FunctionExpression')
children = child.value.body.body
else if (type === 'ExportDefaultDeclaration')
children = child.declaration.arguments
else if (type === 'VariableDeclaration')
children = declarations
else if (type === 'VariableDeclarator')
children = init
else if (type === 'ReturnStatement')
children = argument
else if (type === 'JSXElement')
children = child.children
if (child.children) { children = child.children }
else if (type === 'ExportNamedDeclaration') { children = child.declaration }
else if (type === 'ObjectExpression') { children = child.properties }
else if (type === 'Property' && child.value.type === 'FunctionExpression') { children = child.value.body.body }
else if (type === 'ExportDefaultDeclaration') {
if (child.declaration.type === 'FunctionDeclaration')
children = child.declaration.body.body
else
children = child.declaration.arguments
}
else if (type === 'JSXExpressionContainer') {
if (child.expression.type === 'CallExpression') { children = child.expression.arguments }
else if (child.expression.type === 'ConditionalExpression') {
children = [
child.expression.alternate,
child.expression.consequent,
].filter(Boolean)
}
else { children = child.expression }
}
else if (type === 'TemplateLiteral') {
children = child.expressions
}
else if (type === 'ConditionalExpression') {
children = [
child.alternate,
child.consequent,
].filter(Boolean)
}
else if (type === 'ArrowFunctionExpression') {
children = child.body
}
else if (type === 'VariableDeclaration') { children = declarations }
else if (type === 'VariableDeclarator') { children = init }
else if (type === 'ReturnStatement') { children = argument }
else if (type === 'JSXElement') { children = child.children }
else if (type === 'ExportNamedDeclaration') { children = child.declaration.body }
else if (type === 'CallExpression') {
children = child.arguments
}
if (children && !Array.isArray(children))
children = [children]

Expand Down

0 comments on commit 4c16683

Please sign in to comment.