(path, options)
| 40 | } |
| 41 | |
| 42 | function expressionNeedsAsiProtection(path, options) { |
| 43 | const { node } = path; |
| 44 | switch (node.type) { |
| 45 | case "ParenthesizedExpression": |
| 46 | case "TypeCastExpression": |
| 47 | case "TSTypeAssertion": |
| 48 | case "ArrayExpression": |
| 49 | case "ArrayPattern": |
| 50 | case "TemplateLiteral": |
| 51 | case "TemplateElement": |
| 52 | case "RegExpLiteral": |
| 53 | return true; |
| 54 | |
| 55 | case "ArrowFunctionExpression": |
| 56 | if (!shouldPrintParamsWithoutParens(path, options)) { |
| 57 | return true; |
| 58 | } |
| 59 | break; |
| 60 | |
| 61 | case "UnaryExpression": { |
| 62 | const { prefix, operator } = node; |
| 63 | if (prefix && (operator === "+" || operator === "-")) { |
| 64 | return true; |
| 65 | } |
| 66 | break; |
| 67 | } |
| 68 | case "BindExpression": |
| 69 | if (!node.object) { |
| 70 | return true; |
| 71 | } |
| 72 | break; |
| 73 | |
| 74 | case "Literal": |
| 75 | if (node.regex) { |
| 76 | return true; |
| 77 | } |
| 78 | break; |
| 79 | |
| 80 | default: |
| 81 | if (isJsxElement(node)) { |
| 82 | return true; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | if (needsParentheses(path, options)) { |
| 87 | return true; |
| 88 | } |
| 89 | |
| 90 | if (!hasNakedLeftSide(node)) { |
| 91 | return false; |
| 92 | } |
| 93 | |
| 94 | return path.call( |
| 95 | () => expressionNeedsAsiProtection(path, options), |
| 96 | ...getLeftSidePathName(node), |
| 97 | ); |
| 98 | } |
| 99 |
no test coverage detected
searching dependent graphs…