( expression: Node, module: SourceModule )
| 129 | // e.g. ["precompile", "vite"] for `precompile.vite`, `aot.precompile.vite` or |
| 130 | // `require("@ark/aot/unplugin").precompile.vite` |
| 131 | const entryReadOf = ( |
| 132 | expression: Node, |
| 133 | module: SourceModule |
| 134 | ): [entry: string, path: string[]] | undefined => { |
| 135 | const node = unwrapExpression(expression) |
| 136 | if (node.type === "AwaitExpression") return entryReadOf(node.argument, module) |
| 137 | if (node.type === "MemberExpression") { |
| 138 | const name = memberNameOf(node) |
| 139 | const object = entryReadOf(node.object, module) |
| 140 | return object && typeof name === "string" ? |
| 141 | [object[0], [...object[1], name]] |
| 142 | : undefined |
| 143 | } |
| 144 | const entry = entryOf(node) |
| 145 | if (entry !== undefined) return [entry, []] |
| 146 | if (node.type !== "Identifier") return |
| 147 | const binding = module.scopes.byId.get(node as never)?.binding |
| 148 | const declaration = binding?.declaration |
| 149 | if ( |
| 150 | declaration?.type === "ImportSpecifier" || |
| 151 | declaration?.type === "ImportNamespaceSpecifier" |
| 152 | ) { |
| 153 | const source = (declaration.parent as { source: { value: string } }).source |
| 154 | .value |
| 155 | if (!(source in entries)) return |
| 156 | return [ |
| 157 | source, |
| 158 | declaration.type === "ImportSpecifier" ? |
| 159 | [exportNameOf(declaration.imported)] |
| 160 | : [] |
| 161 | ] |
| 162 | } |
| 163 | if ( |
| 164 | binding?.kind !== "const" || |
| 165 | declaration?.type !== "VariableDeclarator" || |
| 166 | !declaration.init |
| 167 | ) |
| 168 | return |
| 169 | const init = entryReadOf(declaration.init, module) |
| 170 | if (!init || declaration.id === binding.id) return init |
| 171 | // e.g. `const { precompile } = require("@ark/aot/unplugin")` |
| 172 | const property = binding.id.parent |
| 173 | return ( |
| 174 | property?.type === "Property" && |
| 175 | property.value === binding.id && |
| 176 | property.parent === declaration.id && |
| 177 | !property.computed |
| 178 | ) ? |
| 179 | [init[0], [...init[1], exportNameOf(property.key)]] |
| 180 | : undefined |
| 181 | } |
| 182 | |
| 183 | // e.g. `{ loader: "@ark/aot/turbopack", options: { config: "..." } }` |
| 184 | const turbopackOptionsOf = (node: ObjectExpression): Node | undefined => { |
no test coverage detected