| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
module.exports = function ({ types: t, template }) { |
| 8 |
return { |
| 9 |
visitor: { |
| 10 |
ImportDeclaration(path) { |
| 11 |
if ( |
| 12 |
t.isStringLiteral(path.node.source, { value: "@babel/core" }) && |
| 13 |
path.node.specifiers.every(node => t.isImportSpecifier(node)) |
| 14 |
) { |
| 15 |
const defaultName = path.scope.generateUidIdentifier("babel"); |
| 16 |
|
| 17 |
const destr = t.objectPattern( |
| 18 |
path.node.specifiers.map(spec => |
| 19 |
t.objectProperty(spec.imported, spec.local) |
| 20 |
) |
| 21 |
); |
| 22 |
|
| 23 |
path.replaceWithMultiple(template.statements.ast` |
| 24 |
import * as ${defaultName} from "@babel/core"; |
| 25 |
const ${destr} = ${defaultName}.default || ${defaultName}; |
| 26 |
`); |
| 27 |
} |
| 28 |
}, |
| 29 |
}, |
| 30 |
}; |
| 31 |
}; |