Sha256: 613983e8d26ea06b8263bb9c2ae3e0e1160dacf456da9a9988013ec346e8a11d

Contents?: true

Size: 2 KB

Versions: 41

Compression:

Stored size: 2 KB

Contents

var isWhiteSpace = require('../../tokenizer').isWhiteSpace;
var cmpStr = require('../../tokenizer').cmpStr;
var TYPE = require('../../tokenizer').TYPE;

var FUNCTION = TYPE.Function;
var URL = TYPE.Url;
var RIGHTPARENTHESIS = TYPE.RightParenthesis;

// <url-token> | <function-token> <string> )
module.exports = {
    name: 'Url',
    structure: {
        value: ['String', 'Raw']
    },
    parse: function() {
        var start = this.scanner.tokenStart;
        var value;

        switch (this.scanner.tokenType) {
            case URL:
                var rawStart = start + 4;
                var rawEnd = this.scanner.tokenEnd - 1;

                while (rawStart < rawEnd && isWhiteSpace(this.scanner.source.charCodeAt(rawStart))) {
                    rawStart++;
                }

                while (rawStart < rawEnd && isWhiteSpace(this.scanner.source.charCodeAt(rawEnd - 1))) {
                    rawEnd--;
                }

                value = {
                    type: 'Raw',
                    loc: this.getLocation(rawStart, rawEnd),
                    value: this.scanner.source.substring(rawStart, rawEnd)
                };

                this.eat(URL);
                break;

            case FUNCTION:
                if (!cmpStr(this.scanner.source, this.scanner.tokenStart, this.scanner.tokenEnd, 'url(')) {
                    this.error('Function name must be `url`');
                }

                this.eat(FUNCTION);
                this.scanner.skipSC();
                value = this.String();
                this.scanner.skipSC();
                this.eat(RIGHTPARENTHESIS);
                break;

            default:
                this.error('Url or Function is expected');
        }

        return {
            type: 'Url',
            loc: this.getLocation(start, this.scanner.tokenStart),
            value: value
        };
    },
    generate: function(node) {
        this.chunk('url');
        this.chunk('(');
        this.node(node.value);
        this.chunk(')');
    }
};

Version data entries

41 entries across 31 versions & 9 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/css-tree/lib/syntax/node/Url.js
optimacms-0.1.61 spec/dummy/node_modules/csso/node_modules/css-tree/lib/syntax/node/Url.js
disco_app-0.18.0 test/dummy/node_modules/css-tree/lib/syntax/node/Url.js
disco_app-0.18.2 test/dummy/node_modules/css-tree/lib/syntax/node/Url.js
disco_app-0.16.1 test/dummy/node_modules/css-tree/lib/syntax/node/Url.js
disco_app-0.15.2 test/dummy/node_modules/css-tree/lib/syntax/node/Url.js
disco_app-0.18.4 test/dummy/node_modules/css-tree/lib/syntax/node/Url.js
disco_app-0.18.1 test/dummy/node_modules/css-tree/lib/syntax/node/Url.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/css-tree/lib/syntax/node/Url.js
disco_app-0.14.0 test/dummy/node_modules/css-tree/lib/syntax/node/Url.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/css-tree/lib/syntax/node/Url.js
isomorfeus-preact-10.5.7 node_modules/css-tree/lib/syntax/node/Url.js
isomorfeus-preact-10.5.6 node_modules/css-tree/lib/syntax/node/Url.js
isomorfeus-preact-10.5.5 node_modules/css-tree/lib/syntax/node/Url.js
isomorfeus-preact-10.5.4 node_modules/css-tree/lib/syntax/node/Url.js
isomorfeus-preact-10.5.3 node_modules/css-tree/lib/syntax/node/Url.js
isomorfeus-preact-10.5.2 node_modules/css-tree/lib/syntax/node/Url.js
tang-0.2.1 spec/tang_app/node_modules/csso/node_modules/css-tree/lib/syntax/node/Url.js
tang-0.2.1 spec/tang_app/node_modules/css-tree/lib/syntax/node/Url.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/csso/node_modules/css-tree/lib/syntax/node/Url.js