(code)
| 154 | return { |
| 155 | name: "resolve-import-meta-resolve", |
| 156 | async transform(code) { |
| 157 | const program = this.parse(code); |
| 158 | const resolves: StringLiteral[] = []; |
| 159 | |
| 160 | simple(program, { |
| 161 | CallExpression(node) { |
| 162 | if ( |
| 163 | node.callee.type === "MemberExpression" && |
| 164 | node.callee.object.type === "MetaProperty" && |
| 165 | node.callee.property.type === "Identifier" && |
| 166 | node.callee.property.name === "resolve" && |
| 167 | node.arguments.length === 1 && |
| 168 | isStringLiteral(node.arguments[0]) |
| 169 | ) { |
| 170 | resolves.push(node.arguments[0]); |
| 171 | } |
| 172 | } |
| 173 | }); |
| 174 | |
| 175 | if (!resolves.length) return null; |
| 176 | |
| 177 | const output = new Sourcemap(code); |
| 178 | for (const source of resolves) { |
| 179 | const specifier = getStringLiteralValue(source); |
| 180 | const resolution = await resolveImport(specifier); |
| 181 | if (resolution) output.replaceLeft(source.start, source.end, annotatePath(relativePath(path, resolution))); |
| 182 | } |
| 183 | |
| 184 | return {code: String(output)}; |
| 185 | } |
| 186 | }; |
| 187 | } |
no test coverage detected