A stylesheet language written in TypeScript that compiles to CSS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

selector.ts 649B

12345678910111213141516171819202122232425
  1. import Token from '../token';
  2. export class Selector {
  3. public name: Token;
  4. public parents: Selector[];
  5. public constructor(name: Token, parents: Selector[] = []) {
  6. this.name = name;
  7. this.parents = parents;
  8. }
  9. public getLineages(): string[] {
  10. if (this.parents.length === 0) return [this.name.value];
  11. return Array.prototype.concat(
  12. ...this.parents.map((parent) => {
  13. return parent.getLineages().map((lineage) => {
  14. if (this.name.value.match(/&/)) {
  15. return this.name.value.replace('&', lineage);
  16. }
  17. return lineage + ' ' + this.name.value;
  18. });
  19. })
  20. );
  21. }
  22. }