(parent: string, child: string | Variant)
| 159 | } |
| 160 | |
| 161 | compoundsWith(parent: string, child: string | Variant) { |
| 162 | let parentInfo = this.variants.get(parent) |
| 163 | let childInfo = |
| 164 | typeof child === 'string' |
| 165 | ? this.variants.get(child) |
| 166 | : child.kind === 'arbitrary' |
| 167 | ? // This isn't strictly necessary but it'll allow us to bail quickly |
| 168 | // when parsing candidates |
| 169 | { compounds: compoundsForSelectors([child.selector]) } |
| 170 | : this.variants.get(child.root) |
| 171 | |
| 172 | // One of the variants don't exist |
| 173 | if (!parentInfo || !childInfo) return false |
| 174 | |
| 175 | // The parent variant is not a compound variant |
| 176 | if (parentInfo.kind !== 'compound') return false |
| 177 | |
| 178 | // The variant `parent` may _compound with_ `child` if `parent` supports the |
| 179 | // rules that `child` generates. We instead use static registration metadata |
| 180 | // about what `parent` and `child` support instead of trying to apply the |
| 181 | // variant at runtime to see if the rules are compatible. |
| 182 | |
| 183 | // The `child` variant cannot compound *ever* |
| 184 | if (childInfo.compounds === Compounds.Never) return false |
| 185 | |
| 186 | // The `parent` variant cannot compound *ever* |
| 187 | // This shouldn't ever happen because `kind` is `compound` |
| 188 | if (parentInfo.compoundsWith === Compounds.Never) return false |
| 189 | |
| 190 | // Any rule that `child` may generate must be supported by `parent` |
| 191 | if ((parentInfo.compoundsWith & childInfo.compounds) === 0) return false |
| 192 | |
| 193 | return true |
| 194 | } |
| 195 | |
| 196 | suggest(name: string, suggestions: () => string[]) { |
| 197 | this.completions.set(name, suggestions) |
no test coverage detected