(lines: string)
| 941 | |
| 942 | function buildEnvTrie(env: Record<string, string | undefined>): EnvTrieNode { |
| 943 | const trie: EnvTrieNode = {} |
| 944 | |
| 945 | for (const [name, value] of Object.entries(env)) { |
| 946 | if (value === undefined) continue |
| 947 | |
| 948 | // Split on "_" and keep empty segments (no special handling for "__") |
| 949 | const segments = name.split("_") |
| 950 | |
| 951 | let node = trie |
| 952 | for (const seg of segments) { |
| 953 | const children = node.children ??= Object.create(null) |
| 954 | node = children[seg] ??= {} |
| 955 | } |
| 956 | } |
| 957 | |
| 958 | return trie |
| 959 | } |
| 960 | |
| 961 | const NUMERIC_INDEX = /^(0|[1-9][0-9]*)$/ |
| 962 | |
| 963 | function nodeAtEnv( |
| 964 | trie: EnvTrieNode, |
| 965 | env: Record<string, string | undefined>, |
| 966 | path: Path, |
| 967 | preserveEmptyStrings: boolean |
| 968 | ): Node | undefined { |
| 969 | const key = path.map(String).join("_") |
| 970 | const leafValue = emptyStringAsMissing(Object.hasOwn(env, key) ? env[key] : undefined, preserveEmptyStrings) |
| 971 | |
| 972 | const trieNode = trieNodeAt(trie, path) |
| 973 | const children = trieNode?.children ? Object.keys(trieNode.children) : [] |
| 974 | |
| 975 | if (children.length === 0) { |
| 976 | return leafValue === undefined ? undefined : makeValue(leafValue) |
| 977 | } |
| 978 | |
| 979 | const allNumeric = children.every((k) => NUMERIC_INDEX.test(k)) |
no test coverage detected
searching dependent graphs…