|
2 | 2 | import SyntaxJSX from '@babel/plugin-syntax-jsx'
|
3 | 3 | import { parse } from '@babel/parser'
|
4 | 4 | import { isJSXElement, transformJSX } from './transform'
|
5 |
| -import type { VisitNodeFunction } from '@babel/traverse' |
| 5 | +import type { NodePath, VisitNodeFunction } from '@babel/traverse' |
6 | 6 | import type { JSXElement, JSXFragment, Node } from '@babel/types'
|
7 | 7 | import type { CompilerOptions } from '@vue-jsx-vapor/compiler'
|
8 | 8 | import type { Visitor } from '@babel/core'
|
@@ -41,7 +41,8 @@ export default (): {
|
41 | 41 | > = (path) => {
|
42 | 42 | if (
|
43 | 43 | (path.parent?.type !== 'JSXExpressionContainer' &&
|
44 |
| - !isJSXElement(path.parent)) || |
| 44 | + !isJSXElement(path.parent) && |
| 45 | + !isConditionalExpression(path.parentPath)) || |
45 | 46 | path.parentPath.parent?.type === 'JSXAttribute'
|
46 | 47 | ) {
|
47 | 48 | state.rootCodes.push(path.getSource())
|
@@ -96,3 +97,14 @@ export default (): {
|
96 | 97 | },
|
97 | 98 | }
|
98 | 99 | }
|
| 100 | + |
| 101 | +export function isConditionalExpression(path: NodePath<Node> | null): boolean { |
| 102 | + return !!( |
| 103 | + path && |
| 104 | + (path?.type === 'LogicalExpression' || |
| 105 | + path.type === 'ConditionalExpression') && |
| 106 | + (path.parent.type === 'JSXExpressionContainer' || |
| 107 | + (path.parent.type === 'ConditionalExpression' && |
| 108 | + isConditionalExpression(path.parentPath))) |
| 109 | + ) |
| 110 | +} |
0 commit comments