The text of a pure string literal (no interpolation or escapes), else null.
(arg: SyntaxNode, source: string)
| 42 | |
| 43 | /** The text of a pure string literal (no interpolation or escapes), else null. */ |
| 44 | function phpLiteralText(arg: SyntaxNode, source: string): string | null { |
| 45 | if (arg.type !== 'string' && arg.type !== 'encapsed_string') return null; |
| 46 | // Pure literal only: any non-`string_content` child (interpolated variable, |
| 47 | // escape sequence, …) means the value isn't a static path. |
| 48 | const parts = arg.namedChildren; |
| 49 | if (parts.some((c: SyntaxNode) => c.type !== 'string_content')) return null; |
| 50 | const content = parts.find((c: SyntaxNode) => c.type === 'string_content'); |
| 51 | return content ? getNodeText(content, source) : null; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * `__DIR__`, `dirname(__FILE__)`, `\\dirname(__DIR__)`, `dirname(__FILE__, 2)` |
no test coverage detected