(parser, expr)
| 151 | * @returns {{ argument: BasicEvaluatedExpression, ids: ExportInfoName[] } | undefined} parsed call |
| 152 | */ |
| 153 | const parseRequireCall = (parser, expr) => { |
| 154 | /** @type {ExportInfoName[]} */ |
| 155 | const ids = []; |
| 156 | while (expr.type === "MemberExpression") { |
| 157 | if (expr.object.type === "Super") return; |
| 158 | if (!expr.property) return; |
| 159 | const prop = expr.property; |
| 160 | if (expr.computed) { |
| 161 | if (prop.type !== "Literal") return; |
| 162 | ids.push(`${prop.value}`); |
| 163 | } else { |
| 164 | if (prop.type !== "Identifier") return; |
| 165 | ids.push(prop.name); |
| 166 | } |
| 167 | expr = expr.object; |
| 168 | } |
| 169 | if (expr.type !== "CallExpression" || expr.arguments.length !== 1) return; |
| 170 | const callee = expr.callee; |
| 171 | if ( |
| 172 | callee.type !== "Identifier" || |
| 173 | parser.getVariableInfo(callee.name) !== "require" |
| 174 | ) { |
| 175 | return; |
| 176 | } |
| 177 | const arg = expr.arguments[0]; |
| 178 | if (arg.type === "SpreadElement") return; |
| 179 | const argValue = parser.evaluateExpression(arg); |
| 180 | return { argument: argValue, ids: ids.reverse() }; |
| 181 | }; |
| 182 | |
| 183 | /** |
| 184 | * Checks if a value is an AST node. |
no test coverage detected