aboutsummaryrefslogtreecommitdiffstats
path: root/vanilla/node_modules/css-tree/lib/syntax/node/GeneralEnclosed.js
blob: 8ac8caed1f8a1dde30c060be282920d487354109 (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
import {
    Function as FunctionToken,
    LeftParenthesis,
    RightParenthesis
} from '../../tokenizer/index.js';


export const name = 'GeneralEnclosed';
export const structure = {
    kind: String,
    function: [String, null],
    children: [[]]
};

// <function-token> <any-value> )
// ( <any-value> )
export function parse(kind) {
    const start = this.tokenStart;
    let functionName = null;

    if (this.tokenType === FunctionToken) {
        functionName = this.consumeFunctionName();
    } else {
        this.eat(LeftParenthesis);
    }

    const children = this.parseWithFallback(
        () => {
            const startValueToken = this.tokenIndex;
            const children = this.readSequence(this.scope.Value);

            if (this.eof === false &&
                this.isBalanceEdge(startValueToken) === false) {
                this.error();
            }

            return children;
        },
        () => this.createSingleNodeList(
            this.Raw(null, false)
        )
    );

    if (!this.eof) {
        this.eat(RightParenthesis);
    }

    return {
        type: 'GeneralEnclosed',
        loc: this.getLocation(start, this.tokenStart),
        kind,
        function: functionName,
        children
    };
}

export function generate(node) {
    if (node.function) {
        this.token(FunctionToken, node.function + '(');
    } else {
        this.token(LeftParenthesis, '(');
    }

    this.children(node);
    this.token(RightParenthesis, ')');
}