source: imaps-frontend/node_modules/css-tree/lib/syntax/node/Ratio.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.9 KB
Line 
1var isDigit = require('../../tokenizer').isDigit;
2var TYPE = require('../../tokenizer').TYPE;
3
4var NUMBER = TYPE.Number;
5var DELIM = TYPE.Delim;
6var SOLIDUS = 0x002F; // U+002F SOLIDUS (/)
7var FULLSTOP = 0x002E; // U+002E FULL STOP (.)
8
9// Terms of <ratio> should be a positive numbers (not zero or negative)
10// (see https://drafts.csswg.org/mediaqueries-3/#values)
11// However, -o-min-device-pixel-ratio takes fractional values as a ratio's term
12// and this is using by various sites. Therefore we relax checking on parse
13// to test a term is unsigned number without an exponent part.
14// Additional checking may be applied on lexer validation.
15function consumeNumber() {
16 this.scanner.skipWS();
17
18 var value = this.consume(NUMBER);
19
20 for (var i = 0; i < value.length; i++) {
21 var code = value.charCodeAt(i);
22 if (!isDigit(code) && code !== FULLSTOP) {
23 this.error('Unsigned number is expected', this.scanner.tokenStart - value.length + i);
24 }
25 }
26
27 if (Number(value) === 0) {
28 this.error('Zero number is not allowed', this.scanner.tokenStart - value.length);
29 }
30
31 return value;
32}
33
34// <positive-integer> S* '/' S* <positive-integer>
35module.exports = {
36 name: 'Ratio',
37 structure: {
38 left: String,
39 right: String
40 },
41 parse: function() {
42 var start = this.scanner.tokenStart;
43 var left = consumeNumber.call(this);
44 var right;
45
46 this.scanner.skipWS();
47
48 if (!this.scanner.isDelim(SOLIDUS)) {
49 this.error('Solidus is expected');
50 }
51 this.eat(DELIM);
52 right = consumeNumber.call(this);
53
54 return {
55 type: 'Ratio',
56 loc: this.getLocation(start, this.scanner.tokenStart),
57 left: left,
58 right: right
59 };
60 },
61 generate: function(node) {
62 this.chunk(node.left);
63 this.chunk('/');
64 this.chunk(node.right);
65 }
66};
Note: See TracBrowser for help on using the repository browser.