1 | import {IsolateModule} from './IsolateModule';
|
2 | import {Scope} from './isolate';
|
3 | import {isEqualNamespace} from './utils';
|
4 |
|
5 | export class ScopeChecker {
|
6 | public readonly _namespace: Array<Scope>;
|
7 | constructor(
|
8 | public readonly namespace: Array<Scope>,
|
9 | private isolateModule: IsolateModule
|
10 | ) {
|
11 | this._namespace = namespace.filter(n => n.type !== 'selector');
|
12 | }
|
13 |
|
14 | |
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | public isDirectlyInScope(leaf: Element): boolean {
|
21 | const namespace = this.isolateModule.getNamespace(leaf);
|
22 | if (!namespace) {
|
23 | return false;
|
24 | }
|
25 |
|
26 | if (
|
27 | this._namespace.length > namespace.length ||
|
28 | !isEqualNamespace(
|
29 | this._namespace,
|
30 | namespace.slice(0, this._namespace.length)
|
31 | )
|
32 | ) {
|
33 | return false;
|
34 | }
|
35 | for (let i = this._namespace.length; i < namespace.length; i++) {
|
36 | if (namespace[i].type === 'total') {
|
37 | return false;
|
38 | }
|
39 | }
|
40 | return true;
|
41 | }
|
42 | }
|