12345678910111213141516171819202122232425 |
- import Token from '../token';
-
- export class Selector {
- public name: Token;
- public parents: Selector[];
-
- public constructor(name: Token, parents: Selector[] = []) {
- this.name = name;
- this.parents = parents;
- }
-
- public getLineages(): string[] {
- if (this.parents.length === 0) return [this.name.value];
- return Array.prototype.concat(
- ...this.parents.map((parent) => {
- return parent.getLineages().map((lineage) => {
- if (this.name.value.match(/&/)) {
- return this.name.value.replace('&', lineage);
- }
- return lineage + ' ' + this.name.value;
- });
- })
- );
- }
- }
|