(node: Node, module: SourceModule)
| 7356 | |
| 7357 | // esbuild's keepNames: `__name(fn, "name")` returns `fn` |
| 7358 | const namedFunctionOf = (node: Node, module: SourceModule): Node => { |
| 7359 | if ( |
| 7360 | node.type !== "CallExpression" || |
| 7361 | node.arguments.length !== 2 || |
| 7362 | node.arguments[1].type !== "Literal" || |
| 7363 | typeof node.arguments[1].value !== "string" |
| 7364 | ) |
| 7365 | return node |
| 7366 | const namer = initOf(node.callee, module) |
| 7367 | if ( |
| 7368 | namer?.type !== "ArrowFunctionExpression" || |
| 7369 | namer.body.type !== "CallExpression" || |
| 7370 | namer.body.callee.type !== "Identifier" |
| 7371 | ) |
| 7372 | return node |
| 7373 | const define = namer.body.callee |
| 7374 | const [target, value] = namer.params.map(param => |
| 7375 | param.type === "Identifier" ? param.name : "" |
| 7376 | ) |
| 7377 | // a minifier renames the parameters and writes `true` as `!0` |
| 7378 | const call = compactTextOf(namer.body, module) |
| 7379 | .replace("{value,", "{value:value,") |
| 7380 | .replace("!0", "true") |
| 7381 | const defineProperty = initOf(define, module) |
| 7382 | return ( |
| 7383 | namer.params.length === 2 && |
| 7384 | target && |
| 7385 | call === |
| 7386 | `${define.name}(${target},"name",{value:${value},configurable:true})` && |
| 7387 | defineProperty?.type === "MemberExpression" && |
| 7388 | compactTextOf(defineProperty, module) === "Object.defineProperty" && |
| 7389 | !module.scopes.byId.get(defineProperty.object)?.binding |
| 7390 | ) ? |
| 7391 | unwrapChain(node.arguments[0]) |
| 7392 | : node |
| 7393 | } |
| 7394 | |
| 7395 | const isNamed = (node: Node, module: SourceModule): boolean => |
| 7396 | node.parent?.parent?.type === "ExpressionStatement" && |
no test coverage detected