* Extract a static path from a PHP include/require expression: a string * literal, or one appended to the including file's own directory or to the * web server's root (#3298). * * Returns null for dynamic forms (`include $var`, interpolated strings, * `$base . '/x'`): they have no resolvable co
(node: SyntaxNode, source: string)
| 31 | * `$base . '/x'`): they have no resolvable compile-time path. |
| 32 | */ |
| 33 | function phpStaticIncludePath(node: SyntaxNode, source: string): string | null { |
| 34 | // The path argument is the expression's first named child; the call-style |
| 35 | // form `require("x")` wraps it in a parenthesized_expression. |
| 36 | let arg: SyntaxNode | null = node.namedChild(0); |
| 37 | if (arg?.type === 'parenthesized_expression') arg = arg.namedChild(0); |
| 38 | if (!arg) return null; |
| 39 | if (arg.type === 'binary_expression') return phpDirectoryIncludePath(arg, source); |
| 40 | return phpLiteralText(arg, source); |
| 41 | } |
| 42 | |
| 43 | /** The text of a pure string literal (no interpolation or escapes), else null. */ |
| 44 | function phpLiteralText(arg: SyntaxNode, source: string): string | null { |
no test coverage detected