aboutsummaryrefslogtreecommitdiffstats
path: root/vanilla/node_modules/css-tree/cjs/syntax/node/Scope.cjs
blob: 1320b0442b9d3956ac04139813b4238bfe6996cf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
'use strict';

const types = require('../../tokenizer/types.cjs');

const name = 'Scope';
const structure = {
    root: ['SelectorList', 'Raw', null],
    limit: ['SelectorList', 'Raw', null]
};

function parse() {
    let root = null;
    let limit = null;

    this.skipSC();

    const startOffset = this.tokenStart;
    if (this.tokenType === types.LeftParenthesis) {
        this.next();
        this.skipSC();
        root = this.parseWithFallback(
            this.SelectorList,
            () => this.Raw(false, true)
        );
        this.skipSC();
        this.eat(types.RightParenthesis);
    }

    if (this.lookupNonWSType(0) === types.Ident) {
        this.skipSC();
        this.eatIdent('to');
        this.skipSC();
        this.eat(types.LeftParenthesis);
        this.skipSC();
        limit = this.parseWithFallback(
            this.SelectorList,
            () => this.Raw(false, true)
        );
        this.skipSC();
        this.eat(types.RightParenthesis);
    }

    return {
        type: 'Scope',
        loc: this.getLocation(startOffset, this.tokenStart),
        root,
        limit
    };
}

function generate(node) {
    if (node.root) {
        this.token(types.LeftParenthesis, '(');
        this.node(node.root);
        this.token(types.RightParenthesis, ')');
    }

    if (node.limit) {
        this.token(types.Ident, 'to');
        this.token(types.LeftParenthesis, '(');
        this.node(node.limit);
        this.token(types.RightParenthesis, ')');
    }
}

exports.generate = generate;
exports.name = name;
exports.parse = parse;
exports.structure = structure;