* Determines whether a TypeScript expression resolves to a plain string value. * Only string literals and t() calls with a string literal argument are considered * string-typed; anything else (variables, conditionals, JSX elements, other calls) * causes the caller to bail out.
(expr: ts.Expression)
| 36 | * causes the caller to bail out. |
| 37 | */ |
| 38 | function isStringTypeExpression(expr: ts.Expression): boolean { |
| 39 | // 'Name' or "Name" |
| 40 | if (ts.isStringLiteral(expr)) { |
| 41 | return true; |
| 42 | } |
| 43 | |
| 44 | // t('Name') — the i18n translation helper |
| 45 | if ( |
| 46 | ts.isCallExpression(expr) && |
| 47 | ts.isIdentifier(expr.expression) && |
| 48 | expr.expression.text === 't' && |
| 49 | expr.arguments.length > 0 && |
| 50 | ts.isStringLiteral(expr.arguments[0]!) |
| 51 | ) { |
| 52 | return true; |
| 53 | } |
| 54 | |
| 55 | return false; |
| 56 | } |
| 57 | |
| 58 | class FormFieldExtractor { |
| 59 | private program: ts.Program; |
no outgoing calls
no test coverage detected