1 | class Scope {
|
2 | |
3 |
|
4 |
|
5 | constructor(data = []) {
|
6 | this._scopes = data;
|
7 | }
|
8 |
|
9 | |
10 |
|
11 |
|
12 |
|
13 |
|
14 | push(scope, parentScope = '') {
|
15 | this._scopes.push({ scope, parentScope });
|
16 | }
|
17 |
|
18 | |
19 |
|
20 |
|
21 |
|
22 | pop() {
|
23 | return this._scopes.pop();
|
24 | }
|
25 |
|
26 | |
27 |
|
28 |
|
29 |
|
30 | getSelector() {
|
31 | const scopes = this._scopes;
|
32 | const selector = [];
|
33 | for (let i = scopes.length - 1; i >= 0; i--) {
|
34 | const scope = scopes[i];
|
35 | selector.unshift(scope.scope);
|
36 |
|
37 | if (scope.parentScope) {
|
38 | selector.unshift(scope.parentScope);
|
39 | break;
|
40 | }
|
41 | }
|
42 |
|
43 | return selector.join(' ');
|
44 | }
|
45 |
|
46 | isEmpty() {
|
47 | return this._scopes.length === 0;
|
48 | }
|
49 | }
|
50 |
|
51 | module.exports = Scope;
|