( ts: TypeScript, factory: typescript.NodeFactory, node: typescript.CallExpression, opts: Opts, sf: typescript.SourceFile )
| 821 | } |
| 822 | |
| 823 | function extractMessagesFromCallExpression( |
| 824 | ts: TypeScript, |
| 825 | factory: typescript.NodeFactory, |
| 826 | node: typescript.CallExpression, |
| 827 | opts: Opts, |
| 828 | sf: typescript.SourceFile |
| 829 | ): typescript.VisitResult<typescript.CallExpression> { |
| 830 | const {onMsgExtracted, additionalFunctionNames} = opts |
| 831 | if (isMultipleMessageDecl(ts, node)) { |
| 832 | const [arg, ...restArgs] = node.arguments |
| 833 | const descriptorsObj = unwrapObjectLiteralExpression(ts, arg) |
| 834 | if (descriptorsObj) { |
| 835 | const properties = descriptorsObj.properties |
| 836 | const msgs = properties |
| 837 | .filter<typescript.PropertyAssignment>( |
| 838 | (prop): prop is typescript.PropertyAssignment => |
| 839 | ts.isPropertyAssignment(prop) |
| 840 | ) |
| 841 | .map(prop => { |
| 842 | const descriptor = unwrapObjectLiteralExpression(ts, prop.initializer) |
| 843 | return ( |
| 844 | descriptor && extractMessageDescriptor(ts, descriptor, opts, sf) |
| 845 | ) |
| 846 | }) |
| 847 | .filter((msg): msg is MessageDescriptor => !!msg) |
| 848 | if (!msgs.length) { |
| 849 | return node |
| 850 | } |
| 851 | debug('Multiple messages extracted from "%s": %s', sf.fileName, msgs) |
| 852 | if (typeof onMsgExtracted === 'function') { |
| 853 | onMsgExtracted(sf.fileName, msgs) |
| 854 | } |
| 855 | |
| 856 | const clonedProperties = factory.createNodeArray( |
| 857 | properties.map((prop, i) => { |
| 858 | if ( |
| 859 | !ts.isPropertyAssignment(prop) || |
| 860 | !ts.isObjectLiteralExpression(prop.initializer) |
| 861 | ) { |
| 862 | return prop |
| 863 | } |
| 864 | |
| 865 | return factory.createPropertyAssignment( |
| 866 | prop.name, |
| 867 | setAttributesInObject( |
| 868 | ts, |
| 869 | factory, |
| 870 | prop.initializer, |
| 871 | { |
| 872 | defaultMessage: opts.removeDefaultMessage |
| 873 | ? undefined |
| 874 | : msgs[i].defaultMessage, |
| 875 | id: msgs[i] ? msgs[i].id : '', |
| 876 | }, |
| 877 | opts.ast |
| 878 | ) |
| 879 | ) |
| 880 | }) |
no test coverage detected