Sha256: 407d51007d0e1ed28b5de959ed7549a8298dfdc66f36685cd62c87a3bc93634b

Contents?: true

Size: 1.71 KB

Versions: 19

Compression:

Stored size: 1.71 KB

Contents

var isNumber = require('../../tokenizer').isNumber;
var TYPE = require('../../tokenizer').TYPE;
var NUMBER = TYPE.Number;
var SOLIDUS = TYPE.Solidus;
var FULLSTOP = TYPE.FullStop;

// Terms of <ratio> should to be a positive number (not zero or negative)
// (see https://drafts.csswg.org/mediaqueries-3/#values)
// However, -o-min-device-pixel-ratio takes fractional values as a ratio's term
// and this is using by various sites. Therefore we relax checking on parse
// to test a term is unsigned number without exponent part.
// Additional checks may to be applied on lexer validation.
function consumeNumber(scanner) {
    var value = scanner.consumeNonWS(NUMBER);

    for (var i = 0; i < value.length; i++) {
        var code = value.charCodeAt(i);
        if (!isNumber(code) && code !== FULLSTOP) {
            scanner.error('Unsigned number is expected', scanner.tokenStart - value.length + i);
        }
    }

    if (Number(value) === 0) {
        scanner.error('Zero number is not allowed', scanner.tokenStart - value.length);
    }

    return value;
}

// <positive-integer> S* '/' S* <positive-integer>
module.exports = {
    name: 'Ratio',
    structure: {
        left: String,
        right: String
    },
    parse: function() {
        var start = this.scanner.tokenStart;
        var left = consumeNumber(this.scanner);
        var right;

        this.scanner.eatNonWS(SOLIDUS);
        right = consumeNumber(this.scanner);

        return {
            type: 'Ratio',
            loc: this.getLocation(start, this.scanner.tokenStart),
            left: left,
            right: right
        };
    },
    generate: function(node) {
        this.chunk(node.left);
        this.chunk('/');
        this.chunk(node.right);
    }
};

Version data entries

19 entries across 18 versions & 4 rubygems

Version Path
disco_app-0.18.0 test/dummy/node_modules/csso/node_modules/css-tree/lib/syntax/node/Ratio.js
disco_app-0.18.2 test/dummy/node_modules/csso/node_modules/css-tree/lib/syntax/node/Ratio.js
disco_app-0.16.1 test/dummy/node_modules/csso/node_modules/css-tree/lib/syntax/node/Ratio.js
disco_app-0.15.2 test/dummy/node_modules/csso/node_modules/css-tree/lib/syntax/node/Ratio.js
disco_app-0.18.4 test/dummy/node_modules/csso/node_modules/css-tree/lib/syntax/node/Ratio.js
disco_app-0.18.1 test/dummy/node_modules/csso/node_modules/css-tree/lib/syntax/node/Ratio.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/csso/node_modules/css-tree/lib/syntax/node/Ratio.js
disco_app-0.14.0 test/dummy/node_modules/csso/node_modules/css-tree/lib/syntax/node/Ratio.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/csso/node_modules/css-tree/lib/syntax/node/Ratio.js
jester-data-8.0.0 node_modules/csso/node_modules/css-tree/lib/syntax/node/Ratio.js
ezii-os-5.2.1 node_modules/csso/node_modules/css-tree/lib/syntax/node/Ratio.js
ezii-os-2.0.1 node_modules/csso/node_modules/css-tree/lib/syntax/node/Ratio.js
ezii-os-1.1.0 node_modules/csso/node_modules/css-tree/lib/syntax/node/Ratio.js
ezii-os-1.0.0 node_modules/csso/node_modules/css-tree/lib/syntax/node/Ratio.js
ezii-os-0.0.0.1.0 node_modules/csso/node_modules/css-tree/lib/syntax/node/Ratio.js
ezii-os-0.0.0.0.1 node_modules/csso/node_modules/css-tree/lib/syntax/node/Ratio.js
locomotivecms-4.0.0.alpha1 app/javascript/node_modules/css-tree/lib/syntax/node/Ratio.js
locomotivecms-4.0.0.alpha1 app/javascript/node_modules/csso/node_modules/css-tree/lib/syntax/node/Ratio.js
locomotivecms-3.4.0 app/javascript/node_modules/csso/node_modules/css-tree/lib/syntax/node/Ratio.js