UNPKG

babel-plugin-react-intl-auto

Version:

i18n for the component age. Auto management react-intl ID

37 lines (29 loc) 910 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isImportLocalName = void 0; const isImportLocalName = (name, allowedNames, { file, opts: { moduleSourceName = 'react-intl' } }) => { const isSearchedImportSpecifier = specifier => specifier.isImportSpecifier() && allowedNames.includes(specifier.node.imported.name) && (!name || specifier.node.local.name === name); let isImported = false; if (file && file.path) { file.path.traverse({ ImportDeclaration: { exit(path) { const specifiers = path.get('specifiers'); isImported = path.node.source.value.includes(moduleSourceName) && specifiers.some(specifier => isSearchedImportSpecifier(specifier)); if (isImported) { path.stop(); } } } }); } return isImported; }; exports.isImportLocalName = isImportLocalName;