PHP 7.4.33
Preview: AttributeSelector.cjs Size: 3.55 KB
/var/www/cookieconsent.bitkit.dk/httpdocs/node_modules/css-tree/cjs/syntax/node/AttributeSelector.cjs
'use strict';

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

const DOLLARSIGN = 0x0024;       // U+0024 DOLLAR SIGN ($)
const ASTERISK = 0x002A;         // U+002A ASTERISK (*)
const EQUALSSIGN = 0x003D;       // U+003D EQUALS SIGN (=)
const CIRCUMFLEXACCENT = 0x005E; // U+005E (^)
const VERTICALLINE = 0x007C;     // U+007C VERTICAL LINE (|)
const TILDE = 0x007E;            // U+007E TILDE (~)

function getAttributeName() {
    if (this.eof) {
        this.error('Unexpected end of input');
    }

    const start = this.tokenStart;
    let expectIdent = false;

    if (this.isDelim(ASTERISK)) {
        expectIdent = true;
        this.next();
    } else if (!this.isDelim(VERTICALLINE)) {
        this.eat(types.Ident);
    }

    if (this.isDelim(VERTICALLINE)) {
        if (this.charCodeAt(this.tokenStart + 1) !== EQUALSSIGN) {
            this.next();
            this.eat(types.Ident);
        } else if (expectIdent) {
            this.error('Identifier is expected', this.tokenEnd);
        }
    } else if (expectIdent) {
        this.error('Vertical line is expected');
    }

    return {
        type: 'Identifier',
        loc: this.getLocation(start, this.tokenStart),
        name: this.substrToCursor(start)
    };
}

function getOperator() {
    const start = this.tokenStart;
    const code = this.charCodeAt(start);

    if (code !== EQUALSSIGN &&        // =
        code !== TILDE &&             // ~=
        code !== CIRCUMFLEXACCENT &&  // ^=
        code !== DOLLARSIGN &&        // $=
        code !== ASTERISK &&          // *=
        code !== VERTICALLINE         // |=
    ) {
        this.error('Attribute selector (=, ~=, ^=, $=, *=, |=) is expected');
    }

    this.next();

    if (code !== EQUALSSIGN) {
        if (!this.isDelim(EQUALSSIGN)) {
            this.error('Equal sign is expected');
        }

        this.next();
    }

    return this.substrToCursor(start);
}

// '[' <wq-name> ']'
// '[' <wq-name> <attr-matcher> [ <string-token> | <ident-token> ] <attr-modifier>? ']'
const name = 'AttributeSelector';
const structure = {
    name: 'Identifier',
    matcher: [String, null],
    value: ['String', 'Identifier', null],
    flags: [String, null]
};

function parse() {
    const start = this.tokenStart;
    let name;
    let matcher = null;
    let value = null;
    let flags = null;

    this.eat(types.LeftSquareBracket);
    this.skipSC();

    name = getAttributeName.call(this);
    this.skipSC();

    if (this.tokenType !== types.RightSquareBracket) {
        // avoid case `[name i]`
        if (this.tokenType !== types.Ident) {
            matcher = getOperator.call(this);

            this.skipSC();

            value = this.tokenType === types.String
                ? this.String()
                : this.Identifier();

            this.skipSC();
        }

        // attribute flags
        if (this.tokenType === types.Ident) {
            flags = this.consume(types.Ident);

            this.skipSC();
        }
    }

    this.eat(types.RightSquareBracket);

    return {
        type: 'AttributeSelector',
        loc: this.getLocation(start, this.tokenStart),
        name,
        matcher,
        value,
        flags
    };
}

function generate(node) {
    this.token(types.Delim, '[');
    this.node(node.name);

    if (node.matcher !== null) {
        this.tokenize(node.matcher);
        this.node(node.value);
    }

    if (node.flags !== null) {
        this.token(types.Ident, node.flags);
    }

    this.token(types.Delim, ']');
}

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

Directory Contents

Dirs: 1 × Files: 51
Name Size Perms Modified Actions
common DIR
- drwxr-xr-x 2025-06-16 05:45:40
Edit Download
7.90 KB lrw-r--r-- 2025-06-16 05:45:39
Edit Download
2.48 KB lrw-r--r-- 2025-06-16 05:45:39
Edit Download
1.11 KB lrw-r--r-- 2025-06-16 05:45:39
Edit Download
3.55 KB lrw-r--r-- 2025-06-16 05:45:39
Edit Download
2.33 KB lrw-r--r-- 2025-06-16 05:45:39
Edit Download
752 B lrw-r--r-- 2025-06-16 05:45:39
Edit Download
460 B lrw-r--r-- 2025-06-16 05:45:39
Edit Download
462 B lrw-r--r-- 2025-06-16 05:45:39
Edit Download
619 B lrw-r--r-- 2025-06-16 05:45:40
Edit Download
1.40 KB lrw-r--r-- 2025-06-16 05:45:40
Edit Download
854 B lrw-r--r-- 2025-06-16 05:45:40
Edit Download
3.54 KB lrw-r--r-- 2025-06-16 05:45:40
Edit Download
4.47 KB lrw-r--r-- 2025-06-16 05:45:40
Edit Download
1.46 KB lrw-r--r-- 2025-06-16 05:45:40
Edit Download
642 B lrw-r--r-- 2025-06-16 05:45:40
Edit Download
1.68 KB lrw-r--r-- 2025-06-16 05:45:40
Edit Download
2.62 KB lrw-r--r-- 2025-06-16 05:45:40
Edit Download
1.04 KB lrw-r--r-- 2025-06-16 05:45:40
Edit Download
1.08 KB lrw-r--r-- 2025-06-16 05:45:40
Edit Download
587 B lrw-r--r-- 2025-06-16 05:45:40
Edit Download
482 B lrw-r--r-- 2025-06-16 05:45:40
Edit Download
847 B lrw-r--r-- 2025-06-16 05:45:40
Edit Download
3.50 KB lrw-r--r-- 2025-06-16 05:45:40
Edit Download
1.44 KB lrw-r--r-- 2025-06-16 05:45:40
Edit Download
3.38 KB lrw-r--r-- 2025-06-16 05:45:40
Edit Download
3.14 KB lrw-r--r-- 2025-06-16 05:45:40
Edit Download
1.83 KB lrw-r--r-- 2025-06-16 05:45:40
Edit Download
1.64 KB lrw-r--r-- 2025-06-16 05:45:40
Edit Download
287 B lrw-r--r-- 2025-06-16 05:45:40
Edit Download
1.15 KB lrw-r--r-- 2025-06-16 05:45:40
Edit Download
734 B lrw-r--r-- 2025-06-16 05:45:40
Edit Download
540 B lrw-r--r-- 2025-06-16 05:45:40
Edit Download
1.02 KB lrw-r--r-- 2025-06-16 05:45:40
Edit Download
479 B lrw-r--r-- 2025-06-16 05:45:40
Edit Download
502 B lrw-r--r-- 2025-06-16 05:45:40
Edit Download
775 B lrw-r--r-- 2025-06-16 05:45:40
Edit Download
507 B lrw-r--r-- 2025-06-16 05:45:40
Edit Download
1.53 KB lrw-r--r-- 2025-06-16 05:45:40
Edit Download
1.59 KB lrw-r--r-- 2025-06-16 05:45:40
Edit Download
1.82 KB lrw-r--r-- 2025-06-16 05:45:40
Edit Download
1.12 KB lrw-r--r-- 2025-06-16 05:45:40
Edit Download
1.22 KB lrw-r--r-- 2025-06-16 05:45:40
Edit Download
781 B lrw-r--r-- 2025-06-16 05:45:40
Edit Download
810 B lrw-r--r-- 2025-06-16 05:45:40
Edit Download
559 B lrw-r--r-- 2025-06-16 05:45:40
Edit Download
1.99 KB lrw-r--r-- 2025-06-16 05:45:40
Edit Download
1.16 KB lrw-r--r-- 2025-06-16 05:45:40
Edit Download
4.43 KB lrw-r--r-- 2025-06-16 05:45:40
Edit Download
1.26 KB lrw-r--r-- 2025-06-16 05:45:40
Edit Download
469 B lrw-r--r-- 2025-06-16 05:45:40
Edit Download
644 B lrw-r--r-- 2025-06-16 05:45:40
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).