license import { ɵParsedMessage , ɵparseMessage } from '@angular/localize' ; import { NodePath , PluginObj } from '@babel/core' ; import { TaggedTemplateExpression } from '@babel/types' ; import { ParsedMessageLegacy } from '../../../cmds/common/util' ; import { isGlobalIdentifier , isNamedIdentifier , unwrapMessagePartsFromTemplateLiteral } from '../source_file_utils' ; import { Diagnostics } from '../../common/diagnostics' ; export function makeEs2015ExtractPlugin ( messages , diagnostics , localizeName = '$localize' ) { return { visitor : { TaggedTemplateExpression ( path ) { const tag = path . get ( 'tag' ) ; if ( isNamedIdentifier ( tag , localizeName ) && isGlobalIdentifier ( tag ) ) { const messageParts = unwrapMessagePartsFromTemplateLiteral ( path . node . quasi . quasis ) ; const message = ɵparseMessage ( messageParts , path . node . quasi . expressions ) ; if ( ! messages . find ( ( msg ) => message . id ? msg . id === message . id : msg . messageId === ( ( < unknown > message ) as ParsedMessageLegacy ) . messageId ) ) { messages . push ( message ) ; } } } } } ; }