| 63 | } |
| 64 | |
| 65 | function templateSimpleExpressionNodeVisitor(parseScriptFn: ScriptParseFn) { |
| 66 | return ( |
| 67 | n: |
| 68 | | ElementNode |
| 69 | | CompoundExpressionNode |
| 70 | | CompoundExpressionNode['children'][0] |
| 71 | ) => { |
| 72 | if (typeof n !== 'object') { |
| 73 | return |
| 74 | } |
| 75 | if (n.type !== NodeTypes.SIMPLE_EXPRESSION) { |
| 76 | return |
| 77 | } |
| 78 | |
| 79 | const {content} = n as SimpleExpressionNode |
| 80 | // Wrap this in () since a vue comp node attribute can just be |
| 81 | // an object literal which, by itself is invalid TS |
| 82 | // but with () it becomes an ExpressionStatement |
| 83 | try { |
| 84 | parseScriptFn(`(${content})`) |
| 85 | } catch (e) { |
| 86 | console.warn( |
| 87 | `Failed to parse "${content}". Ignore this if content has no extractable message`, |
| 88 | e |
| 89 | ) |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | export function parseFile( |
| 95 | source: string, |