* Check if a plugin already exists in the array expression
( code: string, node: Node, importName: string, displayName: string, pluginType: string, )
| 82 | * Check if a plugin already exists in the array expression |
| 83 | */ |
| 84 | function pluginExists( |
| 85 | code: string, |
| 86 | node: Node, |
| 87 | importName: string, |
| 88 | displayName: string, |
| 89 | pluginType: string, |
| 90 | ): boolean { |
| 91 | if (node.type !== 'ArrayExpression') return false |
| 92 | |
| 93 | for (const element of node.elements) { |
| 94 | if (!element) continue |
| 95 | |
| 96 | if (pluginType === 'function') { |
| 97 | if ( |
| 98 | element.type === 'CallExpression' && |
| 99 | element.callee.type === 'Identifier' && |
| 100 | element.callee.name === importName |
| 101 | ) { |
| 102 | return true |
| 103 | } |
| 104 | } else { |
| 105 | if (element.type !== 'ObjectExpression') continue |
| 106 | for (const prop of element.properties) { |
| 107 | if ( |
| 108 | prop.type === 'Property' && |
| 109 | prop.key.type === 'Identifier' && |
| 110 | prop.key.name === 'name' && |
| 111 | prop.value.type === 'Literal' && |
| 112 | code.slice(prop.value.start + 1, prop.value.end - 1) === displayName |
| 113 | ) { |
| 114 | return true |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | return false |
| 121 | } |
| 122 | |
| 123 | function buildPluginString( |
| 124 | importName: string, |
no outgoing calls
no test coverage detected