( node: SvelteNode, source: string, parseScriptFn: ScriptParseFn )
| 96 | } |
| 97 | |
| 98 | function extractMessageComponent( |
| 99 | node: SvelteNode, |
| 100 | source: string, |
| 101 | parseScriptFn: ScriptParseFn |
| 102 | ): void { |
| 103 | if (typeof node.name !== 'string' || !isValidIdentifier(node.name)) { |
| 104 | return |
| 105 | } |
| 106 | |
| 107 | const props: string[] = [] |
| 108 | for (const attr of node.attributes || []) { |
| 109 | if ( |
| 110 | attr.type !== 'Attribute' || |
| 111 | typeof attr.name !== 'string' || |
| 112 | !MESSAGE_DESCRIPTOR_PROPS.has(attr.name) |
| 113 | ) { |
| 114 | continue |
| 115 | } |
| 116 | |
| 117 | const expression = getAttributeExpression(attr, source) |
| 118 | if (expression != null) { |
| 119 | props.push(`${attr.name}: ${expression}`) |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | if (!props.length) { |
| 124 | return |
| 125 | } |
| 126 | |
| 127 | try { |
| 128 | parseScriptFn(`${node.name}({${props.join(', ')}})`) |
| 129 | } catch (e) { |
| 130 | console.warn( |
| 131 | `Failed to parse ${node.name} message component. Ignore this if component has no extractable message`, |
| 132 | e |
| 133 | ) |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | function walkNode( |
| 138 | node: SvelteNode, |
no test coverage detected