(expr: ts.Expression | undefined, sf: ts.SourceFile, seen = new Set<ts.Node>())
| 208 | type HideState = 'hidden' | 'absent' | 'unhidden'; |
| 209 | |
| 210 | function hideState(expr: ts.Expression | undefined, sf: ts.SourceFile, seen = new Set<ts.Node>()): HideState { |
| 211 | if (!expr) return 'absent'; |
| 212 | const e = unwrap(expr); |
| 213 | if (seen.has(e)) return 'unhidden'; // a cycle proves nothing |
| 214 | // Path-local: two call sites passing the same options object both resolve. |
| 215 | const trail = new Set(seen).add(e); |
| 216 | if (ts.isObjectLiteralExpression(e)) { |
| 217 | let state: HideState = 'absent'; |
| 218 | for (const prop of e.properties) { |
| 219 | if (ts.isSpreadAssignment(prop)) { |
| 220 | const spread = hideState(prop.expression, sf, trail); |
| 221 | if (spread !== 'absent') state = spread; |
| 222 | } else if (ts.isComputedPropertyName(prop.name)) { |
| 223 | state = 'unhidden'; // `[key]: …` may be windowsHide |
| 224 | } else if (prop.name.text === 'windowsHide') { |
| 225 | // Quoted or not, the same property. Only a literal `true` is provable: |
| 226 | // a shorthand, a method or an accessor is not. |
| 227 | state = ts.isPropertyAssignment(prop) && unwrap(prop.initializer).kind === ts.SyntaxKind.TrueKeyword ? 'hidden' : 'unhidden'; |
| 228 | } |
| 229 | } |
| 230 | return state; // last write wins, matching object-literal semantics |
| 231 | } |
| 232 | if (ts.isIdentifier(e)) { |
| 233 | const binding = resolveBinding(e.text, e); |
| 234 | if (!binding) return 'unhidden'; |
| 235 | if (ts.isVariableDeclaration(binding)) { |
| 236 | // A `let` or `var` can be reassigned after its initializer. |
| 237 | const list = binding.parent; |
| 238 | if (!ts.isVariableDeclarationList(list) || !(list.flags & ts.NodeFlags.Const)) return 'unhidden'; |
| 239 | return binding.initializer ? hideState(binding.initializer, sf, trail) : 'unhidden'; |
| 240 | } |
| 241 | const sites = callSitesOf(binding, sf); |
| 242 | if (sites === null) return 'unhidden'; |
| 243 | const states = new Set(sites.map((arg) => hideState(arg, sf, trail))); |
| 244 | return states.size === 1 ? [...states][0] : 'unhidden'; |
| 245 | } |
| 246 | return 'unhidden'; |
| 247 | } |
| 248 | |
| 249 | /** True when `expr` provably evaluates to options with `windowsHide: true`. */ |
| 250 | function hidesWindow(expr: ts.Expression | undefined, sf: ts.SourceFile): boolean { |
no test coverage detected