(path)
| 2 | name: 'transform-import-meta-url', |
| 3 | visitor: { |
| 4 | MemberExpression(path) { |
| 5 | const { object, property, computed } = path.node; |
| 6 | if (computed) return; |
| 7 | if (!t.isMetaProperty(object)) return; |
| 8 | if (!t.isIdentifier(object.meta, { name: 'import' })) return; |
| 9 | if (!t.isIdentifier(object.property, { name: 'meta' })) return; |
| 10 | if (!t.isIdentifier(property, { name: 'url' })) return; |
| 11 | const requireUrl = t.callExpression( |
| 12 | t.memberExpression(t.identifier('module'), t.identifier('require')), |
| 13 | [t.stringLiteral('url')] |
| 14 | ); |
| 15 | const pathToFileURL = t.memberExpression( |
| 16 | requireUrl, |
| 17 | t.identifier('pathToFileURL') |
| 18 | ); |
| 19 | const fileUrl = t.callExpression(pathToFileURL, [ |
| 20 | t.identifier('__filename'), |
| 21 | ]); |
| 22 | path.replaceWith(t.memberExpression(fileUrl, t.identifier('href'))); |
| 23 | }, |
| 24 | }, |
| 25 | }); |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…