You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
736 B
31 lines
736 B
import { addDefault, addNamed } from '@babel/helper-module-imports'
|
|
|
|
export function addImport(
|
|
state: any,
|
|
importSource: string,
|
|
importedSpecifier: string,
|
|
nameHint?: string
|
|
) {
|
|
let cacheKey = ['import', importSource, importedSpecifier].join(':')
|
|
if (state[cacheKey] === undefined) {
|
|
let importIdentifier
|
|
if (importedSpecifier === 'default') {
|
|
importIdentifier = addDefault(state.file.path, importSource, { nameHint })
|
|
} else {
|
|
importIdentifier = addNamed(
|
|
state.file.path,
|
|
importedSpecifier,
|
|
importSource,
|
|
{
|
|
nameHint
|
|
}
|
|
)
|
|
}
|
|
state[cacheKey] = importIdentifier.name
|
|
}
|
|
return {
|
|
type: 'Identifier',
|
|
name: state[cacheKey]
|
|
}
|
|
}
|